MediaWiki:Perseids-toolbar.js

From EAGLE MediaWiki
Revision as of 16:02, 15 September 2014 by Pietrodn (talk | contribs)
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
function generateButton(type, itemId, claimId, lang) {
	
	var editUrl = 'http://sosol.perseids.org/sosol/cts_publications/create_from_agent?agent='
		+ 'http://www.eagle-network.eu&id=' + itemId + '&filter=' + claimId;
	var addUrl = 'http://sosol.perseids.org/sosol/cts_publications/create_from_agent?agent='
		+ 'http://www.eagle-network.eu&id=' + itemId + '&lang=' + lang;
	
	var pulsanti = {
		'edit':
			$( '<a>' )
			.attr( {
				'class': 'wikibase-toolbarbutton perseids-edit',
				'href': editUrl,
			} )
			.before( '|' )
			.text( 'edit in Perseids' ),
		
		'save':
			$( '<a>' )
			.attr( {
				'class': 'wikibase-toolbarbutton perseids-save',
				'href': 'javascript:void(0);'
			} )
			.before( '|' )
			.text( 'save to Perseids' ),
		
		'add':
			$( '<a>' )
			.attr( {
				'class': 'wikibase-toolbarbutton perseids-add',
				'href': addUrl,
			} )
			.before( '|' )
			.text( 'add via Perseids' ),
	};
	
	return pulsanti[type].clone();
}

$( '.wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar .wikibase-toolbarbutton:first-child' ).each(function(){
	var itemId = wb.entity.getId();
	var claimId = $(this).parents('.wb-statement-claim').find('.wb-claim').attr('class').split(' ')[1];
	
	$(this).after(generateButton('edit', itemId, claimId, null));
});

$( '.wb-addtoolbar .wb-editsection a.wikibase-toolbarbutton:first-child').each(function(){
	var itemId = wb.entity.getId();
	$(this).after(generateButton('add', itemId, null, 'EN'));
});

$( '.wikibase-toolbareditgroup-ineditmode .wikibase-toolbar .wikibase-toolbarbutton:first-child')
	.after(generateButton('save'));

/* Quando clicco sul pulsante "edit"... */
$( '.wikibase-toolbareditgroup .wikibase-toolbarbutton:first-child:not(.wikibase-toolbarbutton-disabled)' ).click(function () {
	/* Genero il pulsante "save to Perseids" */
	$( '.wikibase-toolbareditgroup-ineditmode .wikibase-toolbar:not(:has(.perseids-save)) .wikibase-toolbarbutton:first-child')
		.after(generateButton('save'));
	
	/* Click su "annulla": rigenero il pulsante "edit" */
	$( '.wikibase-toolbareditgroup-ineditmode .wikibase-toolbar .wikibase-toolbarbutton:last-child').click(function(){
		$( '.wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar:not(:has(.perseids-edit)) .wikibase-toolbarbutton:first-child' ).after(generateButton('edit'));
	});
});