MediaWiki:Common.js: Difference between revisions
Content deleted Content added
Johnrdorazio (talk | contribs) No edit summary |
Johnrdorazio (talk | contribs) No edit summary Tags: Mobile edit Mobile web edit |
||
(6 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
* dependency hasn't arrived yet it'll make sure those are loaded before this. |
* dependency hasn't arrived yet it'll make sure those are loaded before this. |
||
*/ |
*/ |
||
console.log('Hello World from Common.js!'); |
|||
/* global mw, $ */ |
/* global mw, $ */ |
||
/* jshint strict:false, browser:true */ |
/* jshint strict:false, browser:true */ |
||
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' || ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) { |
|||
mw.loader.load("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript"); |
|||
} |
|||
mw.loader.using( [ 'mediawiki.util' ] ).done( function () { |
mw.loader.using( [ 'mediawiki.util' ] ).done( function () { |
||
/* Begin of mw.loader.using callback */ |
/* Begin of mw.loader.using callback */ |
||
/** |
|||
* Main Page layout fixes |
|||
* |
|||
* Description: Adds an additional link to the complete list of languages available. |
|||
* Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]] |
|||
*/ |
|||
if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) { |
|||
$( function () { |
|||
mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias', |
|||
'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias' ); |
|||
} ); |
|||
} |
|||
/** |
/** |
||
Line 40: | Line 25: | ||
*/ |
*/ |
||
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' ); |
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' ); |
||
/** |
|||
* Extract a URL parameter from the current URL |
|||
* @deprecated: Use mw.util.getParamValue with proper escaping |
|||
*/ |
|||
mw.log.deprecate( window, 'getURLParamValue', mw.util.getParamValue, 'Use mw.util.getParamValue instead' ); |
|||
/** |
/** |
||
Line 83: | Line 62: | ||
* Description: WikiMiniAtlas is a popup click and drag world map. |
* Description: WikiMiniAtlas is a popup click and drag world map. |
||
* This script causes all of our coordinate links to display the WikiMiniAtlas popup button. |
* This script causes all of our coordinate links to display the WikiMiniAtlas popup button. |
||
* The script itself is located on |
* The script itself is located on the Meta-Wiki because it is used by many projects. |
||
* See [[Meta:WikiMiniAtlas]] for more information. |
* See [[Meta:WikiMiniAtlas]] for more information. |
||
* Note - use of this service is recommended to be replaced with mw:Help:Extension:Kartographer |
* Note - use of this service is recommended to be replaced with mw:Help:Extension:Kartographer |
||
Line 163: | Line 142: | ||
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup ); |
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup ); |
||
/** |
|||
* Dynamic Navigation Bars (experimental) |
|||
* |
|||
* Description: See [[Wikipedia:NavFrame]]. |
|||
* Maintainers: UNMAINTAINED |
|||
*/ |
|||
var collapseCaption = 'hide'; |
|||
var expandCaption = 'show'; |
|||
// Set up the words in your language |
|||
var navigationBarHide = '[' + collapseCaption + ']'; |
|||
var navigationBarShow = '[' + expandCaption + ']'; |
|||
/** |
|||
* Shows and hides content and picture (if available) of navigation bars. |
|||
* |
|||
* @param {number} indexNavigationBar The index of navigation bar to be toggled |
|||
* @param {jQuery.Event} event Event object |
|||
* @return {boolean} |
|||
*/ |
|||
function toggleNavigationBar( indexNavigationBar, event ) { |
|||
var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar ); |
|||
var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar ); |
|||
var navChild; |
|||
if ( !navFrame || !navToggle ) { |
|||
return false; |
|||
} |
|||
// If shown now |
|||
if ( navToggle.firstChild.data === navigationBarHide ) { |
|||
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) { |
|||
if ( $( navChild ).hasClass( 'NavContent' ) ) { |
|||
navChild.style.display = 'none'; |
|||
} |
|||
} |
|||
navToggle.firstChild.data = navigationBarShow; |
|||
// If hidden now |
|||
} else if ( navToggle.firstChild.data === navigationBarShow ) { |
|||
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) { |
|||
if ( $( navChild ).hasClass( 'NavContent' ) ) { |
|||
navChild.style.display = 'block'; |
|||
} |
|||
} |
|||
navToggle.firstChild.data = navigationBarHide; |
|||
} |
|||
event.preventDefault(); |
|||
} |
|||
/** |
|||
* Adds show/hide-button to navigation bars. |
|||
* |
|||
* @param {jQuery} $content |
|||
*/ |
|||
function createNavigationBarToggleButton( $content ) { |
|||
var j, navChild, navToggle, navToggleText, isCollapsed, |
|||
indexNavigationBar = 0; |
|||
// Iterate over all < div >-elements |
|||
var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' ); |
|||
$divs.each( function ( i, navFrame ) { |
|||
indexNavigationBar++; |
|||
navToggle = document.createElement( 'a' ); |
|||
navToggle.className = 'NavToggle'; |
|||
navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); |
|||
navToggle.setAttribute( 'href', '#' ); |
|||
$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) ); |
|||
isCollapsed = $( navFrame ).hasClass( 'collapsed' ); |
|||
/** |
|||
* Check if any children are already hidden. This loop is here for backwards compatibility: |
|||
* the old way of making NavFrames start out collapsed was to manually add style="display:none" |
|||
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make |
|||
* the content visible without JavaScript support), the new recommended way is to add the class |
|||
* "collapsed" to the NavFrame itself, just like with collapsible tables. |
|||
*/ |
|||
for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) { |
|||
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) { |
|||
if ( navChild.style.display === 'none' ) { |
|||
isCollapsed = true; |
|||
} |
|||
} |
|||
} |
|||
if ( isCollapsed ) { |
|||
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) { |
|||
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) { |
|||
navChild.style.display = 'none'; |
|||
} |
|||
} |
|||
} |
|||
navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide ); |
|||
navToggle.appendChild( navToggleText ); |
|||
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) |
|||
for ( j = 0; j < navFrame.childNodes.length; j++ ) { |
|||
if ( $( navFrame.childNodes[ j ] ).hasClass( 'NavHead' ) ) { |
|||
navToggle.style.color = navFrame.childNodes[ j ].style.color; |
|||
navFrame.childNodes[ j ].appendChild( navToggle ); |
|||
} |
|||
} |
|||
navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar ); |
|||
} ); |
|||
} |
|||
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); |
|||
/** |
/** |
||
Line 303: | Line 174: | ||
} ); |
} ); |
||
} |
} |
||
/* Actions specific to the edit page */ |
|||
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) { |
|||
/** |
|||
* Fix edit summary prompt for undo |
|||
* |
|||
* Fixes the fact that the undo function combined with the "no edit summary prompter" |
|||
* complains about missing editsummary, if leaving the edit summary unchanged. |
|||
* Added by [[User:Deskana]], code by [[User:Tra]]. |
|||
* See also [[phab:T10912]]. |
|||
*/ |
|||
$( function () { |
|||
if ( document.location.search.indexOf( 'undo=' ) !== -1 && document.getElementsByName( 'wpAutoSummary' )[ 0 ] ) { |
|||
document.getElementsByName( 'wpAutoSummary' )[ 0 ].value = '1'; |
|||
} |
|||
} ); |
|||
} |
|||
/* End of mw.loader.using callback */ |
/* End of mw.loader.using callback */ |
||
} ); |
} ); |
||
/* DO NOT ADD CODE BELOW THIS LINE */ |
|||
mw.loader.load( '/w/index.php?title=MediaWiki:BibleGet.js&action=raw&ctype=text/javascript' ); |
|||
$(document).ready(function(){ |
|||
alert("hello world!"); |
|||
}); |