From 1f091544b558a387de7d82c4917d2e4735ec65cd Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 19 Jan 2011 17:50:23 +0000 Subject: [PATCH] Followup r80554, r80575: wrap in (function( $ ) { ... })(jQuery); --- .../mediawiki.action/mediawiki.action.edit.js | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/resources/mediawiki.action/mediawiki.action.edit.js b/resources/mediawiki.action/mediawiki.action.edit.js index 032dc64745..e5b5095827 100644 --- a/resources/mediawiki.action/mediawiki.action.edit.js +++ b/resources/mediawiki.action/mediawiki.action.edit.js @@ -2,28 +2,29 @@ * has not been jQuery-ized. */ -//make sure edit summary does not exceed byte limit -$( '#wpSummary' ).attr( 'maxLength', 250 ).keypress( function( e ) { - // first check to see if this is actually a character key - // being pressed. - // Based on key-event info from http://unixpapa.com/js/key.html - // JQuery should also normalize e.which to be consistent cross-browser, - // however the same check is still needed regardless of jQuery. +(function( $ ) { + //make sure edit summary does not exceed byte limit + $( '#wpSummary' ).attr( 'maxLength', 250 ).keypress( function( e ) { + // first check to see if this is actually a character key + // being pressed. + // Based on key-event info from http://unixpapa.com/js/key.html + // JQuery should also normalize e.which to be consistent cross-browser, + // however the same check is still needed regardless of jQuery. - if ( e.which === 0 || e.charCode === 0 || e.ctrlKey || e.altKey || e.metaKey ) { - return true; //a special key (backspace, etc) so don't interfere. - } + if ( e.which === 0 || e.charCode === 0 || e.ctrlKey || e.altKey || e.metaKey ) { + return true; //a special key (backspace, etc) so don't interfere. + } - // This basically figures out how many bytes a UTF-16 string (which is what js sees) - // will take in UTF-8 by replacing a 2 byte character with 2 *'s, etc, and counting that. - // Note, surrogate (\uD800-\uDFFF) characters are counted as 2 bytes, since there's two of them - // and the actual character takes 4 bytes in UTF-8 (2*2=4). Might not work perfectly in edge cases - // such as illegal sequences, but that should never happen. - - var len = this.value.replace( /[\u0080-\u07FF\uD800-\uDFFF]/g, '**' ).replace( /[\u0800-\uD7FF\uE000-\uFFFF]/g, '***' ).length; - //247 as this doesn't count character about to be inserted. - if ( len > 247 ) { - e.preventDefault(); - } -}); + // This basically figures out how many bytes a UTF-16 string (which is what js sees) + // will take in UTF-8 by replacing a 2 byte character with 2 *'s, etc, and counting that. + // Note, surrogate (\uD800-\uDFFF) characters are counted as 2 bytes, since there's two of them + // and the actual character takes 4 bytes in UTF-8 (2*2=4). Might not work perfectly in edge cases + // such as illegal sequences, but that should never happen. + var len = this.value.replace( /[\u0080-\u07FF\uD800-\uDFFF]/g, '**' ).replace( /[\u0800-\uD7FF\uE000-\uFFFF]/g, '***' ).length; + //247 as this doesn't count character about to be inserted. + if ( len > 247 ) { + e.preventDefault(); + } + }); +})(jQuery); -- 2.20.1