}
};
- var levels = {'fatal': true, 'error': true, 'warning' : true, 'info' : true, 'debug' : false};
-
var methods = {
init : function( options ) {
var $this = $(this);
instance=new Messages (options,$this);
$this.data('Messages',instance);
- for (level in levels) {
+ for (level in options.levels) {
(function (instance,level) {
- $.subscribe("messages:"+level, function (e, msg){ instance.display_message (msg,level)});
+ $.subscribe("/messages/"+level, function (e, msg){ instance.display_message (msg,level)});
}) (instance,level);
}
- $.publish ("messages:info", 'Subscribed to all 5 message channels');
+ // kind of patchy, notify the convenience functions that somebody is listening...
+ try {messages.ready=true;}
+ catch (err) { console.log("Could not set messages.ready");}
+ // this happens very early - even before the document is loaded
+ // so it won't show right away; no big deal though
+ $.publish ("/messages/info", 'Subscribed to all 5 message channels');
});
},
destroy : function( ) {
},
this.initialize = function () {
- this.plugindiv.find("div.messages-buttons>input").each(this.init_button);
+ var init_button=this.init_button;
+ var levels=this.options.levels;
+ this.plugindiv.find("div.messages-buttons>input").each(
+ function (i,input) {init_button (input, levels)});
var arm_button=this.arm_button;
var toggle_handler=this.toggle_handler;
this.plugindiv.find("div.messages-buttons>input").each(
- function (i,input) {arm_button (input,toggle_handler); }
- );
+ function (i,input) {arm_button (input,toggle_handler); });
},
- this.init_button = function (_,input) {
+ this.init_button = function (input,levels) {
/* set initial 'checked' state for that input from global 'levels' above */
var level=input.name;
if (levels[level]) $(input).attr('checked','checked');
/* as an event handler toggle_handler will see the DOM <input> as 'this' */
this.toggle_handler = function (e) {
var $this=$(this);
- var before=$this.attr('checked');
+ // toggle the state of the checkbox
if ($this.attr('checked')) $this.removeAttr('checked');
else $this.attr('checked',true);
+ // turn messages on or off
var level=this.name;
- var after=$this.attr('checked');
var display = $this.attr('checked') ? "list-item" : "none";
var plugindiv=$this.closest("div.Messages");
plugindiv.find("li."+level).css("display",display);
})(jQuery);
-// temporary
-
+/* turn this on for an auto-test on startup
var messages_test = {
// set this to 0 to disable
counter : 2,
period : 1000,
sample : function () {
- $.publish("messages:fatal","a fatal message (" + messages_test.counter + " runs to go)");
- $.publish("messages:error","an error message");
- $.publish("messages:warning","a warning message");
- $.publish("messages:info","an info message");
- $.publish("messages:debug","a debug message");
+ $.publish("/messages/fatal","a fatal message (" + messages_test.counter + " runs to go)");
+ $.publish("/messages/error","an error message");
+ $.publish("/messages/warning","a warning message");
+ $.publish("/messages/info","an info message");
+ $.publish("/messages/debug","a debug message");
messages_test.counter -= 1;
if (messages_test.counter == 0)
window.clearInterval (messages_test.interval_id);
}
}
messages_test.run()
-
+*/