##// END OF EJS Templates
Add documentation to NotificationWidget methods
Jessica B. Hamrick -
Show More
@@ -20,16 +20,34 define([
20 this.element.append(this.inner);
20 this.element.append(this.inner);
21 };
21 };
22
22
23 /**
24 * Add the 'notification_widget' CSS class to the widget element.
25 *
26 * @method style
27 */
23 NotificationWidget.prototype.style = function () {
28 NotificationWidget.prototype.style = function () {
24 this.element.addClass('notification_widget');
29 this.element.addClass('notification_widget');
25 };
30 };
26
31
27 // msg : message to display
32 /**
28 // timeout : time in ms before diseapearing
33 * Set the notification widget message to display for a certain
29 //
34 * amount of time (timeout). The widget will be shown forever if
30 // if timeout <= 0
35 * timeout is <= 0 or undefined. If the widget is clicked while it
31 // click_callback : function called if user click on notification
36 * is still displayed, execute an optional callback
32 // could return false to prevent the notification to be dismissed
37 * (click_callback). If the callback returns false, it will
38 * prevent the notification from being dismissed.
39 *
40 * Options:
41 * class - CSS class name for styling
42 * icon - CSS class name for the widget icon
43 * title - HTML title attribute for the widget
44 *
45 * @method set_message
46 * @param {string} msg - The notification to display
47 * @param {integer} [timeout] - The amount of time in milliseconds to display the widget
48 * @param {function} [click_callback] - The function to run when the widget is clicked
49 * @param {Object} [options] - Additional options
50 */
33 NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, options) {
51 NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, options) {
34 options = options || {};
52 options = options || {};
35
53
@@ -43,7 +61,7 define([
43 // reset previous set style
61 // reset previous set style
44 this.element.removeClass();
62 this.element.removeClass();
45 this.style();
63 this.style();
46 if (options.class){
64 if (options.class) {
47 this.element.addClass(options.class);
65 this.element.addClass(options.class);
48 }
66 }
49
67
@@ -68,8 +86,8 define([
68 this.element.click(function() {
86 this.element.click(function() {
69 if (click_callback() !== false) {
87 if (click_callback() !== false) {
70 that.element.fadeOut(100, function () {that.inner.text('');});
88 that.element.fadeOut(100, function () {that.inner.text('');});
71 that.element.unbind('click');
72 }
89 }
90 that.element.unbind('click');
73 if (that.timeout !== null) {
91 if (that.timeout !== null) {
74 clearTimeout(that.timeout);
92 clearTimeout(that.timeout);
75 that.timeout = null;
93 that.timeout = null;
@@ -78,6 +96,12 define([
78 }
96 }
79 };
97 };
80
98
99 /**
100 * Display an information message (styled with the 'info'
101 * class). Arguments are the same as in set_message.
102 *
103 * @method info
104 */
81 NotificationWidget.prototype.info = function (msg, timeout, click_callback, options) {
105 NotificationWidget.prototype.info = function (msg, timeout, click_callback, options) {
82 options = options || {};
106 options = options || {};
83 options.class = options.class + ' info';
107 options.class = options.class + ' info';
@@ -85,18 +109,36 define([
85 this.set_message(msg, timeout, click_callback, options);
109 this.set_message(msg, timeout, click_callback, options);
86 };
110 };
87
111
112 /**
113 * Display a warning message (styled with the 'warning'
114 * class). Arguments are the same as in set_message.
115 *
116 * @method warning
117 */
88 NotificationWidget.prototype.warning = function (msg, timeout, click_callback, options) {
118 NotificationWidget.prototype.warning = function (msg, timeout, click_callback, options) {
89 options = options || {};
119 options = options || {};
90 options.class = options.class + ' warning';
120 options.class = options.class + ' warning';
91 this.set_message(msg, timeout, click_callback, options);
121 this.set_message(msg, timeout, click_callback, options);
92 };
122 };
93
123
124 /**
125 * Display a danger message (styled with the 'danger'
126 * class). Arguments are the same as in set_message.
127 *
128 * @method danger
129 */
94 NotificationWidget.prototype.danger = function (msg, timeout, click_callback, options) {
130 NotificationWidget.prototype.danger = function (msg, timeout, click_callback, options) {
95 options = options || {};
131 options = options || {};
96 options.class = options.class + ' danger';
132 options.class = options.class + ' danger';
97 this.set_message(msg, timeout, click_callback, options);
133 this.set_message(msg, timeout, click_callback, options);
98 };
134 };
99
135
136 /**
137 * Get the text of the widget message.
138 *
139 * @method get_message
140 * @return {string} - the message text
141 */
100 NotificationWidget.prototype.get_message = function () {
142 NotificationWidget.prototype.get_message = function () {
101 return this.inner.html();
143 return this.inner.html();
102 };
144 };
General Comments 0
You need to be logged in to leave comments. Login now