Skip to content

Commit 240ce72

Browse files
author
tower1229
committed
update doc.js
1 parent 830044d commit 240ce72

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

Diff for: docs/js/doc.js

+38-34
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
define(function(require) {
55
var $ = require('jquery');
66
var base = require('base');
7-
87
/*生成目录*/
8+
99
var $nav = $('#nav'),
1010
$section = $('section.wrap'),
1111
_nav;
@@ -23,71 +23,72 @@ define(function(require) {
2323
$nav.html(_nav);
2424

2525
/*生成模块目录*/
26-
var $modMenu = $('#modules_index'),
27-
$modItems = $('#modules_list'),
28-
_mod;
29-
_mod = '<ul class="full-row">';
30-
$modItems.find('tr[id]').each(function(i, e) {
31-
var _modName = $(e).attr('id');
32-
_mod += '<li class="span-4 smal-8"><a href="#' + _modName + '">' + _modName + '</a></li>';
33-
});
34-
_mod += '</ul>';
35-
$modMenu.html(_mod);
36-
37-
//查看demo
38-
$('#modules_list').find('tr').each(function(i, e) {
39-
if ($(e).children('td:last').find('pre').length > 1) {
40-
$(e).children('td:last').append('<p><a href="javascript:;" target="_blank" class="viewDemo">viewDemo</a></p>');
26+
var createNavfromTable = function(nav, table) {
27+
var $modMenu = nav,
28+
$modItems = table,
29+
_mod;
30+
_mod = '<ul class="full-row">';
31+
$modItems.find('dt[id]').each(function(i, e) {
32+
var _modName = $(e).attr('id'),
33+
_cont = $(e).next('dd');
34+
_mod += '<li class="span-4 smal-6"><a href="#' + encodeURI(_modName) + '" class="el">' + _modName + '</a></li>';
35+
//代码预览
36+
if (_cont.length && _cont.find('pre').length > 1) {
37+
_cont.append('<p><a href="javascript:;" target="_blank" class="LiveDemo"><i class="ion">&#xe668;</i> LiveDemo </a></p>');
4138
}
42-
43-
}).end()
44-
.on('click', '.viewDemo', function(e) {
39+
}).end().on('click', '.LiveDemo', function(e) {
4540
e.preventDefault();
46-
window.DemoTitle = $(this).parents('tr').find('td').eq(0).text();
47-
window.DemoHtml = $(this).parents('td').find('pre').eq(-2).text();
48-
window.DemoJs = $(this).parents('td').find('pre').eq(-1).text();
49-
window.open('demo.html');
41+
window.DemoTitle = $(this).parents('dd').prev('dt[id]').text();
42+
window.DemoHtml = $(this).parents('dd').find('pre').eq(-2).text();
43+
window.DemoJs = $(this).parents('dd').find('pre').eq(-1).text();
44+
window.open('run.html?page=' + window.DemoTitle);
5045
});
46+
_mod += '</ul>';
47+
$modMenu.html(_mod);
48+
};
49+
50+
createNavfromTable($('#component_index'), $('#component_list'));
51+
createNavfromTable($('#modules_index'), $('#modules_list'));
5152

5253
/*代码着色*/
5354
require('copy');
5455
require('box');
55-
var copybtn = $('<div id="d_clip_button">Copy</div>').appendTo('body');
56+
var copybtn = $('<div id="d_clip_button"><i class="ion">&#xe6b5;</i> Copy</div>').appendTo('body');
5657
var copyCode = '';
5758
copybtn.css({
5859
position: 'absolute',
5960
padding: '3px 14px',
60-
border: '1px solid #ccc',
61-
background: '#fff',
6261
top: '-999px',
6362
zIndex: 999,
64-
borderRadius: '3px'
63+
color:'#61ce3c',
64+
border:'1px solid #61ce3c',
65+
borderRadius:'2px'
6566
});
6667
var showCopyBtn = function(e) {
6768
var pre = $(e.target).is('pre') ? $(e.target) : $(e.target).parents('pre');
68-
if(!pre.data('oncopy')){
69+
if (!pre.data('oncopy')) {
6970
copyCode = pre.data('code');
7071
copybtn.css({
7172
left: pre.offset().left + (pre.outerWidth(true) - copybtn.outerWidth(true)),
7273
top: pre.offset().top
7374
}).show().zclip('remove').zclip({
7475
copy: copyCode,
7576
afterCopy: function() {
76-
$.box.msg('复制成功',{
77-
delay:1000
77+
$.box.msg('复制成功', {
78+
delay: 1000
7879
});
7980
}
8081
});
81-
$('pre').data('oncopy',false);
82-
pre.data('oncopy',true);
82+
$('pre').data('oncopy', false);
83+
pre.data('oncopy', true);
8384
}
8485
};
8586

8687
if (!base.browser.isMobile) {
8788
if (base.browser.ie && base.browser.ie < 9) {
8889
$.box.msg('您的浏览器版本太低,无法启用代码高亮和demo演示,建议使用chrome或360浏览器。', {
8990
color: "danger",
90-
delay:3000
91+
delay: 3000
9192
});
9293
} else {
9394
require.async('lib/highlight/highlight.pack', function(hl) {
@@ -102,6 +103,10 @@ define(function(require) {
102103
$('body').on('mouseenter', 'pre', showCopyBtn);
103104
});
104105
}
106+
}else{
107+
//移动端
108+
$('pre code').css('display', 'block');
109+
$('body').addClass('Mobile');
105110
}
106111

107112
if (window.console) {
@@ -112,5 +117,4 @@ define(function(require) {
112117
}
113118
}
114119

115-
116120
});

0 commit comments

Comments
 (0)