Topic: Help with extended hover functionality

Hello to all

I'm a big fan of this lovely script since quite a long time. I used a old version (1.2dev) in combination with Mif.Menu. The main purpose is some sort of product categories browser. With the Mif.Menu i gave the user the ability to add, edit, rename or delete further categories to the existing category tree (with the right click event of Mif.Menu). This worked (and still does) like a charm, but I'm not happy any more with the right click navigation.

So I started to implement a navigation bar on the right if the node, solved with the "onHover" event of the current version of Mif.Tree.
Therefore I have extended the Mif.Tree class with 2 new functions. On the attached file you can see a sample how I have implemented this. (it is based on the IconUrl demo, my final version is a bit more complex, of corse).

The problem that I'm crossing now is that the onHover event is not working as expected. When you put your mouse on the node name and then move the mouse from left to right (without leaving the row), the onHover event fires an "mouse out", which is not true. The "mif-tree-hover-node" class is still applied, as you can see on the underlined node name (again in the IconUrl sample).

It is a bit complicated for me to describe, as English is obviously not my first language. The best thing is to replace the demo.js in the /Demos/IconUrl folder. Then you can see what I mean.


Does any one have an other idea how to implement my wanted feature? Any comments, ideas are highly appreciated.

Thanks in advance !!

Here's the code:

Mif.TreeExtended = new Class({

    Extends: Mif.Tree,

    initialize: function(tree, options) {
        alert('extended Version of Mif.Tree');
        var toolBar = new Element('div', {
            'id': 'toolbar',
            'class': 'mif-tree-toolbar',
            styles: {
                'position': 'absolute',
                'left': '160px',
                'top': '1px',
                'height': this.options.height,
                'width': '20px',
                'height': '18px',
                'display':'none',
                'border': '1px solid #FF0000'
            }
        });
        this.toolBar = toolBar;
        this.parent(tree, options);
    },

    hoverToolBarShow: function (coord, node, state) {
        this.toolBar.setStyles({
            'top': document.id('mif-tree-'+node.UID).getCoordinates(tree.wrapper).top,
            'display':'block'
        });
    },

    hoverToolBarHide: function (coord, node, state) {
        this.toolBar.setStyles({
            'display':'none'
        });
    }
    
});

window.addEvent('domready',function(){
    tree = new Mif.TreeExtended({
        container: $('tree_container'),// tree container
        onHover: function (node, target, state) {
            if(state == 'over') { this.hoverToolBarShow(document.id('mif-tree-'+node.UID).getCoordinates(), node, state); }
            if(state == 'out') {    this.hoverToolBarHide(document.id('mif-tree-'+node.UID).getCoordinates(), node, state);    }
        },
        types: {// node types
            folder: {
                openIcon: 'mif-tree-open-icon',//css class open icon
                closeIcon: 'mif-tree-close-icon'// css class close icon
            }
        },
        dfltType: 'folder',//default node type
        height: 18//node height
    });

    var json = [
        {
            "property": {
                "name": "root"
            },
            "children": [
                {
                    "property": {
                        "name": "node1"
                    }
                },
                {
                    "property": {
                        "name": "node2",
                        "openIconUrl": "IconUrl/folder-open.gif",
                        "closeIconUrl": "IconUrl/folder-close.gif"
                    },
                    "state": {
                        "open": true
                    },
                    "children":[
                        {
                            "property": {
                                "name": "node2.1"
                            }
                        },
                        {
                            "property": {
                                "name": "node2.2"
                            }
                        }
                    ]
                },
                {
                    "property": {
                        "name": "node4"
                    }
                },
                {
                    "property": {
                        "name": "node3"
                    }
                }
            ]
        }
    ];
    
    // load tree from json.
    tree.load({
        json: json
    });
    tree.toolBar.inject(tree.wrapper, 'bottom');
});

Last edited by mogi (2010-12-02 19:54:37)

Post's attachments

demo.js 2.25 kb, 4 downloads since 2010-12-02 

You don't have the permssions to download the attachments of this post.

Re: Help with extended hover functionality

I've found a solution (not very elegant), just if someone else should cross this problem.

On line 891 of the current release ('1.2.6.3') of Mif.tree the hover function checks the node and the target

if(node == cnode && (target == 'node'||target==ctarget)) return;

The problem is now that when you are hovering the name, the target is 'name' and not 'node'.
So by adding ||target=='name' to the if statment everything is working as expected (at least for me ;-)

So the edited line 891 looks now:

if(node == cnode && (target=='node'||target==ctarget||target=='name')) return;

cheers

Re: Help with extended hover functionality

onHover: function (node, target, state) {
            if(target != 'node') return;
            ...