Commits

Anonymous committed f7f2327

Update to 1.6.11

Comments (0)

Files changed (4)

 CHANGES
 *******
 
-1.6.6 (unreleased)
-==================
+1.6.11 (unreleased)
+===================
 
-- Nothing changed yet.
+- Update to 1.6.11
 
 
 1.6.5 (2011-05-10)

js/jquery_elastic/__init__.py

 
 elastic = Resource(library,
                    'jquery.elastic.source.js',
-                   minified='jquery.elastic.js',
                    depends=[jquery])

js/jquery_elastic/resources/jquery.elastic.js

-(function(g){g.fn.extend({elastic:function(){var h=["paddingTop","paddingRight","paddingBottom","paddingLeft","fontSize","lineHeight","fontFamily","width","fontWeight"];return this.each(function(){function i(c,j){curratedHeight=Math.floor(parseInt(c,10));a.height()!=curratedHeight&&a.css({height:curratedHeight+"px",overflow:j})}function k(){var c=a.val().replace(/&/g,"&amp;").replace(/ /g,"&nbsp;").replace(/<|>/g,"&gt;").replace(/\n/g,"<br />"),j=b.html().replace(/<br>/ig,"<br />");if(c+"&nbsp;"!= j){b.html(c+"&nbsp;");if(Math.abs(b.height()+l-a.height())>3){c=b.height()+l;if(c>=d)i(d,"auto");else c<=e?i(e,"hidden"):i(c,"hidden")}}}if(this.type!="textarea")return false;var a=g(this),b=g("<div />").css({position:"absolute",display:"none","word-wrap":"break-word"}),l=parseInt(a.css("line-height"),10)||parseInt(a.css("font-size"),"10"),e=parseInt(a.css("height"),10)||l*3,d=parseInt(a.css("max-height"),10)||Number.MAX_VALUE,f=0;if(d<0)d=Number.MAX_VALUE;b.appendTo(a.parent());for(f=h.length;f--;)b.css(h[f].toString(), a.css(h[f].toString()));a.css({overflow:"hidden"});a.bind("keyup change cut paste",function(){k()});a.bind("blur",function(){if(b.height()<d)b.height()>e?a.height(b.height()):a.height(e)});a.live("input paste",function(){setTimeout(k,250)});k()})}})})(jQuery);

js/jquery_elastic/resources/jquery.elastic.source.js

 /**
 *	@name							Elastic
-*	@descripton						Elastic is Jquery plugin that grow and shrink your textareas automaticliy
-*	@version						1.6.5
-*	@requires						Jquery 1.2.6+
+*	@descripton						Elastic is jQuery plugin that grow and shrink your textareas automatically
+*	@version						1.6.11
+*	@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
+*	@licence						MIT License - http://www.opensource.org/licenses/mit-license.php
 */
 
-(function(jQuery){ 
+(function($){ 
 	jQuery.fn.extend({  
 		elastic: function() {
 		
 				'lineHeight',
 				'fontFamily',
 				'width',
-				'fontWeight'];
+				'fontWeight',
+				'border-top-width',
+				'border-right-width',
+				'border-bottom-width',
+				'border-left-width',
+				'borderTopStyle',
+				'borderTopColor',
+				'borderRightStyle',
+				'borderRightColor',
+				'borderBottomStyle',
+				'borderBottomColor',
+				'borderLeftStyle',
+				'borderLeftColor'
+				];
 			
 			return this.each( function() {
-				
+
 				// Elastic only works on textareas
-				if ( this.type != 'textarea' ) {
+				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;
+					
+			var $textarea	= jQuery(this),
+				$twin		= jQuery('<div />').css({
+					'position'		: 'absolute',
+					'display'		: 'none',
+					'word-wrap'		: 'break-word',
+					'white-space'	:'pre-wrap'
+				}),
+				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;
 				
 				// Opera returns max-height of -1 if not set
 				if (maxheight < 0) { maxheight = Number.MAX_VALUE; }
 					$twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()));
 				}
 				
+				// Updates the width of the twin. (solution for textareas with widths in percent)
+				function setTwinWidth(){
+					var curatedWidth = Math.floor(parseInt($textarea.width(),10));
+					if($twin.width() !== curatedWidth){
+						$twin.css({'width': curatedWidth + 'px'});
+						
+						// Update height of textarea
+						update(true);
+					}
+				}
 				
 				// Sets a given height and overflow state on the textarea
 				function setHeightAndOverflow(height, overflow){
-					curratedHeight = Math.floor(parseInt(height,10));
-					if($textarea.height() != curratedHeight){
+				
+					var 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() {
+				function update(forced) {
 					
 					// Get curated content from the textarea.
-					var textareaContent = $textarea.val().replace(/&/g,'&amp;').replace(/  /g, '&nbsp;').replace(/<|>/g, '&gt;').replace(/\n/g, '<br />');
+					var textareaContent = $textarea.val().replace(/&/g,'&amp;').replace(/ {2}/g, '&nbsp;').replace(/<|>/g, '&gt;').replace(/\n/g, '<br />');
 					
 					// Compare curated content with curated twin.
 					var twinContent = $twin.html().replace(/<br>/ig,'<br />');
 					
-					if(textareaContent+'&nbsp;' != twinContent){
+					if(forced || textareaContent+'&nbsp;' !== twinContent){
 					
 						// Add an extra white space so new rows are added when you are at the end of a row.
 						$twin.html(textareaContent+'&nbsp;');
 					update(); 
 				});
 				
+				// Update width of twin if browser or textarea is resized (solution for textareas with widths in percent)
+				$(window).bind('resize', setTwinWidth);
+				$textarea.bind('resize', setTwinWidth);
+				$textarea.bind('update', update);
+				
 				// Compact textarea on blur
-				// Lets animate this....
 				$textarea.bind('blur',function(){
 					if($twin.height() < maxheight){
 						if($twin.height() > minheight) {
 				});
 				
 				// And this line is to catch the browser paste event
-				$textarea.live('input paste',function(e){ setTimeout( update, 250); });				
+				$textarea.bind('input paste',function(e){ setTimeout( update, 250); });				
 				
 				// Run update once when elastic is initialized
 				update();