|
280 | 280 | , defaults = { container: 'epiceditor'
|
281 | 281 | , basePath: 'epiceditor'
|
282 | 282 | , localStorageName: 'epiceditor'
|
283 |
| - , file: { name: opts.container || 'epiceditor' // Use the container's ID for an unique persistent file name - will be overwritten if passed a file.name opt |
284 |
| - , defaultContent: '' |
| 283 | + , file: { name: null |
| 284 | + , defaultContent: '' |
285 | 285 | , autoSave: 100 // Set to false for no auto saving
|
286 | 286 | }
|
287 | 287 | , theme: { base: '/themes/base/epiceditor.css'
|
|
306 | 306 | }
|
307 | 307 | }
|
308 | 308 |
|
| 309 | + |
| 310 | + // Grab the container element and save it to self.element |
| 311 | + // if it's a string assume it's an ID and if it's an object |
| 312 | + // assume it's a DOM element |
| 313 | + if (typeof self.settings.container == 'string') { |
| 314 | + self.element = document.getElementById(self.settings.container); |
| 315 | + } |
| 316 | + else if (typeof self.settings.container == 'object') { |
| 317 | + self.element = self.settings.container; |
| 318 | + } |
| 319 | + |
| 320 | + // Figure out the file name. If no file name is given we'll use the ID. |
| 321 | + // If there's no ID either we'll use a namespaced file name that's incremented |
| 322 | + // based on the calling order. As long as it doesn't change, drafts will be saved. |
| 323 | + if (!self.settings.file.name) { |
| 324 | + if (typeof self.settings.container == 'string') { |
| 325 | + self.settings.file.name = self.settings.container; |
| 326 | + } |
| 327 | + else if (typeof self.settings.container == 'object') { |
| 328 | + if (self.element.id) { |
| 329 | + self.settings.file.name = self.element.id; |
| 330 | + } |
| 331 | + else { |
| 332 | + if (!EpicEditor._data.unnamedEditors) { |
| 333 | + EpicEditor._data.unnamedEditors = []; |
| 334 | + } |
| 335 | + EpicEditor._data.unnamedEditors.push(self); |
| 336 | + self.settings.file.name = '__epiceditor-untitled-' + EpicEditor._data.unnamedEditors.length; |
| 337 | + } |
| 338 | + } |
| 339 | + } |
| 340 | + |
309 | 341 | // Protect the id and overwrite if passed in as an option
|
310 | 342 | // TODO: Put underscrore to denote that this is private
|
311 |
| - self.instanceId = 'epiceditor-' + Math.round(Math.random() * 100000); |
| 343 | + self._instanceId = 'epiceditor-' + Math.round(Math.random() * 100000); |
312 | 344 |
|
313 | 345 | self._canSave = true;
|
314 | 346 |
|
|
343 | 375 | self.events = {};
|
344 | 376 | }
|
345 | 377 |
|
346 |
| - if (typeof self.settings.container == 'string') { |
347 |
| - self.element = document.getElementById(self.settings.container); |
348 |
| - } |
349 |
| - else if (typeof self.settings.container == 'object') { |
350 |
| - self.element = self.settings.container; |
351 |
| - } |
352 |
| - |
353 | 378 | return this;
|
354 | 379 | }
|
355 | 380 |
|
|
428 | 453 | }
|
429 | 454 | }
|
430 | 455 | // Write an iframe and then select it for the editor
|
431 |
| - self.element.innerHTML = '<iframe scrolling="no" frameborder="0" id= "' + self.instanceId + '"></iframe>'; |
432 |
| - iframeElement = document.getElementById(self.instanceId); |
| 456 | + self.element.innerHTML = '<iframe scrolling="no" frameborder="0" id= "' + self._instanceId + '"></iframe>'; |
| 457 | + iframeElement = document.getElementById(self._instanceId); |
433 | 458 |
|
434 | 459 | // Store a reference to the iframeElement itself
|
435 | 460 | self.iframeElement = iframeElement;
|
|
839 | 864 | }
|
840 | 865 |
|
841 | 866 | var self = this
|
842 |
| - , editor = window.parent.document.getElementById(self.instanceId); |
| 867 | + , editor = window.parent.document.getElementById(self._instanceId); |
843 | 868 |
|
844 | 869 | editor.parentNode.removeChild(editor);
|
845 | 870 | self.eeState.loaded = false;
|
|
1173 | 1198 |
|
1174 | 1199 | EpicEditor.version = '0.1.0';
|
1175 | 1200 |
|
| 1201 | + // Used to store information to be shared acrossed editors |
| 1202 | + EpicEditor._data = {}; |
| 1203 | + |
1176 | 1204 | window.EpicEditor = EpicEditor;
|
1177 | 1205 | })(window);
|
1178 | 1206 |
|
|
0 commit comments