Difference between revisions of "MediaWiki:Common.js"
(New page: →Any JavaScript here will be loaded for all users on every page load.: var hasClass = (function () { var reCache = {}; return function (element, className) { return (r...) |
m (Step 2 of imageheight change.) |
||
(265 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* 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 hasClass = (function () { | ||
var reCache = {}; | var reCache = {}; | ||
return function (element, className) { | return function (element, className) { | ||
− | return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp( | + | 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); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
} | } | ||
− | + | /** | |
− | + | * Import more specific scripts. | |
− | + | */ | |
− | + | importScript('MediaWiki:Collapsible.js'); | |
+ | importScript('MediaWiki:Calculator.js'); | ||
− | + | if (wgAction == 'edit' || wgAction == 'submit') | |
− | + | { | |
− | + | importScript('MediaWiki:Editbar.js'); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− |
Latest revision as of 12:30, 24 August 2011
/* 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); } } /** * Import more specific scripts. */ importScript('MediaWiki:Collapsible.js'); importScript('MediaWiki:Calculator.js'); if (wgAction == 'edit' || wgAction == 'submit') { importScript('MediaWiki:Editbar.js'); }