includes/clientside/static/enano-lib-basic.js
changeset 582 a38876c0793c
parent 581 5e8fd89c02ea
child 583 c97d5f0d6636
equal deleted inserted replaced
581:5e8fd89c02ea 582:a38876c0793c
    69 if ( typeof(DISABLE_MCE) == undefined )
    69 if ( typeof(DISABLE_MCE) == undefined )
    70 {
    70 {
    71   var DISABLE_MCE = false;
    71   var DISABLE_MCE = false;
    72 }
    72 }
    73 
    73 
    74 // Obsolete JSON kill switch
       
    75 function disableJSONExts() { };
       
    76 
       
    77 is_Safari = checkIt('safari') ? true : false;
    74 is_Safari = checkIt('safari') ? true : false;
    78 
    75 
    79 var cmt_open;
    76 var cmt_open;
       
    77 var editor_open = false;
    80 var list;
    78 var list;
    81 var edit_open = false;
    79 var edit_open = false;
    82 var catlist = new Array();
    80 var catlist = new Array();
    83 var arrDiff1Buttons = new Array();
    81 var arrDiff1Buttons = new Array();
    84 var arrDiff2Buttons = new Array();
    82 var arrDiff2Buttons = new Array();
    88 var unSelectMenuOn = false;
    86 var unSelectMenuOn = false;
    89 var unObjDivCurrentId = false;
    87 var unObjDivCurrentId = false;
    90 var unObjCurrentSelection = false;
    88 var unObjCurrentSelection = false;
    91 var userlist = new Array();
    89 var userlist = new Array();
    92 var submitAuthorized = true;
    90 var submitAuthorized = true;
       
    91 var timelist = [];
    93 var rDnsObj;
    92 var rDnsObj;
    94 var rDnsBannerObj;
    93 var rDnsBannerObj;
    95 var ns4 = document.layers;
    94 var ns4 = document.layers;
    96 var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) ||(navigator.userAgent.indexOf("Opera/5")!=-1);
    95 var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) ||(navigator.userAgent.indexOf("Opera/5")!=-1);
    97 var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) ||(navigator.userAgent.indexOf("Opera/6")!=-1);
    96 var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) ||(navigator.userAgent.indexOf("Opera/6")!=-1);
   120 var startwidth  = false;
   119 var startwidth  = false;
   121 var startheight = false;
   120 var startheight = false;
   122 var do_width    = false;
   121 var do_width    = false;
   123 var ajax_load_icon = scriptPath + '/images/loading.gif';
   122 var ajax_load_icon = scriptPath + '/images/loading.gif';
   124 var editor_use_modal_window = false;
   123 var editor_use_modal_window = false;
       
   124 var Spry = {};
   125 
   125 
   126 // You have an NSIS coder in your midst...
   126 // You have an NSIS coder in your midst...
   127 var MB_OK = 1;
   127 var MB_OK = 1;
   128 var MB_OKCANCEL = 2;
   128 var MB_OKCANCEL = 2;
   129 var MB_YESNO = 4;
   129 var MB_YESNO = 4;
   133 var MB_ICONEXCLAMATION = 64;
   133 var MB_ICONEXCLAMATION = 64;
   134 var MB_ICONSTOP = 128;
   134 var MB_ICONSTOP = 128;
   135 var MB_ICONQUESTION = 256;
   135 var MB_ICONQUESTION = 256;
   136 var MB_ICONLOCK = 512;
   136 var MB_ICONLOCK = 512;
   137 
   137 
       
   138 // Can be set to true by slow themes (St. Patty)
       
   139 if ( typeof(pref_disable_js_fx) != 'boolean' )
       
   140 {
       
   141   var pref_disable_js_fx = false;
       
   142 }
       
   143 var aclDisableTransitionFX = ( is_firefox2 || pref_disable_js_fx ) ? true : false;
       
   144 
   138 // Syntax:
   145 // Syntax:
   139 // messagebox(MB_OK|MB_ICONINFORMATION, 'Title', 'Text');
   146 // messagebox(MB_OK|MB_ICONINFORMATION, 'Title', 'Text');
   140 // :-D
   147 // :-D
   141 
       
   142 var main_css = document.getElementById('mdgCss').href;
       
   143 if(main_css.indexOf('?') > -1) {
       
   144   sep = '&';
       
   145 } else sep = '?';
       
   146 var _css = false;
       
   147 var print_css = main_css + sep + 'printable';
       
   148 
       
   149 var shift;
       
   150 
       
   151 function makeUrl(page, query, html_friendly)
       
   152 {
       
   153   url = contentPath+page;
       
   154   if(url.indexOf('?') > 0) sep = '&';
       
   155   else sep = '?';
       
   156   if(query)
       
   157   {
       
   158     url = url + sep + query;
       
   159   }
       
   160   if(html_friendly)
       
   161   {
       
   162     url = url.replace('&', '&');
       
   163     url = url.replace('<', '&lt;');
       
   164     url = url.replace('>', '&gt;');
       
   165   }
       
   166   return url;
       
   167 }
       
   168 
       
   169 function makeUrlNS(namespace, page, query, html_friendly)
       
   170 {
       
   171   var url = contentPath+namespace_list[namespace]+(page.replace(/ /g, '_'));
       
   172   if(url.indexOf('?') > 0) sep = '&';
       
   173   else sep = '?';
       
   174   if(query)
       
   175   {
       
   176     url = url + sep + query;
       
   177   }
       
   178   if(html_friendly)
       
   179   {
       
   180     url = url.replace('&', '&amp;');
       
   181     url = url.replace('<', '&lt;');
       
   182     url = url.replace('>', '&gt;');
       
   183   }
       
   184   return append_sid(url);
       
   185 }
       
   186 
       
   187 function strToPageID(string)
       
   188 {
       
   189   // Convert Special:UploadFile to ['UploadFile', 'Special'], but convert 'Image:Enano.png' to ['Enano.png', 'File']
       
   190   for(var i in namespace_list)
       
   191     if(namespace_list[i] != '')
       
   192       if(namespace_list[i] == string.substr(0, namespace_list[i].length))
       
   193         return [string.substr(namespace_list[i].length), i];
       
   194   return [string, 'Article'];
       
   195 }
       
   196 
       
   197 function append_sid(url)
       
   198 {
       
   199   sep = ( url.indexOf('?') > 0 ) ? '&' : '?';
       
   200   if(ENANO_SID.length > 10)
       
   201   {
       
   202     url = url + sep + 'auth=' + ENANO_SID;
       
   203     sep = '&';
       
   204   }
       
   205   if ( pagepass.length > 0 )
       
   206   {
       
   207     url = url + sep + 'pagepass=' + pagepass;
       
   208   }
       
   209   return url;
       
   210 }
       
   211 
       
   212 var stdAjaxPrefix = append_sid(scriptPath+'/ajax.php?title='+title);
       
   213 
   148 
   214 var $_REQUEST = new Object();
   149 var $_REQUEST = new Object();
   215 if ( window.location.hash )
   150 if ( window.location.hash )
   216 {
   151 {
   217   var hash = String(window.location.hash);
   152   var hash = String(window.location.hash);
   224     b = reqobj[i].substr( ( reqobj[i].indexOf(':') + 1 ) );
   159     b = reqobj[i].substr( ( reqobj[i].indexOf(':') + 1 ) );
   225     $_REQUEST[a] = b;
   160     $_REQUEST[a] = b;
   226   }
   161   }
   227 }
   162 }
   228 
   163 
   229 var onload_hooks = new Array();
   164 if ( !onload_hooks )
       
   165   var onload_hooks = new Array();
   230 
   166 
   231 function addOnloadHook(func)
   167 function addOnloadHook(func)
   232 {
   168 {
   233   if ( typeof ( func ) == 'function' )
   169   if ( typeof ( func ) == 'function' )
   234   {
   170   {
   257       _f(e);
   193       _f(e);
   258     }
   194     }
   259   }
   195   }
   260 }
   196 }
   261 
   197 
       
   198 var loaded_components = {};
       
   199 function load_component(file)
       
   200 {
       
   201   if ( !file.match(/\.js$/) )
       
   202     file = file + '.js';
       
   203   
       
   204   console.info('Loading component %s via AJAX', file.replace(/\.js$/, ''));
       
   205   
       
   206   if ( loaded_components[file] )
       
   207   {
       
   208     // already loaded
       
   209     return true;
       
   210   }
       
   211   
       
   212   load_show_win(file);
       
   213   
       
   214   // get an XHR instance
       
   215   var ajax = ajaxMakeXHR();
       
   216   
       
   217   var uri = scriptPath + '/includes/clientside/static/' + file;
       
   218   ajax.open('GET', uri, false);
       
   219   ajax.send(null);
       
   220   if ( ajax.readyState == 4 && ajax.status == 200 )
       
   221   {
       
   222     onload_hooks = new Array();
       
   223     eval_global(ajax.responseText);
       
   224     load_hide_win();
       
   225     runOnloadHooks();
       
   226   }
       
   227   
       
   228   loaded_components[file] = true;
       
   229   return true;
       
   230 }
       
   231 
       
   232 function load_show_win(file)
       
   233 {
       
   234   var img = '<img style="margin-right: 5px" src="' + scriptPath + '/images/loading.gif" />';
       
   235   if ( document.getElementById('_js_load_component') )
       
   236   {
       
   237     document.getElementById('_js_load_component').innerHTML = img + msg_loading_component.replace('%component%', file);
       
   238     return;
       
   239   }
       
   240   file = file.replace(/\.js$/, '');
       
   241   var ld = document.createElement('div');
       
   242   ld.style.padding = '10px';
       
   243   ld.style.height = '12px';
       
   244   ld.style.position = 'fixed';
       
   245   ld.style.right = '5px';
       
   246   ld.style.bottom = '0px';
       
   247   ld.innerHTML = img + msg_loading_component.replace('%component%', file);
       
   248   ld.id = '_js_load_component';
       
   249   
       
   250   ld.style.backgroundImage = 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAA1JREFUCNdj+P///xkACcgDypG+nnEAAAAASUVORK5CYII=)';
       
   251   
       
   252   document.body.appendChild(ld);
       
   253 }
       
   254 
       
   255 function load_hide_win()
       
   256 {
       
   257   var ld = document.getElementById('_js_load_component');
       
   258   ld.parentNode.removeChild(ld);
       
   259 }
       
   260 
       
   261 // evaluate a snippet of code in the global context, used for dynamic component loading
       
   262 // from: http://dean.edwards.name/weblog/2006/11/sandbox/
       
   263 function eval_global(_jsString)
       
   264 {
       
   265   if (typeof _jsString != "string")
       
   266   {
       
   267     return false;
       
   268   }
       
   269 
       
   270   // Check whether window.eval executes code in the global scope.
       
   271   window.eval("var __INCLUDE_TEST_1__ = true;");
       
   272   if (typeof window.__INCLUDE_TEST_1__ != "undefined")
       
   273   {
       
   274     delete window.__INCLUDE_TEST_1__;
       
   275     window.eval(_jsString);
       
   276   }
       
   277   else if (typeof window.execScript != "undefined")	// IE only
       
   278   {
       
   279     window.execScript(_jsString);
       
   280   }
       
   281   else
       
   282   {
       
   283     // Test effectiveness of creating a new SCRIPT element and adding it to the document.
       
   284     this._insertScriptTag = function (_jsCode) {
       
   285       var _script = document.createElement("script");
       
   286       _script.type = "text/javascript";
       
   287       _script.defer = false;
       
   288       _script.text = _jsCode;
       
   289       var _headNodeSet = document.getElementsByTagName("head");
       
   290       if (_headNodeSet.length)
       
   291       {
       
   292         _script = _headNodeSet.item(0).appendChild(_script);
       
   293       }
       
   294       else
       
   295       {
       
   296         var _head = document.createElement("head");
       
   297         _head = document.documentElement.appendChild(_head);
       
   298         _script = _head.appendChild(_script);
       
   299       }
       
   300       return _script;
       
   301     }
       
   302     var _testScript = this._insertScriptTag("var __INCLUDE_TEST_2__ = true;");
       
   303     if (typeof window.__INCLUDE_TEST_2__ == "boolean")
       
   304     {
       
   305       _testScript.parentNode.removeChild(_testScript);
       
   306       this._insertScriptTag(_jsString);
       
   307     }
       
   308     else
       
   309     {
       
   310       // Check whether window.setTimeout works in real time.
       
   311       window.setTimeout("var __INCLUDE_TEST_3__ = true;", 0);
       
   312       if (typeof window.__INCLUDE_TEST_3__ != "undefined")
       
   313       {
       
   314         delete window.__INCLUDE_TEST_3__;
       
   315         window.setTimeout(_jsString, 0);
       
   316       }
       
   317     }
       
   318   }
       
   319 
       
   320   return true;
       
   321 }
       
   322 
   262 var head = document.getElementsByTagName('head')[0];
   323 var head = document.getElementsByTagName('head')[0];
   263 
       
   264 var script = document.createElement('script');
       
   265 script.type="text/javascript";
       
   266 script.src=scriptPath+"/includes/clientside/firebug/firebug.js";
       
   267 head.appendChild(script);
       
   268 
   324 
   269 // placeholder for window.console - used if firebug isn't present
   325 // placeholder for window.console - used if firebug isn't present
   270 // http://getfirebug.com/firebug/firebugx.js
   326 // http://getfirebug.com/firebug/firebugx.js
   271 if (!window.console || !console.firebug)
   327 if (!window.console || !console.firebug)
   272 {
   328 {
   289 
   345 
   290 // Start loading files
   346 // Start loading files
   291 // The string from the [ to the ] needs to be valid JSON, it's parsed by jsres.php.
   347 // The string from the [ to the ] needs to be valid JSON, it's parsed by jsres.php.
   292 var thefiles = [
   348 var thefiles = [
   293   'dynano.js',
   349   'dynano.js',
   294   'misc.js',
   350   'functions.js',
   295   'l10n.js',
       
   296   'login.js',
       
   297   'admin-menu.js',
       
   298   'ajax.js',
       
   299   'autofill.js',
       
   300   'base64.js',
       
   301   'dropdown.js',
   351   'dropdown.js',
   302   'faders.js',
       
   303   'fat.js',
       
   304   'grippy.js',
       
   305   'json.js',
   352   'json.js',
   306   'md5.js',
       
   307   'libbigint.js',
       
   308   'enanomath.js',
       
   309   'diffiehellman.js',
       
   310   'sha256.js',
       
   311   'sliders.js',
   353   'sliders.js',
   312   'toolbar.js',
       
   313   'rijndael.js',
       
   314   'template-compiler.js',
       
   315   'acl.js',
       
   316   'comments.js',
       
   317   'editor.js',
       
   318   'flyin.js',
       
   319   'paginate.js',
       
   320   'pwstrength.js',
   354   'pwstrength.js',
   321   'theme-manager.js',
       
   322   'rank-manager.js',
       
   323   'SpryEffects.js',
       
   324   'SpryData.js',
       
   325   'SpryJSONDataSet.js',
       
   326   'SpryAutoSuggest.js',
       
   327   'loader.js'
   355   'loader.js'
   328 ];
   356 ];
   329 
   357 
   330 var problem_scripts = {
   358 var problem_scripts = {
   331   'json.js' : true,
   359   'json.js' : true,
   369         ajaxHistory();
   397         ajaxHistory();
   370         break;
   398         break;
   371       case 'catedit':
   399       case 'catedit':
   372         ajaxCatEdit();
   400         ajaxCatEdit();
   373         break;
   401         break;
       
   402       case 'rename':
       
   403         ajaxRename();
       
   404         break;
   374     }
   405     }
   375   }
   406   }
   376 });
   407 });
   377 
   408 
       
   409 function Placeholder(funcname, filename)
       
   410 {
       
   411   this.filename = filename;
       
   412   this.funcname = funcname;
       
   413   this.go = function()
       
   414   {
       
   415     window[funcname] = null;
       
   416     load_component(filename);
       
   417     var arglist = [];
       
   418     for ( var i = 0; i < arguments.length; i++ )
       
   419     {
       
   420       arglist[arglist.length] = 'arguments['+i+']';
       
   421     }
       
   422     arglist = implode(', ', arglist);
       
   423     eval(funcname + '(' + arglist + ');');
       
   424   }
       
   425 }
       
   426 
       
   427 // list of public functions that need placeholders that fetch the component
       
   428 var placeholder_list = {
       
   429   ajaxReset: 'ajax.js',
       
   430   ajaxComments: 'comments.js',
       
   431   ajaxEditor: 'editor.js',
       
   432   ajaxHistory: 'ajax.js',
       
   433   ajaxRename: 'ajax.js',
       
   434   ajaxDelVote: 'ajax.js',
       
   435   ajaxProtect: 'ajax.js',
       
   436   ajaxClearLogs: 'ajax.js',
       
   437   ajaxResetDelVotes: 'ajax.js',
       
   438   ajaxDeletePage: 'ajax.js',
       
   439   ajaxSetPassword: 'ajax.js',
       
   440   ajaxChangeStyle: 'ajax.js',
       
   441   ajaxOpenACLManager: 'acl.js',
       
   442   ajaxAdminPage: 'login.js',
       
   443   ajaxInitLogout: 'login.js',
       
   444   ajaxStartLogin: 'login.js',
       
   445   ajaxStartAdminLogin: 'login.js',
       
   446   ajaxAdminPage: 'login.js',
       
   447   mb_logout: 'login.js',
       
   448   selectButtonMajor: 'toolbar.js',
       
   449   selectButtonMinor: 'toolbar.js',
       
   450   unselectAllButtonsMajor: 'toolbar.js',
       
   451   unselectAllButtonsMinor: 'toolbar.js',
       
   452   darken: 'fadefilter.js',
       
   453   enlighten: 'fadefilter.js',
       
   454 }
       
   455 
       
   456 var placeholder_instances = {};
       
   457 
       
   458 for ( var i in placeholder_list )
       
   459 {
       
   460   var file = placeholder_list[i];
       
   461   placeholder_instances[i] = new Placeholder(i, file);
       
   462   window[i] = placeholder_instances[i].go;
       
   463 }
       
   464 
   378 //*/
   465 //*/