I still prefer the old ternary operator way:

$.ajax('url.php', function(data){
   $('#result').addClass(data.success ? 'ui-state-highlight' : 'ui-
state-error');
}, 'json');

Any possibilities I'm missing here?

On Feb 9, 5:12 pm, Eric Garside <gars...@gmail.com> wrote:
> Hey guys,
>
> I had an idea this morning which quickly turned into a small but, I
> think powerful, plugin. I'd love some review on it from the list, to
> see if anyone can see any glaring errors I missed, or has an easier/
> already done way of doing it. The source code and some examples are
> located here:http://snipplr.com/view/12045/jquery-conditional-chains/
>
> The basic idea was to add functionality to jQuery to conditionally
> execute functions on the chain, based on dynamic values. Take for
> example:
>
> $.ajax('url.php', function(data){
>    $('#result').cond(data.success, 'addClass', 'ui-state-
> highlight').cond(!data.success, 'addClass', 'ui-state-error');
>
> }, 'json');
>
> Instead of
>
> $.ajax('url.php', function(data){
>    if (result.data)
>       $('#result').addClass('ui-state-highlight');
>    else
>       $('#result').addClass('ui-state-error');
>
> }, 'json');
>
> Also, it has functionality to stop/resume the chain based on boolean
> variables.
>
> $.ajax('url.php', function(data){
>    $('#result')
>    .stop(!data.success).addClass('ui-state-highlight').text('Success!
> Excelsior!')
>    .resume(!data.success)).addClass('ui-state-error').text('Failure!
> Oh Noes!')
>
> }, 'json');
>
> Thoughts? Comments? Ideas for improvement? What do ya'll think?

Reply via email to