2 * Interface Elements for jQuery
\r
5 * http://interface.eyecon.ro
\r
7 * Copyright (c) 2006 Stefan Petre
\r
8 * Dual licensed under the MIT (MIT-LICENSE.txt)
\r
9 * and GPL (GPL-LICENSE.txt) licenses.
\r
15 * Expands text and textarea elements while new characters are typed to the a miximum width
\r
18 * @description Expands text and textarea elements while new characters are typed to the a miximum width
\r
19 * @param Mixed limit integer if only expands in width, array if expands in width and height
\r
21 * @cat Plugins/Interface
\r
22 * @author Stefan Petre
\r
35 fontFamily: jQuery(this).css('fontFamily')||'',
\r
36 fontSize: jQuery(this).css('fontSize')||'',
\r
37 fontWeight: jQuery(this).css('fontWeight')||'',
\r
38 fontStyle: jQuery(this).css('fontStyle')||'',
\r
39 fontStretch: jQuery(this).css('fontStretch')||'',
\r
40 fontVariant: jQuery(this).css('fontVariant')||'',
\r
41 letterSpacing: jQuery(this).css('letterSpacing')||'',
\r
42 wordSpacing: jQuery(this).css('wordSpacing')||''
\r
44 jQuery.iExpander.helper.css(style);
\r
45 html = jQuery.iExpander.htmlEntities(text);
\r
46 html = html.replace(new RegExp( "\\n", "g" ), "<br />");
\r
47 jQuery.iExpander.helper.html('pW');
\r
48 spacer = jQuery.iExpander.helper.get(0).offsetWidth;
\r
49 jQuery.iExpander.helper.html(html);
\r
50 width = jQuery.iExpander.helper.get(0).offsetWidth + spacer;
\r
51 if (this.Expander.limit && width > this.Expander.limit[0]) {
\r
52 width = this.Expander.limit[0];
\r
54 this.style.width = width + 'px';
\r
55 if (this.tagName == 'TEXTAREA') {
\r
56 height = jQuery.iExpander.helper.get(0).offsetHeight + spacer;
\r
57 if (this.Expander.limit && height > this.Expander.limit[1]) {
\r
58 height = this.Expander.limit[1];
\r
60 this.style.height = height + 'px';
\r
63 htmlEntities : function(text)
\r
71 for(i in entities) {
\r
72 text = text.replace(new RegExp(i,'g'),entities[i]);
\r
76 build : function(limit)
\r
78 if (jQuery.iExpander.helper == null) {
\r
79 jQuery('body', document).append('<div id="expanderHelper" style="position: absolute; top: 0; left: 0; visibility: hidden;"></div>');
\r
80 jQuery.iExpander.helper = jQuery('#expanderHelper');
\r
85 if (/TEXTAREA|INPUT/.test(this.tagName)) {
\r
86 if (this.tagName == 'INPUT') {
\r
87 elType = this.getAttribute('type');
\r
88 if (!/text|password/.test(elType)) {
\r
92 if (limit && (limit.constructor == Number || (limit.constructor == Array && limit.length == 2))) {
\r
93 if (limit.constructor == Number)
\r
94 limit = [limit, limit];
\r
96 limit[0] = parseInt(limit[0])||400;
\r
97 limit[1] = parseInt(limit[1])||400;
\r
104 .blur(jQuery.iExpander.expand)
\r
105 .keyup(jQuery.iExpander.expand)
\r
106 .keypress(jQuery.iExpander.expand);
\r
107 jQuery.iExpander.expand.apply(this);
\r
114 jQuery.fn.Autoexpand = jQuery.iExpander.build;