public/javascripts/yui/treeview/treeview.js
function () {
        var focused = false, self = this;

        if (this.tree.currentFocus) {
            this.tree.currentFocus._removeFocus();
        }
    
        var  expandParent = function (node) {
            if (node.parent) {
                expandParent(node.parent);
                node.parent.expand();
            } 
        };
        expandParent(this);

        Dom.getElementsBy  ( 
            function (el) {
                return (/ygtv(([tl][pmn]h?)|(content))/).test(el.className);
            } ,
            'td' , 
            self.getEl().firstChild , 
            function (el) {
                Dom.addClass(el, YAHOO.widget.TreeView.FOCUS_CLASS_NAME );
                if (!focused) { 
                    var aEl = el.getElementsByTagName('a');
                    if (aEl.length) {
                        aEl = aEl[0];
                        aEl.focus();
                        self._focusedItem = aEl;
                        Event.on(aEl,'blur',function () {
                            //console.log('f1');
                            self.tree.fireEvent('focusChanged',{oldNode:self.tree.currentFocus,newNode:null});
                            self.tree.currentFocus = null;
                            self._removeFocus();
                        });
                        focused = true;
                    }
                }
                self._focusHighlightedItems.push(el);
            }
        );
        if (focused) { 
                            //console.log('f2');
            this.tree.fireEvent('focusChanged',{oldNode:this.tree.currentFocus,newNode:this});
            this.tree.currentFocus = this;
        } else {
                            //console.log('f3');
            this.tree.fireEvent('focusChanged',{oldNode:self.tree.currentFocus,newNode:null});
            this.tree.currentFocus = null;
            this._removeFocus(); 
        }
        return focused;
    }
function () {
        var focused = false, self = this;

        if (this.tree.currentFocus) {
            this.tree.currentFocus._removeFocus();
        }
    
        var  expandParent = function (node) {
            if (node.parent) {
                expandParent(node.parent);
                node.parent.expand();
            } 
        };
        expandParent(this);

        Dom.getElementsBy  ( 
            function (el) {
                return (/ygtv(([tl][pmn]h?)|(content))/).test(el.className);
            } ,
            'td' , 
            self.getEl().firstChild , 
            function (el) {
                Dom.addClass(el, YAHOO.widget.TreeView.FOCUS_CLASS_NAME );
                if (!focused) { 
                    var aEl = el.getElementsByTagName('a');
                    if (aEl.length) {
                        aEl = aEl[0];
                        aEl.focus();
                        self._focusedItem = aEl;
                        Event.on(aEl,'blur',function () {
                            //console.log('f1');
                            self.tree.fireEvent('focusChanged',{oldNode:self.tree.currentFocus,newNode:null});
                            self.tree.currentFocus = null;
                            self._removeFocus();
                        });
                        focused = true;
                    }
                }
                self._focusHighlightedItems.push(el);
            }
        );
        if (focused) { 
                            //console.log('f2');
            this.tree.fireEvent('focusChanged',{oldNode:this.tree.currentFocus,newNode:this});
            this.tree.currentFocus = this;
        } else {
                            //console.log('f3');
            this.tree.fireEvent('focusChanged',{oldNode:self.tree.currentFocus,newNode:null});
            this.tree.currentFocus = null;
            this._removeFocus(); 
        }
        return focused;
    }
function ( ) { var focused = false , self = this ; if ( this . tree . currentFocus ) { this . tree . currentFocus . _removeFocus ( ) ; } var expandParent = function ( node ) { if ( node . parent ) { expandParent ( node . parent ) ; node . parent . expand ( ) ; } } ; expandParent ( this ) ; Dom . getElementsBy ( function ( el ) { return ( / ygtv(([tl][pmn]h?)|(content)) / ) . test ( el . className ) ; } , 'td' , self . getEl ( ) . firstChild , function ( el ) { Dom . addClass ( el , YAHOO . widget . TreeView . FOCUS_CLASS_NAME ) ; if ( ! focused ) { var aEl = el . getElementsByTagName ( 'a' ) ; if ( aEl . length ) { aEl = aEl [ 0 ] ; aEl . focus ( ) ; self . _focusedItem = aEl ; Event . on ( aEl , 'blur' , function ( ) { //console.log('f1'); self . tree . fireEvent ( 'focusChanged' , { oldNode : self . tree . currentFocus , newNode : null } ) ; self . tree . currentFocus = null ; self . _removeFocus ( ) ; } ) ; focused = true ; } } self . _focusHighlightedItems . push ( el ) ; } ) ; if ( focused ) { //console.log('f2'); this . tree . fireEvent ( 'focusChanged' , { oldNode : this . tree . currentFocus , newNode : this } ) ; this . tree . currentFocus = this ; } else { //console.log('f3'); this . tree . fireEvent ( 'focusChanged' , { oldNode : self . tree . currentFocus , newNode : null } ) ; this . tree . currentFocus = null ; this . _removeFocus ( ) ; } return focused ; }
Sets the focus on the node element.
It will only be able to set the focus on nodes that have anchor elements in it.
Toggle or branch icons have anchors and can be focused on.
If will fail in nodes that have no anchor
@method focus
@return {boolean} success
Sets the focus on the node element . It will only be able to set the focus on nodes that have anchor elements in it . Toggle or branch icons have anchors and can be focused on . If will fail in nodes that have no anchor