http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90677
Revision: 90677
Author: kaldari
Date: 2011-06-23 20:58:46 +0000 (Thu, 23 Jun 2011)
Log Message:
-----------
updating jQuery elastic plugin
Modified Paths:
--------------
trunk/extensions/WikiLove/modules/jquery.elastic/jquery.elastic.js
Modified: trunk/extensions/WikiLove/modules/jquery.elastic/jquery.elastic.js
===================================================================
--- trunk/extensions/WikiLove/modules/jquery.elastic/jquery.elastic.js
2011-06-23 20:45:13 UTC (rev 90676)
+++ trunk/extensions/WikiLove/modules/jquery.elastic/jquery.elastic.js
2011-06-23 20:58:46 UTC (rev 90677)
@@ -1,7 +1,7 @@
/**
* @name Elastic
* @descripton Elastic is
jQuery plugin that grow and shrink your textareas automatically
-* @version 1.6.5
+* @version 1.6.10
* @requires jQuery 1.2.6+
*
* @author Jan Jarfalk
@@ -29,22 +29,35 @@
'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;
- 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;
-
// Opera returns max-height of -1 if not set
if (maxheight < 0) { maxheight =
Number.MAX_VALUE; }
@@ -58,18 +71,32 @@
$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(){
+ 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){
+
var curratedHeight =
Math.floor(parseInt(height,10));
- if($textarea.height() !=
curratedHeight){
+ if($textarea.height() !==
curratedHeight){
$textarea.css({'height':
curratedHeight + 'px','overflow':overflow});
+
+ // Fire the custom event resize
+ $textarea.trigger('resize');
+
}
}
-
// 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,'&').replace(/ {2}/g,
' ').replace(/<|>/g, '>').replace(/\n/g, '<br />');
@@ -77,7 +104,7 @@
// Compare curated content with curated
twin.
var twinContent =
$twin.html().replace(/<br>/ig,'<br />');
- if(textareaContent+' ' !=
twinContent){
+ if(forced || textareaContent+' '
!== twinContent){
// Add an extra white space so
new rows are added when you are at the end of a row.
$twin.html(textareaContent+' ');
@@ -108,8 +135,12 @@
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) {
@@ -121,7 +152,7 @@
});
// 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();
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs