forked from jakiestfu/Medium.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs.js
124 lines (104 loc) · 2.71 KB
/
docs.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
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
var applyPrism = function(){
var jsPattern = /[.](js)$/i;
$('[data-src]').each(function(){
var that = this,
src = this.getAttribute('src') || this.getAttribute('data-src'),
htmlSource = this.innerHTML;
$.ajax({
url: 'partials/' + src + '?' + new Date().getTime(),
dataType:'text',
success: function(d){
if (that.nodeName === 'PRE') {
var html = $(that)
.text(d)
.addClass(src.match('.js') ? 'language-javascript' : 'language-markup');
Prism.highlightElement(that);
setTimeout(function() {
html.attr('data-language', src.match('.js') ? 'javascript' : 'html');
}, 1);
} else {
var htmlPre = $('<pre>').insertAfter(that),
html = $('<code>')
.text(htmlSource.replace(/\n\s{12}/g, '\n'))
.appendTo(htmlPre),
jsPre = $('<pre>').insertAfter(htmlPre),
js = $('<code>')
.text(d)
.appendTo(jsPre);
html.addClass('language-markup');
js.addClass('language-javascript');
Prism.highlightElement(html[0]);
Prism.highlightElement(js[0]);
setTimeout(function() {
html.attr('data-language', 'html');
},1);
jsPre.hide();
htmlPre.hide();
$('<img class="view-source" src="img/eye.svg" alt="view source" title="view source"/>')
.click(function() {
if (jsPre.is(':hidden')) {
$(that).slideUp();
jsPre.slideDown();
htmlPre.slideDown();
} else {
$(that).slideDown();
jsPre.slideUp();
htmlPre.slideUp();
}
})
.insertBefore($(that).prev());
if (!htmlSource.match('<')) {
htmlPre.remove();
}
}
}
});
});
};
//override the internal event handler to use jQuery for easy demoing
Medium.Utilities.triggerEvent = function(element, eventName) {
$(element).trigger(eventName);
};
applyPrism();
$(function(){
//Make menu toggle-able, so it doesn't hog all the realestate
var menu = $('#menu'),
links = menu.find('ul'),
viewPort = $('html,body');
menu.down = function() {
this.isUp = false;
menu.css('top', 0);
};
menu.up = function() {
menu.isUp = true;
menu.css('top', (-links.outerHeight() + 5) + 'px');
};
menu.toggleUpDown = function() {
if (menu.isUp) {
menu.down();
} else {
menu.up();
}
};
links.find('a[href^="#"]').click(function(e) {
var target = $(this.getAttribute('href').valueOf());
e.preventDefault();
viewPort.animate({
'scrollTop': target.offset().top
}, 1000, function() {
target.animate({
'padding-left': '10%'
},500, function() {
target.animate({
'padding-left': '0px'
}, 2000);
});
});
});
menu.up();
menu.find('.actuator')
.click(function(e) {
e.preventDefault();
menu.toggleUpDown();
});
});