BUGFIX: Explicitly destroy TinyMCE instances when loading a new page, in an attempt to reduce memory leaks

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@74924 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-04-22 00:16:53 +00:00
parent 119f821b94
commit f6386a4c47
2 changed files with 25 additions and 14 deletions

View File

@ -39,11 +39,9 @@ CMSForm.prototype = {
*/ */
closeIfSetTo: function(id) { closeIfSetTo: function(id) {
if(this.elements.ID && this.elements.ID.value == id) { if(this.elements.ID && this.elements.ID.value == id) {
this.innerHTML = "<p>" + ss.i18n._t('LeftAndMain.PAGEWASDELETED') + "</p>";
// Note: TinyMCE coupling // Note: TinyMCE coupling
if((typeof tinymce != 'undefined') && tinymce.EditorManager) { tinymce_removeAll();
tinymce.EditorManager.editors = {}; this.innerHTML = "<p>" + ss.i18n._t('LeftAndMain.PAGEWASDELETED') + "</p>";
}
} }
}, },
@ -87,6 +85,9 @@ CMSForm.prototype = {
// Rewrite iframe links (for IE) // Rewrite iframe links (for IE)
rightHTML = rightHTML.replace(/(<iframe[^>]*src=")([^"]+)("[^>]*>)/g, '$1' + baseHref() + '$2$3'); rightHTML = rightHTML.replace(/(<iframe[^>]*src=")([^"]+)("[^>]*>)/g, '$1' + baseHref() + '$2$3');
// Note: TinyMCE coupling
tinymce_removeAll();
// Prepare iframes for removal, otherwise we get loading bugs // Prepare iframes for removal, otherwise we get loading bugs
var i, allIframes = this.getElementsByTagName('iframe'); var i, allIframes = this.getElementsByTagName('iframe');
if(allIframes) for(i=0;i<allIframes.length;i++) { if(allIframes) for(i=0;i<allIframes.length;i++) {
@ -126,11 +127,6 @@ CMSForm.prototype = {
for(var i=0;i<tabs.length;i++) if(tabs[i].tagName) initTabstrip(tabs[i]); for(var i=0;i<tabs.length;i++) if(tabs[i].tagName) initTabstrip(tabs[i]);
} catch(er) { /*alert('b: '+ er.message + '\n' + er.line);*/ } } catch(er) { /*alert('b: '+ er.message + '\n' + er.line);*/ }
// Note: TinyMCE coupling
if((typeof tinymce != 'undefined') && tinymce.EditorManager) {
tinymce.EditorManager.editors = {};
}
// We assume that an evaluated response is generated by FormResponse // We assume that an evaluated response is generated by FormResponse
// which takes care of calling these method it // which takes care of calling these method it
if (!evalResponse) { if (!evalResponse) {
@ -451,3 +447,20 @@ function windowName(suffix) {
var base = document.getElementsByTagName('base')[0].href.replace('~','').replace('http://','').replace(/\//g,'_').replace(/\./g,'_'); var base = document.getElementsByTagName('base')[0].href.replace('~','').replace('http://','').replace(/\//g,'_').replace(/\./g,'_');
return base + suffix; return base + suffix;
} }
/**
* Remove all the currently active TinyMCE editors.
* Note: everything that calls this has an inappropriate coupling to TinyMCE.
* Perhaps an observer pattern could be used, where TinyMCE listens to a onBeforeCMSPageLoad
* event?
*/
function tinymce_removeAll() {
if((typeof tinymce != 'undefined') && tinymce.EditorManager) {
var id;
for(id in tinymce.EditorManager.editors) {
tinymce.EditorManager.editors[id].remove();
}
tinymce.EditorManager.editors = {};
}
}

View File

@ -71,6 +71,9 @@ Behaviour.register({
rightHTML = formContent; rightHTML = formContent;
rightHTML = rightHTML.replace(/href *= *"#/g, 'href="' + window.location.href.replace(/#.*$/,'') + '#'); rightHTML = rightHTML.replace(/href *= *"#/g, 'href="' + window.location.href.replace(/#.*$/,'') + '#');
// Note: TinyMCE coupling
tinymce_removeAll();
// Prepare iframes for removal, otherwise we get loading bugs // Prepare iframes for removal, otherwise we get loading bugs
var i, allIframes = this.getElementsByTagName('iframe'); var i, allIframes = this.getElementsByTagName('iframe');
if(allIframes) for(i=0;i<allIframes.length;i++) { if(allIframes) for(i=0;i<allIframes.length;i++) {
@ -96,11 +99,6 @@ Behaviour.register({
for(var i=0;i<tabs.length;i++) if(tabs[i].tagName) initTabstrip(tabs[i]); for(var i=0;i<tabs.length;i++) if(tabs[i].tagName) initTabstrip(tabs[i]);
} catch(er) { /*alert('b: '+ er.message + '\n' + er.line); */} } catch(er) { /*alert('b: '+ er.message + '\n' + er.line); */}
// Note: TinyMCE coupling
if((typeof tinymce != 'undefined') && tinymce.EditorManager) {
tinymce.EditorManager.editors = {};
}
// if(this.prepareForm) this.prepareForm(); // if(this.prepareForm) this.prepareForm();
Behaviour.apply($('Form_EditForm')); Behaviour.apply($('Form_EditForm'));
if(this.prepareForm) if(this.prepareForm)