Fixed a few js memory leaks in EditSurvey page (SimpleEditor appears to
have a memory leak of its own which we either need to get fixed or work-around).
This commit is contained in:
parent
a02cbf95a7
commit
d5f6d8603e
2 changed files with 71 additions and 31 deletions
|
|
@ -8,6 +8,16 @@ Survey.Data = (function(){
|
||||||
var lastDataSet = {};
|
var lastDataSet = {};
|
||||||
var focus;
|
var focus;
|
||||||
var lastId = -1;
|
var lastId = -1;
|
||||||
|
|
||||||
|
// Keep references to widgets here so that we can destory any instances before
|
||||||
|
// creating new ones (to avoid memory leaks)
|
||||||
|
var autoComplete;
|
||||||
|
var sButton, qButton, aButton;
|
||||||
|
|
||||||
|
function purgeNode(node) {
|
||||||
|
YAHOO.util.Event.purgeElement(node, true);
|
||||||
|
document.getElementById(node).innerHTML = '';
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dragDrop: function(did){
|
dragDrop: function(did){
|
||||||
|
|
@ -57,6 +67,11 @@ Survey.Data = (function(){
|
||||||
else {
|
else {
|
||||||
lastId = d.address;
|
lastId = d.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// First purge any event handlers bound to sections node..
|
||||||
|
YAHOO.util.Event.purgeElement('sections', true);
|
||||||
|
|
||||||
|
// Now we can re-write its innerHTML without fear of memory leaks
|
||||||
document.getElementById('sections').innerHTML = d.ddhtml;
|
document.getElementById('sections').innerHTML = d.ddhtml;
|
||||||
|
|
||||||
//add event handlers for if a tag is clicked
|
//add event handlers for if a tag is clicked
|
||||||
|
|
@ -68,28 +83,25 @@ Survey.Data = (function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the add object buttons
|
sButton && sButton.destroy();
|
||||||
// if(d.buttons['section']){
|
sButton = new YAHOO.widget.Button({
|
||||||
document.getElementById('addSection').innerHTML = '';
|
|
||||||
document.getElementById('addQuestion').innerHTML = '';
|
|
||||||
document.getElementById('addAnswer').innerHTML = '';
|
|
||||||
var sButton = new YAHOO.widget.Button({
|
|
||||||
label: "Add Section",
|
label: "Add Section",
|
||||||
id: "addsection",
|
id: "addsection",
|
||||||
container: "addSection"
|
container: "addSection"
|
||||||
});
|
});
|
||||||
sButton.on("click", this.addSection);
|
sButton.on("click", this.addSection);
|
||||||
// }
|
|
||||||
// if(d.buttons['question']){
|
qButton && qButton.destroy();
|
||||||
var qButton = new YAHOO.widget.Button({
|
qButton = new YAHOO.widget.Button({
|
||||||
label: "Add Question",
|
label: "Add Question",
|
||||||
id: "addquestion",
|
id: "addquestion",
|
||||||
container: "addQuestion"
|
container: "addQuestion"
|
||||||
});
|
});
|
||||||
qButton.on("click", this.addQuestion, d.buttons.question);
|
qButton.on("click", this.addQuestion, d.buttons.question);
|
||||||
// }
|
|
||||||
if (d.buttons.answer) {
|
if (d.buttons.answer) {
|
||||||
var aButton = new YAHOO.widget.Button({
|
aButton && aButton.destroy();
|
||||||
|
aButton = new YAHOO.widget.Button({
|
||||||
label: "Add Answer",
|
label: "Add Answer",
|
||||||
id: "addanswer",
|
id: "addanswer",
|
||||||
container: "addAnswer"
|
container: "addAnswer"
|
||||||
|
|
@ -102,12 +114,16 @@ Survey.Data = (function(){
|
||||||
|
|
||||||
// build the goto auto-complete widget
|
// build the goto auto-complete widget
|
||||||
if (d.gotoTargets && document.getElementById('goto')) {
|
if (d.gotoTargets && document.getElementById('goto')) {
|
||||||
var ds = new YAHOO.util.LocalDataSource(d.gotoTargets);
|
var ds = new YAHOO.util.LocalDataSource(d.gotoTargets);
|
||||||
var ac = new YAHOO.widget.AutoComplete('goto', 'goto-yui-ac-container', ds);
|
autoComplete = new YAHOO.widget.AutoComplete('goto', 'goto-yui-ac-container', ds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
document.getElementById('edit').innerHTML = "";
|
Survey.ObjectTemplate.unloadObject();
|
||||||
|
if (autoComplete) {
|
||||||
|
autoComplete.destroy();
|
||||||
|
autoComplete = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lastDataSet = d;
|
lastDataSet = d;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,32 @@ if (typeof Survey === "undefined") {
|
||||||
|
|
||||||
Survey.ObjectTemplate = (function(){
|
Survey.ObjectTemplate = (function(){
|
||||||
|
|
||||||
var editor;
|
// Keep references to widgets here so that we can destory any instances before
|
||||||
|
// creating new ones (to avoid memory leaks)
|
||||||
var dialog;
|
var dialog;
|
||||||
|
var editor;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
|
unloadObject: function(){
|
||||||
|
// First destory the editor..
|
||||||
|
if (editor) {
|
||||||
|
editor.destroy();
|
||||||
|
editor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// And then the Dialog that contains it.
|
||||||
|
if (dialog) {
|
||||||
|
dialog.destroy();
|
||||||
|
dialog = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
loadObject: function(html, type){
|
loadObject: function(html, type){
|
||||||
|
// Make sure we purge any event listeners before overwrite innerHTML..
|
||||||
|
YAHOO.util.Event.purgeElement('edit', true);
|
||||||
document.getElementById('edit').innerHTML = html;
|
document.getElementById('edit').innerHTML = html;
|
||||||
|
|
||||||
var btns = [{
|
var btns = [{
|
||||||
text: "Submit",
|
text: "Submit",
|
||||||
handler: function(){
|
handler: function(){
|
||||||
|
|
@ -39,8 +56,23 @@ Survey.ObjectTemplate = (function(){
|
||||||
document.getElementById('delete').value = 1;
|
document.getElementById('delete').value = 1;
|
||||||
this.submit();
|
this.submit();
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
text: "Preview",
|
||||||
|
handler: function(){
|
||||||
|
if (type === 'answer') {
|
||||||
|
alert('Sorry, preview is only supported for Sections and Questions, not Answers');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var msg = 'This will delete any Survey responses you have made under this ' +
|
||||||
|
'user account and redirect you to the Take Survey page starting at the selected item. ' +
|
||||||
|
"\n\nAre you sure you want to continue?";
|
||||||
|
if (confirm(msg)) {
|
||||||
|
window.location.search = 'func=jumpTo;id=' + dialog.getData().id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
dialog = new YAHOO.widget.Dialog(type, {
|
dialog = new YAHOO.widget.Dialog(type, {
|
||||||
width: "600px",
|
width: "600px",
|
||||||
context: [document.body, 'tr', 'tr'],
|
context: [document.body, 'tr', 'tr'],
|
||||||
|
|
@ -48,26 +80,19 @@ Survey.ObjectTemplate = (function(){
|
||||||
constraintoviewport: true,
|
constraintoviewport: true,
|
||||||
buttons: btns
|
buttons: btns
|
||||||
});
|
});
|
||||||
|
|
||||||
if (type !== 'answer') {
|
|
||||||
btns.push({
|
|
||||||
text: "Preview",
|
|
||||||
handler: function(){
|
|
||||||
window.location.search = 'func=jumpTo;id=' + dialog.getData().id;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
dialog.callback = Survey.Comm.callback;
|
dialog.callback = Survey.Comm.callback;
|
||||||
dialog.render();
|
dialog.render();
|
||||||
|
|
||||||
var textareaId = type + 'Text';
|
var textareaId = type + 'Text';
|
||||||
var textarea = YAHOO.util.Dom.get(textareaId);
|
var textarea = YAHOO.util.Dom.get(textareaId);
|
||||||
|
|
||||||
var height = YAHOO.util.Dom.getStyle(textarea, 'height');
|
var height = YAHOO.util.Dom.getStyle(textarea, 'height');
|
||||||
if (!height) {
|
if (!height) {
|
||||||
height = '300px';
|
height = '300px';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// N.B. SimpleEditor has a memory leak so this eats memory on every instantiation
|
||||||
editor = new YAHOO.widget.SimpleEditor(textareaId, {
|
editor = new YAHOO.widget.SimpleEditor(textareaId, {
|
||||||
height: height,
|
height: height,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
|
@ -83,4 +108,3 @@ Survey.ObjectTemplate = (function(){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue