Skip to content

Commit

Permalink
Fix issue where elements array is lost after destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
nmielnik committed May 26, 2015
1 parent ab697a8 commit cfc79d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 12 additions & 3 deletions spec/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe('Initialization TestCase', function () {
it('should do nothing when selector does not return any elements', function () {
spyOn(MediumEditor.prototype, 'setup');
var editor = this.newMediumEditor('.test');
expect(editor.id).toBe(undefined);
expect(editor.setup).not.toHaveBeenCalled();
expect(editor.isActive).toBeFalsy();
expect(editor.events).toBeUndefined();
expect(editor.toolbar).toBeUndefined();
expect(editor.getExtensionByName('anchor')).toBeUndefined();
expect(editor.getExtensionByName('anchor-preview')).toBeUndefined();
Expand Down Expand Up @@ -85,6 +85,15 @@ describe('Initialization TestCase', function () {
expect(editor.elements.length).toBe(0);
editor.destroy();
});

it('should be available after destroying and calling setup again', function () {
var editor = this.newMediumEditor('.editor');
expect(editor.elements.length).toBe(1);
editor.destroy();
expect(editor.elements.length).toBe(0);
editor.setup();
expect(editor.elements.length).toBe(1);
});
});

describe('With a valid element', function () {
Expand Down Expand Up @@ -197,4 +206,4 @@ describe('Initialization TestCase', function () {
expect(div.appendChild).toHaveBeenCalled();
});
});
});
});
10 changes: 6 additions & 4 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,7 @@ function MediumEditor(elements, options) {
var uniqueId = 1;

this.options = mergeOptions.call(this, this.defaults, options);
createElementsArray.call(this, elements);
if (this.elements.length === 0) {
return;
}
this.origElements = elements;

if (!this.options.elementsContainer) {
this.options.elementsContainer = this.options.ownerDocument.body;
Expand All @@ -611,6 +608,11 @@ function MediumEditor(elements, options) {
return;
}

createElementsArray.call(this, this.origElements);
if (this.elements.length === 0) {
return;
}

this.events = new Events(this);
this.isActive = true;

Expand Down

0 comments on commit cfc79d7

Please sign in to comment.