forked from RubyLouvre/avalon.oniui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
349 lines (344 loc) · 15.3 KB
/
index.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" class="xjb_html">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>去哪儿avalon ui</title>
<link type="text/css" rel="stylesheet" href="./style/avalon.doc.css" />
<link type="text/css" rel="stylesheet" href="./style/avalon.index.css" />
<script src="avalon.js"></script>
<script src="history.js"></script>
<script src="./highlight/shCore.js"></script>
<link rel=stylesheet type=text/css href="pages/timeline/css/base.css"/>
<script>
var page = avalon.define("pages", function(vm) {
vm.pages = [{
title: "组件库",
href: "pages/library/index.html"
},
{
title: "组件概览",
href: "pages/timeline/index.html"
},
{
title: "APIs",
href: "pages/apis/index.html"
},
{
title: "下载",
href: "pages/download/index.html"
}
]
vm.changeActiveIndex = function(index) {
vm.activeIndex = index
}
vm.activeIndex = 0
vm.computeActiveIndex = function(url) {
var url = url || location.hash.replace(/#/g, "");
for(var i = 0, len = page.pages.length; i < len; i++) {
if(page.pages[i].href === url) {
return i;
}
}
return 0
}
})
page.activeIndex = page.computeActiveIndex();
require(["uptop/avalon.uptop"], function() {
avalon.scan(document.body, page)
})
</script>
</head>
<body class="ms-controller" ms-controller="pages" ms-uptop data-uptop-background-url="uptop/up.png">
<div class="header">
<div class="fix">
<div class="nav">
<ul>
<li ms-repeat-page="pages" ms-class="active: $index == activeIndex" ms-click="changeActiveIndex($index)">
<a ms-href="#{{page.href}}" >{{page.title | html}}</a>
</li>
</ul>
<div class="search">
<input type="text"/>
</div>
</div>
</div>
<div class="placeHolder"></div>
<h1><span>Avalon新一代UI库: OniUI</span></h1>
</div>
<div class="content" ms-class="content{{activeIndex}}">
<div ms-repeat-page="pages" ms-if-loop="$index == activeIndex" ms-include-src="page.href"></div>
</div>
<div class="footer">
<ul>
<li><a href="#">关于AvalonUI</a></li>
<li><a href="#">联系我们</a></li>
<li><a href="#">业务合作</a></li>
<li><a href="#">常见问题</a></li>
<li class="last"><a href="#">友情链接</a></li>
</ul>
</div>
<script>
require(["dialog/avalon.dialog.js"], function(avalon) {
var docCssReg = /<link[^>]*style\/avalon\.doc\.css[^>]*\>/img,
widgets = ["accordion", "at","browser", "checkboxlist", "colorpicker", "cookie",
"coupledatepicker", "datepicker", "daterangepicker", "dialog",
"doublelist", "draggable", "dropdown", "flipswitch", "miniswitch",
"notice", "pager", "position", "preview", "progressbar", "promise", "rating",
"resizable", "scrollbar", "scrollspy", "simplegrid", "slider",
"spinner", "store", "switchdropdown", "tab", "textbox", "tooltip"].sort(),
defaultHref = "accordion/avalon.accordion.doc.html";
function getHref(urlHash) {
var hash = (urlHash || location.hash).match(/avalon[\S]+\.html/g) || "",
page = false,
widget = hash && hash[0].split(".")[1];
if (widget) {
switch (widget) {
case "coupledatepicker":
case "daterangepicker":
widget = "datepicker";
break;
}
}
if(hash) {
hash = widget + "/" + hash[0]
}
if (!hash && (urlHash || location.hash)) {
hash = urlHash || location.hash.replace(/^#/, "");
page = true;
}
return {
page: page,
hash: hash
}
}
function setHash(hash) {
if(!hash.match(/^#/g)) hash = "#" + defaultHref.split("/")[1]
location.hash = hash
}
// decide currentIndex by vmodel.href
function getcurrentIndex(hash) {
var widgetName = hash.split("/")[0];
for(var i = 0, len = widgets.length; i < len; i++) {
if(widgets[i] === widgetName) return i;
}
return 0
}
function getcurrentPageIndex(hash, nav) {
var hash = (hash || "").replace(/^#/g, "");
for(var i = 0, len = nav.length; i < len; i++) {
if(hash === nav[i].href) return i
}
return 0
}
function throttleIndex(fn, delay, mustRunDelay, args){
var timer = null;
var t_start;
return function(){
var context = this, t_curr = +new Date();
clearTimeout(timer);
if(!t_start){
t_start = t_curr;
}
if(t_curr - t_start >= mustRunDelay){
fn.apply(context, args || []);
t_start = t_curr;
}
else {
timer = setTimeout(function(){
fn.apply(context, args || []);
}, delay);
}
};
};
function fixUiList() {
var uiListTop = vmodel.uiListTop,
totalTop = uiListTop + vmodel.uiListHeight,
scrollTop = document.body.scrollTop + document.documentElement.scrollTop,
scrollHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
clientHeight = avalon(window).height();
if ((scrollTop + clientHeight) > totalTop) {
vmodel.position = "fixed";
vmodel.fixTop = "auto";
vmodel.fixBottom = 0;
} else {
vmodel.position = "absolute";
vmodel.fixTop = 45;
vmodel.fixBottom = "auto";
}
// 避免滚动到最底部时,白色背景上导航的尴尬,且无法显示底部的组件列表
if ((scrollTop + clientHeight + 120) >= scrollHeight) {
vmodel.position = "absolute";
vmodel.fixTop = "auto";
vmodel.fixBottom = 80;
}
}
avalon(window).bind("scroll", throttleIndex(fixUiList, 50, 100));
var oldHref, vmodel = avalon.define("avalonUiDocument", function(vm) {
vm.$skipArray = ["uiListTop"];
vm.widgets = widgets;
vm.href = getHref().hash || defaultHref;
vm.contentWidth = 760;
vm.currentIndex = getcurrentIndex(vm.href);
vm.uiListHeight = 0;
vm.uiListTop = 0;
vm.hashchangeSupport = !navigator.userAgent.match(/MSIE [5-7]/);
vm.timer = "";
vm.page = false;
vm.nav = [
{
href: defaultHref,
name: "组件库",
pageName: "pageUiLibrary"
},
{
href: "ui_timeline",
name: "组件概览",
pageName: "pageTimeline"
},
{
href: "pages/apis/index.html",
name: "APIs",
pageName: "apis"
}
];
// 保留历史功能
vm.currentPageIndex = getcurrentPageIndex(location.hash, vm.nav);
vm.position = "absolute";
vm.fixTop = 45;
vm.fixBottom = "auto";
vm.$uiList = null;
vm.padBottom = location.hash === "#ui_timeline" ? 0 : 80;
vm.imgUrl = ""; // dialog的大图图片路径
vm.$dialogOpts = {
width: 840,
type: "alert",
title: "组件使用演示",
confirmName: "关闭"
}
vm.canThisPageShow = function(pageName) {
return vmodel.nav[vmodel.currentPageIndex].pageName === pageName
}
vm.changePage = function(event, href, index, item) {
event.preventDefault();
if(!vmodel.hashchangeSupport) {
vmodel.href = href;
}
switch(item.pageName) {
case "pageUiLibrary":
vmodel.padBottom = 80;
break;
case "pageTimeline":
vmodel.padBottom = 0;
break;
}
setHash("#"+href);
vm.currentPageIndex = index;
}
vm.pageLoaded = function(template) {
template = template.replace(/"(static\/)/img, '"ui_timeline/$1')
return template;
};
vm.showDocument = function(widget, event, index) {
event.preventDefault();
if(!vmodel.hashchangeSupport) {
switch (widget) {
case "coupledatepicker":
vmodel.href = "datepicker/avalon.coupledatepicker.doc.html";
break;
case "daterangepicker":
vmodel.href = "datepicker/avalon.daterangepicker.doc.html";
break;
default:
vmodel.href = widget + "/avalon." + widget + ".doc.html";
break;
}
}
setHash("#avalon." + widget + ".doc.html");
vmodel.currentIndex = index;
};
vm.afterTemplateLoaded = function(template) {
template = template.replace(docCssReg, "");
return template;
};
vm.uiListRendered = function() {
vmodel.uiListHeight = avalon(this).height();
vmodel.uiListTop = avalon(this).offset().top;
}
vm.renderIframe = function() {
if(!vmodel.hashchangeSupport) return "";
return '<iframe id="doccanvas" scrolling="no" name="doccanvas" ms-class="ui-doc:!page" style="border:none;" frameborder="none" src="' + vmodel.href + '" ms-css-width="'+ vmodel.contentWidth +'"></iframe>'
}
vm.showBigPic = function(url) {
vm.imgUrl = url;
avalon.vmodels.treeLeafBig.toggle = true;
}
vm.setHeight = function() {
clearInterval(vmodel.timer);
var counter = 0;
// 扫描,修改高度
vmodel.timer = setInterval(function() {
var iframe = document.getElementById("doccanvas")
if(!iframe) return clearInterval(vmodel.timer)
var nwindow = iframe.contentWindow
try{
if(nwindow.document && nwindow.document.getElementsByTagName("body")[0]) {
nwindow = nwindow.document
h = avalon(nwindow.body).outerHeight() + avalon(nwindow.body).offset().top;
avalon(iframe).css("height", h + "px");
counter++;
if(counter > 50) clearInterval(vmodel.timer)
if(oldHref !== nwindow.location.href) {
oldHref = nwindow.location.href
if(!oldHref.match(/avalon\.[\S]+\.doc\./g)) return;
// 把iframe的src同步到父页面hash
if(!vmodel.hashchangeSupport) {
var h = oldHref.split("/")
setHash("#" + h[h.length - 1]);
}
var ols = nwindow.getElementsByTagName("ol");
if(!ols.length) ols = nwindow.getElementsByTagName("ul");
for(var i = 0, len = ols.length; i < len; i++) {
if(!ols[i].className.match(/example\-lists|example\-links/g)) continue;
var as = ols[i].getElementsByTagName("a")
avalon.each(as, function(x, item) {
item.onclick= function(e) {
var e = e || iframe.contentWindow.event;
e.preventDefault && e.preventDefault();
e.returnValue = false;
var h = item.getAttribute("href").split("/");
h = h[h.length - 1];
setHash("#" + (h.match(/avalon[\S]+\.html/g) || []).join(""));
if(!vmodel.hashchangeSupport) {
vmodel.href = h.split(".")[1] + "/" + h
; }
}
})
}
}
}
}catch(e) {
clearInterval(vmodel.timer)
}
}, 100)
}
})
window.setHeight = vmodel.setHeight
avalon.scan();
if(vmodel.hashchangeSupport) {
vmodel.setHeight();
window.onhashchange = function(e) {
vmodel.currentPageIndex = getcurrentPageIndex(location.hash, vmodel.nav);
var hash = location.hash.split("#")[1],
hrefObj = {};
hash = hash || defaultHref.split("/")[1];
hrefObj = getHref(hash);
vmodel.href = hrefObj.hash;
vmodel.contentWidth = hrefObj.page ? (vmodel.page=true) && 990 : (vmodel.page=false) || 760;
!vmodel.page && vmodel.setHeight()
}
}
})
</script>
</body>
</html>