forked from joaool/MotherGithub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backbone_menu5.html
275 lines (259 loc) · 10.1 KB
/
backbone_menu5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Backbone/menu v5.0</title>
<!-- Bootstrap core CSS -->
<!--
<link href="../smartmenus-master/src/libs/demo-assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="../bootstrap/css/cosmos.css" rel="stylesheet">
<link href="../bootstrap/css/readable.css" rel="stylesheet">
<link href="../bootstrap/css/spacelab.css" rel="stylesheet">
<link href="../bootstrap/css/amelia.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<link href="../x-editable-master/dist/bootstrap3-editable/css/bootstrap-editable.css" rel="stylesheet">
<script src="../x-editable-master/dist/bootstrap3-editable/js/bootstrap-editable.js"></script>
-->
<link href="../bootstrap/css/cerulean.css" rel="stylesheet">
<!-- SmartMenus jQuery Bootstrap Addon CSS -->
<!--
-->
<link href="../smartmenus-master/src/addons/bootstrap/jquery.smartmenus.bootstrap.css" rel="stylesheet">
</head>
<body style="padding-top:40px;">
<p><strong>FrameLink Menus: Bootstrap with smartmenus addon, Backbone and contextMenu and x-Editable for bootstrap. Menus 100% json. CSS is bootstrap bootswatch</strong></p>
<div id="list-template">
<li><a href=""></a></li>
</div>
<div id="submenu-template">
<li><a href=""></a>
<ul class="dropdown-menu">
<li><a href="#">Item 2-2-1</a></li>
</ul>
</li>
</div>
<a href="#" id="username" data-type="text" data-placement="right" data-title="Enter username">User Name</a>
<input type="text" name="fusername"><br>
<div class="container">
<div class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a id="FLBrand" class="navbar-brand" href="./index.html"><img style="height:55px;" src="../bootstrap/img/framelink-logoWithText.png"></a>
</div>
<div class="navbar-collapse collapse">
<ul id="begin_menu" class="nav navbar-nav">
</ul>
</div>
</div>
</div>
<!--
<script type="text/javascript" charset="utf-8" src="../rivets/dist/rivets.js" ></script>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
-->
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="../smartmenus-master/src/libs/demo-assets/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../smartmenus-master/src/jquery.smartmenus.js"></script>
<script type="text/javascript" src="../smartmenus-master/src/addons/bootstrap/jquery.smartmenus.bootstrap.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
<link href="../x-editable-master/dist/bootstrap3-editable/css/bootstrap-editable.css" rel="stylesheet">
<script src="../x-editable-master/dist/bootstrap3-editable/js/bootstrap-editable.js"></script>
<!--
<script src="../jQuery-contextMenu-master/src/jquery.contextMenu.js" type="text/javascript"></script>
<link href="../jQuery-contextMenu-master/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
-->
<script src="../jQuery-contextMenu-gh-pages/src/jquery.contextMenu.js" type="text/javascript"></script>
<link href="../jQuery-contextMenu-gh-pages/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var oMenu = {
"menu" : [
{
"title" : "FrameLink",
"uri":"http://framelink.co"
},
{
"title" : "Main2",
"uri" : "#",
"menu" : [
{
"title" : "Item21 ",
"uri":"#",
},
{
"title" : "Item22",
"uri":"#",
"menu" : [
{
"title" : "Item221 ",
"uri":"#"
}
]
}
]
},
{
"title" : "Main3",
"uri":"#3",
}
]
};
var abc=_.template('<p><%= text %></p>', {text: 'Hello underscore'});
// $("body").html(abc);//body becomes html(abc)
$(abc).insertBefore("#xcontainer");
model = new Backbone.Model({
data:[
{text:"Google",href:"http://google.com"},
{text:"Facebook",href:"http://facebook.com"},
{text:"YouTube",href:"http://youtube.com"}
]
});
Menu = Backbone.Model.extend({
initialize: function(){
console.log("Initializing menu");
},
defaults:{
title:null,
uri:null,
menu:null
}
});
var Menus = Backbone.Collection.extend({
model:Menu
});
var menus = new Menus;//menus is a collection of Menu models
for(var i=0;i<oMenu.menu.length;i++){//for each oMenu[i] we build a Menu Model and add it to the collection
var menuModel = new Menu({title:oMenu.menu[i].title, uri:oMenu.menu[i].uri,menu:oMenu.menu[i].menu});
menus.add(menuModel);
}
menuHTML = function(menuItem){
// now we clone the template, and manipulate it finding element "a" and changing attribute "href" to the uri and change the text in the element to title - after that we do an end in order to get back to the li element
// var htmlToAppend =listTemplate.clone().find("a").attr("href",menuItem.uri).text(menuItem.title).end();
var htmlStr = "<li id=" + menuItem.title + " class='menuItem'><a href=" + menuItem.uri + ">" + menuItem.title + "</a></li>";
// if ( menuItem.title == "FrameLink")
// htmlStr = "<li id='FrameLink'><a href=" + menuItem.uri + ">" + menuItem.title + "</a></li>";
if(menuItem.menu){
var htmlStr = "<li><a href=" + menuItem.uri + ">" + menuItem.title + "</a>";
htmlStr += "<ul class='dropdown-menu'>";
var subMenuItem = menuItem.menu;
for (var i=0;i<subMenuItem.length;i++){
// htmlStr += "<li><a href=" + subMenuItem[i].uri + ">" + subMenuItem[i].title + "</a></li>";
htmlStr += menuHTML(subMenuItem[i])
}
htmlStr += "</ul>";
htmlStr += "</li>";
}
return htmlStr;
};
var MenuView = Backbone.View.extend({
initialize: function(){
console.log("Initializing menu view "+this.el);
this.render();
},
el: "#begin_menu",
render: function(){
var data = menus.toJSON();
// console.log("Total to Render ====>"+JSON.stringify(data));
for (var i=0;i<data.length;i++){
console.log("Render menu ====>"+data[i].title);
this.$el.append( $( menuHTML( data[i] ) ) );//with $(htmlStr) we convert htmlStr to a JQuery object
}
$('#username').editable();
// $('#FLBrand').editable();
var xEditable = "FrameLink";
// $('#'+xEditable).editable();
// $('#Main2').editable();
// $('#Main3').editable();
$('#Item21').editable();
$('#Item22').editable();
$('#Item221').editable();
// $.contextMenu({
// selector: '.menuItem',
// callback: function(key, options) {
// var m = "clicked: " + key;
// window.console && console.log(m) || alert(m);
// },
// items: {
// "edit ": {name: "Edit container", icon: "edit"},
// "cut": {name: "Cut", icon: "cut"},
// "delete": {name: "Delete", icon: "delete"},
// "sep1": "---------",
// "quit": {name: "Quit", icon: "quit"}
// }
// });
$.contextMenu({
selector: '#FLBrand',
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: {
"edit ": {name: "Edit Brand", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"copy": {name: "Copy", icon: "copy"},
"paste": {name: "Paste", icon: "paste"},
"delete": {name: "Delete", icon: "delete"},
"sep1": "---------",
"quit": {name: "Quit", icon: "quit"}
}
});
$.contextMenu({
selector: '#FrameLink',
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: {
"edit ": {name: "Edit FrameLink", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"delete": {name: "Delete", icon: "delete"},
"sep1": "---------",
"quit": {name: "Quit", icon: "quit"}
}
});
$.contextMenu({
selector: '#Main2',
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: {
"edit ": {name: "Edit Main2", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"delete": {name: "Delete", icon: "delete"},
"sep1": "---------",
"quit": {name: "Quit", icon: "quit"}
}
});
$.contextMenu({
selector: '#Main3',
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: {
"edit ": {name: "Edit Main3", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"delete": {name: "Delete", icon: "delete"},
"sep1": "---------",
"quit": {name: "Quit", icon: "quit"}
}
});
$('.context-menu-one').on('click', function(e){
console.log('clicked', this);
})
}
});
var menuView = new MenuView({model:model});
console.log(document.title+"...... END..");
</script>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
</body>
</html>