r80576 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80575‎ | r80576 | r80577 >
Date:17:50, 19 January 2011
Author:catrope
Status:ok
Tags:
Comment:
Followup r80554, r80575: wrap in (function( $ ) { ... })(jQuery);
Modified paths:
  • /trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js
@@ -2,28 +2,29 @@
33 * has not been jQuery-ized.
44 */
55
6 -//make sure edit summary does not exceed byte limit
7 -$( '#wpSummary' ).attr( 'maxLength', 250 ).keypress( function( e ) {
8 - // first check to see if this is actually a character key
9 - // being pressed.
10 - // Based on key-event info from http://unixpapa.com/js/key.html
11 - // JQuery should also normalize e.which to be consistent cross-browser,
12 - // however the same check is still needed regardless of jQuery.
 6+(function( $ ) {
 7+ //make sure edit summary does not exceed byte limit
 8+ $( '#wpSummary' ).attr( 'maxLength', 250 ).keypress( function( e ) {
 9+ // first check to see if this is actually a character key
 10+ // being pressed.
 11+ // Based on key-event info from http://unixpapa.com/js/key.html
 12+ // JQuery should also normalize e.which to be consistent cross-browser,
 13+ // however the same check is still needed regardless of jQuery.
1314
14 - if ( e.which === 0 || e.charCode === 0 || e.ctrlKey || e.altKey || e.metaKey ) {
15 - return true; //a special key (backspace, etc) so don't interfere.
16 - }
 15+ if ( e.which === 0 || e.charCode === 0 || e.ctrlKey || e.altKey || e.metaKey ) {
 16+ return true; //a special key (backspace, etc) so don't interfere.
 17+ }
1718
18 - // This basically figures out how many bytes a UTF-16 string (which is what js sees)
19 - // will take in UTF-8 by replacing a 2 byte character with 2 *'s, etc, and counting that.
20 - // Note, surrogate (\uD800-\uDFFF) characters are counted as 2 bytes, since there's two of them
21 - // and the actual character takes 4 bytes in UTF-8 (2*2=4). Might not work perfectly in edge cases
22 - // such as illegal sequences, but that should never happen.
 19+ // This basically figures out how many bytes a UTF-16 string (which is what js sees)
 20+ // will take in UTF-8 by replacing a 2 byte character with 2 *'s, etc, and counting that.
 21+ // Note, surrogate (\uD800-\uDFFF) characters are counted as 2 bytes, since there's two of them
 22+ // and the actual character takes 4 bytes in UTF-8 (2*2=4). Might not work perfectly in edge cases
 23+ // such as illegal sequences, but that should never happen.
2324
24 - var len = this.value.replace( /[\u0080-\u07FF\uD800-\uDFFF]/g, '**' ).replace( /[\u0800-\uD7FF\uE000-\uFFFF]/g, '***' ).length;
25 - //247 as this doesn't count character about to be inserted.
26 - if ( len > 247 ) {
27 - e.preventDefault();
28 - }
29 -});
30 -
 25+ var len = this.value.replace( /[\u0080-\u07FF\uD800-\uDFFF]/g, '**' ).replace( /[\u0800-\uD7FF\uE000-\uFFFF]/g, '***' ).length;
 26+ //247 as this doesn't count character about to be inserted.
 27+ if ( len > 247 ) {
 28+ e.preventDefault();
 29+ }
 30+ });
 31+})(jQuery);

Follow-up revisions

RevisionCommit summaryAuthorDate
r810001.17: MFT r80576, r80583, r80656, r80842, r80900, r80913, r80918, r80919, r80...catrope22:49, 25 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r80554(follow-up r66913) Per CR, make the editsummary length checker use jQuery/RL ...bawolff03:59, 19 January 2011
r80575Followup r80554: coding style, add varcatrope17:49, 19 January 2011

Status & tagging log