includes/clientside/static/dynano.js
changeset 748 e39454295bbb
parent 699 c7d737202d59
child 832 7152ca0a0ce9
equal deleted inserted replaced
747:cffe13960330 748:e39454295bbb
     1 // The "Dynano" Javascript framework. Similar in syntax to JQuery but only has what Enano needs.
     1 // The "Dynano" Javascript framework. Similar in syntax to JQuery but highly Enano-specific (TinyMCE, etc).
     2 
     2 
     3 var $ = function(id)
     3 var $ = function(id)
     4 {
     4 {
     5   return new DNobj(id);
     5   return new DNobj(id);
     6 }
     6 }
    17     console.warn('Dynano: requested object is bad. id parameter follows.');
    17     console.warn('Dynano: requested object is bad. id parameter follows.');
    18     console.debug(id);
    18     console.debug(id);
    19     this.object = false;
    19     this.object = false;
    20     return this;
    20     return this;
    21   }
    21   }
       
    22   if ( this.object.Dynano )
       
    23   {
       
    24     return this.object.Dynano;
       
    25   }
       
    26   this.object.Dynano = this;
       
    27   
    22   this.height = __DNObjGetHeight(this.object);
    28   this.height = __DNObjGetHeight(this.object);
    23   this.width = __DNObjGetWidth(this.object);
    29   this.width = __DNObjGetWidth(this.object);
    24   
    30   
    25   if ( this.object.tagName == 'TEXTAREA' && ( typeof(tinyMCE) == 'object' || typeof(tinyMCE_GZ) == 'object' ) )
    31   if ( this.object.tagName == 'TEXTAREA' && ( typeof(tinyMCE) == 'object' || typeof(tinyMCE_GZ) == 'object' ) )
    26   {
    32   {
    27     this.object.dnIsMCE = 'no';
    33     this.object.dnIsMCE = 'no';
    28     this.switchToMCE = DN_switchToMCE;
    34     this.switchToMCE = DN_switchToMCE;
    29     this.destroyMCE = DN_destroyMCE;
    35     this.destroyMCE = DN_destroyMCE;
    30     this.getContent = DN_mceFetchContent;
    36     this.getContent = DN_mceFetchContent;
    31     this.setContent = DN_mceSetContent;
    37     this.setContent = DN_mceSetContent;
       
    38     this.makeSwitchable = DN_makeSwitchableTA;
    32   }
    39   }
    33 }
    40 }
    34 function __DNObjGetHeight(o) {
    41 function __DNObjGetHeight(o) {
    35   return o.offsetHeight;
    42   return o.offsetHeight;
    36 }
    43 }
   177     }
   184     }
   178   }
   185   }
   179   else
   186   else
   180   {
   187   {
   181     this.object.value = text;
   188     this.object.value = text;
       
   189   }
       
   190 }
       
   191 
       
   192 var P_BOTTOM = 1;
       
   193 var P_TOP = 2;
       
   194 
       
   195 function DN_makeSwitchableTA(pos)
       
   196 {
       
   197   if ( this.toggler )
       
   198     return false;
       
   199   
       
   200   if ( !pos )
       
   201     pos = P_BOTTOM;
       
   202   
       
   203   load_component('l10n');
       
   204   var cookiename = 'enano_editor_mode';
       
   205   
       
   206   var toggler = document.createElement('div');
       
   207   toggler.dynano = this;
       
   208   this.toggler = toggler;
       
   209   
       
   210   if ( !this.object.id )
       
   211     this.object.id = 'dynano_auto_' + Math.floor(Math.random() * 1000000);
       
   212   
       
   213   toggler.s_mode_text = $lang.get('editor_btn_wikitext');
       
   214   toggler.s_mode_graphical = $lang.get('editor_btn_graphical');
       
   215   
       
   216   toggler.set_text = function()
       
   217   {
       
   218     if ( this.dynano.object.dnIsMCE == 'yes' )
       
   219       this.dynano.destroyMCE();
       
   220     
       
   221     this.innerHTML = '';
       
   222     this.appendChild(document.createTextNode(this.s_mode_text + ' | '));
       
   223     
       
   224     var link = document.createElement('a');
       
   225     link.href = '#';
       
   226     link.onclick = function()
       
   227     {
       
   228       this.parentNode.set_graphical();
       
   229       return false;
       
   230     }
       
   231     link.appendChild(document.createTextNode(this.s_mode_graphical));
       
   232     this.appendChild(link);
       
   233     
       
   234     createCookie('enano_editor_mode', 'text', 365);
       
   235   }
       
   236   
       
   237   toggler.set_graphical = function()
       
   238   {
       
   239     this.dynano.switchToMCE();
       
   240     this.innerHTML = '';
       
   241     
       
   242     var link = document.createElement('a');
       
   243     link.href = '#';
       
   244     link.onclick = function()
       
   245     {
       
   246       this.parentNode.set_text();
       
   247       return false;
       
   248     }
       
   249     link.appendChild(document.createTextNode(this.s_mode_text));
       
   250     this.appendChild(link);
       
   251     
       
   252     this.appendChild(document.createTextNode(' | ' + this.s_mode_graphical));
       
   253     createCookie('enano_editor_mode', 'tinymce', 365);
       
   254   }
       
   255   
       
   256   toggler.style.styleFloat = 'right';
       
   257   toggler.style.cssFloat = 'right';
       
   258   if ( pos == P_BOTTOM )
       
   259   {
       
   260     insertAfter(this.object.parentNode, toggler, this.object);
       
   261   }
       
   262   else
       
   263   {
       
   264     this.object.parentNode.insertBefore(toggler, this.object);
       
   265   }
       
   266   
       
   267   if ( readCookie(cookiename) == 'tinymce' )
       
   268   {
       
   269     toggler.set_graphical();
       
   270   }
       
   271   else
       
   272   {
       
   273     toggler.set_text();
   182   }
   274   }
   183 }
   275 }
   184 
   276 
   185 // A basic Wikitext to XHTML converter
   277 // A basic Wikitext to XHTML converter
   186 function DN_WikitextToXHTML(text)
   278 function DN_WikitextToXHTML(text)