Skip to content

Commit

Permalink
MINOR Fixed change detection false positives for TinyMCE in IE, use T…
Browse files Browse the repository at this point in the history
…inyMCE.isDirty() rather than string comparison
  • Loading branch information
chillu committed Dec 15, 2011
1 parent bf11a32 commit bad1b88
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions admin/javascript/LeftAndMain.EditForm.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -196,9 +196,15 @@
onmatch : function() { onmatch : function() {
var self = this; var self = this;
this.closest('form').bind('beforesave', function() { this.closest('form').bind('beforesave', function() {
tinyMCE.triggerSave(); if(typeof tinyMCE == 'undefined') return;
// TinyMCE assigns value attr directly, which doesn't trigger change event
self.trigger('change'); // TinyMCE modifies input, so change tracking might get false
// positives when comparing string values - don't save if the editor doesn't think its dirty.
if(self.isChanged()) {
tinyMCE.triggerSave();
// TinyMCE assigns value attr directly, which doesn't trigger change event
self.trigger('change');
}
}); });


// Only works after TinyMCE.init() has been invoked, see $(window).bind() call below for details. // Only works after TinyMCE.init() has been invoked, see $(window).bind() call below for details.
Expand All @@ -223,14 +229,26 @@
}); });
ed.render(); ed.render();


// Handle editor de-registration by hooking into state changes.
// TODO Move to onunmatch for less coupling (once we figure out how to work with detached DOM nodes in TinyMCE)
$('.cms-container').bind('beforestatechange', function() {
self.css('visibility', 'hidden');
var ed = tinyMCE.get(self.attr('id'));
if(ed) ed.remove();
});

this._super(); this._super();
}, },


isChanged: function() { isChanged: function() {
if(typeof tinyMCE == 'undefined') return;

return tinyMCE.getInstanceById(this.attr('id')).isDirty(); return tinyMCE.getInstanceById(this.attr('id')).isDirty();
}, },


resetChanged: function() { resetChanged: function() {
if(typeof tinyMCE == 'undefined') return;

var inst = tinyMCE.getInstanceById(this.attr('id')); var inst = tinyMCE.getInstanceById(this.attr('id'));
if (inst) inst.startContent = tinymce.trim(inst.getContent({format : 'raw', no_events : 1})); if (inst) inst.startContent = tinymce.trim(inst.getContent({format : 'raw', no_events : 1}));
}, },
Expand All @@ -243,6 +261,7 @@
this._super(); this._super();
} }
}); });

}); });


}(jQuery)); }(jQuery));

0 comments on commit bad1b88

Please sign in to comment.