MediaWiki:Gadget-KeyShortcuts.js: Difference between revisions

From Wikidata
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 () {
$( '.wb-claims .wb-editsection' ).last().find( '.wikibase-toolbarbutton' ).click();
$( '.wikibase-toolbar-button-add' ).last().find( 'a' ).first().click();
},
},
editLabel = function () {
editLabel = function () {
var eb = $( '.wb-ui-labeledittool .wikibase-toolbarbutton' );
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-ui-labeledittool input.wb-ui-propertyedittool-editablevalueinterface' ).focus();
$( '.wb-firstHeading .wikibase-labelview .wikibase-labelview-text input' ).focus();
}
}
},
},
editDescription = function () {
editDescription = function () {
var eb = $( '.wb-description .wikibase-toolbarbutton' );
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-description input.wb-ui-propertyedittool-editablevalueinterface' ).focus();
$( '.wb-firstHeading + .wikibase-descriptionview .wikibase-descriptionview-text input' ).focus();
}
}
},
},
scrollToStatements = function () {
scrollToStatements = function () {
$( 'html, body' ).animate( {
$( 'html, body' ).animate( {
scrollTop: $( '.wb-claims .wb-claimlist' ).first().offset().top + 20
scrollTop: $( '#claims' ).offset().top
}, 400 );
}, 400 );
},
},
scrollToSitelinks = function () {
scrollToSitelinks = function () {
$( 'html, body' ).animate( {
$( 'html, body' ).animate( {
scrollTop: $( '.wb-sitelinks' ).first().prev().offset().top + 20
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
			}
		 }
	} );
} );