Mam problem z jednoczesnym działaniem dwóch skryptów jQuery
Chodzi o dostosowywanie wysokości textarea w zależności od treści i odblokowywania/zablokowania tego pola
Kiedy są osobno to wszystko działa, kiedy jednak są razem to działa dostosowywanie rozmiaru a odblokowanie nie działa
Liczę na Waszą pomoc
Poniżej daję wszystkie kody
przykładowy kod (wiem, że nie ma podstawowych znaczników, ale to tylko przykład, a z nimi i tak skrypt nie działa)
CODE
<script type="text/javascript"> // <![CDATA[ jQuery.noConflict(); jQuery(document).ready(function(){ jQuery('textarea').elastic(); jQuery('textarea').trigger('update'); }); // ]]> </script> <script type="text/javascript"> $(document).ready(function(){ $('#inputtext_demo1').EnableDisable({ enabler: '#checkbox_demo1' }); }); </script>
jquery.elastic.source
CODE
/** * @name Elastic * @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 * */ (function($){ 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', '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' ) { return false; } 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; } // 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())); } // 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){ 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(forced) { // Get curated content from the textarea. var textareaContent = $textarea.val().replace(/&/g,'&').replace(/ {2}/g, ' ').replace(/<|>/g, '>').replace(/\n/g, '<br />'); // Compare curated content with curated twin. 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+' '); // 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, change, cut and paste $textarea.bind('keyup change cut paste', function(){ 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 $textarea.bind('blur',function(){ if($twin.height() < maxheight){ if($twin.height() > minheight) { $textarea.height($twin.height()); } else { $textarea.height(minheight); } } }); // And this line is to catch the browser paste event $textarea.bind('input paste',function(e){ setTimeout( update, 250); }); // Run update once when elastic is initialized update(); }); } }); })(jQuery);
jquery.enable.disable.plugin.min
CODE
* Licensed under GPL (http://www.opensource.org/licenses/gpl-2.0.php) * Use only for non-commercial usage. * Version : 0.1 * Requires: jQuery 1.2+ */ (function($){jQuery.fn.EnableDisable=function(options){var defaults={enabler:null,enablerVal:null,on_enable:function(){},on_disable:function(){}};var opts=$.extend(defaults,options);return this.each(function(){var field_to_be_enabled_or_disabled=this;var enable=false;jQuery(opts.enabler).each(function(){if(this.tagName=="INPUT"){if(jQuery(this).attr('checked')){enable=true;}}else if(this.tagName=="SELECT"){if(jQuery.inArray(jQuery(this).val(),opts.enablerVal)>=0){enable=true;}}});if(enable){jQuery(field_to_be_enabled_or_disabled).removeAttr('disabled');}else {jQuery(field_to_be_enabled_or_disabled).attr('disabled','disabled');}var radios=new Array();var selects=new Array();var checkboxs=new Array();jQuery(opts.enabler).each(function(){if(this.tagName=="INPUT"&&this.type=="radio"){radios.push($(this).attr('name'));}else if(this.tagName=="INPUT"&&this.type=="checkbox"){checkboxs.push($(this).attr('id'));}else if(this.tagName=="SELECT"){selects.push($(this).attr('id'));}});radios=array_unique(radios);selects=array_unique(selects);checkboxs=array_unique(checkboxs);jQuery.each(radios,function(){jQuery('input[name='+this+']').click(function(){var this_field=this;var enable=false;jQuery(opts.enabler).each(function(){if(jQuery(this).attr('id')==jQuery(this_field).attr('id')&&jQuery(this).attr('checked')){enable=true;}});jQuery.enable_or_disable(field_to_be_enabled_or_disabled,enable,opts);});});jQuery.each(selects,function(){jQuery('#'+this).bind("change",function(){var this_field=this;var enable=false;jQuery(opts.enabler).each(function(){if(jQuery(this).attr('id')==jQuery(this_field).attr('id')&&jQuery.inArray(jQuery(this).val(),opts.enablerVal)>=0){enable=true;}});jQuery.enable_or_disable(field_to_be_enabled_or_disabled,enable,opts);});});jQuery.each(checkboxs,function(){jQuery('#'+this).bind("change",function(){var this_field=this;var enable=false;jQuery(opts.enabler).each(function(){if(jQuery(this).attr('id')==jQuery(this_field).attr('id')&&jQuery(this).attr('checked')){enable=true;}});jQuery.enable_or_disable(field_to_be_enabled_or_disabled,enable,opts);});});});}})(jQuery);function array_unique(arr){if(arr.length>1){var arr=arr.sort();var arrUnique=new Array(arr[0]);for(i=1;i<arr.length;i++){if(arr[i]!=arrUnique[arrUnique.length-1]){arrUnique.push(arr[i]);}}return arrUnique;}else {return arr;}}jQuery.enable_or_disable=function(field_to_be_enabled_or_disabled,enable,opts){if(enable){jQuery(field_to_be_enabled_or_disabled).removeAttr('disabled');opts.on_enable();}else {jQuery(field_to_be_enabled_or_disabled).attr('disabled','disabled');opts.on_disable();}};