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 * Open or focus the editor identified by the given <code>uri</code>. 115 * This will open a new editor tab, and will attempt to dereference 116 * the given URI. The URI <em>should</em> be on the same server as 117 * the user is currently logged in, and <em>should</em> use the same 118 * endpoint (i.e. exactly the same host name and port number), in 119 * order for Content Studio to correctly identify the content item. 120 * 121 * @param uri The uri of the editor to open/focus 122 * @memberOf content-studio 123 * @function 124 * @name openEditor 125 * @example 126 * CS.openEditor("https://example.com/webservice/content/article/123"); 127 */ 128 this.openEditor = function(uri) { 129 jsStudioContext.openEditor(uri); 130 }; 131 132 /** 133 * Request to close the editor identified by the given <code>uri</code>, 134 * if it exists. This may result in the user wanting to save their 135 * changes, or a close of the editor with no prompt if there were no 136 * modifications done by the user. 137 * 138 * @param uri The uri of the editor to close 139 * @memberOf content-studio 140 * @function 141 * @name requestCloseEditor 142 */ 143 this.requestCloseEditor = function(uri) { 144 jsStudioContext.requestCloseEditor(uri); 145 }; 146 147 /** 148 * Create a panel in Content Studio with the given <code>uri</code>. 149 * A side panel will be created and associated with a URI. The URI is 150 * later used in events, to recognise the "initialisation" 151 * <p> 152 * The panel will be created, and an EventEmitter will be returned which 153 * can emit the <code>action</code> event. This event will be fired 154 * typically whenever the user activates (double clicks) on something 155 * in the panel. 156 157 * @param uri The urn of the panel. This will be used to identify the panel. 158 * @param name The label of the panel 159 * @param shortcut The shortcut of the panel 160 * @memberOf content-studio 161 * @function 162 * @name createPanel 163 */ 164 this.createPanel = function(uri, name, shortcut) { 165 var action = require('actions').createAction(name,shortcut); 166 var emitter = new EventEmitter(); 167 jsStudioContext.createPanel(uri, action.emitterAction, new com.escenic.studio.core.script.EventEmitter(emitter)); 168 return emitter; 169 }; 170 171 /** 172 * Opens the panel in Content Studio with the given <code>uri</code> 173 * 174 * @param uri The urn of the panel 175 * @memberOf content-studio 176 * @function 177 * @name openPanel 178 */ 179 this.openPanel = function(uri){ 180 jsStudioContext.openPanel(uri); 181 } 182 183 /** 184 * Remove the panel from Content Studio with the given <code>uri</code>. 185 * 186 * @param uri The urn of the panel 187 * @memberOf content-studio 188 * @function 189 * @name removePanel 190 */ 191 this.removePanel = function(uri) { 192 jsStudioContext.removePanel(uri); 193 }; 194 195 /** 196 * Opens a stand-alone browser window with the specified URI. This actually opens up 197 * whatever browser the user has installed on his machine, e.g. Internet Explorer, 198 * Safari, Mozilla FireFox. 199 * 200 * @param uri The web page to open 201 * @memberOf content-studio 202 * @function 203 * @name browse 204 */ 205 this.browse = function(uri) { 206 jsStudioContext.browse(uri); 207 }; 208 209 /** 210 * Returns the text that the user has selected right now, or null if 211 * no text is selected. Returns null if the currently focused item doesn't 212 * support selecting text. 213 * @ignore (not part of 5.4.0 release, since it has issues) 214 * @memberOf content-studio 215 * @function 216 * @name getSelectedText 217 */ 218 this.getSelectedText = function() { 219 return jsStudioContext.getSelectedText(); 220 }; 221 222 /** 223 * Returns an array of the URIs of the items that the user has selected right 224 * now. The list is empty if no items are selected or the currently focused 225 * item doesn't support selecting items. 226 * @ignore (not part of 5.4.0 release, since it has issues) 227 * @memberOf content-studio 228 * @function 229 * @name getSelectedItems 230 */ 231 this.getSelectedItems = function() { 232 array = jsStudioContext.getSelectedItems(); 233 var result = []; 234 // ugly conversion from java space to javascript. ugh. 235 for (var i = 0; i < array.length; i++) { 236 result.push("" + array[i]); 237 } 238 return result; 239 }; 240 241 /** 242 * This event is fired whenever an object of a supported MIME type is dropped in 243 * Content Studio. Event handlers listening for events of this type can then retrieve 244 * information about the dropped object. 245 * <p> 246 * The event passes a <code>DropControl</code> object that provides the event handler 247 * with access to the dropped object. 248 * @event 249 * @name content-studio-drop-listen 250 * @memberOf content-studio 251 * @param {DropControl} dropcontrol A DropControl object that can be used to access 252 * the dropped object. 253 */ 254 255 /** 256 * Enables drop support for a specified <code>mimeType</code> in Content Studio. 257 * When an object of the specified MIME type is dropped into the 258 * Content Studio window, a <code>content-studio.drop-listen</code> event will be fired. 259 * @param mimeType The MIME type for which drop support is to be added. 260 * @memberOf content-studio 261 * @function 262 * @name enableDrop 263 */ 264 this.enableDrop = function(mimeType) { 265 jsStudioContext.enableDrop(mimeType); 266 } 267 268 /** 269 * Disables drop support for the specified <code>mimeType</code> in Content Studio 270 * which was enabled using <code>enableDrop</code>. Content studio no longer 271 * fires the <code>content-studio.drop-listen</code> event when the content is dropped. 272 * @param mimeType The MIME type for which drop support is to be disabled. 273 * @memberOf content-studio 274 * @function 275 * @name disableDrop 276 */ 277 this.disableDrop = function(mimeType) { 278 jsStudioContext.disableDrop(mimeType); 279 } 280 } 281 282 //todo this is a util method ... should be moved some other place 283 // also defined in actions.js 284 /** @ignore */ 285 function heir(p) { 286 /** @ignore */ 287 function F() { 288 } 289 290 F.prototype = p; 291 return new F(); 292 } 293 294 ContentStudio.prototype = heir(EventEmitter.prototype); 295 296 // set the constructor to the subclass prototype 297 ContentStudio.prototype.constructor = ContentStudio; 298 299 var contentStudio = new ContentStudio(); 300 jsStudioContext.setEventEmitter(new com.escenic.studio.core.script.EventEmitter(contentStudio)); 301 302 Require['content-studio'] = contentStudio; 303 304 })(); 305