only emit attach if the element was not previously attached.

This commit is contained in:
Christopher Jeffrey 2013-07-18 15:06:33 -05:00
parent 48c2bae2a0
commit f03f51267b

View File

@ -57,7 +57,7 @@ Node.prototype.__proto__ = EventEmitter.prototype;
Node.prototype.type = 'node'; Node.prototype.type = 'node';
Node.prototype.insert = function(element, i) { Node.prototype.insert = function(element, i) {
// var old = element.parent; var old = element.parent;
element.detach(); element.detach();
element.parent = this; element.parent = this;
@ -79,16 +79,16 @@ Node.prototype.insert = function(element, i) {
element.emit('reparent', this); element.emit('reparent', this);
this.emit('adopt', element); this.emit('adopt', element);
// if (!old) { if (!old) {
(function emit(el) { // element.emitDescendants('attach', function(el) {
el._detached = false; // el._detached = false;
el.emit('attach'); // });
if (el.children) el.children.forEach(emit); (function emit(el) {
})(element); el._detached = false;
el.emit('attach');
// element.emitDescendants('attach', function(el) { if (el.children) el.children.forEach(emit);
// el._detached = false; })(element);
// }); }
}; };
Node.prototype.prepend = function(element) { Node.prototype.prepend = function(element) {
@ -110,6 +110,8 @@ Node.prototype.insertAfter = function(element, other) {
}; };
Node.prototype.remove = function(element) { Node.prototype.remove = function(element) {
if (element.parent !== this) return;
element.parent = null; element.parent = null;
var i = this.children.indexOf(element); var i = this.children.indexOf(element);
@ -131,22 +133,20 @@ Node.prototype.remove = function(element) {
element.emit('reparent', null); element.emit('reparent', null);
this.emit('remove', element); this.emit('remove', element);
// element.emitDescendants('detach', function(el) {
// el._detached = true;
// });
(function emit(el) { (function emit(el) {
el._detached = true; el._detached = true;
el.emit('detach'); el.emit('detach');
if (el.children) el.children.forEach(emit); if (el.children) el.children.forEach(emit);
})(element); })(element);
// element.emitDescendants('detach', function(el) {
// el._detached = true;
// });
// this.clearPos(); // this.clearPos();
}; };
Node.prototype.detach = function() { Node.prototype.detach = function() {
if (this.parent) this.parent.remove(this); return this.parent.remove(this);
// this.clearPos();
}; };
Node.prototype.emitDescendants = function() { Node.prototype.emitDescendants = function() {
@ -406,7 +406,6 @@ Screen.prototype._listenMouse = function(el) {
// if (self.grabKeys && self.focused !== el // if (self.grabKeys && self.focused !== el
// && !el.hasAncestor(self.focused)) continue; // && !el.hasAncestor(self.focused)) continue;
// Get the true coordinates.
ret = el.lpos; ret = el.lpos;
if (!ret) continue; if (!ret) continue;
left = ret.xi; left = ret.xi;