Difference between revisions of "MediaWiki:Perseids-toolbar.js"
Jump to navigation
Jump to search
| Line 16: | Line 16: | ||
'p15': 'fr', |
'p15': 'fr', |
||
'p18': 'si', |
'p18': 'si', |
||
| − | 'p61': 'se' |
+ | 'p61': 'se' |
}; |
}; |
||
| Line 55: | Line 55: | ||
.attr( { |
.attr( { |
||
'class': 'wikibase-toolbarbutton perseids-edit', |
'class': 'wikibase-toolbarbutton perseids-edit', |
||
| − | 'href': editUrl |
+ | 'href': editUrl |
} ) |
} ) |
||
.before( '|' ) |
.before( '|' ) |
||
| Line 78: | Line 78: | ||
.attr( { |
.attr( { |
||
'class': 'wikibase-toolbarbutton perseids-add', |
'class': 'wikibase-toolbarbutton perseids-add', |
||
| − | 'href': addUrl |
+ | 'href': addUrl |
} ) |
} ) |
||
.before( '|' ) |
.before( '|' ) |
||
.text( 'add via Perseids' ); |
.text( 'add via Perseids' ); |
||
| + | |||
| + | $(this).after(addButton); |
||
| + | } |
||
| + | |||
| + | function makeLanguageSelector() { |
||
| + | |||
| + | var addselector = $('<select>') |
||
| + | .before( '|' ) |
||
| + | .text( 'select language for new statement' ); |
||
| + | |||
| + | |||
| + | } |
||
| + | function makeAddStatementButton() { |
||
| + | |||
| + | var uri_template = $(".wikibase-toolbarbutton perseids-add").attr("href") |
||
| + | var lang = $("#language_selector").val(); |
||
| + | var new_uri = uri_template + "&lang="+ lang |
||
| + | $(".wikibase-toolbarbutton perseids-add").attr("href",new_uri) |
||
| + | |||
| + | var addUrl = 'http://sosol.perseids.org/sosol/cts_publications/create_from_agent?agent=' |
||
| + | + 'http://www.eagle-network.eu&id=' + itemId + '&lang=' + langCode; |
||
| + | |||
| + | var addButton = $( '<a>' ) |
||
| + | .attr( { |
||
| + | 'class': 'wikibase-toolbarbutton perseids-add', |
||
| + | 'href': addUrl |
||
| + | } ) |
||
| + | .before( '|' ) |
||
| + | .text( 'add new statement via Perseids' ); |
||
$(this).after(addButton); |
$(this).after(addButton); |
||
| Line 105: | Line 134: | ||
jQuery(document).ready(function() { |
jQuery(document).ready(function() { |
||
| − | // Only displays the buttons if the item has a Trismegistos ID. |
+ | // Only displays the buttons if the item has a Trismegistos ID or an idest. |
if($('.wb-claims .wb-claim-section-p3').length === 0 && $('.wb-claims .wb-claim-section-p69').length === 0 ) { |
if($('.wb-claims .wb-claim-section-p3').length === 0 && $('.wb-claims .wb-claim-section-p69').length === 0 ) { |
||
return; |
return; |
||
| Line 113: | Line 142: | ||
$( '.wb-claimlist .wb-statement-claim .wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar .wikibase-toolbarbutton:first-child' ) |
$( '.wb-claimlist .wb-statement-claim .wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar .wikibase-toolbarbutton:first-child' ) |
||
.each(makeEditButton); |
.each(makeEditButton); |
||
| + | |||
| + | // Add language selector |
||
| + | $( '.wb-claimlist .wikibase-toolbar wb-addtoolbar .wb-editsection .wikibase-toolbar .wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar a.wikibase-toolbarbutton:first-child') |
||
| + | .each(makeLanguageSelector); |
||
| + | |||
| + | // AddNew Statement buttons |
||
| + | $( '.wb-claimlist .wikibase-toolbar wb-addtoolbar .wb-editsection .wikibase-toolbar .wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar a.wikibase-toolbarbutton:second-child') |
||
| + | .each(makeAddStatementButton); |
||
// Add buttons |
// Add buttons |
||
Revision as of 16:24, 23 July 2015
// For each translation property, this function returns the translation language code.
function langFromProperty(prop) {
// prop: p1, p2, p13, ...
// returns null if the property is not a translation
var propToLang = {
'p11': 'en',
'p13': 'it',
'p16': 'el',
'p19': 'hu',
'p14': 'es',
'p17': 'ru',
'p20': 'ro',
'p57': 'hr',
'p12': 'de',
'p15': 'fr',
'p18': 'si',
'p61': 'se'
};
if (prop in propToLang)
return propToLang[prop];
else
return null;
}
// Returns the name of the property, e.g. 'p59'
function getAssociatedProperty(elem) {
var theClass = elem.parents('.wb-claim-section').attr('class').split(' ')[1];
return theClass.replace('wb-claim-section-', '');
}
// Returns claim ID
function getAssociatedClaim(elem) {
var claimClass = elem.parents('.wb-statement-claim').find('.wb-claim').attr('class').split(' ')[1];
return claimClass.replace('wb-claim-', '');
}
// These functions generate and attach the buttons.
function makeEditButton() {
var itemId = wb.entity.getId();
var claimId = getAssociatedClaim($(this));
var langProp = getAssociatedProperty($(this));
var langCode = langFromProperty(langProp);
if(!langCode) // only for translation claims
return;
var editUrl = 'http://sosol.perseids.org/sosol/cts_publications/create_from_agent?agent='
+ 'http://www.eagle-network.eu&id=' + itemId + '&filter=' + claimId;
var editButton = $( '<a>' )
.attr( {
'class': 'wikibase-toolbarbutton perseids-edit',
'href': editUrl
} )
.before( '|' )
.text( 'edit in Perseids' );
$(this).after(editButton);
}
function makeAddButton() {
var itemId = wb.entity.getId();
var langProp = getAssociatedProperty($(this));
var langCode = langFromProperty(langProp);
if(!langCode) // only for translation claims
return;
var addUrl = 'http://sosol.perseids.org/sosol/cts_publications/create_from_agent?agent='
+ 'http://www.eagle-network.eu&id=' + itemId + '&lang=' + langCode;
var addButton = $( '<a>' )
.attr( {
'class': 'wikibase-toolbarbutton perseids-add',
'href': addUrl
} )
.before( '|' )
.text( 'add via Perseids' );
$(this).after(addButton);
}
function makeLanguageSelector() {
var addselector = $('<select>')
.before( '|' )
.text( 'select language for new statement' );
}
function makeAddStatementButton() {
var uri_template = $(".wikibase-toolbarbutton perseids-add").attr("href")
var lang = $("#language_selector").val();
var new_uri = uri_template + "&lang="+ lang
$(".wikibase-toolbarbutton perseids-add").attr("href",new_uri)
var addUrl = 'http://sosol.perseids.org/sosol/cts_publications/create_from_agent?agent='
+ 'http://www.eagle-network.eu&id=' + itemId + '&lang=' + langCode;
var addButton = $( '<a>' )
.attr( {
'class': 'wikibase-toolbarbutton perseids-add',
'href': addUrl
} )
.before( '|' )
.text( 'add new statement via Perseids' );
$(this).after(addButton);
}
function makeSaveButton() {
var langProp = getAssociatedProperty($(this));
var langCode = langFromProperty(langProp);
if(!langCode) // only for translation claims
return;
var saveButton = $( '<a>' )
.attr( {
'class': 'wikibase-toolbarbutton perseids-save',
'href': 'javascript:void(0);'
} )
.before( '|' )
.text( 'save to Perseids' );
$(this).after(saveButton);
}
jQuery(document).ready(function() {
// Only displays the buttons if the item has a Trismegistos ID or an idest.
if($('.wb-claims .wb-claim-section-p3').length === 0 && $('.wb-claims .wb-claim-section-p69').length === 0 ) {
return;
}
// Edit buttons
$( '.wb-claimlist .wb-statement-claim .wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar .wikibase-toolbarbutton:first-child' )
.each(makeEditButton);
// Add language selector
$( '.wb-claimlist .wikibase-toolbar wb-addtoolbar .wb-editsection .wikibase-toolbar .wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar a.wikibase-toolbarbutton:first-child')
.each(makeLanguageSelector);
// AddNew Statement buttons
$( '.wb-claimlist .wikibase-toolbar wb-addtoolbar .wb-editsection .wikibase-toolbar .wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar a.wikibase-toolbarbutton:second-child')
.each(makeAddStatementButton);
// Add buttons
$( '.wb-claimlist .wb-claim-section > .wb-addtoolbar .wb-editsection a.wikibase-toolbarbutton:first-child')
.each(makeAddButton);
// When I click on "edit"...
$( '.wb-claimlist .wb-statement-claim .wikibase-toolbareditgroup .wikibase-toolbarbutton:first-child:not(.wikibase-toolbarbutton-disabled)' ).click(function () {
// I make the "save to Perseids" button
$( '.wb-claimlist .wb-statement-claim .wikibase-toolbareditgroup-ineditmode .wikibase-toolbar:not(:has(.perseids-save)) .wikibase-toolbarbutton:first-child')
.each(makeSaveButton);
// Click on "undo": recreates "edit" button
$( '.wb-claimlist .wb-statement-claim .wikibase-toolbareditgroup-ineditmode .wikibase-toolbar .wikibase-toolbarbutton:last-child').click(function(){
$( '.wb-claimlist .wb-statement-claim .wikibase-toolbareditgroup-innoneditmode .wikibase-toolbar:not(:has(.perseids-edit)) .wikibase-toolbarbutton:first-child' )
.each(makeEditButton);
});
});
});