wiki.techinc.nl/resources/mediawiki.special/mediawiki.special.block.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

/* JavaScript for Special:Block */
Moving IP-check to mw.util & some enhancements to and applying code conventions to mw.special.block.js * This commit addresses the @TODOs that were in mediawiki.legacy.block before it was migrated to /resources in r83183 ("@TODO: find some better JS file for [is IP functions]") * JSHint warning fixed: Using ==== when comparing to '' (safer and faster than ==) * Instead of checking the initial onload state by faking a onkeyup/onchange event, seperate the two functions and use those ** --> This fixes issue where it falsely triggers other bindings on-load that are globally bound to input elements via $('input').live() or $('[type="text"]').delegate() because of the .keyup()/.change() call ) * Caching selectors (var $wpBlockExpiry = $(..) etc.) instead of re-creating a dozen jQuery objects again and getting the document element by id – on *every* onkeyup/onchange ** --> Notable speed improvement in Safari 3 and IE6 with the caching, these had a little bit of a lag when typing fast, mw.legacy.block.js had the lag as well. Fixed now. * Adding instantToggle-argument to switch between fade or hiding/showing right away. When setting the initial state they're called with instant=true so that there's no fading, the page loads and stuff hides that shouldn't be visible. Any later interaction will still have the fade. ** Calling a function like foo(true) sucks, adding a local DO_INSTANT = true. * Making behaviour the same as the legacy.block was (if isEmpty, do bring the element back to view ( show() / fadeIn) instead of doing nothing)
2011-03-04 01:48:24 +00:00
jQuery( function( $ ) {
Moving IP-check to mw.util & some enhancements to and applying code conventions to mw.special.block.js * This commit addresses the @TODOs that were in mediawiki.legacy.block before it was migrated to /resources in r83183 ("@TODO: find some better JS file for [is IP functions]") * JSHint warning fixed: Using ==== when comparing to '' (safer and faster than ==) * Instead of checking the initial onload state by faking a onkeyup/onchange event, seperate the two functions and use those ** --> This fixes issue where it falsely triggers other bindings on-load that are globally bound to input elements via $('input').live() or $('[type="text"]').delegate() because of the .keyup()/.change() call ) * Caching selectors (var $wpBlockExpiry = $(..) etc.) instead of re-creating a dozen jQuery objects again and getting the document element by id – on *every* onkeyup/onchange ** --> Notable speed improvement in Safari 3 and IE6 with the caching, these had a little bit of a lag when typing fast, mw.legacy.block.js had the lag as well. Fixed now. * Adding instantToggle-argument to switch between fade or hiding/showing right away. When setting the initial state they're called with instant=true so that there's no fading, the page loads and stuff hides that shouldn't be visible. Any later interaction will still have the fade. ** Calling a function like foo(true) sucks, adding a local DO_INSTANT = true. * Making behaviour the same as the legacy.block was (if isEmpty, do bring the element back to view ( show() / fadeIn) instead of doing nothing)
2011-03-04 01:48:24 +00:00
var DO_INSTANT = true,
$blockTarget = $( '#mw-bi-target' ),
2011-10-01 06:16:08 +00:00
$anonOnlyRow = $( '#mw-input-wpHardBlock' ).closest( 'tr' ),
$enableAutoblockRow = $( '#mw-input-wpAutoBlock' ).closest( 'tr' ),
$hideUser = $( '#mw-input-wpHideUser' ).closest( 'tr' ),
$watchUser = $( '#mw-input-wpWatch' ).closest( 'tr' );
Moving IP-check to mw.util & some enhancements to and applying code conventions to mw.special.block.js * This commit addresses the @TODOs that were in mediawiki.legacy.block before it was migrated to /resources in r83183 ("@TODO: find some better JS file for [is IP functions]") * JSHint warning fixed: Using ==== when comparing to '' (safer and faster than ==) * Instead of checking the initial onload state by faking a onkeyup/onchange event, seperate the two functions and use those ** --> This fixes issue where it falsely triggers other bindings on-load that are globally bound to input elements via $('input').live() or $('[type="text"]').delegate() because of the .keyup()/.change() call ) * Caching selectors (var $wpBlockExpiry = $(..) etc.) instead of re-creating a dozen jQuery objects again and getting the document element by id – on *every* onkeyup/onchange ** --> Notable speed improvement in Safari 3 and IE6 with the caching, these had a little bit of a lag when typing fast, mw.legacy.block.js had the lag as well. Fixed now. * Adding instantToggle-argument to switch between fade or hiding/showing right away. When setting the initial state they're called with instant=true so that there's no fading, the page loads and stuff hides that shouldn't be visible. Any later interaction will still have the fade. ** Calling a function like foo(true) sucks, adding a local DO_INSTANT = true. * Making behaviour the same as the legacy.block was (if isEmpty, do bring the element back to view ( show() / fadeIn) instead of doing nothing)
2011-03-04 01:48:24 +00:00
var updateBlockOptions = function( instant ) {
if ( !$blockTarget.length ) {
return;
}
Moving IP-check to mw.util & some enhancements to and applying code conventions to mw.special.block.js * This commit addresses the @TODOs that were in mediawiki.legacy.block before it was migrated to /resources in r83183 ("@TODO: find some better JS file for [is IP functions]") * JSHint warning fixed: Using ==== when comparing to '' (safer and faster than ==) * Instead of checking the initial onload state by faking a onkeyup/onchange event, seperate the two functions and use those ** --> This fixes issue where it falsely triggers other bindings on-load that are globally bound to input elements via $('input').live() or $('[type="text"]').delegate() because of the .keyup()/.change() call ) * Caching selectors (var $wpBlockExpiry = $(..) etc.) instead of re-creating a dozen jQuery objects again and getting the document element by id – on *every* onkeyup/onchange ** --> Notable speed improvement in Safari 3 and IE6 with the caching, these had a little bit of a lag when typing fast, mw.legacy.block.js had the lag as well. Fixed now. * Adding instantToggle-argument to switch between fade or hiding/showing right away. When setting the initial state they're called with instant=true so that there's no fading, the page loads and stuff hides that shouldn't be visible. Any later interaction will still have the fade. ** Calling a function like foo(true) sucks, adding a local DO_INSTANT = true. * Making behaviour the same as the legacy.block was (if isEmpty, do bring the element back to view ( show() / fadeIn) instead of doing nothing)
2011-03-04 01:48:24 +00:00
var blocktarget = $.trim( $blockTarget.val() );
var isEmpty = ( blocktarget === '' );
var isIp = mw.util.isIPv4Address( blocktarget, true ) || mw.util.isIPv6Address( blocktarget, true );
var isIpRange = isIp && blocktarget.match( /\/\d+$/ );
if ( isIp && !isEmpty ) {
$enableAutoblockRow.goOut( instant );
$hideUser.goOut( instant );
} else {
Moving IP-check to mw.util & some enhancements to and applying code conventions to mw.special.block.js * This commit addresses the @TODOs that were in mediawiki.legacy.block before it was migrated to /resources in r83183 ("@TODO: find some better JS file for [is IP functions]") * JSHint warning fixed: Using ==== when comparing to '' (safer and faster than ==) * Instead of checking the initial onload state by faking a onkeyup/onchange event, seperate the two functions and use those ** --> This fixes issue where it falsely triggers other bindings on-load that are globally bound to input elements via $('input').live() or $('[type="text"]').delegate() because of the .keyup()/.change() call ) * Caching selectors (var $wpBlockExpiry = $(..) etc.) instead of re-creating a dozen jQuery objects again and getting the document element by id – on *every* onkeyup/onchange ** --> Notable speed improvement in Safari 3 and IE6 with the caching, these had a little bit of a lag when typing fast, mw.legacy.block.js had the lag as well. Fixed now. * Adding instantToggle-argument to switch between fade or hiding/showing right away. When setting the initial state they're called with instant=true so that there's no fading, the page loads and stuff hides that shouldn't be visible. Any later interaction will still have the fade. ** Calling a function like foo(true) sucks, adding a local DO_INSTANT = true. * Making behaviour the same as the legacy.block was (if isEmpty, do bring the element back to view ( show() / fadeIn) instead of doing nothing)
2011-03-04 01:48:24 +00:00
$enableAutoblockRow.goIn( instant );
$hideUser.goIn( instant );
}
Moving IP-check to mw.util & some enhancements to and applying code conventions to mw.special.block.js * This commit addresses the @TODOs that were in mediawiki.legacy.block before it was migrated to /resources in r83183 ("@TODO: find some better JS file for [is IP functions]") * JSHint warning fixed: Using ==== when comparing to '' (safer and faster than ==) * Instead of checking the initial onload state by faking a onkeyup/onchange event, seperate the two functions and use those ** --> This fixes issue where it falsely triggers other bindings on-load that are globally bound to input elements via $('input').live() or $('[type="text"]').delegate() because of the .keyup()/.change() call ) * Caching selectors (var $wpBlockExpiry = $(..) etc.) instead of re-creating a dozen jQuery objects again and getting the document element by id – on *every* onkeyup/onchange ** --> Notable speed improvement in Safari 3 and IE6 with the caching, these had a little bit of a lag when typing fast, mw.legacy.block.js had the lag as well. Fixed now. * Adding instantToggle-argument to switch between fade or hiding/showing right away. When setting the initial state they're called with instant=true so that there's no fading, the page loads and stuff hides that shouldn't be visible. Any later interaction will still have the fade. ** Calling a function like foo(true) sucks, adding a local DO_INSTANT = true. * Making behaviour the same as the legacy.block was (if isEmpty, do bring the element back to view ( show() / fadeIn) instead of doing nothing)
2011-03-04 01:48:24 +00:00
if ( !isIp && !isEmpty ) {
$anonOnlyRow.goOut( instant );
} else {
$anonOnlyRow.goIn( instant );
}
if ( isIpRange && !isEmpty ) {
$watchUser.goOut( instant );
} else {
$watchUser.goIn( instant );
}
};
// Bind functions so they're checked whenever stuff changes
$blockTarget.keyup( updateBlockOptions );
// Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
updateBlockOptions( DO_INSTANT );
2011-10-01 06:16:08 +00:00
});