Skip to content

Commit 0aa0b7a

Browse files
committed
Ticket #102 - Fixed bug where filename would be [object HTMLDivElement] if the element didnt have an ID and no file name was given.
Also added unloads where applicable in the spec which sped up the tests.
1 parent 4e90fd4 commit 0aa0b7a

File tree

4 files changed

+184
-42
lines changed

4 files changed

+184
-42
lines changed

epiceditor/js/epiceditor.js

+41-13
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@
280280
, defaults = { container: 'epiceditor'
281281
, basePath: 'epiceditor'
282282
, 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: ''
285285
, autoSave: 100 // Set to false for no auto saving
286286
}
287287
, theme: { base: '/themes/base/epiceditor.css'
@@ -306,9 +306,41 @@
306306
}
307307
}
308308

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+
309341
// Protect the id and overwrite if passed in as an option
310342
// 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);
312344

313345
self._canSave = true;
314346

@@ -343,13 +375,6 @@
343375
self.events = {};
344376
}
345377

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-
353378
return this;
354379
}
355380

@@ -428,8 +453,8 @@
428453
}
429454
}
430455
// 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);
433458

434459
// Store a reference to the iframeElement itself
435460
self.iframeElement = iframeElement;
@@ -839,7 +864,7 @@
839864
}
840865

841866
var self = this
842-
, editor = window.parent.document.getElementById(self.instanceId);
867+
, editor = window.parent.document.getElementById(self._instanceId);
843868

844869
editor.parentNode.removeChild(editor);
845870
self.eeState.loaded = false;
@@ -1173,6 +1198,9 @@
11731198

11741199
EpicEditor.version = '0.1.0';
11751200

1201+
// Used to store information to be shared acrossed editors
1202+
EpicEditor._data = {};
1203+
11761204
window.EpicEditor = EpicEditor;
11771205
})(window);
11781206

0 commit comments

Comments
 (0)