Merge branch 'stable'
[libreplanet-static.git] / 2014 / assets / js / jquery.textarearesizer.js
diff --git a/2014/assets/js/jquery.textarearesizer.js b/2014/assets/js/jquery.textarearesizer.js
new file mode 100644 (file)
index 0000000..6d47321
--- /dev/null
@@ -0,0 +1,89 @@
+/* \r
+ *   jQuery TextAreaResizer plugin\r
+ *\r
+ *   jQuery TextAreaResizer plugin\r
+ *   Created on 17th January 2008 by Ryan O'Dell \r
+ *   Version 1.0.4\r
+ *               \r
+ *   Converted from Drupal -> textarea.js\r
+ *   Found source: http://plugins.jquery.com/misc/textarea.js\r
+ *   $Id: textarea.js,v 1.11.2.1 2007/04/18 02:41:19 drumm Exp $\r
+ *\r
+ *   1.0.1 Updates to missing global 'var', added extra global variables, fixed multiple instances, improved iFrame support\r
+ *   1.0.2 Updates according to textarea.focus\r
+ *   1.0.3 Further updates including removing the textarea.focus and moving private variables to top\r
+ *   1.0.4 Re-instated the blur/focus events, according to information supplied by dec\r
+ *   \r
+ */\r
+$(document).ready(function() {\r
+       cj('#crm-container textarea.huge:not(.textarea-processed), #crm-container textarea.form-textarea:not(.textarea-processed)').each(function() {\r
+        $this = cj(this);\r
+               if ($this.parents('div.civicrm-drupal-wysiwyg').length == 0) \r
+        $this.TextAreaResizer();\r
+    });\r
+});\r
+\r
+(function($) {\r
+    /* private variable "oHover" used to determine if you're still hovering over the same element */\r
+    var textarea, staticOffset; \r
+    // added the var declaration for 'staticOffset' thanks to issue logged by dec.\r
+    var iLastMousePos = 0;\r
+    //mininum text area height\r
+    var iMin          = 32;\r
+    \r
+    var grip;\r
+    /* TextAreaResizer plugin */\r
+    $.fn.TextAreaResizer = function() {\r
+       return this.each(function() {\r
+        textarea = $(this).addClass('textarea-processed'), staticOffset = null;  \r
+           \r
+        // When wrapping the text area, work around an IE margin bug.  See:\r
+           // http://jaspan.com/ie-inherited-margin-bug-form-elements-and-haslayout\r
+           $(this).wrap('<div class="resizable-textarea"><span></span></div>')\r
+           .parent().append($('<div class="grippie"></div>').bind("mousedown",{el: this} , startDrag));\r
+\r
+           var grippie = $('div.grippie', $(this).parent())[0];\r
+           grippie.style.marginRight = (grippie.offsetWidth - $(this)[0].offsetWidth) +'px';\r
+       });\r
+    };\r
+    \r
+    /* private functions */\r
+    function startDrag(e) {\r
+       textarea = $(e.data.el);\r
+       textarea.blur();\r
+       iLastMousePos = mousePosition(e).y;\r
+       staticOffset  = textarea.height() - iLastMousePos;\r
+       textarea.css('opacity', 0.25);\r
+       $(document).mousemove(performDrag).mouseup(endDrag);\r
+       return false;\r
+    }\r
+\r
+    function performDrag(e) {\r
+       var iThisMousePos = mousePosition(e).y;\r
+       var iMousePos     = staticOffset + iThisMousePos;\r
+       if ( iLastMousePos >= ( iThisMousePos ) ) {\r
+           iMousePos -= 5;\r
+       }\r
+       iLastMousePos = iThisMousePos;\r
+       iMousePos     = Math.max(iMin, iMousePos);\r
+       textarea.height( iMousePos + 'px' );\r
+       if ( iMousePos < iMin ) {\r
+           endDrag(e);\r
+       }\r
+       return false;\r
+    }\r
+    \r
+    function endDrag(e) {\r
+       $(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag);\r
+       textarea.css('opacity', 1);\r
+       textarea.focus();\r
+       textarea      = null;\r
+       staticOffset  = null;\r
+       iLastMousePos = 0;\r
+    }\r
+    \r
+    function mousePosition(e) {\r
+       return { x: e.clientX + document.documentElement.scrollLeft, y: e.clientY + document.documentElement.scrollTop };\r
+    };\r
+})(jQuery);\r
+\r