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?

On Jul 25, 4:07 pm, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> Leandro Vieira Pinho wrote:
> > Hi,
>
> > It´s a simple plugin, that let you clear and reset the value of input
> > elements.
>
> > Example of usage:
>
> > $(function() {
> >  $('input').resetDefaultValue(); // for all input elements
> >  $('input.className').resetDefaultValue(); // for some elements
> >  $('#q').resetDefaultValue(); // for a especific element
> > });
>
> > The plugin code:
>
> > /**
> >  * jQuery resetDefaultValue plugin
> >  * @version 0.9
> >  * @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
> >  * });
> >  * 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/5ca50fd...
> > ]
> >  */
> > jQuery.fn.resetDefaultValue = function() {
> >    function _clearDefaultValue() {
> >            var _$ = $(this);
> >            if ( _$.val() == this.defaultValue ) { _$.val(''); }
> >    };
> >    function _resetDefaultValue() {
> >            var _$ = $(this);
> >            if ( _$.val() == '' ) { _$.val(this.defaultValue); }
> >    };
> >    return
> > this.filter('[EMAIL 
> > PROTECTED]').click(_clearDefaultValue).focus(_clearDefaultValue).blur(_resetDefaultValue);
> > }
>
> > The resetDefaultValue plugin has borned here:
> >http://groups.google.com/group/jquery-en/browse_thread/thread/5ca50fd...
>
> Leandro,
>
> another thought: I think it is reasonable to filter the result set for
> the type, but you're also returning the filtered set, which kind of
> breaks chainability and might give unexpected results, as some elements
> are missing after your plugin's method in the chain.
>
> That said, here's what I propose:
>
> jQuery.fn.resetDefaultValue = function() {
>         function _clearDefaultValue() {
>                 var _$ = $(this);
>                 if ( _$.val() == this.defaultValue ) { _$.val(''); }
>         };
>         function _resetDefaultValue() {
>                 var _$ = $(this);
>                 if ( _$.val() == '' ) { _$.val(this.defaultValue); }
>         };
>
>          this
>              .filter('[EMAIL PROTECTED]')
>              .click(_clearDefaultValue)
>              .focus(_clearDefaultValue)
>              .blur(_resetDefaultValue);
>          return this;
>
> }
>
> Ah, or just add an end() at the end of the chain, that's shorter:
>
>          return this
>              .filter('[EMAIL PROTECTED]')
>              .click(_clearDefaultValue)
>              .focus(_clearDefaultValue)
>              .blur(_resetDefaultValue)
>              .end();
>
> Cheers, Klaus

Reply via email to