Content deleted Content added
correction |
clean up |
||
Line 1:
/*
anno.js
Annotation toggle
Applies to annotations everywhere,
whether in outlines, list pages, or embedded lists.
Based on:
https://en.wikipedia.org/w/index.php?title=User:TheDJ/thetranshumanist.js&oldid=746366603
by TheDJ
*/
if ( mw.config.get('wgAction') === 'view' ) {
mw.hook( 'wikipage.content').add( function ($contents ) {
var listItems = $contents.find( 'li:not([class]):not([id])' );
listItems.each( function( index, li ) {
var nodes = $(li).contents();
var marker = false;
var ul = false;
for ( var i = 0; i < nodes.length; i++ ) {
if ( nodes[i].nodeType === Node.TEXT_NODE &&
nodes[i].textContent.indexOf(' – ') >= 0)
{
marker = i;
break;
}
}
if( nodes[nodes.length-1].tagName === "UL" ) {
ul = nodes[nodes.length-1];
}
if( marker > 0 ) {
var wrapper = $('<span>').addClass('myscript-wrapper');
wrapper.append(nodes.slice(marker, ul ? nodes.length-1 : nodes.length));
$(li).append(wrapper);
if ( ul ) {
$(li).append( ul );
}
}
});
$( '.myscript-wrapper' ).hide();
});
}
// //////////////////////////////////////////////////////////////////////////
/* Walk through of above code (with extensive remarks)
// Run only on view (not edit) pages. See [[mw:Manual:Interface/JavaScript#Page-specific]]
Line 112 ⟶ 109:
});
}
*/
/* Further notes (tutorial)
var i = 0;
i++;
// This runs immediately.
// It is safe to do things like this, UNLESS they need to change something in the page.
// You CAN use it to do data processing, start requests to the api etc.
// An anonymous function block wrapped inside $()
$( function() {
// do stuff to change the page
});
// $() is an alias for jQuery(), the main function of the jQuery library,
// which is always available for script writers on Wikipedia
// When used like this, it is a shortcut for $( document ).ready(), and it will
// execute your anonymous function as soon as the page is ready to be
// manipulated by JS, or immediately if it is ready now.
// See also: http://api.jquery.com/jquery/#jQuery3
// Attach a function to be run once the 'wikipage.content' part of a page is available
mw.hook( 'wikipage.content').add( function ($content ) {
// Like document.ready, this will run once that part of the page is
// ready/updated.
// $content is a jQuery list of DOM elements, that has just become available.
// See also: http://api.jquery.com/jquery/
});
// This is used by many scripts in MediaWiki, because it also works after
// saving with Visual Editor, or when previewing with Live preview tools etc.
// There are several such named hooks like:
// wikipage.diff, wikipage.editform, wikipage.categories
// mw, an alias for mediaWiki, is another javascript libary that is always
// available to MediaWiki and Wikipedia scripters.
// See also: https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw
// For the hook specific part of this library, which we use above, see:
// https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook
// Note that large parts of this mw library are not ready for usage by default,
// and you might have to load some parts using mw.loader, before they can be used.
// For loading dependencies and guaranteeing order between dependencies,
// use ResourceLoader.
// See also: https://www.mediawiki.org/wiki/ResourceLoader/Developing_with_ResourceLoader#Client-side_.28dynamically.29
*/
/*
|