1 (function() { 2 /** 3 * <code>notifier</code> is something that must be accessed via a <code>require()</code>. 4 * It provides the <code>notify()</code> method. 5 * @namespace The notifier namespace provides a single function, namely <code>notify</code> 6 * which can provide notification pop-ups to the user. 7 * <p> 8 * To access this namespace, call <code>require('notifier')</code>. 9 * @name notifier 10 * @example 11 * var n = require("notifier"); 12 */ 13 14 var notifier; 15 16 })(); 17 18 19 Require['notifier'] = { 20 /** 21 * Shows a pop-up notification in Content Studio. The notification will appear in a way 22 * that does not interfere with Content Studio's 23 * @function 24 * @name notify 25 * @memberOf notifier 26 * @param {String} message The text to provide in the pop-up, required. 27 * @param {Number} [duration=3000 (3 seconds)] The length of time (in milliseconds) to show the pop-up 28 * @param {Function} [callback] A function that will be invoked after the notification has 29 * completed, and has been removed from the screen. 30 * @example 31 * n.notify("Hello, World"); 32 * n.notify("Something important just happened", function() { 33 * n.notify("No, just kidding"); 34 * }); 35 */ 36 notify : function(message, duration, callback) { 37 var args, _message, _duration, _callback; 38 if (typeof(message) === 'string') { 39 _message = message; 40 if (typeof(duration) === 'number') { 41 _duration = duration; 42 if (typeof(callback) === 'function') { 43 _callback = callback; 44 } 45 } 46 else if (typeof(duration) === 'function' && callback === undefined) { 47 _callback = duration; 48 } 49 } 50 else if (typeof(message) === 'object') { 51 args = message 52 _message = args['message'] == undefined ? null : args['message']; 53 _duration = args['duration'] == undefined ? null : parseInt(args['duration']); 54 _callback = args['callback'] == undefined ? null : args['callback']; 55 } 56 var javaCallback = _callback == null ? null : new com.escenic.studio.core.notification.Notification.Callback({ 57 'dismissed': function() { 58 _callback(); 59 } 60 }); 61 var notification; 62 if (_duration == null && _callback == null) { 63 notification = new com.escenic.studio.core.script.notifier.ScriptNotification(_message); 64 } 65 else if (javaCallback == null) { 66 notification = new com.escenic.studio.core.script.notifier.ScriptNotification(_message, _duration); 67 } 68 else if (_duration == null) { 69 notification = new com.escenic.studio.core.script.notifier.ScriptNotification(_message, javaCallback); 70 } 71 else { 72 notification = new com.escenic.studio.core.script.notifier.ScriptNotification(_message, _duration, javaCallback); 73 } 74 javaNotifier.notify(notification); 75 } 76 }; 77