MediaWiki:Common.js
From Wikibooks, the open-content textbooks collection
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences.
//<nowiki> Common javascript code which effects everyone // hasClass() // Description: Uses regular expressions and caching for better performance. // Maintainers: User:Mike Dillon, User:R. Koot, User:SG var hasClass = (function () { var reCache = {}; return function (element, className) { return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className); }; })(); // for backwards compatibility var addLoadEvent = addOnloadHook; var import_script = importScript; var import_style = importStylesheet; // book name var wgBookName = wgPageName.split("/", 1)[0] || wgPageName; wgBookName = wgBookName.split(':', 2).join(":"); // Provides an easy way to disable load dependent features function delLoadEvent(func) { for (var i = 0; i < onloadFuncts.length; i++) { if (onloadFuncts[i] == func) onloadFuncts.splice(i, 1); } } function get_query_value(query, name) { if (typeof query != "string" || typeof name != "string") return ""; var value = query.match('[&?]' + name + '=([^&]*)'); if (value) return decodeURIComponent(value[1]); else return ""; } // cross-browser event attachment (John Resig) // http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html function addEvent(obj, type, fn) { if (obj.addEventListener) obj.addEventListener( type, fn, false ); else if (obj.attachEvent) { obj["e"+type+fn] = fn; obj[type+fn] = function() { obj["e"+type+fn]( window.event ); } obj.attachEvent( "on"+type, obj[type+fn] ); } } // cross-browser XMLHtttpRequest compatibility if (typeof XMLHttpRequest == "undefined") XMLHttpRequest = function() { try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {}; try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {}; try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}; try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}; throw new Error("This browser does not support XMLHttpRequest or XMLHTTP."); }; //Adds a dismissable message to the watchlist if (wgCanonicalSpecialPageName == "Watchlist") importScript('MediaWiki:Common.js/WatchlistNotice.js'); // Removes the default no-license option for image uploads. // All new image uploads must be tagged with a license or nld function remove_no_license() { if (wgPageName != "Special:Upload") return; var license = document.getElementById("wpLicense"); if (!license) return; var options = license.getElementsByTagName("option"); if (!options) return; license.removeChild(options[0]); } addOnloadHook(remove_no_license); // import additional scripts // import_script('MediaWiki:Common.js/ExtraTools.js'); import_script('MediaWiki:Common.js/Navigation.js'); import_script('MediaWiki:Common.js/NavigationTabs.js'); import_script('MediaWiki:Common.js/Displaytitle.js'); import_script('MediaWiki:Common.js/RandomBook.js'); import_script('MediaWiki:Common.js/Edittools.js'); // adds buttons to the edit toolbar if (mwCustomEditButtons) import_script('MediaWiki:Common.js/EditToolbar.js'); //Search within a book using Google// // 0 - Main / 102 - Cookbook / 110 - Wikijunior if ( wgNamespaceNumber == 0 || wgNamespaceNumber == 102 || wgNamespaceNumber == 110) importScript('MediaWiki:Common.js/BookSearch.js'); //</nowiki> End of Common.js