Index: trunk/phase3/CREDITS |
— | — | @@ -92,6 +92,7 @@ |
93 | 93 | * FunPika |
94 | 94 | * Harry Burt |
95 | 95 | * Ireas |
| 96 | +* Jan Paul Posma |
96 | 97 | * Jaska Zedlik |
97 | 98 | * Jeremy Baron |
98 | 99 | * Jidanni |
Index: trunk/phase3/resources/jquery/jquery.byteLimit.js |
— | — | @@ -0,0 +1,41 @@ |
| 2 | +/** |
| 3 | + * jQuery byteLimit |
| 4 | + */ |
| 5 | +( function( $ ) { |
| 6 | + |
| 7 | + /** |
| 8 | + * Enforces a byte limit to a textbox, so that UTF-8 entries are not arbitrarily truncated. |
| 9 | + */ |
| 10 | + $.fn.byteLimit = function( limit ) { |
| 11 | + return $(this).attr( 'maxLength', limit ).keypress( function( e ) { |
| 12 | + // first check to see if this is actually a character key |
| 13 | + // being pressed. |
| 14 | + // Based on key-event info from http://unixpapa.com/js/key.html |
| 15 | + // jQuery should also normalize e.which to be consistent cross-browser, |
| 16 | + // however the same check is still needed regardless of jQuery. |
| 17 | + |
| 18 | + // Note: At the moment, for some older opera versions (~< 10.5) |
| 19 | + // some special keys won't be recognized (aka left arrow key). |
| 20 | + // Backspace will be, so not big issue. |
| 21 | + |
| 22 | + if ( e.which === 0 || e.charCode === 0 || e.which === 8 || |
| 23 | + e.ctrlKey || e.altKey || e.metaKey ) |
| 24 | + { |
| 25 | + return true; //a special key (backspace, etc) so don't interfere. |
| 26 | + } |
| 27 | + |
| 28 | + // This basically figures out how many bytes a UTF-16 string (which is what js sees) |
| 29 | + // will take in UTF-8 by replacing a 2 byte character with 2 *'s, etc, and counting that. |
| 30 | + // Note, surrogate (\uD800-\uDFFF) characters are counted as 2 bytes, since there's two of them |
| 31 | + // and the actual character takes 4 bytes in UTF-8 (2*2=4). Might not work perfectly in edge cases |
| 32 | + // such as illegal sequences, but that should never happen. |
| 33 | + |
| 34 | + var len = this.value.replace( /[\u0080-\u07FF\uD800-\uDFFF]/g, '**' ).replace( /[\u0800-\uD7FF\uE000-\uFFFF]/g, '***' ).length; |
| 35 | + // limit-3 as this doesn't count character about to be inserted. |
| 36 | + if ( len > ( limit-3 ) ) { |
| 37 | + e.preventDefault(); |
| 38 | + } |
| 39 | + }); |
| 40 | + }; |
| 41 | + |
| 42 | +} )( jQuery ); |
Property changes on: trunk/phase3/resources/jquery/jquery.byteLimit.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 43 | + native |
Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js |
— | — | @@ -51,37 +51,8 @@ |
52 | 52 | window.insertTags = mw.toolbar.insertTags; |
53 | 53 | |
54 | 54 | //make sure edit summary does not exceed byte limit |
55 | | - $( '#wpSummary' ).attr( 'maxLength', 250 ).keypress( function( e ) { |
56 | | - // first check to see if this is actually a character key |
57 | | - // being pressed. |
58 | | - // Based on key-event info from http://unixpapa.com/js/key.html |
59 | | - // jQuery should also normalize e.which to be consistent cross-browser, |
60 | | - // however the same check is still needed regardless of jQuery. |
61 | | - |
62 | | - // Note: At the moment, for some older opera versions (~< 10.5) |
63 | | - // some special keys won't be recognized (aka left arrow key). |
64 | | - // Backspace will be, so not big issue. |
65 | | - |
66 | | - if ( e.which === 0 || e.charCode === 0 || e.which === 8 || |
67 | | - e.ctrlKey || e.altKey || e.metaKey ) |
68 | | - { |
69 | | - return true; //a special key (backspace, etc) so don't interfere. |
70 | | - } |
71 | | - |
72 | | - // This basically figures out how many bytes a UTF-16 string (which is what js sees) |
73 | | - // will take in UTF-8 by replacing a 2 byte character with 2 *'s, etc, and counting that. |
74 | | - // Note, surrogate (\uD800-\uDFFF) characters are counted as 2 bytes, since there's two of them |
75 | | - // and the actual character takes 4 bytes in UTF-8 (2*2=4). Might not work perfectly in edge cases |
76 | | - // such as illegal sequences, but that should never happen. |
77 | | - |
78 | | - var len = this.value.replace( /[\u0080-\u07FF\uD800-\uDFFF]/g, '**' ).replace( /[\u0800-\uD7FF\uE000-\uFFFF]/g, '***' ).length; |
79 | | - //247 as this doesn't count character about to be inserted. |
80 | | - if ( len > 247 ) { |
81 | | - e.preventDefault(); |
82 | | - } |
83 | | - }); |
| 55 | + $( '#wpSummary' ).byteLimit( 250 ); |
84 | 56 | |
85 | | - |
86 | 57 | $( document ).ready( function() { |
87 | 58 | /** |
88 | 59 | * Restore the edit box scroll state following a preview operation, |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -73,6 +73,9 @@ |
74 | 74 | 'scripts' => 'resources/jquery/jquery.autoEllipsis.js', |
75 | 75 | 'dependencies' => 'jquery.highlightText', |
76 | 76 | ), |
| 77 | + 'jquery.byteLimit' => array( |
| 78 | + 'scripts' => 'resources/jquery/jquery.byteLimit.js', |
| 79 | + ), |
77 | 80 | 'jquery.checkboxShiftClick' => array( |
78 | 81 | 'scripts' => 'resources/jquery/jquery.checkboxShiftClick.js', |
79 | 82 | ), |
— | — | @@ -415,7 +418,10 @@ |
416 | 419 | ), |
417 | 420 | 'mediawiki.action.edit' => array( |
418 | 421 | 'scripts' => 'resources/mediawiki.action/mediawiki.action.edit.js', |
419 | | - 'dependencies' => 'jquery.textSelection', |
| 422 | + 'dependencies' => array( |
| 423 | + 'jquery.textSelection', |
| 424 | + 'jquery.byteLimit', |
| 425 | + ), |
420 | 426 | ), |
421 | 427 | 'mediawiki.action.view.rightClickEdit' => array( |
422 | 428 | 'scripts' => 'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js', |