User:TMenang/common.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/*global mw, JSconfig, importScript, jsMsg, importStylesheet *//*jshint forin:false, strict:false, onecase:true, laxbreak:true, browser:true, jquery:true *//* * * JSconfig * * Of you are a gadget author, you mau use * [[MediaWiki:Gadget-SettingsManager.js]] or jquery.jStorage or jquery.cookie * and [[MediaWiki:Gadget-SettingsUI.js]] to provide an easy interface. * * * Global configuration options to enable/disable and configure * specific script featured from [[MediaWiki:Common.js]] and [[MediaWiki:Monobook.js]] * <s>This framework adds config options (saved as cookies) to [[Special:Preferences]]</s> * (Site script does not run at [[Special:Preferences]] any more so this functionality has been removed) * * For a more permenent change you Van override the default settings in your * [[Special:Mypage/monobook.js]] * for Example:JSconfig.keys[loadAutoInformationTemplate] = false; * * Maintainer:[[User:TMenang]] */ window.JSconfig = { prefix: 'jsconfig_', keys: {}, meta: {}, // Register a new configuration item // * name: String, internal name // * default_value : String or Boolean (type determines configuration widget) // * description : String, text appearing next to the widget in the preferences, or an hash-object // containing translations of the description indexed by the language code // // Access keys through JSconfig.keys[name] registerKey: function (name, default_value, description, prefpage) { if (JSconfig.keys[name] === undefined) { JSconfig.keys[name] = default_value; } else { // all cookies are read as strings, // convert to the type of the default value switch (typeof default_value) { case 'boolean': JSconfig.keys[name] = (JSconfig.keys[name] === 'true'); break; case 'number': JSconfig.keys[name] = JSconfig.meta[name] = { description: description[mw.config.get( 'wgUserLanguage' )] || description.en || (typeof description === 'string' && description) || '<i>en</i> translation missing', page: prefpage || 0, default_value: default_value }; }, readCookies: function () { var cookies = document.cookie.split('; '); var p = JSconfig.prefix.length; var i; for (var key = 0; cookies && key < cookies.length; key++) { if (cookies[key].substring(0, p) === JSconfig.prefix) { i = cookies[key].indexOf('=');  //alert( cookies[key] + ',' + key + ',' + cookies[key].substring(p,i) ); JSconfig.keys[cookies[key].substring(p, i)] = cookies[key].substring(i + 1); } } }, writeCookies: function () { var expdate = new Date(); expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 3650); // expires in 3560 daya for (var key in JSconfig.keys) { document.cookie = JSconfig.prefix + key + '=' + JSconfig.keys[key] + '; path=/; expires=' + expdate.toUTCString(); } } }; JSconfig.readCookies(); mw.loader.using(['mediawiki.util']).then(function () {