Difference between revisions of "MediaWiki:Perseids-toolbar.js"
Jump to navigation
Jump to search
(using javascript:void(0); instead of # for href) |
(implementing edit function) |
||
Line 1: | Line 1: | ||
− | function generateButton(type) { |
+ | 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 = { |
var pulsanti = { |
||
'edit': |
'edit': |
||
Line 5: | Line 5: | ||
.attr( { |
.attr( { |
||
'class': 'wikibase-toolbarbutton perseids-edit', |
'class': 'wikibase-toolbarbutton perseids-edit', |
||
− | 'href': |
+ | 'href': editUrl, |
} ) |
} ) |
||
.before( '|' ) |
.before( '|' ) |
||
− | .text( 'edit in Perseids' ) |
+ | .text( 'edit in Perseids' ), |
− | .click( function ( event ) { |
||
− | event.preventDefault(); |
||
− | } ), |
||
'save': |
'save': |
||
Line 17: | Line 17: | ||
} ) |
} ) |
||
.before( '|' ) |
.before( '|' ) |
||
− | .text( 'save to Perseids' ) |
+ | .text( 'save to Perseids' ), |
− | .click( function ( event ) { |
||
− | event.preventDefault(); |
||
− | } ), |
||
'add': |
'add': |
||
Line 23: | Line 23: | ||
.attr( { |
.attr( { |
||
'class': 'wikibase-toolbarbutton perseids-add', |
'class': 'wikibase-toolbarbutton perseids-add', |
||
− | 'href': |
+ | 'href': addUrl, |
} ) |
} ) |
||
.before( '|' ) |
.before( '|' ) |
||
− | .text( 'add via Perseids' ) |
+ | .text( 'add via Perseids' ), |
− | .click( function ( event ) { |
||
− | event.preventDefault(); |
||
− | } ), |
||
}; |
}; |
||
Line 32: | Line 32: | ||
} |
} |
||
− | $( '.wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar .wikibase-toolbarbutton:first-child' ) |
+ | $( '.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') |
+ | $( '.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') |
$( '.wikibase-toolbareditgroup-ineditmode .wikibase-toolbar .wikibase-toolbarbutton:first-child') |
Revision as of 16:00, 15 September 2014
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')); }); });