source: branches/testa/js/context-menu.js @ 84

Last change on this file since 84 was 23, checked in by anonymous, 6 years ago

init

File size: 3.8 KB
Line 
1function contextmenux2( menu_sel ) {
2        $(menu_sel).contextmenu({
3                delegate: ".hasmenu",
4                hide: { effect: "explode", duration: "slow" },
5                menu: "#options",
6//        position: {my: "left top", at: "left bottom"},
7                position: function(event, ui){
8                        return {my: "left top", at: "left bottom", of: ui.target};
9                },
10                preventSelect: true,
11                show: { effect: "fold", duration: "slow"},
12                taphold: true,
13                uiMenuOptions: { // Additional options, used when UI Menu is created
14                        position: { my: "left top", at: "right+10 top+10" }
15                },
16                focus: function(event, ui) {
17                        var menuId = ui.item.find(">a").attr("href");
18                        $("#info").text("focus " + menuId);
19                        console.log("focus", ui.item);
20                },
21                blur: function(event, ui) {
22                        $("#info").text("");
23                        console.log("blur", ui.item);
24                },
25                beforeOpen: function(event, ui) {
26//                      $("#container").contextmenu("replaceMenu", "#options2");
27//                      $("#container").contextmenu("replaceMenu", [{title: "aaa"}, {title: "bbb"}]);
28                },
29                open: function(event, ui) {
30//          alert("open on " + ui.target.text());
31                },
32                select: function(event, ui) {
33                        alert("select " + ui.cmd + " on " + ui.target.text());
34                }
35        });
36}
37
38function contextmenux( menu_sel ) {
39        $(menu_sel).contextmenu({
40                delegate: ".hasmenu",
41                autoFocus: true,
42                preventContextMenuForPopup: true,
43                preventSelect: true,
44                taphold: true,
45                menu: [
46                        {title: "Menu Header", cmd: "cat1", isHeader: true},
47                        {title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "ui-icon-scissors"},
48                        {title: "Copy <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "ui-icon-copy"},
49                        {title: "Paste <kbd>Ctrl+V</kbd>", cmd: "paste", uiIcon: "ui-icon-clipboard", disabled: true },
50                        {title: "----"},
51                        {title: "More", children: [
52                                {title: "Sub 1 (callback)", action: function(event, ui) { alert("action callback sub1");} },
53                                {title: "Sub 2 (dynamic state)", cmd: "sub2", disabled: function(event, ui) {
54                                        return true;
55                                } },
56                                {title: "Sub 3 (dynamic hide)", cmd: "sub3", disabled: function(event, ui) {
57                                        return "hide";
58                                } },
59                                {title: "Sub 4 (tooltip)", cmd: "sub4", tooltip: "My tooltip"},
60                                {title: "Sub 5 (dynamic tooltip)", cmd: "sub5", tooltip: function(event, ui) {
61                                        return ui.item.text() + " !!!";
62                                } },
63                                {cmd: "sub6", title: function(event, ui) {
64                                        return "Sub 6 (dynamic title): " + ui.target.text();
65                                } }
66                                ]}
67                        ],
68                // Handle menu selection to implement a fake-clipboard
69                select: function(event, ui) {
70                        var $target = ui.target;
71                        switch(ui.cmd){
72                        case "copy":
73                                CLIPBOARD = $target.text();
74                                break
75                        case "paste":
76                                CLIPBOARD = "";
77                                break
78                        }
79                        alert("select " + ui.cmd + " on " + $target.text());
80                        // Optionally return false, to prevent closing the menu now
81                },
82                // Implement the beforeOpen callback to dynamically change the entries
83                beforeOpen: function(event, ui) {
84                        var $menu = ui.menu,
85                                $target = ui.target,
86                                extraData = ui.extraData; // passed when menu was opened by call to open()
87
88                        // console.log("beforeOpen", event, ui, event.originalEvent.type);
89
90                        // NOTE: zIndex() was removed in jQuery 1.12:
91                        // https://jqueryui.com/upgrade-guide/1.12/#removed-zindex
92//                      ui.menu.zIndex( $(event.target).zIndex() + 1);
93
94                        $(document)
95//                              .contextmenu("replaceMenu", [{title: "aaa"}, {title: "bbb"}])
96//                              .contextmenu("replaceMenu", "#options2")
97//                              .contextmenu("updateEntry", "cut", {title: "Cuty", uiIcon: "ui-icon-heart", disabled: true})
98                                .contextmenu("setTitle", "copy", "Copy '" + $target.text() + "'")
99                                .contextmenu("setTitle", "paste", "Paste" + (CLIPBOARD ? " '" + CLIPBOARD + "'" : ""))
100                                .contextmenu("enableEntry", "paste", (CLIPBOARD !== ""));
101
102                        // $(document)
103                        //      .contextmenu("setIcon", "paste", "ui-icon-heart")
104                        //      .contextmenu("setTooltip", "paste", "ui-icon-heart");
105
106                        // Optionally return false, to prevent opening the menu now
107                }
108        });
109}
Note: See TracBrowser for help on using the repository browser.