Author: jmorliaguet Date: Tue Dec 20 19:05:05 2005 New Revision: 2070 Modified: cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js Log:
- better registration of events to avoid registering the same event twice - optimizations. Modified: cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js (original) +++ cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js Tue Dec 20 19:05:05 2005 @@ -23,14 +23,23 @@ Element.setStyle(widget_area, {'cursor': 'default'}); // register the tooltip - Event.observe(widget_area, 'mousemove', this.showTooltip.bind(this)); - Event.observe(widget_area, 'mouseout', this.hideTooltip.bind(this)); + Event.observe(widget_area, 'mousemove', + this.showTooltip.bindAsEventListener(this)); + Event.observe(widget_area, 'mouseout', + this.hideTooltip.bindAsEventListener(this)); new Ajax.Updater(widget_area, 'renderPreview', { parameters: $H({widget_type: widget_type}).toQueryString(), }); - Event.observe(widget_area, 'click', this.onClick.bind(this)); + Event.observe(widget_area, 'click', + this.onClick.bindAsEventListener(this)); + }, + + destroy: function() { + Event.stopObserving(widget_area, 'mousemove', this.showTooltip); + Event.stopObserving(widget_area, 'mouseout', this.hideTooltip); + Event.stopObserving(widget_area, 'click', this.onClick); }, showTooltip: function(e) { @@ -55,9 +64,12 @@ // ignore inactive elements if (elem.getAttribute("inactive")) return; // Get the element selector - this.selector = getSelectorInContext(elem, context=widget_area); + var selector = getSelectorInContext(elem, context=widget_area); + if (selector == this.selector) return; + this.selector = selector; // Set the current selector style // Now we can open the edit form for this style + if (this.form) this.form.destroy(); this.form = new EditForm(this); this.form.create(); }, @@ -140,6 +152,15 @@ }, onComplete: this.onComplete.bind(this), }); + + // Register the event + Event.observe(form_area, 'change', + this.onChange.bindAsEventListener(this)); + }, + + destroy: function() { + // Unregister the event + Event.stopObserving(form_area, 'change', this.onChange); }, onComplete: function(request) { @@ -194,8 +215,6 @@ } form_area.replaceChild(form, form_area.firstChild); - // Register the event - Event.observe(form_area, 'change', this.onChange.bind(this)); }, onChange: function(e) { @@ -207,6 +226,7 @@ attrs[field.name] = field.value; preview.updateStyle(attrs); + // Update the model on the server preview.setSelectorStyle(); } -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins