improve removal of elements

This commit is contained in:
rlx 2011-11-01 23:14:29 +00:00
parent 7848277593
commit 7761b9dea4
3 changed files with 32 additions and 8 deletions

View file

@ -321,8 +321,12 @@ Ox.Element = function(options, self) {
}; };
that.empty = function() { that.empty = function() {
that.$element.children('.OxElement').each(function() { that.$element.find('.OxElement').each(function() {
Ox.UI.elements[$(this).data('oxid')].removeElement(); var oxid = $(this).data('oxid'),
element = Ox.UI.elements[oxid];
//!element && Ox.print('NO ELEMENT FOR', oxid, this.className)
//element && Ox.print('OK', oxid, this.className)
element && element.removeElement(false);
}); });
that.$element.empty(); that.$element.empty();
return that; return that;
@ -378,14 +382,33 @@ Ox.Element = function(options, self) {
removeElement <function> Removes an element object and its event handler removeElement <function> Removes an element object and its event handler
() -> <obj> This element () -> <obj> This element
@*/ @*/
that.remove = that.removeElement = function() { that.remove = that.removeElement = function(remove) {
that.$element.children('.OxElement').each(function() { //remove !== false && (len = Ox.len(Ox.UI.elements));
Ox.UI.elements[$(this).data('oxid')].removeElement(); ///*
remove !== false && that.$element.find('.OxElement').each(function() {
var oxid = $(this).data('oxid'),
element = Ox.UI.elements[oxid];
//!element && Ox.print('NO ELEMENT FOR', oxid, this.className)
//element && Ox.print('OK', oxid, this.className)
element && element.removeElement(false);
}); });
//*/
Ox.Focus.remove(that.id); Ox.Focus.remove(that.id);
delete self.$eventHandler; delete self.$eventHandler;
delete Ox.UI.elements[that.id]; delete Ox.UI.elements[that.id];
that.$element.remove(); that.$tooltip && that.$tooltip.remove();
remove !== false && that.$element.remove();
/*
if (remove !== false) {
var orphaned = 0;
Ox.forEach(Ox.UI.elements, function(element) {
if (!element.parent().length) {
orphaned++;
}
});
Ox.print('LEN', len, '-->', Ox.len(Ox.UI.elements), 'orphaned:', orphaned);
}
*/
return that; return that;
}; };

View file

@ -49,8 +49,8 @@ Ox.forEach($('<div>'), function(val, key) {
// if the $element of an ox object was returned // if the $element of an ox object was returned
// then return the ox object instead // then return the ox object instead
// so that we can do oxObj.jqFn().oxFn() // so that we can do oxObj.jqFn().oxFn()
return ret && ret.jquery && Ox.UI.elements[id = ret.data('oxid')] ? return ret && ret.jquery && Ox.UI.elements[id = ret.data('oxid')]
Ox.UI.elements[id] : ret; ? Ox.UI.elements[id] : ret;
}; };
} }
}, true); }, true);

View file

@ -201,6 +201,7 @@ Ox.SplitPanel = function(options, self) {
//self.options.elements[pos].element.replaceWith(element.$element.$element || element.$element) //self.options.elements[pos].element.replaceWith(element.$element.$element || element.$element)
//self.options.elements[pos].element = element; //self.options.elements[pos].element = element;
///* ///*
Ox.print('REPLACE ELEMENT')
self.options.elements[pos].element.replaceWith( self.options.elements[pos].element.replaceWith(
self.options.elements[pos].element = element self.options.elements[pos].element = element
); );