Skip to content

Instantly share code, notes, and snippets.

@Satyam
Created May 5, 2012 10:36
Show Gist options
  • Save Satyam/2601422 to your computer and use it in GitHub Desktop.
Save Satyam/2601422 to your computer and use it in GitHub Desktop.
TreeView Editor patch
(function () {
var TV = YAHOO.widget.TreeView,
TVProt = TV.prototype,
Event = YAHOO.util.Event,
Dom = YAHOO.util.Dom;
TVProt.draw = TVProt.render = function () {
var html = this.root.getHtml(),
el = this.getEl(),
ed = TV.editorData;
// If there is an editor, hide it and preserve it
if (ed && ed.editorPanel) {
ed.active = false;
ed.node = null;
ed = ed.editorPanel;
document.createElement('div').appendChild(ed);
Dom.setStyle(ed, 'display', 'none');
} else {
ed = null;
}
// Set the contents of the tree
el.innerHTML = html;
// restore the preserved editor
if (ed) {
el.appendChild(ed);
}
if (!this._hasEvents) {
Event.on(el, 'click', this._onClickEvent, this, true);
Event.on(el, 'dblclick', this._onDblClickEvent, this, true);
Event.on(el, 'mouseover', this._onMouseOverEvent, this, true);
Event.on(el, 'mouseout', this._onMouseOutEvent, this, true);
Event.on(el, 'keydown', this._onKeyDownEvent, this, true);
}
this._hasEvents = true;
};
TVProt._deleteNode = function (node) {
var el = node.getEl(),
ed = TV.editorData;
// If there is an editor and is attached to this node, close it
if (ed && ed.node === node) {
this._closeEditor(false);
ed.node = false;
}
// Remove all the child nodes first
this.removeChildren(node);
// Remove the node from the tree
this.popNode(node);
// The node won't be used, simply wipe it out
if (el) {
el.innerHTML = '';
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment