Changeset 1128


Ignore:
Timestamp:
11/21/08 21:15:44 (11 years ago)
Author:
douglas
Message:

FIXED Ticket #1338 Autodetect _editor_url and adds some options for passing arguments

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/XinhaLoader.js

    r1057 r1128  
    11var Xinha = {}; 
     2 
     3// Auto detect _editor_url if it's not set. 
     4if (!window._editor_url) { 
     5  // Because of the way the DOM is loaded, this is guaranteed to always pull our script tag. 
     6  var this_script = Array.prototype.slice.call(document.getElementsByTagName('script'),-1)[0]; 
     7 
     8  // We'll allow two ways to specify arguments.  We'll accept them in the 
     9  // argument of the script, or we'll accept them embedded into our script tag. 
     10  var args = this_script.src.split('?'); 
     11  args = args.length == 2 ? args[1].split('&') : ''; 
     12  for (var index=0; index<args.length; ++index) { 
     13    var arg = args[index].split('='); 
     14    if (arg.length == 2) { 
     15        switch (arg[0]) { 
     16            case 'lang': 
     17            case 'icons': 
     18            case 'skin': 
     19            case 'url': 
     20              window['_editor_'+arg[0]] = arg[1]; 
     21              break; 
     22        } 
     23    } 
     24  } 
     25 
     26  // We can grab the script innerHTML and execute that to cut down on script 
     27  // tags.  Thanks John Resig! 
     28  // http://ejohn.org/blog/degrading-script-tags/ 
     29  if (this_script.innerHTML.replace(/\s+/,'')) { 
     30      eval(this_script.innerHTML); 
     31  } 
     32 
     33  // Default values 
     34  _editor_lang = window._editor_lang || 'de'; 
     35 
     36  // Chop off any query string.  Chop the filename off of the URL. 
     37  _editor_url = window._editor_url || this_script.src.split('?')[0].split('/').slice(0,-1).join('/'); 
     38} 
    239 
    340_editor_url = _editor_url.replace(/\x2f*$/, '/'); 
  • trunk/examples/Newbie.html

    r1000 r1128  
    66  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    77   
    8   <script type="text/javascript"> 
    9     _editor_url  = "../"  // (preferably absolute) URL (including trailing slash) where Xinha is installed 
    10     _editor_lang = "en";      // And the language we need to use in the editor. 
    11     _editor_skin = "silva";   // If you want use skin, add the name here 
     8  <script type="text/javascript" src="../XinhaLoader.js?lang=en&skin=silva"> 
     9    _editor_icons = "Tango" // You can pass arguments via the script URL or embed them here. 
    1210  </script> 
    13   <script type="text/javascript" src="../XinhaLoader.js"></script> 
    1411  <script type="text/javascript" src="XinhaConfig.js"></script> 
    1512</head> 
Note: See TracChangeset for help on using the changeset viewer.