forked from joaool/MotherGithub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backbone_menu4.html
169 lines (163 loc) · 5.74 KB
/
backbone_menu4.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Backbone/menu v4.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">
-->
<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 x-Editable for bootstrap. Menus 100% json. CSS is bootstrap bootswatch</strong></p>
<div id="xcontainer">
<button>Load</button>
<ul id="list">
</ul>
</div>
<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>
<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 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="../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>
<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><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
}
}
});
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>