BVB Source Codes

Pcook CMS bubble guest v3.0 SDCMS version Show xhtmleditor.js Source code

Return Download Pcook CMS bubble guest v3.0 SDCMS version: download xhtmleditor.js Source code - Download Pcook CMS bubble guest v3.0 SDCMS version Source code - Type:.js
  1. var oUtil = new EditorUtil();
  2.  
  3. var onloadOverrided = false;
  4.  
  5. function onload_new()
  6.   {
  7.   onload_original();  
  8.   setMozEdit();
  9.   }
  10.  
  11. function onload_original()
  12.   {
  13.   }  
  14.  
  15. function setMozEdit(oName)
  16.   {
  17.     if ((oName != null) && (oName!="")) {
  18.         try {document.getElementById("idContent" + oName).contentDocument.designMode="on";} catch(e) {}
  19.     } else {
  20.         for (var i=0; i<oUtil.arrEditor.length; i++)
  21.         {
  22.         try {document.getElementById("idContent" + oUtil.arrEditor[i]).contentDocument.designMode="on";} catch(e) {alert(e)}
  23.         }
  24.     }
  25.   }
  26.  
  27. function EditorUtil() {
  28.     this.obj = null;
  29.     this.oEditor = null;
  30.     this.arrEditor = [];
  31. }
  32.  
  33. function InnovaEditor(oName) {
  34.     this.oName = oName;
  35.     this.height = "400px";
  36.     this.width = "100%";
  37.    
  38.     this.RENDER = RENDER;
  39.     this.doCmd = edt_doCmd;
  40.     this.getHTMLBody = edt_getHTMLBody;
  41.     this.getXHTMLBody = edt_getXHTMLBody;
  42.     this.insertHTML = edt_insertHTML;
  43.     this.cleanDeprecated = edt_cleanDeprecated;
  44.     this.cleanEmptySpan =  edt_cleanEmptySpan;
  45.     this.cleanFonts = edt_cleanFonts;
  46.     this.cleanTags = edt_cleanTags;
  47.     this.replaceTags = edt_replaceTags;
  48.     this.toggleViewSource = edt_toggleViewSource;
  49.     this.viewSource = edt_viewSource;
  50.     this.applySource = edt_applySource;
  51. }
  52.  
  53. function RENDER() {
  54. }
  55.  
  56. function edt_doCmd(sCmd,sOption)
  57.         {
  58.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  59.     oEditor.document.execCommand(sCmd,false,sOption);
  60.     }
  61.  
  62. function edt_getHTMLBody()
  63.         {
  64.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  65.     sHTML=oEditor.document.body.innerHTML;
  66.     sHTML=String(sHTML).replace(/ contentEditable=true/g,"");
  67.     sHTML = String(sHTML).replace(/\<PARAM NAME=\"Play\" VALUE=\"0\">/ig,"<PARAM NAME=\"Play\" VALUE=\"-1\">");
  68.     return sHTML;
  69.         }
  70.  
  71. function edt_getXHTMLBody()
  72.   {
  73.         if (document.getElementById("chkViewSource"+this.oName).checked)
  74.             {
  75.             var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  76.                 return oEditor.document.body.textContent;
  77.         } else {
  78.             var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  79.             this.cleanDeprecated();
  80.  
  81.             return recur(oEditor.document.body,"");
  82.         }    
  83.   }
  84.  
  85. /*Insert custon HTML function*/
  86. function edt_insertHTML(sHTML)
  87.   {
  88.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  89.   var oSel=oEditor.getSelection();
  90.   var range = oSel.getRangeAt(0);
  91.    
  92.   var docFrag = range.createContextualFragment(sHTML);
  93.   range.collapse(true);
  94.   var lastNode = docFrag.childNodes[docFrag.childNodes.length-1];
  95.   range.insertNode(docFrag);
  96.   try { oEditor.document.designMode="on"; } catch (e) {}
  97.   if (lastNode.nodeType==Node.TEXT_NODE)
  98.     {
  99.     range = oEditor.document.createRange();
  100.     range.setStart(lastNode, lastNode.nodeValue.length);
  101.     range.setEnd(lastNode, lastNode.nodeValue.length);
  102.     oSel = oEditor.getSelection();
  103.     oSel.removeAllRanges();
  104.     oSel.addRange(range);
  105.     }
  106.   }
  107.  
  108. /************************************
  109.         CLEAN DEPRECATED TAGS; Used in loadHTML, getHTMLBody, getXHTMLBody
  110. *************************************/
  111. function edt_cleanDeprecated()
  112.   {
  113.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  114.  
  115.   var elements;
  116.  
  117.   elements=oEditor.document.body.getElementsByTagName("STRIKE");
  118.   this.cleanTags(elements,"line-through");
  119.   elements=oEditor.document.body.getElementsByTagName("S");
  120.   this.cleanTags(elements,"line-through");
  121.  
  122.   elements=oEditor.document.body.getElementsByTagName("U");
  123.   this.cleanTags(elements,"underline");
  124.  
  125.   this.replaceTags("DIR","DIV");
  126.   this.replaceTags("MENU","DIV");
  127.   this.replaceTags("CENTER","DIV");
  128.   this.replaceTags("XMP","PRE");
  129.   this.replaceTags("BASEFONT","SPAN");//will be removed by cleanEmptySpan()
  130.  
  131.   elements=oEditor.document.body.getElementsByTagName("APPLET");
  132.   while(elements.length>0)
  133.     {
  134.     var f = elements[0];
  135.     theParent = f.parentNode;
  136.     theParent.removeChild(f);
  137.     }
  138.  
  139.   this.cleanFonts();
  140.   this.cleanEmptySpan();
  141.  
  142.   return true;
  143.   }
  144.  
  145. function edt_cleanEmptySpan()
  146.   {
  147.   var bReturn=false;
  148.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  149.   var reg = /<\s*SPAN\s*>/gi;
  150.  
  151.   while (true)
  152.     {
  153.     var allSpans = oEditor.document.getElementsByTagName("SPAN");
  154.     if(allSpans.length==0) break;
  155.  
  156.     var emptySpans = [];
  157.     for (var i=0; i<allSpans.length; i++)
  158.       {
  159.       if (getOuterHTML(allSpans[i]).search(reg) == 0)
  160.         emptySpans[emptySpans.length]=allSpans[i];
  161.       }
  162.     if (emptySpans.length == 0) break;
  163.     var theSpan, theParent;
  164.     for (var i=0; i<emptySpans.length; i++)
  165.       {
  166.       theSpan = emptySpans[i];
  167.       theParent = theSpan.parentNode;
  168.       if (!theParent) continue;
  169.       if (theSpan.hasChildNodes())
  170.         {
  171.         var range = oEditor.document.createRange();
  172.         range.selectNodeContents(theSpan);
  173.         var docFrag = range.extractContents();
  174.         theParent.replaceChild(docFrag, theSpan);
  175.         }
  176.       else
  177.         {
  178.         theParent.removeChild(theSpan);
  179.         }
  180.       bReturn=true;
  181.       }
  182.     }
  183.   return bReturn;
  184.   }
  185.        
  186. function edt_cleanFonts()
  187.   {
  188.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  189.   var allFonts = oEditor.document.body.getElementsByTagName("FONT");
  190.   if(allFonts.length==0)return false;
  191.  
  192.   var f; var range;
  193.   while (allFonts.length>0)
  194.     {
  195.     f = allFonts[0];
  196.     if (f.hasChildNodes && f.childNodes.length==1 && f.childNodes[0].nodeType==1 && f.childNodes[0].nodeName=="SPAN")
  197.       {
  198.       //if font containts only span child node
  199.      
  200.       var theSpan = f.childNodes[0];
  201.       copyAttribute(theSpan, f);
  202.      
  203.       range = oEditor.document.createRange();
  204.       range.selectNode(f);
  205.       range.insertNode(theSpan);
  206.       range.selectNode(f);
  207.       range.deleteContents();
  208.       }
  209.     else
  210.       if (f.parentNode.nodeName=="SPAN" && f.parentNode.childNodes.length==1)
  211.         {
  212.         //font is the only child node of span.
  213.         var theSpan = f.parentNode;
  214.         copyAttribute(theSpan, f);
  215.         theSpan.innerHTML = f.innerHTML;
  216.         }
  217.       else
  218.         {
  219.         var newSpan = oEditor.document.createElement("SPAN");
  220.         copyAttribute(newSpan, f);
  221.         newSpan.innerHTML = f.innerHTML;
  222.         f.parentNode.replaceChild(newSpan, f);
  223.         }
  224.     }
  225.   return true;
  226.   }
  227. function edt_cleanTags(elements,sVal)
  228.   {
  229.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  230.   if(elements.length==0)return false;
  231.  
  232.   var f;var range;
  233.   while(elements.length>0)
  234.     {
  235.     f = elements[0];
  236.     if(f.hasChildNodes && f.childNodes.length==1 && f.childNodes[0].nodeType==1 && f.childNodes[0].nodeName=="SPAN")
  237.       {//if font containts only span child node      
  238.       var theSpan=f.childNodes[0];
  239.       if(sVal=="bold")theSpan.style.fontWeight="bold";
  240.       if(sVal=="italic")theSpan.style.fontStyle="italic";
  241.       if(sVal=="line-through")theSpan.style.textDecoration="line-through";
  242.       if(sVal=="underline")theSpan.style.textDecoration="underline";
  243.  
  244.       range=oEditor.document.createRange();
  245.       range.selectNode(f);
  246.       range.insertNode(theSpan);
  247.       range.selectNode(f);
  248.       range.deleteContents();
  249.       }
  250.     else
  251.       if (f.parentNode.nodeName=="SPAN" && f.parentNode.childNodes.length==1)
  252.         {
  253.         //font is the only child node of span.
  254.         var theSpan=f.parentNode;
  255.         if(sVal=="bold")theSpan.style.fontWeight="bold";
  256.         if(sVal=="italic")theSpan.style.fontStyle="italic";
  257.         if(sVal=="line-through")theSpan.style.textDecoration="line-through";
  258.         if(sVal=="underline")theSpan.style.textDecoration="underline";
  259.        
  260.         theSpan.innerHTML=f.innerHTML;
  261.         }
  262.       else
  263.         {
  264.         var newSpan = oEditor.document.createElement("SPAN");
  265.         if(sVal=="bold")newSpan.style.fontWeight="bold";
  266.         if(sVal=="italic")newSpan.style.fontStyle="italic";
  267.         if(sVal=="line-through")newSpan.style.textDecoration="line-through";
  268.         if(sVal=="underline")newSpan.style.textDecoration="underline";
  269.  
  270.         newSpan.innerHTML=f.innerHTML;
  271.         f.parentNode.replaceChild(newSpan,f);
  272.         }
  273.     }
  274.   return true;
  275.   }
  276.  
  277. function edt_replaceTags(sFrom,sTo)
  278.   {
  279.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  280.  
  281.   var elements=oEditor.document.body.getElementsByTagName(sFrom);
  282.  
  283.   while(elements.length>0)
  284.     {
  285.     f = elements[0];
  286.    
  287.     var newSpan = oEditor.document.createElement(sTo);
  288.     newSpan.innerHTML=f.innerHTML;
  289.     f.parentNode.replaceChild(newSpan,f);
  290.     }
  291.   }
  292. function copyAttribute(newSpan,f)
  293.     {
  294.     if ((f.face != null) && (f.face != ""))newSpan.style.fontFamily=f.face;
  295.     if ((f.size != null) && (f.size != ""))
  296.         {
  297.         var nSize="";
  298.         if(f.size==1)nSize="8pt";
  299.         else if(f.size==2)nSize="10pt";
  300.         else if(f.size==3)nSize="12pt";
  301.         else if(f.size==4)nSize="14pt";
  302.         else if(f.size==5)nSize="18pt";
  303.         else if(f.size==6)nSize="24pt";
  304.         else if(f.size>=7)nSize="36pt";
  305.         else if(f.size<=-2||f.size=="0")nSize="8pt";
  306.         else if(f.size=="-1")nSize="10pt";
  307.         else if(f.size==0)nSize="12pt";
  308.         else if(f.size=="+1")nSize="14pt";
  309.         else if(f.size=="+2")nSize="18pt";
  310.         else if(f.size=="+3")nSize="24pt";
  311.         else if(f.size=="+4"||f.size=="+5"||f.size=="+6")nSize="36pt";
  312.         else nSize="";
  313.         if(nSize!="")newSpan.style.fontSize=nSize;
  314.         }
  315.     if ((f.style.backgroundColor != null)&&(f.style.backgroundColor != ""))newSpan.style.backgroundColor=f.style.backgroundColor;
  316.     if ((f.color != null)&&(f.color != ""))newSpan.style.color=f.color;
  317.     }
  318. function GetElement(oElement,sMatchTag)//Used in realTime() only.
  319.     {
  320.     while (oElement!=null&&oElement.tagName!=sMatchTag)
  321.         {
  322.         if(oElement.tagName=="BODY")return null;
  323.         oElement=oElement.parentNode;
  324.         }
  325.     return oElement;
  326.     }
  327.  
  328. /************************************
  329.         HTML to XHTML
  330. *************************************/
  331. function lineBreak1(tag) //[0]<TAG>[1]text[2]</TAG>
  332.   {
  333.   arrReturn = ["\n","",""];
  334.   if( tag=="A"||tag=="B"||tag=="CITE"||tag=="CODE"||tag=="EM"||
  335.     tag=="FONT"||tag=="I"||tag=="SMALL"||tag=="STRIKE"||tag=="BIG"||
  336.     tag=="STRONG"||tag=="SUB"||tag=="SUP"||tag=="U"||tag=="SAMP"||
  337.     tag=="S"||tag=="VAR"||tag=="BASEFONT"||tag=="KBD"||tag=="TT")
  338.     arrReturn=["","",""];
  339.  
  340.   if( tag=="TEXTAREA"||tag=="TABLE"||tag=="THEAD"||tag=="TBODY"||
  341.     tag=="TR"||tag=="OL"||tag=="UL"||tag=="DIR"||tag=="MENU"||
  342.     tag=="FORM"||tag=="SELECT"||tag=="MAP"||tag=="DL"||tag=="HEAD"||
  343.     tag=="BODY"||tag=="HTML")
  344.     arrReturn=["\n","","\n"];
  345.  
  346.   if( tag=="STYLE"||tag=="SCRIPT")
  347.     arrReturn=["\n","",""];
  348.  
  349.   if(tag=="BR"||tag=="HR")
  350.     arrReturn=["","\n",""];
  351.  
  352.   return arrReturn;
  353.   }  
  354. function fixAttr(s)
  355.   {
  356.   s = String(s).replace(/&/g, "&amp;");
  357.   s = String(s).replace(/</g, "&lt;");
  358.   s = String(s).replace(/"/g, "&quot;");
  359.   return s;
  360.   }  
  361. function fixVal(s)
  362.   {
  363.   s = String(s).replace(/&/g, "&amp;");
  364.   s = String(s).replace(/</g, "&lt;");
  365.   var x = escape(s);
  366.   x = unescape(x.replace(/\%A0/gi, "-*REPL*-"));
  367.   s = x.replace(/-\*REPL\*-/gi, "&nbsp;");
  368.   return s;
  369.   }  
  370. function recur(oEl,sTab)
  371.   {
  372.   var sHTML="";
  373.   for(var i=0;i<oEl.childNodes.length;i++)
  374.     {
  375.     var oNode=oEl.childNodes[i];
  376.     if(oNode.nodeType==1)//tag
  377.       {
  378.       var sTagName = oNode.nodeName;
  379.  
  380.       var bDoNotProcess=false;
  381.       if(sTagName.substring(0,1)=="/")
  382.         {
  383.         bDoNotProcess=true;//do not process
  384.         }
  385.       else
  386.         {
  387.         /*** tabs ***/
  388.         var sT= sTab;
  389.         sHTML+= lineBreak1(sTagName)[0];  
  390.         if(lineBreak1(sTagName)[0] !="") sHTML+= sT;//If new line, use base Tabs
  391.         /************/
  392.         }
  393.  
  394.       if(bDoNotProcess)
  395.         {
  396.         ;//do not process
  397.         }
  398.       else if(sTagName=="OBJECT" || sTagName=="EMBED")
  399.         {  
  400.         s=getOuterHTML(oNode);
  401.  
  402.         s=s.replace(/\"[^\"]*\"/ig,function(x){          
  403.             x=x.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/\s+/ig,"#_#");
  404.             return x});
  405.         s=s.replace(/<([^ >]*)/ig,function(x){return x.toLowerCase()})            
  406.         s=s.replace(/ ([^=]+)=([^"' >]+)/ig," $1=\"$2\"");//new
  407.        
  408.         s=s.replace(/ ([^=]+)=/ig,function(x){return x.toLowerCase()});
  409.         s=s.replace(/#_#/ig," ");
  410.        
  411.         s=s.replace(/<param([^>]*)>/ig,"\n<param$1 />").replace(/\/ \/>$/ig," \/>");//no closing tag
  412.  
  413.         if(sTagName=="EMBED")
  414.           if(oNode.innerHTML=="")
  415.             s=s.replace(/>$/ig," \/>").replace(/\/ \/>$/ig,"\/>");//no closing tag
  416.        
  417.         s=s.replace(/<param name=\"Play\" value=\"0\" \/>/,"<param name=\"Play\" value=\"-1\" \/>")
  418.        
  419.         sHTML+=s;
  420.         }
  421.       else if(sTagName=="TITLE")
  422.         {
  423.         sHTML+="<title>"+oNode.innerHTML+"</title>";
  424.         }
  425.       else
  426.         {
  427.         if(sTagName=="AREA")
  428.           {
  429.           var sCoords=oNode.coords;
  430.           var sShape=oNode.shape;
  431.           }
  432.          
  433.         var oNode2=oNode.cloneNode(false);      
  434.         s=getOuterHTML(oNode2).replace(/<\/[^>]*>/,"");
  435.        
  436.         if(sTagName=="STYLE")
  437.           {
  438.           var arrTmp=s.match(/<[^>]*>/ig);
  439.           s=arrTmp[0];
  440.           }      
  441.  
  442.         s=s.replace(/\"[^\"]*\"/ig,function(x){
  443.             //x=x.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/\s+/ig,"#_#");
  444.             //x=x.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\s+/ig,"#_#");
  445.             x=x.replace(/&/g, "&amp;").replace(/&amp;amp;/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\s+/ig,"#_#");
  446.             return x});
  447.             //info ttg: .replace(/&amp;amp;/g, "&amp;")
  448.             //ini karena '&' di (hanya) '&amp;' selalu di-replace lagi dgn &amp;.
  449.             //tapi kalau &lt; , &gt; tdk (no problem) => default behaviour
  450.    
  451.         s=s.replace(/<([^ >]*)/ig,function(x){return x.toLowerCase()})            
  452.         s=s.replace(/ ([^=]+)=([^" >]+)/ig," $1=\"$2\"");
  453.         s=s.replace(/ ([^=]+)=/ig,function(x){return x.toLowerCase()});
  454.         s=s.replace(/#_#/ig," ");
  455.        
  456.         //single attribute
  457.         s=s.replace(/[<hr]?(noshade="")/ig,"noshade=\"noshade\"");
  458.         s=s.replace(/[<input]?(checked="")/ig,"checked=\"checked\"");
  459.         s=s.replace(/[<select]?(multiple="")/ig,"multiple=\"multiple\"");
  460.         s=s.replace(/[<option]?(selected="")/ig,"selected=\"true\"");
  461.         s=s.replace(/[<input]?(readonly="")/ig,"readonly=\"readonly\"");
  462.         s=s.replace(/[<input]?(disabled="")/ig,"disabled=\"disabled\"");
  463.         s=s.replace(/[<td]?(nowrap="" )/ig,"nowrap=\"nowrap\" ");
  464.         s=s.replace(/[<td]?(nowrap=""\>)/ig,"nowrap=\"nowrap\"\>");
  465.        
  466.         s=s.replace(/ contenteditable=\"true\"/ig,"");
  467.        
  468.        if(sTagName=="AREA")
  469.          {
  470.          s=s.replace(/ coords=\"0,0,0,0\"/ig," coords=\""+sCoords+"\"");
  471.           s=s.replace(/ shape=\"RECT\"/ig," shape=\""+sShape+"\"");
  472.           }
  473.          
  474.         var bClosingTag=true;
  475.         if(sTagName=="IMG"||sTagName=="BR"||
  476.           sTagName=="AREA"||sTagName=="HR"||
  477.           sTagName=="INPUT"||sTagName=="BASE"||
  478.           sTagName=="LINK")//no closing tag
  479.           {
  480.           s=s.replace(/>$/ig," \/>").replace(/\/ \/>$/ig,"\/>");//no closing tag
  481.           bClosingTag=false;      
  482.           }        
  483.        
  484.         sHTML+=s;      
  485.          
  486.         /*** tabs ***/
  487.         if(sTagName!="TEXTAREA")sHTML+= lineBreak1(sTagName)[1];
  488.         if(sTagName!="TEXTAREA")if(lineBreak1(sTagName)[1] !="") sHTML+= sT;//If new line, use base Tabs
  489.         /************/  
  490.        
  491.         if(bClosingTag)
  492.           {
  493.           /*** CONTENT ***/
  494.           s=getOuterHTML(oNode);
  495.           if(sTagName=="SCRIPT")
  496.             {
  497.             s = s.replace(/<script([^>]*)>[\n+\s+\t+]*/ig,"<script$1>");//clean spaces
  498.             s = s.replace(/[\n+\s+\t+]*<\/script>/ig,"<\/script>");//clean spaces
  499.             s = s.replace(/<script([^>]*)>\/\/<!\[CDATA\[/ig,"");
  500.             s = s.replace(/\/\/\]\]><\/script>/ig,"");
  501.             s = s.replace(/<script([^>]*)>/ig,"");
  502.             s = s.replace(/<\/script>/ig,"");        
  503.             s = s.replace(/^\s+/,'').replace(/\s+$/,'');            
  504.  
  505.             sHTML+="\n"+
  506.               sT + "//<![CDATA[\n"+
  507.               sT + s + "\n" +
  508.               sT + "//]]>\n"+sT;
  509.  
  510.             }
  511.           if(sTagName=="STYLE")
  512.             {      
  513.             s = s.replace(/<style([^>]*)>[\n+\s+\t+]*/ig,"<style$1>");//clean spaces
  514.             s = s.replace(/[\n+\s+\t+]*<\/style>/ig,"<\/style>");//clean spaces        
  515.             s = s.replace(/<style([^>]*)><!--/ig,"");
  516.             s = s.replace(/--><\/style>/ig,"");
  517.             s = s.replace(/<style([^>]*)>/ig,"");
  518.             s = s.replace(/<\/style>/ig,"");          
  519.             s = s.replace(/^\s+/,"").replace(/\s+$/,"");            
  520.            
  521.             sHTML+="\n"+
  522.               sT + "<!--\n"+
  523.               sT + s + "\n" +
  524.               sT + "-->\n"+sT;
  525.             }
  526.           if(sTagName=="DIV"||sTagName=="P")
  527.             {
  528.             if(oNode.innerHTML==""||oNode.innerHTML=="&nbsp;")
  529.               {
  530.               sHTML+="&nbsp;";
  531.               }
  532.             else sHTML+=recur(oNode,sT+"\t");
  533.             }
  534.           else
  535.           if (sTagName == "STYLE" || sTagName=="SCRIPT")
  536.             {
  537.             //do nothing
  538.             }
  539.           else
  540.             {
  541.             sHTML+=recur(oNode,sT+"\t");  
  542.             }        
  543.            
  544.           /*** tabs ***/
  545.           if(sTagName!="TEXTAREA")sHTML+=lineBreak1(sTagName)[2];
  546.           if(sTagName!="TEXTAREA")if(lineBreak1(sTagName)[2] !="")sHTML+=sT;//If new line, use base Tabs
  547.           /************/
  548.            
  549.           sHTML+="</" + sTagName.toLowerCase() + ">";
  550.           }    
  551.         }    
  552.       }
  553.     else if(oNode.nodeType==3)//text
  554.       {
  555.       sHTML+= fixVal(oNode.nodeValue);
  556.       }
  557.     else if(oNode.nodeType==8)
  558.       {
  559.       if(getOuterHTML(oNode).substring(0,2)=="<"+"%")
  560.         {//server side script
  561.         sTmp=(getOuterHTML(oNode).substring(2))
  562.         sTmp=sTmp.substring(0,sTmp.length-2)
  563.         sTmp = sTmp.replace(/^\s+/,"").replace(/\s+$/,"");
  564.        
  565.         /*** tabs ***/
  566.         var sT= sTab;
  567.         /************/
  568.        
  569.         sHTML+="\n" +
  570.           sT + "<%\n"+
  571.           sT + sTmp + "\n" +
  572.           sT + "%>\n"+sT;
  573.         }
  574.       else
  575.         {//comments
  576.  
  577.         /*** tabs ***/
  578.         var sT= sTab;
  579.         /************/
  580.        
  581.         sTmp=oNode.nodeValue;
  582.         sTmp = sTmp.replace(/^\s+/,"").replace(/\s+$/,"");
  583.        
  584.         sHTML+="\n" +
  585.           sT + "<!--\n"+
  586.           sT + sTmp + "\n" +
  587.           sT + "-->\n"+sT;
  588.         }
  589.       }
  590.     else
  591.       {
  592.       ;//Not Processed
  593.       }
  594.     }
  595.   return sHTML;
  596.   }
  597.  
  598. function getOuterHTML(node)
  599.   {
  600.     var sHTML = "";
  601.     switch (node.nodeType)
  602.     {
  603.         case Node.ELEMENT_NODE:
  604.             sHTML = "<" + node.nodeName;
  605.            
  606.             var tagVal ="";
  607.             for (var atr=0; atr < node.attributes.length; atr++)
  608.         {      
  609.                 if (node.attributes[atr].nodeName.substr(0,4) == "_moz" ) continue;
  610.                 if (node.attributes[atr].nodeValue.substr(0,4) == "_moz" ) continue;//yus                
  611.                 if (node.nodeName=='TEXTAREA' && node.attributes[atr].nodeName.toLowerCase()=='value')
  612.           {
  613.                     tagVal = node.attributes[atr].nodeValue;
  614.           }
  615.         else
  616.           {
  617.                     sHTML += ' ' + node.attributes[atr].nodeName + '="' + node.attributes[atr].nodeValue + '"';
  618.           }
  619.         }
  620.             sHTML += '>';
  621.             sHTML += (node.nodeName!='TEXTAREA' ? node.innerHTML : tagVal);
  622.             sHTML += "</"+node.nodeName+">";
  623.             break;
  624.         case Node.COMMENT_NODE:
  625.             sHTML = "<!"+"--"+node.nodeValue+ "--"+">"; break;
  626.         case Node.TEXT_NODE:
  627.             sHTML = node.nodeValue; break;
  628.     }
  629.     return sHTML
  630.   }
  631.  
  632. function edt_toggleViewSource(chk) {
  633.     if (chk.checked) {
  634.         //view souce
  635.         this.viewSource();
  636.     } else {
  637.         //wysiwyg mode
  638.         this.applySource();
  639.     }
  640. }
  641.  
  642. function edt_viewSource() {
  643.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  644.    
  645.     this.cleanDeprecated();
  646.     var sHTML=recur(oEditor.document.body,"");
  647.  
  648.     var docBody = oEditor.document.body;
  649.     docBody.innerHTML = "";
  650.     docBody.appendChild(oEditor.document.createTextNode(sHTML));
  651. }
  652.  
  653. function edt_applySource() {
  654.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  655.    
  656.     var range = oEditor.document.body.ownerDocument.createRange();
  657.     range.selectNodeContents(oEditor.document.body);
  658.     var sHTML = range.toString();
  659.     sHTML = sHTML.replace(/>\s+</gi, "><"); //replace space between tag
  660.     sHTML = sHTML.replace(/\r/gi, ""); //replace space between tag
  661.     sHTML = sHTML.replace(/(<br>)\s+/gi, "$1"); //replace space between BR and text
  662.     sHTML = sHTML.replace(/(<br\s*\/>)\s+/gi, "$1"); //replace space between <BR/> and text. spasi antara <br /> menyebebkan content menggeser kekanan saat di apply
  663.     sHTML = sHTML.replace(/\s+/gi, " "); //replace spaces with space    
  664.     oEditor.document.body.innerHTML = sHTML;
  665. }
downloadxhtmleditor.js Source code - Download Pcook CMS bubble guest v3.0 SDCMS version Source code
Related Source Codes/Software:
Oo 126 CMS movie site system - This procedure ASP + ACC/ASP + SQL, using new kern... 2016-09-21
IDC sales web site - Beautiful IDC sales web site source code 2016-09-21
NPOINT virtual host v1.7.0 formal version management system - The system main function is introduced 2016-09-21
Classified information network business in suzhou - Overall module: classification of supply and deman... 2016-09-21
Jie Yang v0.6.3 article system - System functions: 1, the system settings A confi... 2016-09-21
Age design website information management system SDCMS v1.1 SP1 - SDCMS is designed to build the information managem... 2016-09-21
Age design website information management system SDCMS v1.1 SP1 - SDCMS is designed to build the information managem... 2016-09-21
C9 v2.1.1 static post system - Program USES ASP + ACC structure design and develo... 2016-09-21
Imitation green download station perfect version - Before increased | software home page, on the basi... 2016-09-21
Subdomain hosting edition v1.9 s taobao, pat - The background site admin 2016-09-21
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top