includes/clientside/static/dynano.js
changeset 335 67bd3121a12e
parent 29 e5484a9e0818
child 413 6607cd646d6d
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
    84     left_offset += obj.offsetTop;
    84     left_offset += obj.offsetTop;
    85   }
    85   }
    86   return left_offset;
    86   return left_offset;
    87 }
    87 }
    88 
    88 
    89 function DN_switchToMCE()
    89 function DN_switchToMCE(performWikiTransform)
    90 {
    90 {
    91   //if ( this.object.dn_is_mce )
    91   //if ( this.object.dn_is_mce )
    92   //  return this;
    92   //  return this;
    93   if ( !this.object.id )
    93   if ( !this.object.id )
    94     this.object.id = 'textarea_' + Math.floor(Math.random() * 1000000);
    94     this.object.id = 'textarea_' + Math.floor(Math.random() * 1000000);
    95   if ( !this.object.name )
    95   if ( !this.object.name )
    96     this.object.name = 'textarea_' + Math.floor(Math.random() * 1000000);
    96     this.object.name = 'textarea_' + Math.floor(Math.random() * 1000000);
    97   tinyMCE.addMCEControl(this.object, this.object.name, document);
    97   // TinyMCE 2.x
       
    98   // tinyMCE.addMCEControl(this.object, this.object.name, document);
       
    99   // TinyMCE 3.x
       
   100   if ( performWikiTransform )
       
   101   {
       
   102     this.object.value = DN_WikitextToXHTML(this.object.value);
       
   103   }
       
   104   tinyMCE.execCommand("mceAddControl", true, this.object.id);
    98   this.object.dnIsMCE = 'yes';
   105   this.object.dnIsMCE = 'yes';
    99   return this;
   106   return this;
   100 }
   107 }
   101 
   108 
   102 function DN_destroyMCE()
   109 function DN_destroyMCE(performWikiTransform)
   103 {
   110 {
   104   //if ( !this.object.dn_is_mce )
   111   //if ( !this.object.dn_is_mce )
   105   //  return this;
   112   //  return this;
   106   if ( this.object.name )
   113   if ( this.object.id )
   107     tinyMCE.removeMCEControl(this.object.name);
   114   {
       
   115     // TinyMCE 2.x
       
   116     // tinyMCE.removeMCEControl(this.object.name);
       
   117     // TinyMCE 3.x
       
   118     var ed = tinyMCE.getInstanceById(this.object.id);
       
   119     if ( ed )
       
   120     {
       
   121       if ( !tinyMCE.execCommand("mceRemoveEditor", false, this.object.id) )
       
   122         alert('could not destroy editor');
       
   123       if ( performWikiTransform )
       
   124       {
       
   125         this.object.value = DN_XHTMLToWikitext(this.object.value);
       
   126       }
       
   127     }
       
   128   }
   108   this.object.dnIsMCE = 'no';
   129   this.object.dnIsMCE = 'no';
   109   return this;
   130   return this;
   110 }
   131 }
   111 
   132 
   112 function DN_mceFetchContent()
   133 function DN_mceFetchContent()
   113 {
   134 {
   114   if ( this.object.name )
   135   if ( this.object.name )
   115   {
   136   {
   116     var text = this.object.value;
   137     var text = this.object.value;
   117     if ( tinyMCE.getInstanceById(this.object.name) )
   138     if ( tinyMCE.get(this.object.id) )
   118       text = tinyMCE.getContent(this.object.name);
   139     {
       
   140       var editor = tinyMCE.get(this.object.id);
       
   141       text = editor.getContent();
       
   142     }
   119     return text;
   143     return text;
   120   }
   144   }
   121   else
   145   else
   122   {
   146   {
   123     return this.object.value;
   147     return this.object.value;
   124   }
   148   }
       
   149 }
       
   150 
       
   151 // A basic Wikitext to XHTML converter
       
   152 function DN_WikitextToXHTML(text)
       
   153 {
       
   154   text = text.replace(/^===[\s]*(.+?)[\s]*===$/g, '<h3>$1</h3>');
       
   155   text = text.replace(/'''(.+?)'''/g, '<b>$1</b>');
       
   156   text = text.replace(/''(.+?)''/g, '<i>$1</i>');
       
   157   text = text.replace(/\[(http|ftp|irc|mailto):([^ \]])+ ([^\]]+?)\]/g, '<a href="$1:$2">$4</a>');
       
   158   return text;
       
   159 }
       
   160 
       
   161 // Inverse of the previous function
       
   162 function DN_XHTMLToWikitext(text)
       
   163 {
       
   164   text = text.replace(/<h3>(.+?)<\/h3>/g, '=== $1 ===');
       
   165   text = text.replace(/<(b|strong)>(.+?)<\/(b|strong)>/g, "'''$2'''");
       
   166   text = text.replace(/<(i|em)>(.+?)<\/(i|em)>/g, "''$2''");
       
   167   text = text.replace(/<a href="([^" ]+)">(.+?)<\/a>/g, '[$1 $2]');
       
   168   text = text.replace(/<\/?p>/g, '');
       
   169   return text;
   125 }
   170 }
   126 
   171 
   127 DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; };
   172 DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; };
   128 DNobj.prototype.rmClass  = function(clsname) { rmClass( this.object, clsname); return this; };
   173 DNobj.prototype.rmClass  = function(clsname) { rmClass( this.object, clsname); return this; };
   129 DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); };
   174 DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); };