Yeah,

I´m wrong. And without the filter inside the plugin, we can use with
textarea too. So, the new code is here. Thanks. I´m learning so much
with these discussion.

/**
 * jQuery resetDefaultValue plugin
 * @version 0.9.1
 * @author Leandro Vieira Pinho <[EMAIL PROTECTED]>
 * How to use
 * $(function() {
 *      $('input').resetDefaultValue(); // for all input elements
 *  $('input.className').resetDefaultValue(); // for some elements
 *      $('#q').resetDefaultValue(); // for a especific element
 *  $('[EMAIL PROTECTED]').resetDefaultValue(); // avoid button/reset/
submit buttons
 *  $('textarea').resetDefaultValue(); // work with textarea too
 * });
 * ChangeLog
 * 0.1 - First relase
 * 0.2 - Filter input elements with type igual text, just it.
 * 0.9 - Rewrite all the plugin code. Thanks to Klaus Hartl [
http://groups.google.com/group/jquery-en/browse_thread/thread/5ca50fd021062331
]
 * 0.9.1 - Doesn´t do the filter inside the plugin
 */
jQuery.fn.resetDefaultValue = function() {
        function _clearDefaultValue() {
                var _$ = $(this);
                if ( _$.val() == this.defaultValue ) { _$.val(''); }
        };
        function _resetDefaultValue() {
                var _$ = $(this);
                if ( _$.val() == '' ) { _$.val(this.defaultValue); }
        };
        return
this.click(_clearDefaultValue).focus(_clearDefaultValue).blur(_resetDefaultValue);
}




On Jul 26, 5:08 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> Leandro Vieira Pinho wrote:
> > Hummmm, I don´t think it´s a good suggestion.
>
> > Imagine: I use the filter to avoid submit/reset/button buttons, for
> > example, so if I did it:
>
> > $('input').resetDefaultValue().height(30);
>
> > All the input elements affected by plugin will have 30 pixels of
> > height. If I use the .end() function, the submit/reset/buttons will
> > have 30 pixels of height too, so, but these kind of input elements isn
> > ´s affected by plugin.
>
> > Do you agree?
>
> No. I would expect every matched element to get the height. For someone,
> who is simply using your plugin and does not know how it works it would
> be totally inobvious why some elements are missing and he would simply
> assume it's a bug somewhere in jQuery.
>
> It's just not transparent what is going on to anyone else than you or
> one who studied the plugin code carefully (which you cannot expect as a
> plugin author).
>
> If I write
>
> $('input').height(30);
>
> or
>
> $('input').resetDefaultValue().height(30);
>
> or
>
> $('input').height(30).resetDefaultValue();
>
> I do expect all matched inputs having the height of 30!
>
> Otherwies you'd need to call the plugin resetDefaultValueWithFilter or
> something.
>
> It should be up to the user to do the filtering in the selector anyway -
> the intention what the code should do is much more obvious to others
> reading the code. The filter in the plugin should simply serve as a
> little safety mechanism if at all required.
>
> The example you've given should be written as this anyway:
>
> $('[EMAIL PROTECTED]"text"]').resetDefaultValue().height(30);
>
> --Klaus

Reply via email to