1 2 /** 3 * The 'content-studio' namespace 4 * @namespace 5 * The content-studio namespace provides an object which provides 6 * a lot of features directly connected to running inside 7 * an instance of Content Studio. The content-studio instance 8 * instance itself is an EventEmitter which emits events when 9 * editors are opened and focused, and you can tell Content 10 * Studio to open side panels and even editors. 11 * @name content-studio 12 * @example 13 * var CS = require("content-studio"); 14 */ 15 16 17 18 (function() { 19 var ContentStudio = function() { 20 // invoke the superclass constructor 21 EventEmitter.call(this); 22 23 // The following JSDoc comments actually make it into the documentation. 24 // Do not delete!!! :-) --mogsie 25 26 /** 27 * The <code>editor-active</code> event is fired whenever a content 28 * editor has been brought up to the front. It does not necessarily 29 * mean that the editor has focus, since the user might be busy in the 30 * search area, but the event does mean that the "current editor" has 31 * changed. 32 * <p> 33 * The event is passed with an object of type EditorControl which allows 34 * further interaction with the editor. 35 * @event 36 * @name content-studio-editor-active 37 * @memberOf content-studio 38 * @param {EditorControl} editor An EditorControl instance used to interact 39 * with the editor. 40 */ 41 42 /** 43 * The <code>editor-inactive</code> event is fired whenever a content 44 * editor that used to be the "active" editor is replaced. 45 * The event means that the "current editor" has changed. 46 * <p> 47 * The event is passed with an object of type EditorControl which allows 48 * identification of the editor. 49 * @event 50 * @name content-studio-editor-inactive 51 * @memberOf content-studio 52 * @param {EditorControl} editor An EditorControl instance used to identify 53 * the editor. 54 */ 55 56 /** 57 * The <code>panel-init</code> event is fired whenever a panel has been 58 * created and is about to be initialized. Typically only the plug-in 59 * that created the panel should continue to initialize it (by adding a 60 * user interface to the panel) but the event mechanism allows plug-ins 61 * to cooperate to share panels, if so desired. 62 * <p> 63 * The event is passed with an object of type PanelControl which allows 64 * further interaction with the panel. 65 * @event 66 * @name content-studio-panel-init 67 * @memberOf content-studio 68 * @param {PanelControl} panel A PanelControl instance used to interact 69 * with the panel. 70 */ 71 72 /** 73 * The <code>panel-destroy</code> event is fired whenever a panel is 74 * destroyed. 75 * <p> 76 * The event is passed with an object of type PanelControl which allows 77 * identification of the panel that was destroyed. 78 * @event 79 * @name content-studio-panel-destroy 80 * @memberOf content-studio 81 * @param {PanelControl} panel A PanelControl instance used to identify 82 * the panel. 83 */ 84 85 /** 86 * The <code>panel-show</code> event is fired whenever a panel has been 87 * shown. This can be used to start background tasks to refresh the 88 * contents of the panel. 89 * <p> 90 * The event is passed with an object of type PanelControl which allows 91 * further interaction with the panel. 92 * @event 93 * @name content-studio-panel-show 94 * @memberOf content-studio 95 * @param {PanelControl} panel A PanelControl instance used to interact 96 * with the panel. 97 */ 98 99 /** 100 * The <code>panel-hide</code> event is fired whenever a panel has been 101 * hidden. This can be used to stop unnecessary background tasks 102 * associated with the panel. 103 * <p> 104 * The event is passed with an object of type PanelControl which allows 105 * further interaction with the panel. 106 * @event 107 * @name content-studio-panel-hide 108 * @memberOf content-studio 109 * @param {PanelControl} panel A PanelControl instance used to interact 110 * with the panel. 111 */ 112 113 /** 114 * The <code>tab-init</code> event is fired whenever a pinned tab has been 115 * created. 116 * <p> 117 * The event is passed with an object of type TabControl which allows 118 * further interaction with the tab. 119 * @event 120 * @name content-studio-tab-init 121 * @memberOf content-studio 122 * @param {TabControl} tab A TabControl instance used to interact 123 * with the tab. 124 */ 125 126 /** 127 * The <code>tab-remove</code> event is fired whenever a pinned tab is 128 * removed. 129 * <p> 130 * The event is passed with the <code>uri</code> of the tab which allows 131 * identification of the tab that was removed. 132 * @event 133 * @name content-studio-tab-remove 134 * @memberOf content-studio 135 * @param {string} uri The <code>uri</code> of the tab. 136 */ 137 138 /** 139 * Open or focus the editor identified by the given <code>uri</code>. 140 * This will open a new editor tab, and will attempt to dereference 141 * the given URI. The URI <em>should</em> be on the same server as 142 * the user is currently logged in, and <em>should</em> use the same 143 * endpoint (i.e. exactly the same host name and port number), in 144 * order for Content Studio to correctly identify the content item. 145 * 146 * @param uri The uri of the editor to open/focus 147 * @memberOf content-studio 148 * @function 149 * @name openEditor 150 * @example 151 * CS.openEditor("https://example.com/webservice/content/article/123"); 152 */ 153 this.openEditor = function(uri) { 154 jsStudioContext.openEditor(uri); 155 }; 156 157 /** 158 * Request to close the editor identified by the given <code>uri</code>, 159 * if it exists. This may result in the user wanting to save their 160 * changes, or a close of the editor with no prompt if there were no 161 * modifications done by the user. 162 * 163 * @param uri The uri of the editor to close 164 * @memberOf content-studio 165 * @function 166 * @name requestCloseEditor 167 */ 168 this.requestCloseEditor = function(uri) { 169 jsStudioContext.requestCloseEditor(uri); 170 }; 171 172 /** 173 * Creates a pinned tab in Content Studio with the given <code>URI</code>, <code>tooltip</code> and 174 * <code>icon</code>. 175 * 176 * @param uri the URI of the HTML page to show in the pinned tab; required. 177 * @param name The tooltip of the tab; required. 178 * @param iconURI the URI of the icon of the pinned tab; optional; must be of type jpeg or png. 179 * @memberOf content-studio 180 * @function 181 * @name createTab 182 */ 183 this.createTab = function (uri, name, iconURI) { 184 jsStudioContext.createTab(uri, name, iconURI); 185 }; 186 187 /** 188 * Shows the pinned tab for the given <code>URI</code>. 189 * 190 * @param uri the URI of the pinned tab; required. 191 * @memberOf content-studio 192 * @function 193 * @name showTab 194 */ 195 this.showTab = function (uri) { 196 jsStudioContext.showTab(uri); 197 }; 198 199 /** 200 * Removes the pinned tab for the given <code>URI</code>. 201 * 202 * @param uri the URI of the pinned tab; required. 203 * @memberOf content-studio 204 * @function 205 * @name removeTab 206 */ 207 this.removeTab = function (uri) { 208 jsStudioContext.removeTab(uri); 209 }; 210 211 /** 212 * Create a panel in Content Studio with the given <code>uri</code>. 213 * A side panel will be created and associated with a URI. The URI is 214 * later used in events, to recognise the "initialisation" 215 * <p> 216 * The panel will be created, and an EventEmitter will be returned which 217 * can emit the <code>action</code> event. This event will be fired 218 * typically whenever the user activates (double clicks) on something 219 * in the panel. 220 221 * @param uri The urn of the panel. This will be used to identify the panel. 222 * @param name The label of the panel 223 * @param shortcut The shortcut of the panel 224 * @param iconURI The uri of the panel's icon 225 * @memberOf content-studio 226 * @function 227 * @name createPanel 228 */ 229 this.createPanel = function(uri, name, shortcut, iconURI) { 230 var action = require('actions').createAction(name,shortcut); 231 var emitter = new EventEmitter(); 232 jsStudioContext.createPanel(uri, action.emitterAction, new com.escenic.studio.core.script.EventEmitter(emitter), iconURI); 233 return emitter; 234 }; 235 236 /** 237 * Opens the panel in Content Studio with the given <code>uri</code> 238 * 239 * @param uri The urn of the panel 240 * @memberOf content-studio 241 * @function 242 * @name openPanel 243 */ 244 this.openPanel = function(uri){ 245 jsStudioContext.openPanel(uri); 246 }; 247 248 /** 249 * Remove the panel from Content Studio with the given <code>uri</code>. 250 * 251 * @param uri The urn of the panel 252 * @memberOf content-studio 253 * @function 254 * @name removePanel 255 */ 256 this.removePanel = function(uri) { 257 jsStudioContext.removePanel(uri); 258 }; 259 260 /** 261 * Opens a stand-alone browser window with the specified URI. This actually opens up 262 * whatever browser the user has installed on his machine, e.g. Internet Explorer, 263 * Safari, Mozilla FireFox. 264 * 265 * @param uri The web page to open 266 * @memberOf content-studio 267 * @function 268 * @name browse 269 */ 270 this.browse = function(uri) { 271 jsStudioContext.browse(uri); 272 }; 273 274 /** 275 * Returns the text that the user has selected right now, or null if 276 * no text is selected. Returns null if the currently focused item doesn't 277 * support selecting text. 278 * @ignore (not part of 5.4.0 release, since it has issues) 279 * @memberOf content-studio 280 * @function 281 * @name getSelectedText 282 */ 283 this.getSelectedText = function() { 284 return jsStudioContext.getSelectedText(); 285 }; 286 287 /** 288 * Returns an array of the URIs of the items that the user has selected right 289 * now. The list is empty if no items are selected or the currently focused 290 * item doesn't support selecting items. 291 * @ignore (not part of 5.4.0 release, since it has issues) 292 * @memberOf content-studio 293 * @function 294 * @name getSelectedItems 295 */ 296 this.getSelectedItems = function() { 297 array = jsStudioContext.getSelectedItems(); 298 var result = []; 299 // ugly conversion from java space to javascript. ugh. 300 for (var i = 0; i < array.length; i++) { 301 result.push("" + array[i]); 302 } 303 return result; 304 }; 305 306 /** 307 * This event is fired whenever an object of a supported MIME type is dropped in 308 * Content Studio. Event handlers listening for events of this type can then retrieve 309 * information about the dropped object. 310 * <p> 311 * The event passes a <code>DropControl</code> object that provides the event handler 312 * with access to the dropped object. 313 * @event 314 * @name content-studio-drop-listen 315 * @memberOf content-studio 316 * @param {DropControl} dropcontrol A DropControl object that can be used to access 317 * the dropped object. 318 */ 319 320 /** 321 * Enables drop support for a specified <code>mimeType</code> in Content Studio. 322 * When an object of the specified MIME type is dropped into the 323 * Content Studio window, a <code>content-studio.drop-listen</code> event will be fired. 324 * @param mimeType The MIME type for which drop support is to be enabled. 325 * @memberOf content-studio 326 * @function 327 * @name enableDrop 328 */ 329 this.enableDrop = function(mimeType) { 330 jsStudioContext.enableDrop(mimeType); 331 }; 332 333 /** 334 * Disables drop support for a specified <code>mimeType</code> in Content Studio 335 * (previously enabled using <code>enableDrop</code>). Content Studio will no longer 336 * fire a <code>content-studio.drop-listen</code> event when an object of 337 * the specified MIME type is dropped into the Content Studio window. 338 * @param mimeType The MIME type for which drop support is to be disabled. 339 * @memberOf content-studio 340 * @function 341 * @name disableDrop 342 */ 343 this.disableDrop = function(mimeType) { 344 jsStudioContext.disableDrop(mimeType); 345 }; 346 }; 347 348 //todo this is a util method ... should be moved some other place 349 // also defined in actions.js 350 /** @ignore */ 351 function heir(p) { 352 /** @ignore */ 353 function F() { 354 } 355 356 F.prototype = p; 357 return new F(); 358 } 359 360 ContentStudio.prototype = heir(EventEmitter.prototype); 361 362 // set the constructor to the subclass prototype 363 ContentStudio.prototype.constructor = ContentStudio; 364 365 var contentStudio = new ContentStudio(); 366 jsStudioContext.setEventEmitter(new com.escenic.studio.core.script.EventEmitter(contentStudio)); 367 368 Require['content-studio'] = contentStudio; 369 370 })(); 371