MediaWiki:Gadget-KeyShortcuts.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Ricordisamoa (talk | contribs) |
Ricordisamoa (talk | contribs) fix element selectors and offsets per request by Jon Harald Søby. Thanks for reporting! |
||
Line 8: | Line 8: | ||
$( document ).ready( function () { |
$( document ).ready( function () { |
||
var addStatement = function () { |
var addStatement = function () { |
||
$( '. |
$( '.wikibase-toolbar-button-add' ).last().find( 'a' ).first().click(); |
||
}, |
}, |
||
editLabel = function () { |
editLabel = function () { |
||
var eb = $( '.wb- |
var eb = $( '.wb-firstHeading .wikibase-labelview .wikibase-toolbar-button-edit a' ); |
||
if ( eb.length === 1 ) { |
if ( eb.length === 1 ) { |
||
eb.first().click(); |
eb.first().click(); |
||
} else { |
} else { |
||
$( '.wb- |
$( '.wb-firstHeading .wikibase-labelview .wikibase-labelview-text input' ).focus(); |
||
} |
} |
||
}, |
}, |
||
editDescription = function () { |
editDescription = function () { |
||
var eb = $( '.wb- |
var eb = $( '.wb-firstHeading + .wikibase-descriptionview .wikibase-toolbar-button-edit a' ); |
||
if ( eb.length === 1 ) { |
if ( eb.length === 1 ) { |
||
eb.first().click(); |
eb.first().click(); |
||
} else { |
} else { |
||
$( '.wb- |
$( '.wb-firstHeading + .wikibase-descriptionview .wikibase-descriptionview-text input' ).focus(); |
||
} |
} |
||
}, |
}, |
||
scrollToStatements = function () { |
scrollToStatements = function () { |
||
$( 'html, body' ).animate( { |
$( 'html, body' ).animate( { |
||
scrollTop: $( ' |
scrollTop: $( '#claims' ).offset().top |
||
}, 400 ); |
}, 400 ); |
||
}, |
}, |
||
scrollToSitelinks = function () { |
scrollToSitelinks = function () { |
||
$( 'html, body' ).animate( { |
$( 'html, body' ).animate( { |
||
scrollTop: $( '. |
scrollTop: $( '.wikibase-sitelinkgroupview-heading' ).first().offset().top |
||
}, 400 ); |
}, 400 ); |
||
}; |
}; |
Revision as of 15:13, 12 December 2014
/* <nowiki>
*
* KeyShortcuts.js by [[User:Ricordisamoa]]
* provides some useful keyboard shortcuts on the Wikidata GUI
*
* based on [[Wikidata talk:Tools#Keyboard shortcuts|this suggestion]] by [[User:Jon Harald Søby]]
*/
$( document ).ready( function () {
var addStatement = function () {
$( '.wikibase-toolbar-button-add' ).last().find( 'a' ).first().click();
},
editLabel = function () {
var eb = $( '.wb-firstHeading .wikibase-labelview .wikibase-toolbar-button-edit a' );
if ( eb.length === 1 ) {
eb.first().click();
} else {
$( '.wb-firstHeading .wikibase-labelview .wikibase-labelview-text input' ).focus();
}
},
editDescription = function () {
var eb = $( '.wb-firstHeading + .wikibase-descriptionview .wikibase-toolbar-button-edit a' );
if ( eb.length === 1 ) {
eb.first().click();
} else {
$( '.wb-firstHeading + .wikibase-descriptionview .wikibase-descriptionview-text input' ).focus();
}
},
scrollToStatements = function () {
$( 'html, body' ).animate( {
scrollTop: $( '#claims' ).offset().top
}, 400 );
},
scrollToSitelinks = function () {
$( 'html, body' ).animate( {
scrollTop: $( '.wikibase-sitelinkgroupview-heading' ).first().offset().top
}, 400 );
};
$( this )
.keydown( function ( event ) {
if ( $( ':focus' ).length === 0 ) {
switch ( event.keyCode ) {
case 65: addStatement();return false; // A
case 68: editDescription();return false; // D
case 73: scrollToSitelinks();return false; // I
case 76: editLabel();return false; // L
case 83: scrollToStatements();return false; // S
}
}
} );
} );