質問するログイン新規登録

質問編集履歴

1

ソースコードの追記

2016/11/23 09:37

投稿

gussan
gussan

スコア7

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,91 @@
1
- 現在、jquary+html5にて、独自の階層付き右クリックメニューを作成しております。
1
+ ```Javascript html5 css3
2
+ 【HTML】
2
3
 
4
+ ①以下のスクリプト、CSSの取り込みを宣言
5
+ <link href="https://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
6
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
7
+ <script src="https://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.js" type="text/javascript"></script>
8
+ <script src="https://swisnl.github.io/jQuery-contextMenu/dist/jquery.ui.position.min.js" type="text/javascript"></script>
9
+
10
+ ②HTMLの右クリック箇所
11
+ <body>
12
+ <p><span class="context-menu-one">right click hear!!</span></p>
13
+ </body>
14
+
15
+ 【JavaScript】
16
+
17
+ <script type="text/javascript">
18
+
19
+ var mainmenu={};
20
+ var historymenu={};
21
+
22
+ $(function(){
23
+ /**************************************************
24
+ * Context-Menu with Sub-Menu
25
+ **************************************************/
26
+
27
+ // メインメニュー表示項目の連想配列を生成
28
+ mainmenu={
29
+ "edit": {"name": "Edit"},
30
+ "cut": {"name": "Cut"},
31
+ "sep1": "---------",
32
+ "quit": {"name": "Quit"},
33
+ "sep2": "---------",
34
+ "fold1": {
35
+ "name": "Sub group",
36
+ "items": {
37
+ "fold1-key1": {"name": "Foo bar"},
38
+ "fold2": {
39
+ "name": "Sub group 2",
40
+ "items": {
41
+ "fold2-key1": {"name": "alpha"},
42
+ "fold2-key2": {"name": "bravo"},
43
+ "fold2-key3": {"name": "charlie"}
44
+ }
45
+ },
46
+ "fold1-key3": {"name": "delta"}
47
+ }
48
+ },
49
+
50
+
51
+ "fold1a": {
52
+ "name": "Other group",
53
+ "items": {
54
+ "fold1a-key1": {"name": "echo"},
55
+ "fold1a-key2": {"name": "foxtrot"},
56
+ "fold1a-key3": {"name": "golf"}
57
+ }
58
+ }
59
+ }
60
+
61
+
62
+ // メインメニューと履歴メニューの配列をマージ
63
+ var arr=mainmenu;
64
+ if(historymenu.length>0){
65
+ arr = $.extend(historymenu, mainmenu);
66
+ }
67
+
68
+ // コンテキストメニューの作成処理
69
+ $.contextMenu({
70
+ selector: '.context-menu-one',
71
+ callback: function(key, options) {
72
+ setHistory(key, options);
73
+ },
74
+ items: arr
75
+
76
+ });
77
+ });
78
+
79
+ // コールバック関数(右クリックメニューを選択後に呼び出される)
80
+ function setHistory(key, options){
81
+ var afterKey=key+"added";
82
+ historymenu.afterKey = { name: options.key.name };// 選択、実行した表示項目文字列をnameキーとしてセット
83
+ }
84
+ </script>
85
+
86
+
87
+ ```現在、jquary+html5にて、独自の階層付き右クリックメニューを作成しております。
88
+
3
89
  右クリックメニューの表示自体は、以下URLを参考に作成できました。
4
90
  ■参考URL:https://swisnl.github.io/jQuery-contextMenu/demo/sub-menus.html
5
91