This repository has been archived by the owner on Jan 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.js
119 lines (114 loc) · 3.8 KB
/
loader.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
/**
* Description: Magnific Popup support for phpBBex
* URI: https://github.com/vralle/mfp
* Author: Vitaliy Ralle
* Email: email4vit [] gmail.com
* License: MIT
*/
!function ($) {
$(function(){
function getImgWidth(img) {
var t = new Image()
t.src = (img.getAttribute ? img.getAttribute("src") : false) || img.src
return t.width
}
function pushLightbox(img) {
var lightboxLink = []
for (var i=0;i<img.length;i++) {
var p = img[i]
var parentEl = p.parentNode
if (parentEl.tagName && parentEl.tagName.toLowerCase() !== "a") {
if (getImgWidth(p) > 400) {
var link = document.createElement("a")
link.href = p.src
link.appendChild(p.cloneNode(true))
parentEl.replaceChild(link, p)
lightboxLink.push(link);
}
} else if (parentEl.tagName && parentEl.tagName.toLowerCase() === "a") {
/\.(jpe?g|png|gif|bmp)(&.*)?$/ig.test(parentEl.href) && lightboxLink.push(parentEl)
}
}
return lightboxLink
}
function addZoomIcon(arr) {
for (i in arr) {
var linkStyle = arr[i].style
linkStyle.position = "relative"
linkStyle.display = "inline-block"
var icon = document.createElement('i')
icon.classList ? icon.classList.add("icon-zoom-large") : icon.className += "icon-zoom-large"
arr[i].appendChild(icon)
}
}
var loader = function(d) {
var js, css,
where = d.getElementsByTagName('script')[0]
function isFileReady( readyState ) {
return ( ! readyState || readyState == "loaded" || readyState == "complete" || readyState == "uninitialized" )
}
return {
addCss: function(url) {
css = d.createElement('link');
css.rel = 'stylesheet';
css.href = url;
where.parentNode.insertBefore(css, where);
},
addJs: function(url, cb) {
var done
js = d.createElement('script');
js.onreadystatechange = js.onload = function () {
if ( ! done && isFileReady( js.readyState ) ) {
done = 1
cb()
js.onload = js.onreadystatechange = null;
}
}
js.src = url;
where.parentNode.insertBefore(js, where);
}
}
}(document)
$(window).on('load', function () {
var img = pushLightbox(document.getElementById("page-body").getElementsByTagName("img"))
if (typeof img !== 'undefined' && img.length > 0) {
addZoomIcon(img)
var targetFolder = document.getElementById("mfp-loader").getAttribute("data-path") + "mfp/"
loader.addCss(targetFolder + "mfp.min.css");
loader.addJs(targetFolder + "jquery.magnific-popup.min.js", function () {
if (document.documentElement.lang == 'ru') {
$.extend(true, $.magnificPopup.defaults, {
tClose: "Закрыть (Esc)", // Alt text on close button
tLoading: "Загрузка...", // Text that is displayed during loading. Can contain %curr% and %total% keys
gallery: {
tPrev: "Назад (Клв. Влево)", // Alt text on left arrow
tNext: "Вперед (Клв. Вправо)", // Alt text on right arrow
tCounter: "%curr% из %total%" // Markup for "1 of 7" counter
},
image: {
tError: '<a href="%url%">Изображение</a> не загружено.' // Error message when image could not be loaded
}
});
}
$(img).magnificPopup({
gallery: {
enabled: true
},
image: {
titleSrc: function(item) {
var $title = "picture"
if( item.el.find("img").attr("title") ) {
$title = item.el.find("img").attr("title")
} else if ( item.el.find("img").attr("alt") ) {
$title = item.el.find("img").attr("alt")
}
return $title +' <a href="' + item.src + '" target="_blank"><i class="icon-link-ext-white"></i></a>'
}
},
type: 'image'
})
})
}
})
})
}(window.jQuery)