Difference between revisions of "MediaWiki:Common.js"
m |
m |
||
Line 70: | Line 70: | ||
* Import more specific scripts. | * Import more specific scripts. | ||
*/ | */ | ||
− | + | function hasCollapsibleTables() { | |
− | + | var collapsibleTables = document.getElementsByClassName(document, 'table', 'collapsible'); | |
− | + | if (collapsibleTables) { | |
− | { | + | importScript('MediaWiki:Common.js/Collapsible.js'); |
− | + | for (var i = 0; i < collapsibleTables.length; i++) { | |
− | + | var headerRow = collapsibleTables[i].getElementsByTagName('tr')[0]; | |
− | + | if (headerRow) { | |
− | + | var header = headerRow.getElementsByTagName('th')[0]; | |
− | + | if (header) { | |
− | + | new CollapseButton(collapsibleTables[i], header); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | if ( | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
} | } | ||
− | } | + | } |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | }); | + | } |
+ | addOnloadHook(hasCollapsibleTables); | ||
− | + | importScript('MediaWiki:Common.js/Calculator.js'); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | if (wgAction == 'edit' || wgAction == 'submit') | |
− | + | { | |
− | + | importScript('MediaWiki:Common.js/Editbar.js'); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− |
Revision as of 12:11, 29 April 2010
/* Any JavaScript here will be loaded for all users on every page load. */ /** * Determines if a particular element possesses a class. */ var hasClass = (function () { var reCache = {}; return function (element, className) { return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp('(?:\\s|^)' + className + '(?:\\s|$)'))).test(element.className); }; })(); /** * Determines if a given value is a number. */ function isNumeric(value) { return new RegExp(/(^\d+$)|(^\d+\.\d+$)/).test(value); } /** * Removes all children from an element. */ function removeChildren(element) { while (element.hasChildNodes()) { element.removeChild(element.firstChild); } } /** * Implementation of classical inheritance for Objects. */ (function(){ var initializing = false, fnTest = /xyz/.test(function() { xyz; }) ? /\b_super\b/ : /.*/; this.Class = function() { }; Class.extend = function(prop) { var _super = this.prototype; initializing = true; var prototype = new this(); initializing = false; for (var name in prop) { prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn) { return function() { var tmp = this._super; this._super = _super[name]; var ret = fn.apply(this, arguments); this._super = tmp; return ret; }; })(name, prop[name]) : prop[name]; } function Class() { if (!initializing && this.init) this.init.apply(this, arguments); } Class.prototype = prototype; Class.constructor = Class; Class.extend = arguments.callee; return Class; }; })(); /** * Import more specific scripts. */ function hasCollapsibleTables() { var collapsibleTables = document.getElementsByClassName(document, 'table', 'collapsible'); if (collapsibleTables) { importScript('MediaWiki:Common.js/Collapsible.js'); for (var i = 0; i < collapsibleTables.length; i++) { var headerRow = collapsibleTables[i].getElementsByTagName('tr')[0]; if (headerRow) { var header = headerRow.getElementsByTagName('th')[0]; if (header) { new CollapseButton(collapsibleTables[i], header); } } } } } addOnloadHook(hasCollapsibleTables); importScript('MediaWiki:Common.js/Calculator.js'); if (wgAction == 'edit' || wgAction == 'submit') { importScript('MediaWiki:Common.js/Editbar.js'); }