Permalink
Browse files

BUGFIX: Use new jQuery.Entwine event capturing, onadd and onremove fe…

…atures to plug some memory leaks
  • Loading branch information...
1 parent bbd1bb7 commit b86a787521b5cb9ae7c854ef9b26f4dbe7ec91fa Hamish Friedlander committed with chillu Jun 12, 2012
@@ -15,12 +15,6 @@
*/
$('.cms-edit-form.cms-add-form').entwine({
/**
- * Variable: Tree
- * (DOMElement)
- */
- Tree: null,
-
- /**
* Variable: OrigOptions
* (Array) Map of <option> values to an object of "title" and "value"
*/
@@ -31,18 +25,24 @@
* (Array) Internal counter to create unique page identifiers prior to ajax saving
*/
NewPages: [],
-
+
+ getTree: function() {
+ return $('.cms-tree');
+ },
+
+ fromTree: {
+ onselect_node: function(e, data){
+ self.refresh(data.rslt.obj);
+ }
+ },
+
/**
* Constructor: onmatch
*/
- onmatch: function() {
+ onadd: function() {
var self = this, typeDropdown = this.find(':input[name=PageType]');
- var tree = $('.cms-tree');
- this.setTree(tree);
-
// Event bindings
- $(tree).bind('select_node.jstree', function(e, data) {self.refresh(data.rslt.obj);});
typeDropdown.bind('change', function(e) {self.refresh();});
// TODO Bind on tree initialization to set dropdown for selected node
@@ -56,9 +56,7 @@
this._super();
},
- onunmatch: function() {
- this._super();
- },
+
/**
* Function: onsubmit
*
@@ -19,50 +19,46 @@
$('#Form_BatchActionsForm').entwine({
/**
- * Variable: Tree
- * (DOMElement)
- */
- Tree: null,
-
- /**
* Variable: Actions
* (Array) Stores all actions that can be performed on the collected IDs as
* function closures. This might trigger filtering of the selected IDs,
* a confirmation message, etc.
*/
Actions: [],
-
+
+ getTree: function() {
+ return $('.cms-tree');
+ },
+
+ fromTree: {
+ oncheck_node: function(e, data){
+ this.serializeFromTree();
+ }
+ },
+
/**
* Constructor: onmatch
*/
- onmatch: function() {
- var self = this, tree = $('.cms-tree');
-
- this.setTree(tree);
-
- tree.bind('check_node.jstree', function(e, data) {
- self.serializeFromTree();
- });
-
- $('.cms-tree-view-modes :input[name=view-mode]').bind('click', function(e) {
- var val = $(e.target).val(), dropdown = self.find(':input[name=Action]');
+ onadd: function() {
+ this._updateStateFromViewMode();
+ this._super();
+ },
+
+ 'from .cms-tree-view-modes :input[name=view-mode]': {
+ onclick: function(e){
+ var val = $(e.target).val(), dropdown = this.find(':input[name=Action]'), tree = this.getTree();
+
if(val == 'multiselect') {
tree.addClass('multiple');
- self.serializeFromTree();
+ this.serializeFromTree();
} else {
- tree.removeClass('multiple');
+ tree.removeClass('multiple');
}
- self._updateStateFromViewMode();
- });
-
- self._updateStateFromViewMode();
-
- this._super();
- },
- onunmatch: function() {
- this._super();
+ this._updateStateFromViewMode();
+ }
},
+
/**
* Updates the select box state according to the current view mode.
*/
@@ -10,7 +10,7 @@
*/
$('.cms-content').entwine({
- onmatch: function() {
+ onadd: function() {
var self = this;
// Force initialization of certain UI elements to avoid layout glitches
@@ -19,10 +19,7 @@
this._super();
},
- onunmatch: function() {
- this._super();
- },
-
+
redraw: function() {
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
@@ -39,7 +36,7 @@
* Load edit form for the selected node when its clicked.
*/
$('.cms-content .cms-tree').entwine({
- onmatch: function() {
+ onadd: function() {
var self = this;
this._super();
@@ -80,9 +77,6 @@
self.removeForm();
}
});
- },
- onunmatch: function() {
- this._super();
}
});
@@ -50,7 +50,7 @@
/**
* Constructor: onmatch
*/
- onmatch: function() {
+ onadd: function() {
var self = this;
// Turn off autocomplete to fix the access tab randomly switching radio buttons in Firefox
@@ -106,7 +106,7 @@
this._super();
},
- onunmatch: function() {
+ onremove: function() {
this.changetracker('destroy');
this._super();
},
@@ -78,23 +78,6 @@
onmatch: function() {
var self = this;
- var updateMenuFromResponse = function(xhr) {
- var controller = xhr.getResponseHeader('X-Controller');
- if(controller) {
- var item = self.find('li#Menu-' + controller);
- if(!item.hasClass('current')) item.select();
- }
- self.updateItems();
- };
- $('.cms-container').live('afterstatechange aftersubmitform', function(e, data) {
- updateMenuFromResponse(data.xhr);
- });
-
- // Sync collapsed state with parent panel
- this.parents('.cms-panel:first').bind('toggle', function(e) {
- self.toggleClass('collapsed', $(this).hasClass('collapsed'));
- });
-
// Select default element (which might reveal children in hidden parents)
this.find('li.current').select();
@@ -105,6 +88,41 @@
onunmatch: function() {
this._super();
},
+
+ updateMenuFromResponse: function(xhr) {
+ var controller = xhr.getResponseHeader('X-Controller');
+ if(controller) {
+ var item = this.find('li#Menu-' + controller);
+ if(!item.hasClass('current')) item.select();
+ }
+ this.updateItems();
+ },
+
+ 'from .cms-container': {
+ onafterstatechange: function(e, data){
+ this.updateMenuFromResponse(data.xhr);
+ },
+ onaftersubmitform: function(e, data){
+ this.updateMenuFromResponse(data.xhr);
+ }
+ },
+
+ 'from .cms-edit-form': {
+ onrelodeditform: function(e, data){
+ this.updateMenuFromResponse(data.xmlhttp);
+ }
+ },
+
+ getContainingPanel: function(){
+ return this.closest('.cms-panel');
+ },
+
+ fromContainingPanel: {
+ ontoggle: function(e){
+ this.toggleClass('collapsed', $(e.target).hasClass('collapsed'));
+ }
+ },
+
updateItems: function() {
// Hide "edit page" commands unless the section is activated
var editPageItem = this.find('#Menu-CMSMain');
@@ -11,15 +11,11 @@
*/
PingIntervalSeconds: 5*60,
- onmatch: function() {
+ onadd: function() {
this._setupPinging();
this._super();
},
- onunmatch: function() {
- this._super();
- },
-
/**
* Function: _setupPinging
*
@@ -43,34 +43,6 @@
if(!self.is('.is-collapsed')) self.loadCurrentPage();
});
- var updateAfterXhr = function() {
- $('.cms-preview-toggle-link')[self.canPreview() ? 'show' : 'hide']();
-
- // Only load when panel is visible (see details in iframe load event handler).
- if(self.is('.is-collapsed')) return;
-
- // var url = ui.xmlhttp.getResponseHeader('x-frontend-url');
- var url = $('.cms-edit-form').find(':input[name=StageURLSegment]').val();
- if(url) {
- self.loadUrl(url);
- self.unblock();
- } else {
- self.block();
- }
- };
-
- // Listen to history state changes
- $('.cms-container').bind('afterstatechange aftersubmitform', function(e) {
- updateAfterXhr();
- });
-
- // Toggle preview when new menu entry is selected.
- // Only do this when preview is actually shown,
- // to avoid auto-expanding the menu in normal CMS mode
- $('.cms-menu-list li').bind('select', function(e) {
- if(!self.hasClass('is-collapsed')) self.collapse();
- });
-
if(this.hasClass('is-expanded')) this.expand();
else this.collapse();
this.data('cms-preview-initialized', true);
@@ -91,6 +63,40 @@
this.find('iframe').attr('src', url);
},
+ updateAfterXhr: function(){
+ $('.cms-preview-toggle-link')[this.canPreview() ? 'show' : 'hide']();
+
+ // Only load when panel is visible (see details in iframe load event handler).
+ if(this.is('.is-collapsed')) return;
+
+ // var url = ui.xmlhttp.getResponseHeader('x-frontend-url');
+ var url = $('.cms-edit-form').find(':input[name=StageURLSegment]').val();
+ if(url) {
+ this.loadUrl(url);
+ this.unblock();
+ } else {
+ this.block();
+ }
+ },
+
+ 'from .cms-container': {
+ onaftersubmitform: function(){
+ this.updateAfterXhr();
+ },
+ onafterstatechange: function(){
+ this.updateAfterXhr();
+ }
+ },
+
+ // Toggle preview when new menu entry is selected.
+ // Only do this when preview is actually shown,
+ // to avoid auto-expanding the menu in normal CMS mode
+ 'from .cms-menu-list li': {
+ onselect: function(){
+ if(!this.hasClass('is-collapsed')) this.collapse();
+ }
+ },
+
/**
* Loads the matching edit form for a page viewed in the preview iframe,
* based on metadata sent along with this document.
@@ -9,8 +9,8 @@
$('.cms-tree').entwine({
Hints: null,
-
- onmatch: function() {
+
+ onadd: function(){
this._super();
// Don't reapply (expensive) tree behaviour if already present
@@ -96,16 +96,22 @@
}
});
});
-
- $('.cms-container').bind('afterstatechange.tree aftersubmitform.tree', function(e, data) {
- self.updateFromEditForm(e.origData);
- });
},
- onunmatch: function() {
- $('.cms-container').unbind('afterstatechange.tree aftersubmitform.tree');
+ onremove: function(){
+ this.jstree('destroy');
this._super();
},
+ 'from .cms-container': {
+ onafterstatechange: function(e){
+ this.updateFromEditForm(e.origData);
+ },
+
+ onaftersubmitform: function(e){
+ this.updateFromEditForm(e.origData);
+ }
+ },
+
getTreeConfig: function() {
var self = this;
return {
Oops, something went wrong.

0 comments on commit b86a787

Please sign in to comment.