-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
79 lines (70 loc) · 2.51 KB
/
app.js
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
(function (global, $, undefined) {
var $win = $(window),
$nav = $('.subnav'),
navTop = $('.subnav').length && $('.subnav').offset().top - 40,
isFixed = 0,
processScroll = function () {
var i, scrollTop = $win.scrollTop()
if (scrollTop >= navTop && !isFixed) {
isFixed = 1;
$nav.addClass('subnav-fixed');
} else if (scrollTop <= navTop && isFixed) {
isFixed = 0;
$nav.removeClass('subnav-fixed');
}
};
$nav.on('click', function () {
if (!isFixed) setTimeout(function () {
$win.scrollTop($win.scrollTop() - 47);
}, 10)
})
$win.on('scroll', processScroll);
processScroll();
// window.prettyPrint && prettyPrint()
})(window, jQuery);
(function (global, $, undefined) {
var $win = $(window),
$demoRows = $('.demo-row'),
template = $("#codeViewTemplate")[0].innerHTML,
removeTab = function(text){
var reg=/^(\t+)\S+.*/gmi,match,dTabCount=99999;
while(match = reg.exec(text)){
dTabCount > match[1].length && (dTabCount = match[1].length);
}
return text.replace(new RegExp("^\\t{"+dTabCount+"}","gmi"),"").replace(/\t/gmi," ");
};
$(".prettyprint").each(function(i, pre){
var text = $(pre).html();
$(pre).html(removeTab(text));
});
$demoRows.each(function(i,row){
var $row = $(row),
$demo = $row.find('.demo-span'),
$demoHtml = $demo.find('.demo-html'),
$demoCss = $demo.find('style'),
$demoJs = $demo.find('script'),
$code = $row.find('.code-span'),
demoId = $demoHtml[0].id,
view = {
id: demoId,
html:removeTab($demoHtml[0].outerHTML),
css:removeTab($demoCss[0].innerHTML),
js:removeTab($demoJs[0].innerHTML)
},
output = Mustache.render(template, view);
$code.append(output);
});
var markdown = new showdown.Converter();
$("[data-md]").each(function(i, mdElement){
$.ajax({ url: $(mdElement).data('md'),
type: 'get',
dataType: 'html',
async: false,
success: function(data) {
$(mdElement).html(markdown.makeHtml(data));
$(".language-javascript", mdElement).parent("pre").addClass("prettyprint linenums");
}
});
});
window.prettyPrint && prettyPrint()
})(window, jQuery);