[#4573] ticket:147 new jQuery plugin for resizing textareas

Yuriy Yuriy 2012-08-14

Dave Brondsema Dave Brondsema 2012-09-05

changed Allura/allura/lib/widgets/form_fields.py
changed ForgeWiki/forgewiki/templates/wiki/page_edit.html
copied Allura/allura/lib/widgets/resources/js/jquery.elastic.js -> Allura/allura/lib/widgets/resources/js/jquery.autosize-min.js
Allura/allura/lib/widgets/form_fields.py Diff Switch to side-by-side view
Loading...
ForgeWiki/forgewiki/templates/wiki/page_edit.html Diff Switch to side-by-side view
Loading...
Allura/allura/lib/widgets/resources/js/jquery.elastic.js to Allura/allura/lib/widgets/resources/js/jquery.autosize-min.js
--- a/Allura/allura/lib/widgets/resources/js/jquery.elastic.js
+++ b/Allura/allura/lib/widgets/resources/js/jquery.autosize-min.js
@@ -1,127 +1,4 @@
-/**
-*	@name							Elastic
-*	@descripton						Elastic is Jquery plugin that grow and shrink your textareas automaticliy
-*	@version						1.6.4
-*	@requires						Jquery 1.2.6+
-*
-*	@author							Jan Jarfalk
-*	@author-email					jan.jarfalk@unwrongest.com
-*	@author-website					http://www.unwrongest.com
-*
-*	@licens							MIT License - http://www.opensource.org/licenses/mit-license.php
-*/
-
-(function(jQuery){ 
-	jQuery.fn.extend({  
-		elastic: function() {
-		
-			//	We will create a div clone of the textarea
-			//	by copying these attributes from the textarea to the div.
-			var mimics = [
-				'paddingTop',
-				'paddingRight',
-				'paddingBottom',
-				'paddingLeft',
-				'fontSize',
-				'lineHeight',
-				'fontFamily',
-				'width',
-				'fontWeight'];
-			
-			return this.each( function() {
-				
-				// Elastic only works on textareas
-				if ( this.type != 'textarea' ) {
-					return false;
-				}
-				
-				var $textarea	=	jQuery(this),
-					$twin		=	jQuery('<div />').css({'position': 'absolute','display':'none','word-wrap':'break-word'}),
-					lineHeight	=	parseInt($textarea.css('line-height'),10) || parseInt($textarea.css('font-size'),'10'),
-					minheight	=	parseInt($textarea.css('height'),10) || lineHeight*3,
-					maxheight	=	parseInt($textarea.css('max-height'),10) || Number.MAX_VALUE,
-					goalheight	=	0,
-					i 			=	0;
-				
-				// Opera returns max-height of -1 if not set
-				if (maxheight < 0) { maxheight = Number.MAX_VALUE; }
-					
-				// Append the twin to the DOM
-				// We are going to meassure the height of this, not the textarea.
-				$twin.appendTo($textarea.parent());
-				
-				// Copy the essential styles (mimics) from the textarea to the twin
-				var i = mimics.length;
-				while(i--){
-					$twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()));
-				}
-				
-				
-				// Sets a given height and overflow state on the textarea
-				function setHeightAndOverflow(height, overflow){
-					curratedHeight = Math.floor(parseInt(height,10));
-					if($textarea.height() != curratedHeight){
-						$textarea.css({'height': curratedHeight + 'px','overflow':overflow});
-						
-					}
-				}
-				
-				
-				// This function will update the height of the textarea if necessary 
-				function update() {
-					
-					// Get curated content from the textarea.
-					var textareaContent = $textarea.val().replace(/&/g,'&amp;').replace(/  /g, '&nbsp;').replace(/<|>/g, '&gt;').replace(/\n/g, '<br />');
-
-					var twinContent = $twin.html();
-					
-					// if the width is zero, this element was probably hidden during init - fix that and force height update
-					var update_from_width = false;
-					if($twin.width() == 0){
-						update_from_width = true;
-						$twin.width($textarea.width());
-					}
-					
-					if(textareaContent+'&nbsp;' != twinContent || update_from_width){
-					
-						// Add an extra white space so new rows are added when you are at the end of a row.
-						$twin.html(textareaContent+'&nbsp;');
-						
-						// Change textarea height if twin plus the height of one line differs more than 3 pixel from textarea height
-						if(Math.abs($twin.height()+lineHeight - $textarea.height()) > 3){
-							
-							var goalheight = $twin.height()+lineHeight;
-							if(goalheight >= maxheight) {
-								setHeightAndOverflow(maxheight,'auto');
-							} else if(goalheight <= minheight) {
-								setHeightAndOverflow(minheight,'hidden');
-							} else {
-								setHeightAndOverflow(goalheight,'hidden');
-							}
-							
-						}
-						
-					}
-					
-				}
-				
-				// Hide scrollbars
-				$textarea.css({'overflow':'hidden'});
-				
-				// Update textarea size on keyup
-				$textarea.keyup(function(){ update(); });
-				
-				// And this line is to catch the browser paste event
-				$textarea.live('input paste',function(e){ setTimeout( update, 250); });				
-
-                // Update when editing a ticket
-                $textarea.bind('editticket.forgetracker', function() { update(); });
-				
-				// Run update once when elastic is initialized
-				update();
-				
-			});
-			
-        } 
-    }); 
-})(jQuery);
+// Autosize 1.11 - jQuery plugin for textareas
+// (c) 2012 Jack Moore - jacklmoore.com
+// license: www.opensource.org/licenses/mit-license.php
+(function(e){var t="hidden",n="border-box",r="lineHeight",i='<textarea tabindex="-1" style="position:absolute; top:-9999px; left:-9999px; right:auto; bottom:auto; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden;">',s=["fontFamily","fontSize","fontWeight","fontStyle","letterSpacing","textTransform","wordSpacing","textIndent"],o="oninput",u="onpropertychange",a=e(i)[0];a.setAttribute(o,"return"),e.isFunction(a[o])||u in a?(e(a).css(r,"99px"),e(a).css(r)==="99px"&&s.push(r),e.fn.autosize=function(r){return this.each(function(){function g(){var e,n;p||(p=!0,l.value=a.value,l.style.overflowY=a.style.overflowY,l.style.width=f.css("width"),l.scrollTop=0,l.scrollTop=9e4,e=l.scrollTop,n=t,e>h?(e=h,n="scroll"):e<c&&(e=c),a.style.overflowY=n,a.style.height=e+m+"px",setTimeout(function(){p=!1},1))}var a=this,f=e(a),l,c=f.height(),h=parseInt(f.css("maxHeight"),10),p,d=s.length,v,m=0;if(f.css("box-sizing")===n||f.css("-moz-box-sizing")===n||f.css("-webkit-box-sizing")===n)m=f.outerHeight()-f.height();if(f.data("mirror")||f.data("ismirror"))return;l=e(i).data("ismirror",!0).addClass(r||"autosizejs")[0],v=f.css("resize")==="none"?"none":"horizontal",f.data("mirror",e(l)).css({overflow:t,overflowY:t,wordWrap:"break-word",resize:v}),h=h&&h>0?h:9e4;while(d--)l.style[s[d]]=f.css(s[d]);e("body").append(l),u in a?o in a?a[o]=a.onkeyup=g:a[u]=g:a[o]=g,e(window).resize(g),f.bind("autosize",g),f.text(f.text()),g()})}):e.fn.autosize=function(){return this}})(jQuery);