-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugins.js
More file actions
99 lines (89 loc) · 2.97 KB
/
plugins.js
File metadata and controls
99 lines (89 loc) · 2.97 KB
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
/* global Fluid, CONFIG */
HTMLElement.prototype.wrap = function(wrapper) {
this.parentNode.insertBefore(wrapper, this);
this.parentNode.removeChild(this);
wrapper.appendChild(this);
};
Fluid.plugins = {
typing: function(text) {
if (!('Typed' in window)) { return; }
var typed = new window.Typed('#subtitle', {
strings: [
' ',
text + ' '
],
cursorChar: CONFIG.typing.cursorChar,
typeSpeed : CONFIG.typing.typeSpeed,
loop : CONFIG.typing.loop
});
typed.stop();
var subtitle = document.getElementById('subtitle');
if (subtitle) {
subtitle.innerText = '';
}
jQuery(document).ready(function() {
typed.start();
});
},
fancyBox: function(selector) {
if (!CONFIG.image_zoom.enable || !('fancybox' in jQuery)) { return; }
jQuery(selector || '.markdown-body :not(a) > img, .markdown-body > img').each(function() {
var $image = jQuery(this);
var imageUrl = $image.attr('data-src') || $image.attr('src') || '';
if (CONFIG.image_zoom.img_url_replace) {
var rep = CONFIG.image_zoom.img_url_replace;
var r1 = rep[0] || '';
var r2 = rep[1] || '';
if (r1) {
if (/^re:/.test(r1)) {
r1 = r1.replace(/^re:/, '');
var reg = new RegExp(r1, 'gi');
imageUrl = imageUrl.replace(reg, r2);
} else {
imageUrl = imageUrl.replace(r1, r2);
}
}
}
var $imageWrap = $image.wrap(`
<a class="fancybox fancybox.image" href="${imageUrl}"
itemscope itemtype="http://schema.org/ImageObject" itemprop="url"></a>`
).parent('a');
if ($imageWrap.length !== 0) {
if ($image.is('.group-image-container img')) {
$imageWrap.attr('data-fancybox', 'group').attr('rel', 'group');
} else {
$imageWrap.attr('data-fancybox', 'default').attr('rel', 'default');
}
var imageTitle = $image.attr('title') || $image.attr('alt');
if (imageTitle) {
$imageWrap.attr('title', imageTitle).attr('data-caption', imageTitle);
}
}
});
jQuery.fancybox.defaults.hash = false;
jQuery('.fancybox').fancybox({
loop : true,
helpers: {
overlay: {
locked: false
}
}
});
},
imageCaption: function(selector) {
if (!CONFIG.image_caption.enable) { return; }
jQuery(selector || `.markdown-body > p > img, .markdown-body > figure > img,
.markdown-body > p > a.fancybox, .markdown-body > figure > a.fancybox`).each(function() {
var $target = jQuery(this);
var $figcaption = $target.next('figcaption');
if ($figcaption.length !== 0) {
$figcaption.addClass('image-caption');
} else {
var imageTitle = $target.attr('title') || $target.attr('alt');
if (imageTitle) {
$target.after(`<figcaption aria-hidden="true" class="image-caption">${imageTitle}</figcaption>`);
}
}
});
}
};