r85320 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85319‎ | r85320 | r85321 >
Date:09:02, 4 April 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
In translation dialog, made input elements grow automatically.
Modified paths:
  • /trunk/extensions/Translate/Translate.css (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/js/jquery.autoresize.js (added) (history)
  • /trunk/extensions/Translate/js/quickedit.js (modified) (history)
  • /trunk/extensions/Translate/utils/MessageTable.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationEditPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.css
@@ -66,6 +66,13 @@
6767 font-size: small;
6868 }
6969
 70+.mw-ajax-dialog #summary {
 71+ width: 5em;
 72+}
 73+.mw-ajax-dialog #summary:focus {
 74+ width: 85%;
 75+}
 76+
7077 .mw-translate-tmsug {
7178 margin-bottom: 0.2em;
7279 }
Index: trunk/extensions/Translate/js/jquery.autoresize.js
@@ -0,0 +1,96 @@
 2+/*
 3+ * jQuery autoResize (textarea auto-resizer)
 4+ * @copyright James Padolsey http://james.padolsey.com
 5+ * @version 1.04
 6+ */
 7+
 8+(function($){
 9+
 10+ $.fn.autoResize = function(options) {
 11+
 12+ // Just some abstracted details,
 13+ // to make plugin users happy:
 14+ var settings = $.extend({
 15+ onResize : function(){},
 16+ animate : true,
 17+ animateDuration : 150,
 18+ animateCallback : function(){},
 19+ extraSpace : 20,
 20+ limit: 1000
 21+ }, options);
 22+
 23+ // Only textarea's auto-resize:
 24+ this.filter('textarea').each(function(){
 25+
 26+ // Get rid of scrollbars and disable WebKit resizing:
 27+ var textarea = $(this).css({resize:'none','overflow-y':'hidden'}),
 28+
 29+ // Cache original height, for use later:
 30+ origHeight = textarea.height(),
 31+
 32+ // Need clone of textarea, hidden off screen:
 33+ clone = (function(){
 34+
 35+ // Properties which may effect space taken up by chracters:
 36+ var props = ['height','width','lineHeight','textDecoration','letterSpacing'],
 37+ propOb = {};
 38+
 39+ // Create object of styles to apply:
 40+ $.each(props, function(i, prop){
 41+ propOb[prop] = textarea.css(prop);
 42+ });
 43+
 44+ // Clone the actual textarea removing unique properties
 45+ // and insert before original textarea:
 46+ return textarea.clone().removeAttr('id').removeAttr('name').css({
 47+ position: 'absolute',
 48+ top: 0,
 49+ left: -9999
 50+ }).css(propOb).attr('tabIndex','-1').insertBefore(textarea);
 51+
 52+ })(),
 53+ lastScrollTop = null,
 54+ updateSize = function() {
 55+
 56+ // Prepare the clone:
 57+ clone.height(0).val($(this).val()).scrollTop(10000);
 58+
 59+ // Find the height of text:
 60+ var scrollTop = Math.max(clone.scrollTop(), origHeight) + settings.extraSpace,
 61+ toChange = $(this).add(clone);
 62+
 63+ // Don't do anything if scrollTip hasen't changed:
 64+ if (lastScrollTop === scrollTop) { return; }
 65+ lastScrollTop = scrollTop;
 66+
 67+ // Check for limit:
 68+ if ( scrollTop >= settings.limit ) {
 69+ $(this).css('overflow-y','');
 70+ return;
 71+ }
 72+ // Fire off callback:
 73+ settings.onResize.call(this);
 74+
 75+ // Either animate or directly apply height:
 76+ settings.animate && textarea.css('display') === 'block' ?
 77+ toChange.stop().animate({height:scrollTop}, settings.animateDuration, settings.animateCallback)
 78+ : toChange.height(scrollTop);
 79+ };
 80+
 81+ // Bind namespaced handlers to appropriate events:
 82+ textarea
 83+ .unbind('.dynSiz')
 84+ .bind('keyup.dynSiz', updateSize)
 85+ .bind('keydown.dynSiz', updateSize)
 86+ .bind('change.dynSiz', updateSize);
 87+
 88+ });
 89+
 90+ // Chain:
 91+ return this;
 92+
 93+ };
 94+
 95+
 96+
 97+})(jQuery);
\ No newline at end of file
Property changes on: trunk/extensions/Translate/js/jquery.autoresize.js
___________________________________________________________________
Added: svn:eol-style
198 + native
Index: trunk/extensions/Translate/js/quickedit.js
@@ -111,6 +111,7 @@
112112
113113 var textarea = form.find( '.mw-translate-edit-area' );
114114 textarea.focus();
 115+ textarea.autoResize({extraSpace: 15, limit: 200}).trigger( 'change' );
115116
116117 if ( form.find( '.mw-translate-messagechecks' ) ) {
117118 var checker = new MessageCheckUpdater( function() {
Index: trunk/extensions/Translate/Translate.php
@@ -136,6 +136,12 @@
137137 'remoteExtPath' => 'Translate',
138138 );
139139
 140+$wgResourceModules['jquery.autoresize'] = array(
 141+ 'scripts' => 'js/jquery.autoresize.js',
 142+ 'localBasePath' => dirname( __FILE__ ),
 143+ 'remoteExtPath' => 'Translate',
 144+);
 145+
140146 /** @endcond */
141147
142148
Index: trunk/extensions/Translate/utils/MessageTable.php
@@ -67,6 +67,7 @@
6868 $wgOut->addModules( array(
6969 'jquery.form',
7070 'jquery.ui.dialog',
 71+ 'jquery.autoresize',
7172 'ext.translate.quickedit',
7273 ) );
7374 } else {
Index: trunk/extensions/Translate/utils/TranslationEditPage.php
@@ -80,11 +80,9 @@
8181 }
8282
8383 $translation = $helpers->getTranslation();
84 - $rows = substr_count( $helpers->getDefinition(), "\n" ) + 2;
8584 $textareaParams = array(
8685 'name' => 'text',
8786 'class' => 'mw-translate-edit-area',
88 - 'rows' => $rows <= 15 ? $rows : 15,
8987 'id' => $id,
9088 /* Target language might differ from interface language. Set
9189 * a suitable default direction */

Status & tagging log