MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
$.fn.bindFirst = function(name, fn) { | |||
// bind as you normally would | |||
// don't want to miss out on any jQuery magic | |||
this.bind(name, fn); | |||
// Thanks to a comment by @Martin, adding support for | |||
// namespaced events too. | |||
var handlers = this.data('events')[name.split('.')[0]]; | |||
// take out the handler we just inserted from the end | |||
var handler = handlers.pop(); | |||
// move it at the beginning | |||
handlers.splice(0, 0, handler); | |||
}; | |||
$(function () { | $(function () { | ||
$(document).keydown | $(document).bindfirst("keydown",function(event){ | ||
if(event.target.name ==="search" && event.keyCode === 13){ | if(event.target.name ==="search" && event.keyCode === 13){ | ||
event.preventDefault(); | event.preventDefault(); |
Revision as of 18:53, 15 January 2024
/* Any JavaScript here will be loaded for all users on every page load. */
$.fn.bindFirst = function(name, fn) {
// bind as you normally would
// don't want to miss out on any jQuery magic
this.bind(name, fn);
// Thanks to a comment by @Martin, adding support for
// namespaced events too.
var handlers = this.data('events')[name.split('.')[0]];
// take out the handler we just inserted from the end
var handler = handlers.pop();
// move it at the beginning
handlers.splice(0, 0, handler);
};
$(function () {
$(document).bindfirst("keydown",function(event){
if(event.target.name ==="search" && event.keyCode === 13){
event.preventDefault();
alert($(event.target).val());
//$(event.target).closest(".cdx-search-input").find(".cdx-search-input__end-button").click();
}
});
});