1

I use OOP and jQuery in my developments. I used to passed my current object this to jQuery functions like this :

$(myElement).live('click', this, function(el){
  // I can access to my JS object using el.data
});

But I can't find how to do similar thing with jQuery function .queue(). Is it possible ?

EDIT

I give you the context in which I want to use .queue() :

CAPTIVEA.widget.Message = {
    /**
     * Displays generated message on the screen
     * @method display
     * @public
     */
    display: function() {
        // Display Message
        $('.message')[this.effects.show](this.effects.duration, function(){
            $(this).show();
            $('.message span').show();
            $('.message').children().show();
        });

        if (this.autoHide)
        {   // Remove message after delay
            $('.message').data('objMessage', this);
            $('.message').delay(3000).queue(function(el){
                $(this).data('objMessage').close();
            });
        }
    },

    /**
     * Removes generated message from the screen
     * @method close
     * @public
     */
    close: function() {
        $('.message')[this.effects.hide](this.effects.duration, function(){
            $(this).remove();
        });
    }
};
6
  • You mean like $(myElement).queue(function(el){});? Cos that's possible... Commented Feb 1, 2012 at 14:26
  • 1
    What kind of object does this represent in your code? Commented Feb 1, 2012 at 14:32
  • @am not i am : it is the object literal. Code example which I gave you is in a method of this object Commented Feb 1, 2012 at 15:34
  • How are you using .queue(). That method just operates on whatever jQuery object it happened to be called from. Do you need this data associated with a particular element, or set of elements? If so, have you considered $.data()? Commented Feb 1, 2012 at 15:46
  • @am not i am : I have edited my post to give you context. Commented Feb 2, 2012 at 9:58

4 Answers 4

2

"Is it possible ?"

No. The live() method is an event handling method, and you're setting event object data. The first argument in the callback is the event object.

I don't know what this represented, but I have a feeling you were misusing event data.

The queue() method has nothing to do with event handling. You pass it a function that is added to a queue. Its first parameter will reference a function that releases the queue.

Sign up to request clarification or add additional context in comments.

Comments

1

You can still access the current object. See my jsfiddle here: http://jsfiddle.net/9upJB/

Aside from that, what others have pointed out is correct. live() (which you should STOP using btw) is an event. queue() is a method and has nothing to do with an event.

When accessing the object, this is executed as the callback (check the jQuery documentation).

Comments

1

you first save the instance as element data and use it in queue function of jquery;

$("#el").data("instance", this);

en after that use in the function

$("#el").queue(function(){
    var instance = $(this).data("instance");
    //do whatever you want
});

Comments

0

You don't pass the queue() function the element instead the function is executed on the matched element.

$('yourelement').queue(); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.