sydcanem / bootstrap-contextmenu

Context menu plugin for Twitter's Bootstrap framework
http://sydcanem.com/bootstrap-contextmenu/
645 stars 193 forks source link

Cannot read property 'left' of undefined #94

Open jasondavis opened 8 years ago

jasondavis commented 8 years ago

I would really like to use this library but when installed all I get is this error in the console...

Uncaught TypeError: Cannot read property 'left' of undefined   bootstrap-contextmenu.js:163

Here is an example of one of the items the context menu should be attached to...

<div class="regular-card box card-record ui-sortable-handle" id="order-item-id-210" data-order-id="2813" data-order-number="100002607" data-order-item-id="210">
    <div class="alert-message warning">

        <div class="orderid">Order #100002607</div>
        <div class="orderid">Order ID: 2813</div>
        <div class="itemid">Item #210</div>
        <div>Date Created: 2014-05-27 15:51:25</div>
        <div>Date Modified: 2015-04-19 19:25:52</div>
        <div><img src="https://www.neonandmore.com/media/catalog/product/cache/0/image/265x/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/image/Shipping-&amp;-Handling-Custom-Neon-Signs-.jpg" class="order-card-image">
        </div>
        <a href="#" id="order-card-210" data-order-id="2813" data-order-item-id="210" data-url="/orders/orderboards/order/item/210" data-target="#myModal" class="btn btn-default openmodal">View Order Item</a>
    </div>
</div>

using...

$('.card-record').contextmenu();

Any ideas for a fix?

Image of the code causing error...

image

AstRonin commented 8 years ago

You may try this vertion. https://github.com/AstRonin/bootstrap-contextmenu/blob/master/bootstrap-contextmenu.js I merged previous PRs for self and maybe it can help you.

rshingleton commented 8 years ago

I was running into the same issue and after much digging around, turns out it was my own fault. I was including a page fragment which was missing the target object (html).

$('#main').contextmenu({ target: '#context-menu', ... });

Make sure that the html node with id #context-menu is on the page.