Files
SIG/Scripts/AjaxControlToolkit/Release/HtmlEditor.ToolbarButtons.RemoveStyles.js
rrene 927295c7ba Revert "-- corr"
This reverts commit 5315c47fcd.
2024-11-05 10:55:34 -07:00

1 line
6.3 KiB
JavaScript

Type.registerNamespace("Sys.Extended.UI.HtmlEditor.ToolbarButtons");Sys.Extended.UI.HtmlEditor.ToolbarButtons.RemoveStyles=function(n){Sys.Extended.UI.HtmlEditor.ToolbarButtons.RemoveStyles.initializeBase(this,[n])};Sys.Extended.UI.HtmlEditor.ToolbarButtons.RemoveStyles.prototype={callMethod:function(){if(!Sys.Extended.UI.HtmlEditor.ToolbarButtons.RemoveStyles.callBaseMethod(this,"callMethod"))return!1;var n=this._designPanel;setTimeout(function(){var ct=Sys.Extended.UI.HtmlEditor.isIE?"":Sys.Extended.UI.HtmlEditor.Trim(n.getSelectedHTML()),h=n._getSelection(),s=n._createRange(h),i=null,ft=!1,e,f,ot,it,r,v,k,st,y,nt,d,o,l,u,c,a,p,tt,ut,t;if(!n.isControl()&&(Sys.Extended.UI.HtmlEditor.isIE&&s.text.length>0||!Sys.Extended.UI.HtmlEditor.isIE&&ct.length>0)?i=n._getTextNodeCollection():(i=n._tryExpand(),ft=!0),i!=null&&i.length>0){var et=!1,p=!0;for(n._saveContent(),e=n._doc.createElement("span"),e.id="_left_",f=n._doc.createElement("span"),f.id="_right_",ot=i[0].parentNode,it=i[i.length-1].parentNode,ot.insertBefore(e,i[0]),i[i.length-1].nextSibling?it.insertBefore(f,i[i.length-1].nextSibling):it.appendChild(f);p;)for(p=!1,o=0;o<i.length;o++)if(r=i[o].parentNode,r&&i[o].previousSibling==null&&i[o].nextSibling==null&&(v=r.tagName.toUpperCase(),Sys.Extended.UI.HtmlEditor.isStyleTag(v)&&v!="A"&&(r.className!=Sys.Extended.UI.HtmlEditor.smartClassName||v.substr(0,1)=="H")))if(k=Sys.Extended.UI.HtmlEditor.differAttr(r,["class","color","face","size"]),et=!0,k.length==0){var y=r.parentNode,l=r.firstChild?r.firstChild:null,g=null;if(v.toUpperCase().substr(0,1)=="H"&&Sys.Extended.UI.HtmlEditor.isIE)for(g=n._doc.createElement("p"),g.className=Sys.Extended.UI.HtmlEditor.smartClassName,y.insertBefore(g,r);r.firstChild;)g.appendChild(r.firstChild);else{while(r.firstChild)y.insertBefore(r.firstChild,r);v.toUpperCase().substr(0,1)=="H"&&(st=n._doc.createElement("br"),y.insertBefore(st,r))}y.removeChild(r);p=!0}else{for(y=r.parentNode,nt=n._doc.createElement(v),d=0;d<k.length;d++)nt.setAttribute(k[d][0],k[d][1]);for(y.insertBefore(nt,r);r.firstChild;)nt.appendChild(r.firstChild);y.removeChild(r)}for(o=0;o<i.length;o++)if(l=i[o],u=i[o].parentNode!=null&&typeof i[o].parentNode!="undefined"?i[o].parentNode:null,u){for(c=null;u&&u.tagName&&u.tagName.toUpperCase()!="BODY"&&Sys.Extended.UI.HtmlEditor.isStyleTag(u.tagName)&&u.tagName.toUpperCase()!="A"&&Sys.Extended.UI.HtmlEditor.differAttr(u,["class","color","face","size"]).length==0;)c=u,u=u.parentNode;if(c){et=!0;function rt(n,t,i,r){var u=i.cloneNode(!1),e,l,s,o,h,f;if(n)if(n.push&&typeof n.push=="function")for(e=0;e<n.length;e++)u.appendChild(n[e]);else u.appendChild(n);while(t)l=r?t.previousSibling:t.nextSibling,(t.nodeType==1||t.nodeType==3&&Sys.Extended.UI.HtmlEditor.Trim(""+t.data+"").length>0)&&(t.nodeType==1&&(Sys.Extended.UI.HtmlEditor.isStyleTag(t.tagName)&&t.tagName.toUpperCase()!="A"&&(!t.id||t.id!="_left_"&&t.id!="_right_")&&Sys.Extended.UI.HtmlEditor.spanJoiner(t),Sys.Extended.UI.HtmlEditor.isStyleTag(t.tagName)&&t.childNodes.length==0&&(!t.id||t.id!="_left_"&&t.id!="_right_")&&(t=null)),t&&(u.childNodes.length!=0&&r?u.insertBefore(t,u.firstChild):u.appendChild(t))),t=l;if(u.childNodes.length==0)delete u,u=null;else if(u.childNodes.length==1&&u.firstChild.nodeType==3&&(""+u.firstChild.data+"").length==0)delete u,u=null;else if(Sys.Extended.UI.HtmlEditor.isStyleTag(u.tagName)){for(s=u.childNodes.length,o=0;o<u.childNodes.length;o++)f=u.childNodes.item(o),f.nodeType!=1||Sys.Extended.UI.HtmlEditor.isStyleTag(f.tagName)||s--;if(s==0){for(h=[];u.firstChild;)f=u.removeChild(u.firstChild),h.push(f);u=h}}return i==c?u:rt(u,r?i.previousSibling:i.nextSibling,i.parentNode,r)}u=l.parentNode;l.previousSibling==null&&l.nextSibling==null&&u&&u.tagName&&u.tagName.toUpperCase()!="BODY"&&Sys.Extended.UI.HtmlEditor.isStyleTag(u.tagName)&&Sys.Extended.UI.HtmlEditor.differAttr(u,["class","color","face","size"]).length>0&&(l=u);var w=rt(null,l.previousSibling,l.parentNode,!0),b=rt(null,l.nextSibling,l.parentNode,!1),r=c.parentNode;if(w){if(w.push&&typeof w.push=="function")for(a=0;a<w.length;a++)r.insertBefore(w[a],c);else r.insertBefore(w,c);Sys.Extended.UI.HtmlEditor.isIE&&(e=n._doc.getElementById("_left_"),f=n._doc.getElementById("_right_"))}if(r.insertBefore(l,c),b){if(b.push&&typeof b.push=="function")for(a=0;a<b.length;a++)r.insertBefore(b[a],c);else r.insertBefore(b,c);Sys.Extended.UI.HtmlEditor.isIE&&(e=n._doc.getElementById("_left_"),f=n._doc.getElementById("_right_"))}r.removeChild(c)}}if(ft)if(Sys.Extended.UI.HtmlEditor.isIE&&n.__saveBM__!=null){try{for(t=e.parentNode,t.removeChild(e);t&&t.childNodes.length==0;)t.parentNode.removeChild(t),t=t.parentNode;for(t=f.parentNode,t.removeChild(f);t&&t.childNodes.length==0;)t.parentNode.removeChild(t),t=t.parentNode;e=null;f=null}catch(lt){}h=n._getSelection();s=n._createRange(h);s.moveToBookmark(n.__saveBM__);s.select();n.__saveBM__=null}else n.__saveBM__!=null&&(n.__saveBM__[0].nodeType==3?(h=n._getSelection(),s=n._doc.createRange(),s.setStart(n.__saveBM__[0],n.__saveBM__[1]),s.setEnd(n.__saveBM__[0],n.__saveBM__[1]),n._removeAllRanges(h),n._selectRange(h,s)):(n._trySelect(n.__saveBM__[0],n.__saveBM__[0]),n.__saveBM__[0].parentNode.removeChild(n.__saveBM__[0])),n.__saveBM__=null);else if(Sys.Extended.UI.HtmlEditor.isIE)try{h=n._getSelection();tt=n._createRange(h);ut=n._createRange(h);tt.moveToElementText(e);ut.moveToElementText(f);tt.setEndPoint("EndToEnd",ut);tt.select()}catch(lt){}else{i=[];p=!1;function ht(n,t){while(n){if(n==f){p=!0;return}if(n.nodeType==3){while(n.nextSibling&&n.nextSibling.nodeType==3)n.data=""+n.data+""+n.nextSibling.data+"",n.parentNode.removeChild(n.nextSibling);Sys.Extended.UI.HtmlEditor.Trim(""+n.data+"").length>0&&i.push(n)}else ht(n.firstChild,!1);if(p)return;var r=n.parentNode;if(t)while(n&&n.nextSibling==null)n=n.parentNode;n=n.nextSibling}}ht(e,!0);s=n._doc.createRange();s.setStart(i[0],0);s.setEnd(i[i.length-1],(""+i[i.length-1].data+"").length);n._removeAllRanges(h);n._selectRange(h,s)}try{if(e!=null)for(t=e.parentNode,t.removeChild(e);t&&t.childNodes.length==0;)t.parentNode.removeChild(t),t=t.parentNode;if(f!=null)for(t=f.parentNode,t.removeChild(f);t&&t.childNodes.length==0;)t.parentNode.removeChild(t),t=t.parentNode}catch(lt){}n.onContentChanged();n._editPanel.updateToolbar()}},0)}};Sys.Extended.UI.HtmlEditor.ToolbarButtons.RemoveStyles.registerClass("Sys.Extended.UI.HtmlEditor.ToolbarButtons.RemoveStyles",Sys.Extended.UI.HtmlEditor.ToolbarButtons.MethodButton);