jekyll-text-theme 2.2.3 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/README.md +2 -2
- data/_data/variables.yml +2 -0
- data/_includes/comments-providers/valine.html +33 -0
- data/_includes/comments.html +2 -0
- data/_includes/scripts/components/lightbox.js +49 -0
- data/_includes/scripts/components/search/search.js +30 -45
- data/_includes/scripts/components/sidebar.js +2 -5
- data/_includes/scripts/lib/affix.js +1 -1
- data/_includes/scripts/lib/gallery.js +89 -0
- data/_includes/scripts/lib/modal.js +62 -0
- data/_includes/scripts/lib/swiper.js +65 -34
- data/_includes/scripts/lib/toc.js +1 -1
- data/_includes/scripts/utils/imagesLoad.js +28 -0
- data/_includes/scripts/{utils.js → utils/utils.js} +8 -3
- data/_includes/scripts/variables.html +2 -1
- data/_includes/search.html +2 -4
- data/_layouts/base.html +4 -2
- data/_layouts/page.html +20 -7
- data/_sass/common/_reset.scss +5 -10
- data/_sass/common/_variables.scss +10 -10
- data/_sass/common/classes/_overflow.scss +22 -4
- data/_sass/common/components/_button.scss +20 -1
- data/_sass/common/components/_card.scss +1 -0
- data/_sass/common/components/_gallery.scss +21 -0
- data/_sass/common/components/_item.scss +1 -1
- data/_sass/common/components/_modal.scss +39 -0
- data/_sass/common/components/_swiper.scss +7 -4
- data/_sass/common/components/_toc.scss +47 -50
- data/_sass/components/_article-content.scss +1 -1
- data/_sass/components/_header.scss +1 -1
- data/_sass/components/_lightbox.scss +7 -0
- data/_sass/components/_search.scss +52 -26
- data/_sass/layout/_base.scss +0 -4
- data/_sass/layout/_page.scss +17 -54
- data/_sass/skins/_chocolate.scss +4 -1
- data/_sass/skins/_dark.scss +4 -1
- data/_sass/skins/_default.scss +4 -1
- data/_sass/skins/_forest.scss +4 -1
- data/_sass/skins/_ocean.scss +9 -6
- data/_sass/skins/_orange.scss +4 -1
- data/assets/css/main.scss +3 -0
- metadata +11 -4
- data/_includes/comments-providers/custom.html +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8f1760199555ebd8714d3c0646fba732b0a3855
|
4
|
+
data.tar.gz: 40e51a18d2e6cfe4c4cd1047ea75daa583b8fde3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 130c88eb50c06c8522745541958e79916897eb1bfdd9f1bebb579b89717b7c6ab3bd05f763ad3bd3eb4e6ae42173fbeb337e00d251a45e7348a4eeaf4f333d5c
|
7
|
+
data.tar.gz: 6febc77d3433bb1d8b808748a5e39f5408f49c67433cda0ed95bcaa13f4bdb70608ac8d1c1b63bded3c7ec37432e9e0279cb3f1da6b1bbecdd9d70d2de23b85f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 2.2.4 (2018-12-10)
|
4
|
+
|
5
|
+
### Enhancements
|
6
|
+
|
7
|
+
- Swiper component Enhancement: support mouse move
|
8
|
+
- Add lightbox (modal image gallery)
|
9
|
+
- Add Valine comment system (@Lloyar)
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
- Fix some spelling errors in documents (@Krinkle)
|
14
|
+
|
3
15
|
## 2.2.3 (2018-11-11)
|
4
16
|
|
5
17
|
### Enhancements
|
@@ -81,7 +93,7 @@
|
|
81
93
|
|
82
94
|
## 2.0.0 (2018-07-01)
|
83
95
|
|
84
|
-
Breaking changes, please check [Update
|
96
|
+
Breaking changes, please check [Update from 1.x to 2.x](https://tianqi.name/jekyll-TeXt-theme/docs/en/update-from-1-to-2) for details
|
85
97
|
|
86
98
|
### Enhancements
|
87
99
|
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ TeXt is a super customizable Jekyll theme for personal site, team site, blog, pr
|
|
26
26
|
- Extensions (audios, videos, slides, demos)
|
27
27
|
- Markdown enhancements ([MathJax](https://www.mathjax.org/), [mermaid](https://mermaidjs.github.io/), [chartjs](http://www.chartjs.org/))
|
28
28
|
- Sharing ([AddToAny](https://www.addtoany.com/), [AddThis](https://www.addthis.com/))
|
29
|
-
- Comments ([Disqus](https://disqus.com/), [Gitalk](https://gitalk.github.io/))
|
29
|
+
- Comments ([Disqus](https://disqus.com/), [Gitalk](https://gitalk.github.io/), [Valine](https://valine.js.org/en/))
|
30
30
|
- Pageview ([LeanCloud](https://leancloud.cn/))
|
31
31
|
- Analytics ([Google Analytics](https://analytics.google.com/analytics/web/))
|
32
32
|
- RSS ([jekyll-feed](https://github.com/jekyll/jekyll-feed))
|
@@ -56,7 +56,7 @@ TeXt use [Tomorrow](https://github.com/chriskempson/tomorrow-theme) as the highl
|
|
56
56
|
### Start
|
57
57
|
|
58
58
|
- [Quick Start](https://tianqi.name/jekyll-TeXt-theme/docs/en/quick-start)
|
59
|
-
- [Update
|
59
|
+
- [Update from 1.x to 2.x](https://tianqi.name/jekyll-TeXt-theme/docs/en/update-from-1-to-2)
|
60
60
|
|
61
61
|
### Customization
|
62
62
|
|
data/_data/variables.yml
CHANGED
@@ -46,6 +46,7 @@ sources:
|
|
46
46
|
gitalk:
|
47
47
|
js: 'https://cdn.bootcss.com/gitalk/1.2.2/gitalk.min.js'
|
48
48
|
css: 'https://cdn.bootcss.com/gitalk/1.2.2/gitalk.min.css'
|
49
|
+
valine: 'https://unpkg.com/valine/dist/Valine.min.js' # bootcdn not available
|
49
50
|
mathjax: 'https://cdn.bootcss.com/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML'
|
50
51
|
mermaid: 'https://cdn.bootcss.com/mermaid/8.0.0-rc.8/mermaid.min.js'
|
51
52
|
unpkg:
|
@@ -56,5 +57,6 @@ sources:
|
|
56
57
|
gitalk:
|
57
58
|
js: 'https://unpkg.com/gitalk@1.2.2/dist/gitalk.min.js'
|
58
59
|
css: 'https://unpkg.com/gitalk@1.2.2/dist/gitalk.css'
|
60
|
+
valine: 'https//unpkg.com/valine/dist/Valine.min.js'
|
59
61
|
mathjax: 'https://unpkg.com/mathjax@2.7.4/unpacked/MathJax.js?config=TeX-MML-AM_CHTML'
|
60
62
|
mermaid: 'https://unpkg.com/mermaid@8.0.0-rc.8/dist/mermaid.min.js'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{%- include snippets/get-sources.html -%}
|
2
|
+
{%- assign _sources = __return -%}
|
3
|
+
|
4
|
+
{%- assign _VALINE_APP_ID = site.comments.valine.app_id -%}
|
5
|
+
{%- assign _VALINE_APP_KEY = site.comments.valine.app_key -%}
|
6
|
+
{%- assign _VALINE_PLACEHOLDER = site.comments.valine.placeholder -%}
|
7
|
+
|
8
|
+
|
9
|
+
{%- if page.key and
|
10
|
+
_VALINE_APP_ID and
|
11
|
+
_VALINE_APP_KEY -%}
|
12
|
+
|
13
|
+
<div id="vcomments"></div>
|
14
|
+
<script>
|
15
|
+
window.Lazyload.js(['{{ _sources.leancloud_js_sdk}}', '{{ _sources.valine }}'], function() {
|
16
|
+
var _config = {
|
17
|
+
el: '#vcomments',
|
18
|
+
appId: '{{ _VALINE_APP_ID }}',
|
19
|
+
appKey: '{{ _VALINE_APP_KEY }}',
|
20
|
+
verify: true,
|
21
|
+
};
|
22
|
+
{%- if _VALINE_PLACEHOLDER -%}
|
23
|
+
_config.placeholder = '{{ _VALINE_PLACEHOLDER }}';
|
24
|
+
{%- endif -%}
|
25
|
+
{%- assign _page_lang_slice = page.lang | slice: 0, 2 -%}
|
26
|
+
{%- if _page_lang_slice != 'zh' -%}
|
27
|
+
_config.lang = 'en';
|
28
|
+
{%- endif -%}
|
29
|
+
new Valine(_config);
|
30
|
+
});
|
31
|
+
</script>
|
32
|
+
|
33
|
+
{%- endif -%}
|
data/_includes/comments.html
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
{%- include comments-providers/disqus.html -%}
|
4
4
|
{%- elsif site.comments.provider == 'gitalk' -%}
|
5
5
|
{%- include comments-providers/gitalk.html -%}
|
6
|
+
{%- elsif site.comments.provider == 'valine' -%}
|
7
|
+
{%- include comments-providers/valine.html -%}
|
6
8
|
{%- elsif site.comments.provider == 'custom' -%}
|
7
9
|
{%- include comments-providers/custom.html -%}
|
8
10
|
{%- endif -%}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
{%- include scripts/utils/imagesLoad.js -%}
|
2
|
+
(function () {
|
3
|
+
var SOURCES = window.TEXT_VARIABLES.sources;
|
4
|
+
window.Lazyload.js(SOURCES.jquery, function() {
|
5
|
+
var $pageGalleryModal = $('.js-page-gallery-modal');
|
6
|
+
var $images = $('.page__content').find('img:not(.lightbox-ignore)');
|
7
|
+
window.imagesLoad($images).then(function() {
|
8
|
+
/* global Gallery */
|
9
|
+
var pageGalleryModal = $pageGalleryModal.modal({ onChange: handleModalChange });
|
10
|
+
var gallery = null;
|
11
|
+
var modalVisible = false;
|
12
|
+
var i, items = [], image, item;
|
13
|
+
if($images && $images.length > 0) {
|
14
|
+
for (i = 0; i < $images.length; i++) {
|
15
|
+
image = $images.eq(i);
|
16
|
+
if (image.get(0).naturalWidth > 800) {
|
17
|
+
items.push({ src: image.attr('src'), w: image.get(0).naturalWidth, h: image.get(0).naturalHeight, $el: image});
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
if(items.length > 0) {
|
23
|
+
gallery = new Gallery('.gallery', items);
|
24
|
+
gallery.setOptions({ disabled: !modalVisible });
|
25
|
+
gallery.init();
|
26
|
+
for (i = 0; i < items.length; i++) {
|
27
|
+
item = items[i];
|
28
|
+
item.$el && (item.$el.addClass('popup-image'), item.$el.on('click', (function() {
|
29
|
+
var index = i;
|
30
|
+
return function() {
|
31
|
+
pageGalleryModal.show();
|
32
|
+
gallery.setOptions({ initialSlide: index });
|
33
|
+
gallery.refresh(true, { animation: false });
|
34
|
+
};
|
35
|
+
})()));
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
function handleModalChange(visible) {
|
40
|
+
modalVisible = visible;
|
41
|
+
gallery && gallery.setOptions({ disabled: !modalVisible });
|
42
|
+
}
|
43
|
+
|
44
|
+
$pageGalleryModal.on('click', function() {
|
45
|
+
pageGalleryModal.hide();
|
46
|
+
});
|
47
|
+
});
|
48
|
+
});
|
49
|
+
})();
|
@@ -56,9 +56,7 @@ window.Lazyload.js([SOURCES.jquery, PAHTS.search_js], function() {
|
|
56
56
|
};
|
57
57
|
|
58
58
|
function render(data) {
|
59
|
-
if (!data) {
|
60
|
-
return null;
|
61
|
-
}
|
59
|
+
if (!data) { return null; }
|
62
60
|
var $root = $('<ul></ul>'), i, j, key, keys, cur, itemIndex = 0;
|
63
61
|
keys = Object.keys(data);
|
64
62
|
for (i = 0; i < keys.length; i++) {
|
@@ -105,38 +103,29 @@ window.Lazyload.js([SOURCES.jquery, PAHTS.search_js], function() {
|
|
105
103
|
});
|
106
104
|
|
107
105
|
// search panel
|
108
|
-
var $
|
109
|
-
var $pageMain = $('.js-page-main');
|
106
|
+
var $searchModal = $('.js-page-search-modal');
|
110
107
|
var $searchToggle = $('.js-search-toggle');
|
111
|
-
var
|
112
|
-
var scrollTop;
|
113
|
-
|
114
|
-
function openSearchPanel() {
|
115
|
-
scrollTop = $(window).scrollTop() || $pageMain.scrollTop();
|
116
|
-
$pageRoot.addClass('show-search-panel');
|
117
|
-
$pageMain.scrollTop(scrollTop);
|
118
|
-
$searchInput[0].focus();
|
119
|
-
}
|
108
|
+
var modalVisible = false;
|
120
109
|
|
121
|
-
|
122
|
-
$pageRoot.removeClass('show-search-panel');
|
123
|
-
$(window).scrollTop(scrollTop);
|
124
|
-
$searchInput[0].blur();
|
125
|
-
setTimeout(function() {
|
126
|
-
$searchInput.val(''); searchBoxEmpty();
|
127
|
-
window.pageAsideAffix && window.pageAsideAffix.refresh();
|
128
|
-
}, 400);
|
129
|
-
}
|
110
|
+
var searchModal = $searchModal.modal({ onChange: handleModalChange });
|
130
111
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
112
|
+
function handleModalChange(visible) {
|
113
|
+
modalVisible = visible;
|
114
|
+
if (visible) {
|
115
|
+
$searchInput[0].focus();
|
116
|
+
} else {
|
117
|
+
$searchInput[0].blur();
|
118
|
+
setTimeout(function() {
|
119
|
+
$searchInput.val(''); searchBoxEmpty();
|
120
|
+
window.pageAsideAffix && window.pageAsideAffix.refresh();
|
121
|
+
}, 400);
|
122
|
+
}
|
138
123
|
}
|
139
124
|
|
125
|
+
$searchToggle.on('click', function() {
|
126
|
+
modalVisible ? searchModal.hide() : searchModal.show();
|
127
|
+
});
|
128
|
+
|
140
129
|
function updateResultItems() {
|
141
130
|
lastActiveIndex >= 0 && $resultItems.eq(lastActiveIndex).removeClass('active');
|
142
131
|
activeIndex >= 0 && $resultItems.eq(activeIndex).addClass('active');
|
@@ -155,18 +144,19 @@ window.Lazyload.js([SOURCES.jquery, PAHTS.search_js], function() {
|
|
155
144
|
}
|
156
145
|
}
|
157
146
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
showSearch && (showSearch = false, closeSearchPanel());
|
164
|
-
} else if (e.which === 38) {
|
165
|
-
showSearch && moveActiveIndex('up');
|
147
|
+
// Char Code: 13 Enter, 37 ⬅, 38 ⬆, 39 ➡, 40 ⬇, 83 S, 191 /
|
148
|
+
$(window).on('keyup', function(e) {
|
149
|
+
if (modalVisible) {
|
150
|
+
if (e.which === 38) {
|
151
|
+
modalVisible && moveActiveIndex('up');
|
166
152
|
} else if (e.which === 40) {
|
167
|
-
|
153
|
+
modalVisible && moveActiveIndex('down');
|
168
154
|
} else if (e.which === 13) {
|
169
|
-
|
155
|
+
modalVisible && $resultItems && activeIndex >= 0 && $resultItems.eq(activeIndex).children('a')[0].click();
|
156
|
+
}
|
157
|
+
} else {
|
158
|
+
if (!window.isFormElement(e.target || e.srcElement) && (e.which === 83 || e.which === 191)) {
|
159
|
+
modalVisible || searchModal.show();
|
170
160
|
}
|
171
161
|
}
|
172
162
|
});
|
@@ -175,9 +165,4 @@ window.Lazyload.js([SOURCES.jquery, PAHTS.search_js], function() {
|
|
175
165
|
var itemIndex = $(this).parent().data('index');
|
176
166
|
itemIndex >= 0 && (lastActiveIndex = activeIndex, activeIndex = itemIndex, updateResultItems());
|
177
167
|
});
|
178
|
-
|
179
|
-
$searchToggle.on('click', function() {
|
180
|
-
showSearch = !showSearch;
|
181
|
-
showSearch ? openSearchPanel() : closeSearchPanel();
|
182
|
-
});
|
183
168
|
});
|
@@ -8,8 +8,6 @@
|
|
8
8
|
var $sidebarShow = $('.js-sidebar-show');
|
9
9
|
var $sidebarHide = $('.js-sidebar-hide');
|
10
10
|
|
11
|
-
var scrollTop;
|
12
|
-
|
13
11
|
function freeze(e) {
|
14
12
|
if (e.target === $pageMask[0]) {
|
15
13
|
e.preventDefault();
|
@@ -24,11 +22,10 @@
|
|
24
22
|
}
|
25
23
|
|
26
24
|
$sidebarShow.on('click', function() {
|
27
|
-
|
28
|
-
stopBodyScrolling(true); $pageRoot.addClass('show-sidebar'); $pageMain.scrollTop(scrollTop);
|
25
|
+
stopBodyScrolling(true); $pageRoot.addClass('show-sidebar');
|
29
26
|
});
|
30
27
|
$sidebarHide.on('click', function() {
|
31
|
-
stopBodyScrolling(false); $pageRoot.removeClass('show-sidebar');
|
28
|
+
stopBodyScrolling(false); $pageRoot.removeClass('show-sidebar');
|
32
29
|
});
|
33
30
|
});
|
34
31
|
})();
|
@@ -0,0 +1,89 @@
|
|
1
|
+
(function() {
|
2
|
+
{%- include scripts/lib/swiper.js -%}
|
3
|
+
var SOURCES = window.TEXT_VARIABLES.sources;
|
4
|
+
window.Lazyload.js(SOURCES.jquery, function() {
|
5
|
+
var template =
|
6
|
+
'<div class="swiper gallery__swiper">' +
|
7
|
+
'<div class="swiper__wrapper">' +
|
8
|
+
'</div>' +
|
9
|
+
'<div class="swiper__button swiper__button--prev fas fa-chevron-left"></div>' +
|
10
|
+
'<div class="swiper__button swiper__button--next fas fa-chevron-right"></div>' +
|
11
|
+
'</div>';
|
12
|
+
function Gallery(root, items, options) {
|
13
|
+
this.$root = $(root);
|
14
|
+
this.$swiper = null;
|
15
|
+
this.$itemWrapper = null;
|
16
|
+
this.swiper = null;
|
17
|
+
this.$items = [];
|
18
|
+
this.items = items;
|
19
|
+
this.disabled = false;
|
20
|
+
this.contentWidth = 0;
|
21
|
+
this.contentHeight = 0;
|
22
|
+
}
|
23
|
+
Gallery.prototype.init = function() {
|
24
|
+
var i, item, items = this.items, itemsSnippet = '', size, self = this;
|
25
|
+
this.$root.append(template);
|
26
|
+
this.$swiper = this.$root.find('.gallery__swiper');
|
27
|
+
this.$itemWrapper = this.$root.find('.swiper__wrapper');
|
28
|
+
this.contentWidth = this.$itemWrapper && this.$itemWrapper.width();
|
29
|
+
this.contentHeight = this.$itemWrapper && this.$itemWrapper.height();
|
30
|
+
for (i = 0; i < items.length; i++) {
|
31
|
+
item = items[i];
|
32
|
+
size = this.calculateImageSize(item.w, item.h);
|
33
|
+
this.$items.push($(
|
34
|
+
'<div class="swiper__slide">' +
|
35
|
+
'<div class="gallery-item">' +
|
36
|
+
'<div class="gallery-item__content">' +
|
37
|
+
'<img src="' + item.src + '" style="width:' + size.w + 'px;height:' + size.h + 'px"/>' +
|
38
|
+
'</div>' +
|
39
|
+
'</div>' +
|
40
|
+
'</div>'
|
41
|
+
));
|
42
|
+
}
|
43
|
+
this.$itemWrapper && this.$itemWrapper.append(this.$items);
|
44
|
+
this.swiper = this.$swiper && this.$swiper.swiper();
|
45
|
+
$(window).on('resize', function() {
|
46
|
+
if (self.disabled) { return; }
|
47
|
+
self.resizeImageSize();
|
48
|
+
});
|
49
|
+
// Char Code: 37 ⬅, 39 ➡
|
50
|
+
$(window).on('keyup', function(e) {
|
51
|
+
if (window.isFormElement(e.target || e.srcElement) || self.disabled) { return; }
|
52
|
+
if (e.which === 37) {
|
53
|
+
self.swiper && self.swiper.previous();
|
54
|
+
} else if (e.which === 39) {
|
55
|
+
self.swiper && self.swiper.next();
|
56
|
+
}
|
57
|
+
});
|
58
|
+
};
|
59
|
+
Gallery.prototype.calculateImageSize = function(w, h) {
|
60
|
+
var scale = 1;
|
61
|
+
if (this.contentWidth > 0 && this.contentHeight > 0 && w > 0 && h > 0) {
|
62
|
+
scale = Math.min(
|
63
|
+
Math.min(w, this.contentWidth) / w,
|
64
|
+
Math.min(h, this.contentHeight) / h);
|
65
|
+
}
|
66
|
+
return { w: Math.floor(w * scale), h: Math.floor(h * scale) };
|
67
|
+
};
|
68
|
+
Gallery.prototype.resizeImageSize = function() {
|
69
|
+
var i, $item, $items = this.$items, item, size;
|
70
|
+
this.contentWidth = this.$itemWrapper && this.$itemWrapper.width();
|
71
|
+
this.contentHeight = this.$itemWrapper && this.$itemWrapper.height();
|
72
|
+
if ($items.length < 1) { return; }
|
73
|
+
for (i = 0; i < $items.length; i++) {
|
74
|
+
item = this.items[i], $item = $items[i];
|
75
|
+
size = this.calculateImageSize(item.w, item.h);
|
76
|
+
$item && $item.find('img').css({ width: size.w, height: size.h });
|
77
|
+
}
|
78
|
+
}
|
79
|
+
Gallery.prototype.refresh = function() {
|
80
|
+
this.swiper && this.swiper.refresh();
|
81
|
+
this.resizeImageSize();
|
82
|
+
};
|
83
|
+
Gallery.prototype.setOptions = function(options) {
|
84
|
+
this.disabled = options.disabled;
|
85
|
+
this.swiper && this.swiper.setOptions(options);
|
86
|
+
};
|
87
|
+
window.Gallery = Gallery;
|
88
|
+
});
|
89
|
+
})();
|
@@ -0,0 +1,62 @@
|
|
1
|
+
(function() {
|
2
|
+
var SOURCES = window.TEXT_VARIABLES.sources;
|
3
|
+
window.Lazyload.js(SOURCES.jquery, function() {
|
4
|
+
var $body = $('body'), $window = $(window);
|
5
|
+
var $pageRoot = $('.js-page-root'), $pageMain = $('.js-page-main');
|
6
|
+
var activeCount = 0;
|
7
|
+
function modal(options) {
|
8
|
+
var $root = this, visible, onChange;
|
9
|
+
var scrollTop;
|
10
|
+
function setOptions(options) {
|
11
|
+
var _options = options || {};
|
12
|
+
visible = _options.initialVisible === undefined ? false : show;
|
13
|
+
onChange = _options.onChange;
|
14
|
+
}
|
15
|
+
function init() {
|
16
|
+
setState(visible);
|
17
|
+
}
|
18
|
+
function setState(isShow) {
|
19
|
+
if (isShow === visible) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
visible = isShow;
|
23
|
+
if (visible) {
|
24
|
+
activeCount ++;
|
25
|
+
scrollTop = $(window).scrollTop() || $pageMain.scrollTop();
|
26
|
+
$root.addClass('modal--show');
|
27
|
+
$pageMain.scrollTop(scrollTop);
|
28
|
+
activeCount === 1 && ($pageRoot.addClass('show-modal'), $body.addClass('of-hidden'));
|
29
|
+
$window.on('scroll', hide);
|
30
|
+
$window.on('keyup', handleKeyup);
|
31
|
+
} else {
|
32
|
+
activeCount > 0 && activeCount --;
|
33
|
+
$root.removeClass('modal--show');
|
34
|
+
$window.scrollTop(scrollTop);
|
35
|
+
activeCount === 0 && ($pageRoot.removeClass('show-modal'), $body.removeClass('of-hidden'));
|
36
|
+
$window.off('scroll', hide);
|
37
|
+
$window.off('keyup', handleKeyup);
|
38
|
+
}
|
39
|
+
onChange && onChange(visible);
|
40
|
+
}
|
41
|
+
function show() {
|
42
|
+
setState(true);
|
43
|
+
}
|
44
|
+
function hide() {
|
45
|
+
setState(false);
|
46
|
+
}
|
47
|
+
function handleKeyup(e) {
|
48
|
+
// Char Code: 27 ESC
|
49
|
+
if (e.which === 27) {
|
50
|
+
hide();
|
51
|
+
}
|
52
|
+
}
|
53
|
+
setOptions(options);
|
54
|
+
init();
|
55
|
+
return {
|
56
|
+
show: show,
|
57
|
+
hide: hide
|
58
|
+
};
|
59
|
+
}
|
60
|
+
$.fn.modal = modal;
|
61
|
+
});
|
62
|
+
})();
|