开发者

How do I create a message queue?

开发者 https://www.devze.com 2023-02-10 20:35 出处:网络
I want to display little messages to provide feedback to the user while he is providing input or just interacting with the UI.

I want to display little messages to provide feedback to the user while he is providing input or just interacting with the UI.

I need it for my firefox addon, so I have to develop it in plain javascript and not jQuery.

I want the message to appear, but only one message can be visible at the same time, so I need some kind of queue to manage incomming messages. After a certain time e.g. 3 sec the message should fade away or just disappear.

For now I am able to add messages to the DOM. An开发者_运维百科y suggestions how to implement the queue and how to push the messages forward according to the time?

Thanks!


Perheps you need the concept of FIFO (First In First Out)

Take a look at this simple example in plan java script language:

function Queue() {
    var data = [];

    this.isEmpty = function() {
        return (data.length == 0);
    };

    this.enqueue = function(obj) {
        data.push(obj);
    };

    this.dequeue = function() {
        return data.shift();
    };

    this.peek = function() {
        return data[0];
    };

    this.clear = function() {
        data = [];
    };
}


You can use jQuery in a firefox plugin:

Include a script tag in the xul file that points to the jQuery file, e.g.:

<script type="text/javascript" src="chrome://extensionname/content/jquery.js" />

In each js function that uses jQuery, insert this line:

$jQuizzle = jQuery.noConflict(); 

In each jQuery call, if you are trying to manipulate the document in the current browser window, you must supply the context as "window.content.document", like this:

$jQuizzle(".myClass", window.content.document).show();

Then you can use this jQuery plugin: http://benalman.com/projects/jquery-message-queuing-plugin/


It's not clear what sort of message you want to display. The nsIAlertsService can display messages but I'm not sure how well it queues them. If you want something simpler then perhaps you could just show a custom <tooltip> element.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号