-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
diff_switch.min.js
1 lines (1 loc) · 1.78 KB
/
diff_switch.min.js
1
var enableDiffSwitch=function(a){var b,c=document.getElementById("diff"),d=document.createElement("a");d.className="diff-switch",d.text=a.i18n.diffSideBySide,d.href="#",d.addEventListener("click",function(e){if(e.preventDefault(),document.getElementById("diff-table"))b.style.length?(c.style="display: none",b.style="",d.text=a.i18n.diffList,d.className="diff-switch diff-switch-list"):(c.style="",b.style="display: none",d.text=a.i18n.diffSideBySide,d.className="diff-switch");else{b=document.createElement("table"),b.id="diff-table";var f,g;Array.prototype.forEach.call(c.children[0].children,function(a,c){if(g&&2!=g.children.length&&"SPAN"!=a.children[0].tagName||(g&&1==g.children.length&&("INS"==f?g.insertBefore(document.createElement("td"),g.children[0]):g.appendChild(document.createElement("td"))),g=document.createElement("tr"),b.appendChild(g),f=""),!f||"SPAN"==a.children[0].tagName||"DEL"==a.children[0].tagName&&"INS"==f||"INS"==a.children[0].tagName&&"DEL"==f){var d=document.createElement("td");d.innerHTML=a.innerHTML,d.className="diff-col-"+a.children[0].tagName.toLowerCase(),g.appendChild(d),"SPAN"==a.children[0].tagName&&g.appendChild(d.cloneNode(!0))}else if(f==a.children[0].tagName){"INS"==f?g.insertBefore(document.createElement("td"),g.children[0]):g.appendChild(document.createElement("td"));var d=document.createElement("td");d.innerHTML=a.innerHTML,d.className="diff-col-"+a.children[0].tagName.toLowerCase(),g=document.createElement("tr"),g.appendChild(d),b.appendChild(g)}f=a.children[0].tagName}),g&&1==g.children.length&&("INS"==f?g.insertBefore(document.createElement("td"),g.children[0]):g.appendChild(document.createElement("td"))),c.parentNode.appendChild(b),c.style="display: none",d.text=a.i18n.diffList,d.className="diff-switch diff-switch-list"}}),c.parentNode.insertBefore(d,c)};