2 * MySlice Messages plugin
4 * URL: http://www.myslice.info
5 * Description: Display debug messages in a DIV
7 * Author: The MySlice Team
8 * Copyright: Copyright 2012 UPMC Sorbonne Universités
14 /* Method calling logic */
15 $.fn.Messages = function( method ) {
16 if ( methods[method] ) {
17 return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
18 } else if ( typeof method === 'object' || ! method ) {
19 return methods.init.apply( this, arguments );
21 $.error( 'Method ' + method + ' does not exist on $.Messages' );
26 init : function( options ) {
28 return this.each(function(){
30 data = $this.data('Messages'),
31 Messages = $('<div />', { text : $this.attr('title') });
33 // If the plugin hasn't been initialized yet
35 $(this).data('Messages', {
36 plugin_uuid: options.plugin_uuid,
41 /* Plugin initialization */
42 $.subscribe("messages:fatal", {'plugindiv': $this,'level':'fatal'}, display_message);
43 $.subscribe("messages:error", {'plugindiv': $this,'level':'error'}, display_message);
44 $.subscribe("messages:warning", {'plugindiv': $this,'level':'warning'}, display_message);
45 $.subscribe("messages:info", {'plugindiv': $this,'level':'info'}, display_message);
46 $.subscribe("messages:debug", {'plugindiv': $this,'level':'debug'}, display_message);
47 $.publish ("messages:info", 'Subscribed to all 5 message channels');
48 /* End of plugin initialization */
52 destroy : function( ) {
54 return this.each(function(){
55 var $this = $(this), data = $this.data('Messages');
56 $(window).unbind('Messages');
57 data.Messages.remove();
58 $this.removeData('Messages');
62 reposition : function( ) { // ... },
63 show : function( ) { // ... },
64 hide : function( ) { // ... },
66 update : function( content ) { },
71 function display_message(e, message) {
72 var level=e.data.level;
73 var domid=e.data.plugindiv.data('Messages').plugin_uuid;
75 html += "<li class='" + level + "'>";
76 html += "[" + level + "]";
77 html += " " + new Date() + " ";
78 // html += "[" + domid + "]";
79 html += " " + message + "</li>";
80 $("ul#"+domid+".messages").append(html);
88 if (tests) // arm this with a timeout rather
91 $.publish("messages:fatal","a fatal message");
92 $.publish("messages:error","an error message");
93 $.publish("messages:warning","a warning message");
94 $.publish("messages:info","an info message");
95 $.publish("messages:debug","a debug message");