This is a migrated thread and some comments may be shown as answers.

problem/bug with Jquery live function

0 Answers 46 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
mahmoud
Top achievements
Rank 1
mahmoud asked on 12 May 2012, 09:27 AM
Dear Teleriks,

I have a simple menu like this : 

@(Html.Telerik().Menu()
            .Name("assResourceActions11")
            .Items(menu =>
            {
                menu.Add()
                    .Text("New...")
                    .SpriteCssClasses("database_add-png")
                    .Visible(Commons.CurrentUser.HasPermission<ResourcePermission>(ResourcePermission.Create))
                    .Items(menuItem =>
                    {
                        menuItem.Add()
                            .Text("New Resource...")
                            .SpriteCssClasses("database_add-png")
                            .Action("create""Resources"new { parentId = Request["ParentId"] }); 
                    });
 
            })
                )

And a jquery live function like this : 

<script type="text/javascript">
    $().ready(function () {
        //$('#assResourceActions11 a').click(function () { alert(22); });
        $('#assResourceActions11 a').live('click'function () { alert(1); });     }); </script>

but it never handles the live function without any javascript error. But the simple click handling (commented line in above js script) works fine.

I tried more: After rendering the page, I extracted the menu rendering result and put it on the page directly like this :

<ul class="t-widget t-reset t-header t-menu" id="assResourceActions11">
    <li class="t-item t-state-default" style=""><span class="t-link"><span class="t-sprite database_add-png">
    </span>عامل جدید<span class="t-icon t-arrow-down"></span></span><div class="t-animation-container"
        style="width138pxheight22pxdisplaynone;">
        <ul class="t-group" style="displayblockwidth136pxmargin-top-22px;">
            <li class="t-item t-state-default"><a class="t-link" href="/safat/Resources/Resources/create">
                <span class="t-sprite database_add-png"></span>عامل ساده جدید...</a></li></ul>
    </div>
    </li>
</ul>
 
although the menu not works as desired but the above script works on it in correcly!
Isn't it a bug??

It seems the related menu script(telerik.menu.min.js) do some strange works that causes this problem.

Thanks in advance

-----------------------------------------------------------------------------------
PS. EDIT : 
I found the source of problem in telerik.menu.min.js file/ click function. I solved it by following corrections (It works in my case but I'm not sure if it is correct in all other cases or not )

        click: function (e, element) {
            //e.stopPropagation(); by moravej
 
            var $li = $(element);
 
            if ($li.hasClass('t-state-disabled')) {
                e.stopPropagation(); //by moravej
                e.preventDefault();
                return;
            }
 
            if ($t.trigger(this.element, 'select', { item: $li[0] })) {
                e.stopPropagation(); //by moravej
                e.preventDefault();
                return;
            }
 
            if (!$li.parent().hasClass('t-menu') || !this.openOnClick) {
                return;
            }
            
            e.stopPropagation(); //by moravej
            e.preventDefault();
 
            this.clicked = true;
 
            this.triggerEvent('open', $li);
 
            this.open($li);
        },

Tags
Menu
Asked by
mahmoud
Top achievements
Rank 1
Share this question
or