Difference between revisions of "MediaWiki:Common.js"

From EAGLE MediaWiki
Jump to navigation Jump to search
m (fix)
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/* <nowiki>
 
  +
/*
*
 
  +
The actual script is at [[MediaWiki:AuthorityControl.js]].
* Adapted from AuthorityControl.js by [[User:Ricordisamoa]] at Wikidata
 
  +
This is needed in order to defer the loading of the code to make the script work correctly.
* Provides a link to various EAGLE Authority Control tools (EDH, ARACHNE, etc.)
 
  +
*/
* for EAGLEwiki elements that have related properties
 
*/
 
$( document ).ready( function() {
 
if( mw.config.get( 'wbEntityType' ) === 'item' ) { // only on items, not properties or other namespaces
 
var baseLanguage = mw.config.get( 'wgUserLanguage' ).replace( /^([a-z]*).*$/g, '$1' ),
 
properties = {
 
3: 'http://www.trismegistos.org/text/$1/', // Trismegistos
 
24: 'http://edh-www.adw.uni-heidelberg.de/edh/inschrift/$1', // Heidelberg
 
39: 'http://edh-www.adw.uni-heidelberg.de/edh/foto/$1', // Heidelberg-foto
 
   
};
 
  +
mw.loader.load('//www.eagle-network.eu/wiki/index.php?title=MediaWiki:AuthorityControl.js&action=raw&ctype=text/javascript');
$.each( properties, function( k, v ) {
 
  +
mw.loader.load('//www.eagle-network.eu/wiki/index.php?title=MediaWiki:Perseids-toolbar.js&action=raw&ctype=text/javascript');
var input = $( '.wb-snak-property a' ).filter( function() {
 
return new RegExp( 'Property:P' + k + '$' ).test( this.href );
 
} )
 
.parent()
 
.parent()
 
.parent()
 
.find( '.wb-snak-value .valueview-value textarea.valueview-input' );
 
if( input && input.size() > 0 ) {
 
input.each( function( i, e ) {
 
var id = $( e ).val();
 
if( k == 213 ) id = id.replace( / /g, '' );
 
var parent = $( e ).parents( '.wb-statement-claim' ).first();
 
if( parent.size() < 1 ) parent = $( e ).parents( '.wb-referenceview' ).first();
 
parent
 
.find( '.wb-editsection .wikibase-toolbarbutton' )
 
.click( function() { // show the textarea and hide the link when the user clicks 'edit'
 
$( e ).show().next().hide();
 
} );
 
$( e )
 
.hide() // 'replace' the textarea with the link
 
.after(
 
$( '<a>' )
 
.text( $( e ).val() )
 
.attr( 'href', v.replace( '$1', id ) )
 
.addClass( 'external' ) // show the 'external link' icon
 
);
 
} );
 
}
 
} );
 
}
 
} );
 
// </nowiki>
 

Latest revision as of 09:06, 26 September 2014

/*
	The actual script is at [[MediaWiki:AuthorityControl.js]].
	This is needed in order to defer the loading of the code to make the script work correctly.
*/

mw.loader.load('//www.eagle-network.eu/wiki/index.php?title=MediaWiki:AuthorityControl.js&action=raw&ctype=text/javascript');
mw.loader.load('//www.eagle-network.eu/wiki/index.php?title=MediaWiki:Perseids-toolbar.js&action=raw&ctype=text/javascript');