Skip to forum content

Mif

— mystic javascript interface

You are not logged in. Please login or register.


Post new reply

Post new reply

Compose and post your new reply

You may use: BBCode Images Smilies

All fields labelled (Required) must be completed before the form is submitted.

Required information for guests



Captcha image. Turn pictures on to see it.
Required information
Optional post settings

Topic review (newest first)

1

good, it's because json_encode return string

"function(){alert('do something')}"


but you want

function(){alert('do something')}

2

Hmm the problem seems to be the php code

If I write my json string without using the php json_encode($str) function it works perfectly.

$jsonResult = '[{
                "name": "Item 1",
                "icon": "mif-menu-add-icon",
                "onAction": function(){alert(\'do something\');}
               },
               {
                "name": "Item 2",
                "icon": "mif-menu-edit-icon",
                "onAction": function(){ alert(\'do something\');}
               }]';

echo($jsonResult);

3

Thanks moro,

your code work fine, but when I am triing to load the menu items via xhtml request (Mootools Request.JSON)
my onAction functions do not get handled.

Do you have a clue what could be the reason

window.addEvent('domready',function(){
    //init a empty menu
    mmenu=new Mif.Menu({
        contextmenu: true,
        target: $('tree_container'),
        offsets: {x:0, y:0},
        initialize: function(){
            new Mif.Menu.KeyNav(this);
        },
        list: {items:[]}
    });
    
    //build the tree
    tree = new Mif.Tree({
        ....
    });
    
    // load tree from url.
    tree.load({
       ....
    });

    //add the context menu functionality
    tree.container.addEvent('contextmenu', function(event){
        var node=tree.mouse.node;
        if(!node) return;
      
            //modifiing the menu items
            //this lines works fine (action functions are handled)
            var list=mmenu.list;
            /*list.options.items=[
                        {
                            name: 'item1',
                            onAction: function(){
                                alert('test');
                            }
                        },
                        {
                            name: 'item2',
                        }
                    ];
            
            //but when i try to load the menu items via xhtml Request (Mootools Request.JSON)
            //my action functions are not handled
            menuItems = SimpleDb.loadContextMenu(node.type); 
            
            list.options.items = menuItems;

            list.items=[];
            list.list.innerHTML='';
            list.initMenu();
            list.drawMenu();
            
        mmenu.show(event); 

        return false;
    });
    
    tree.addEvent('mousedown', function(){
        if (!mmenu) return;
        mmenu.hide();
    });
});

Php code to get the menu items

$items = array();
$items[0]["name"] = "Item A";
$items[0]["onAction"] = "function(){alert('do something')}";
                
$items[1]["name"] = "Item B";
$items[2]["name"] = "Item C";
$items[3]["name"] = "Item D";

echo(json_encode($items));

thanks again,
Jeff

4

menu will be rewriten and transform functionalyti will be added. Now you can fill main menu using this code:

var list=myMenu.list;
list.options.items=[
            {
                name: 'item1'
            },
            {
                name: 'item2',
            }
        ];
list.items=[];
list.list.innerHTML='';
list.initMenu();
list.drawMenu();

5

Hi all,

Knows anybody if it's possible to fill the menu list items dynamically.
I found an example to do so for the sub items but none for the main items.

Thanks for the help