1 /** 2 * @namespace 3 */ 4 var Ozone = Ozone ? Ozone : {}; 5 6 /** 7 * @ignore 8 * @namespace 9 */ 10 Ozone.launcher = Ozone.launcher ? Ozone.launcher : {}; 11 12 (function() { 13 14 var launchChannelName = "_WIDGET_LAUNCHER_CHANNEL"; 15 16 /** 17 * @deprecated Since OWF 3.7.0 You should use <a href="#.getInstance">Ozone.launcher.WidgetLauncher.getInstance</a> 18 * @constructor widgetEventingController - Ozone.eventing.Widget object 19 * @param {Ozone.eventing.Widget} [widgetEventingController] - widget eventing object which handles eventing for the widget 20 * @description This object is used launch other widgets. To do so it requires a widgetEventingController 21 * 22 */ 23 Ozone.launcher.WidgetLauncher = function() { 24 if (Ozone.launcher.WidgetLauncher.instance == null) { 25 this.version = Ozone.version.owfversion + Ozone.version.widgetLauncher 26 27 Ozone.launcher.WidgetLauncher.instance = this; 28 } 29 30 return Ozone.launcher.WidgetLauncher.instance; 31 }; 32 33 Ozone.launcher.WidgetLauncher.prototype = { 34 35 /** 36 * @description launches a Widget based on the config 37 * @param {Object} config object see example for structure 38 * @param {Function} callback a function to be called once after the launchWidget is executed 39 * 40 * @example 41 * 42 * //Example for launching a widget 43 * var widgetEventingController = Ozone.eventing.Widget.getInstance(); 44 * var widgetLauncher = Ozone.launcher.WidgetLauncher.getInstance(this.widgetEventingController); 45 * var data = { 46 * channel: channel, 47 * message: message 48 * }; 49 * var dataString = Ozone.util.toString(data); 50 * widgetLauncher.launchWidget({ 51 * universalName: <universal name of widget to launch>, //universalName or guid maybe identify the widget to be launched 52 * guid: <guid of widget to launch>, 53 * launchOnlyIfClosed: true, //if true will only launch the widget if it is not already opened. 54 * //if it is opened then the widget will be restored 55 * data: dataString //initial launch config data to be passed to a widget only if the widget is opened. this must be a string 56 * }); 57 * 58 */ 59 launchWidget: function(config,callback) { 60 //send message to launch a widget 61 var jsonString = gadgets.json.stringify(config); 62 gadgets.rpc.call('..', launchChannelName, callback, OWF.getIframeId(), jsonString); 63 } 64 }; 65 66 /** 67 * @constructor none 68 * @description Utility functions for a widget that has been launched 69 * 70 */ 71 Ozone.launcher.WidgetLauncherUtils = { 72 /** 73 * @description gets initial launch config data for this widget if it was just launched 74 * @returns {Object} data object which contains initial information for the widget 75 * @example 76 * 77 * var launchConfig = Ozone.launcher.WidgetLauncherUtils.getLaunchConfigData(); 78 * if (launchConfig != null) { 79 * var data = Ozone.util.parseJson(launchConfig); //in this example the data object has two fields: channel and message 80 * if (data != null) { 81 * //do something with the data 82 * scope.subscribeToChannel(data.channel); 83 * scope.addToGrid(null,data.message,data.channel); 84 * } 85 * } 86 * 87 */ 88 getLaunchConfigData: function() { 89 var launchConfig = null; 90 91 //check for data in window.name 92 var configParams = Ozone.util.parseWindowNameData(); 93 if (configParams != null) { 94 95 //get launchConfig 96 launchConfig = configParams.data; 97 } 98 99 return launchConfig; 100 } 101 }; 102 103 /** 104 * @description Retrieves Ozone.eventing.Widget Singleton instance. This object is used launch other widgets. 105 * @example 106 * this.widgetLauncher = Ozone.launcher.WidgetLauncher.getInstance(this.widgetEventingController); 107 */ 108 Ozone.launcher.WidgetLauncher.getInstance = function() { 109 if (Ozone.launcher.WidgetLauncher.instance == null) { 110 Ozone.launcher.WidgetLauncher.instance = new Ozone.launcher.WidgetLauncher(); 111 } 112 return Ozone.launcher.WidgetLauncher.instance; 113 }; 114 115 }()); 116