Comments (9)
I've tried the provided demos in Chrome Stable (18.0.1025.168) and Canary (21.0.1134.0) builds. They both show the correct order of items. If the demos show up correctly, but your code does not, please share your code in a fiddle so I can investigate.
from jquery-contextmenu.
Hi,
first of all: WOW, great response time! :)
The code:
$.contextMenu({
selector: ".context-menu-user",
trigger: "left",
callback: function(key, options) {
// var m = "clicked: " + key + "on element " + $(this).attr("id");
// window.console && console.log(m) || alert(m);
var cnt = "O";
if( key == 2 ) cnt= "Enviar";
if( key == 1 ) cnt= "Devolver";
$(this).children("div").html( cnt );
$(this).children("input[name^='ctx']").val( key );
validateRow( $(this).parent().parent() /* the <tr> */);
},
items: {
"-1": { name: "<nenhuma>",
icon: "edit"
},
"2": { name: "Enviar",
icon: "edit",
disabled: function(key, opt) {
// this references the trigger element
var e = $(this).children("input[name^='estado']").val();
return !( e==0 || e==1 ) /*pendente ou devolvido */;
}
},
"0": { name: "Cancelar envio",
icon: "cut",
disabled: function(key, opt) {
// this references the trigger element
var e = $(this).children("input[name^='estado']").val();
return !( e==2 ) /* enviado/recebido */;
}
}
}
});
Later today I'll try this code in an "empty" web page, just in case some other css is messing with the menu...
Thanks in advance for your support.
from jquery-contextmenu.
I guess this is a problem of chrome, then. This fiddle reduces your issue to the root-problem.
Now that I see this, I imagine to remember having read something about »the order of object properties not being reliable« or something. I'll investigate (once I find the time).
from jquery-contextmenu.
So the problem is with the "-1" ... seems it is treated as string.
And now i see how the items are ordered :) so I'll solve it by modifying the item names ..
Again, thanks for the great support.
from jquery-contextmenu.
Just wanted to add that Firefox seems to show the items in the order that you code them and Chrome seems to sort them based on the key..
from jquery-contextmenu.
There are tons of questions on StackOverflow, like http://stackoverflow.com/questions/3186770/chrome-re-ordering-object-keys-if-numerics-is-that-normal-expected - even pointing you to the related V8 issue.
from jquery-contextmenu.
I found that this behavior is also found in IE9. Creating context menu items with a key value of type integer appear out of order. I reproduced it also with the above jsfiddle in IE9. It's hacky but I was able to work around the issue by prefixing a string before the "real" integer value and stripping it off later.
Is it a concern that it is just a defacto standard that object properties are retrieved in insertion order, rather than being a documented behavior? A possible solution might be to add a "order" property or something that can be added to each item at registration time, and then sorting on this when creating the
from jquery-contextmenu.
I'm curious how this is fixed, because reading the linked question above, apparently there isn't really a way to work around the issue.
AFICT, basically the only way to actually solve this is to not use an object to pass in the items to be placed into the menu. It might "work" right now, but it's working by virtue of an implementation artifact, rather then because it's correct. This is basically working by depending on the JS equivalent of C undefined behaviour.
Passing in a map doesn't appear to currently work, though it's the currently "correct" way of having an ordered key-value store.
from jquery-contextmenu.
Yeah for now it is indeed relying on the behaviour that reordering only happens when the keys are numeric. This might not be ideal, but if this is changed, it needs to be backward compatible.
I wouldn't mind the plugin to accept a Map and get values with a getter then. I would recommend making a new issue with the request for the items to accept a Map as definition.
from jquery-contextmenu.
Related Issues (20)
- How can i rebind the event and overwrite items callback ? HOT 1
- Disable Icons HOT 2
- Allow the selector receive an Element or JQueryNode
- Context menu jumps to the top of the screen HOT 1
- Display bug for a long list of submenu
- Seeking an official way to change context menu items style
- bug?: defining left click as trigger type triggers "oncontextmenu" of trigger button HOT 1
- get the element where the context menu was shown on right click HOT 2
- Issue with menu that is taller than the viewport with submenu items HOT 1
- Chrome v96.0.4664.45 HOT 1
- Do beta (v3) docs exist? The 'v3 Documentation' link goes to v2 Docs currently.
- Can't get Font Awesome icons working HOT 5
- use custom svg icons by gulp HOT 1
- Is it possible to hide a separator? HOT 1
- Animations do not work.
- Security - CVE-2021-41184: Upgrade embedded jQuery UI Position to 1.13+ (v2.x)
- Left click picking up parent as well as targeted child div HOT 1
- Context Menu Titles
- Append to an existing contextMenu?
- Jquery-contextMenu does not trigger the event on the new target element
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-contextmenu.