incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [47/50] git commit: [#4573] ticket:147 new jQuery plugin for resizing textareas
Date Wed, 19 Sep 2012 18:43:28 GMT
[#4573] ticket:147 new jQuery plugin for resizing textareas


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/72708c0a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/72708c0a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/72708c0a

Branch: refs/heads/master
Commit: 72708c0adb7c1f67399c1029eeed25281792383d
Parents: 0349e46
Author: Yuriy <yuriyarhipovua@yandex.ru>
Authored: Tue Aug 14 17:04:19 2012 +0400
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Sep 5 22:06:15 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/widgets/form_fields.py           |    6 +-
 .../widgets/resources/js/jquery.autosize-min.js    |    4 +
 .../lib/widgets/resources/js/jquery.elastic.js     |  127 ---------------
 ForgeWiki/forgewiki/templates/wiki/page_edit.html  |    1 +
 4 files changed, 7 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/72708c0a/Allura/allura/lib/widgets/form_fields.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/form_fields.py b/Allura/allura/lib/widgets/form_fields.py
index 099b0d9..6424562 100644
--- a/Allura/allura/lib/widgets/form_fields.py
+++ b/Allura/allura/lib/widgets/form_fields.py
@@ -190,11 +190,9 @@ class AutoResizeTextarea(ew.TextArea):
         css_class='auto_resize')
 
     def resources(self):
-        yield ew.JSLink('js/jquery.elastic.js')
+        yield ew.JSLink('js/jquery.autosize-min.js')
         yield onready('''
-            $('textarea.auto_resize').elastic().focus(function(){
-                $(this).keyup();
-            });
+            $('textarea.auto_resize').focus(function(){$(this).autosize();});
         ''')
 
 class MarkdownEdit(AutoResizeTextarea):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/72708c0a/Allura/allura/lib/widgets/resources/js/jquery.autosize-min.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/jquery.autosize-min.js b/Allura/allura/lib/widgets/resources/js/jquery.autosize-min.js
new file mode 100644
index 0000000..278da76
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/jquery.autosize-min.js
@@ -0,0 +1,4 @@
+// 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);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/72708c0a/Allura/allura/lib/widgets/resources/js/jquery.elastic.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/jquery.elastic.js b/Allura/allura/lib/widgets/resources/js/jquery.elastic.js
deleted file mode 100644
index faef556..0000000
--- a/Allura/allura/lib/widgets/resources/js/jquery.elastic.js
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
-*	@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);

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/72708c0a/ForgeWiki/forgewiki/templates/wiki/page_edit.html
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/page_edit.html b/ForgeWiki/forgewiki/templates/wiki/page_edit.html
index 70e0398..224cdda 100644
--- a/ForgeWiki/forgewiki/templates/wiki/page_edit.html
+++ b/ForgeWiki/forgewiki/templates/wiki/page_edit.html
@@ -51,6 +51,7 @@
 {% block wiki_extra_js %}
 <script type="text/javascript">
   /*<![CDATA[*/
+  $('textarea.auto_resize').autosize();
   $('span.removable').click(function(e){
     var vals = $('#page_edit_form').serialize();
     var del_name = $('input', this)[0].name.replace('.id','.delete');


Mime
View raw message