includes/clientside/static/dynano.js
changeset 832 7152ca0a0ce9
parent 748 e39454295bbb
child 864 09c3ba4f6fbf
equal deleted inserted replaced
831:45e887f23282 832:7152ca0a0ce9
    34     this.switchToMCE = DN_switchToMCE;
    34     this.switchToMCE = DN_switchToMCE;
    35     this.destroyMCE = DN_destroyMCE;
    35     this.destroyMCE = DN_destroyMCE;
    36     this.getContent = DN_mceFetchContent;
    36     this.getContent = DN_mceFetchContent;
    37     this.setContent = DN_mceSetContent;
    37     this.setContent = DN_mceSetContent;
    38     this.makeSwitchable = DN_makeSwitchableTA;
    38     this.makeSwitchable = DN_makeSwitchableTA;
       
    39     this.isMCE = DN_isMCE;
    39   }
    40   }
    40 }
    41 }
    41 function __DNObjGetHeight(o) {
    42 function __DNObjGetHeight(o) {
    42   return o.offsetHeight;
    43   return o.offsetHeight;
    43 }
    44 }
   152   }
   153   }
   153   this.object.dnIsMCE = 'no';
   154   this.object.dnIsMCE = 'no';
   154   return this;
   155   return this;
   155 }
   156 }
   156 
   157 
       
   158 function DN_isMCE()
       
   159 {
       
   160   return ( this.object.dnIsMCE == 'yes' );
       
   161 }
       
   162 
   157 function DN_mceFetchContent()
   163 function DN_mceFetchContent()
   158 {
   164 {
   159   if ( this.object.name )
   165   if ( this.object.name )
   160   {
   166   {
   161     var text = this.object.value;
   167     var text = this.object.value;
   272   {
   278   {
   273     toggler.set_text();
   279     toggler.set_text();
   274   }
   280   }
   275 }
   281 }
   276 
   282 
   277 // A basic Wikitext to XHTML converter
       
   278 function DN_WikitextToXHTML(text)
   283 function DN_WikitextToXHTML(text)
   279 {
   284 {
   280   text = text.replace(/^===[\s]*(.+?)[\s]*===$/g, '<h3>$1</h3>');
   285   return DN_AjaxGetTransformedText(text, 'xhtml');
   281   text = text.replace(/'''(.+?)'''/g, '<b>$1</b>');
   286 }
   282   text = text.replace(/''(.+?)''/g, '<i>$1</i>');
   287 
   283   text = text.replace(/\[(http|ftp|irc|mailto):([^ \]])+ ([^\]]+?)\]/g, '<a href="$1:$2">$4</a>');
       
   284   return text;
       
   285 }
       
   286 
       
   287 // Inverse of the previous function
       
   288 function DN_XHTMLToWikitext(text)
   288 function DN_XHTMLToWikitext(text)
   289 {
   289 {
   290   text = text.replace(/<h3>(.+?)<\/h3>/g, '=== $1 ===');
   290   return DN_AjaxGetTransformedText(text, 'wikitext');
   291   text = text.replace(/<(b|strong)>(.+?)<\/(b|strong)>/g, "'''$2'''");
   291 }
   292   text = text.replace(/<(i|em)>(.+?)<\/(i|em)>/g, "''$2''");
   292 
   293   text = text.replace(/<a href="([^" ]+)">(.+?)<\/a>/g, '[$1 $2]');
   293 // AJAX to the server to transform text
   294   text = text.replace(/<\/?p>/g, '');
   294 function DN_AjaxGetTransformedText(text, to)
       
   295 {
       
   296   // get an XHR instance
       
   297   var ajax = ajaxMakeXHR();
       
   298   
       
   299   var uri = stdAjaxPrefix + '&_mode=transform&to=' + to;
       
   300   var parms = 'text=' + ajaxEscape(text);
       
   301   try
       
   302   {
       
   303     ajax.open('POST', uri, false);
       
   304     ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
       
   305     // Setting Content-length in Safari triggers a warning
       
   306     if ( !is_Safari )
       
   307     {
       
   308       ajax.setRequestHeader("Content-length", parms.length);
       
   309     }
       
   310     ajax.send(parms);
       
   311     // async request, so if status != 200 at this point then we're screwed
       
   312     if ( ajax.readyState == 4 && ajax.status == 200 )
       
   313     {
       
   314       var response = String(ajax.responseText + '');
       
   315       if ( !check_json_response(response) )
       
   316       {
       
   317         handle_invalid_json(response);
       
   318         return text;
       
   319       }
       
   320       response = parseJSON(response);
       
   321       if ( response.mode == 'error' )
       
   322       {
       
   323         alert(response.error);
       
   324         return text;
       
   325       }
       
   326       return response.text;
       
   327     }
       
   328   }
       
   329   catch(e)
       
   330   {
       
   331     console.warn('DN_AjaxGetTransformedText: XHR failed');
       
   332   }
   295   return text;
   333   return text;
   296 }
   334 }
   297 
   335 
   298 DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; };
   336 DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; };
   299 DNobj.prototype.rmClass  = function(clsname) { rmClass( this.object, clsname); return this; };
   337 DNobj.prototype.rmClass  = function(clsname) { rmClass( this.object, clsname); return this; };