Skip to content

Commit 71a2be0

Browse files
committed
v1.3, close #129
1 parent cece4e6 commit 71a2be0

File tree

11 files changed

+224
-19
lines changed

11 files changed

+224
-19
lines changed

_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# hexo-theme-indigo
22
# https://github.com/yscoder/hexo-theme-indigo
3-
version: 1.2.7
3+
version: 1.3
44

55
#添加新菜单项遵循以下规则
66
# menu:
@@ -32,7 +32,7 @@ menu:
3232
rss: /atom.xml
3333

3434
#你的头像url
35-
avatar: //placekitten.com/200/200
35+
avatar: /img/avatar.jpg
3636
#favicon
3737
favicon: /favicon.ico
3838

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hexo-theme-material-indigo",
3-
"version": "1.2.7",
3+
"version": "1.3.0",
44
"description": "Material Design theme for Hexo.",
55
"keywords": [
66
"hexo",

scripts/plugins.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
hexo.extend.tag.register('image', ([src, title]) => {
1+
function renderImage(src, title) {
22
return `<figure class="image-bubble">
3-
<img src="${src}" alt="${title}">
3+
<div class="img-lightbox">
4+
<div class="aspect-ratio">
5+
<div class="placeholder"></div>
6+
<img src="${src}" alt="${title}">
7+
</div>
8+
</div>
49
<div class="image-caption">${title}</div>
510
</figure>`
11+
}
12+
13+
14+
hexo.extend.tag.register('image', ([src, title]) => {
15+
return renderImage(src, title)
16+
})
17+
18+
hexo.extend.filter.register('before_post_render', data => {
19+
data.content = data.content.replace(/\!\[(.*)\]\((.+)\)/gmi, (match, title, src) => {
20+
const attrs = src.split(' ')
21+
title = title || (attrs[1] && attrs[1].replace(/\"|\'/g, '')) || '未定义'
22+
return `{% image ${attrs[0]} ${title} %}`
23+
})
24+
return data
625
})

source/css/_partial/article.less

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
padding: 35px;
102102
background: #fff;
103103
border-radius: 4px;
104-
box-shadow: 0 0 30px rgba(0, 0, 0, .3);
104+
box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
105105
.post-meta {
106106
margin-top: 8px;
107107
}
@@ -206,13 +206,13 @@
206206
}
207207

208208
.image-bubble {
209-
img {
210-
margin: 20px auto 10px;
211-
}
209+
margin-top: 20px;
210+
margin-bottom: 20px;
212211
text-align: center;
213212
}
214213
.image-caption {
215214
display: inline-block;
215+
margin-top: 10px;
216216
color: @secondaryTextColor;
217217
}
218218

@@ -329,7 +329,8 @@
329329
p:first-child,
330330
pre:first-child,
331331
table:first-child,
332-
ul:first-child {
332+
ul:first-child,
333+
figure:first-child {
333334
margin-top: 0
334335
}
335336

@@ -344,10 +345,6 @@
344345
max-width: 100%;
345346
}
346347

347-
img {
348-
display: block;
349-
margin: 40px auto;
350-
}
351348

352349
blockquote {
353350
position: relative;

source/css/_partial/lightbox.less

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.img-lightbox {
2+
text-align: center;
3+
.aspect-ratio {
4+
position: relative;
5+
}
6+
7+
img {
8+
display: inline;
9+
margin: 0;
10+
cursor: pointer;
11+
cursor: -webkit-zoom-in;
12+
&.zoom-img {
13+
cursor: -webkit-zoom-out;
14+
}
15+
}
16+
17+
.zoom-img,
18+
.zoom-img-wrap {
19+
position: relative;
20+
z-index: 889;
21+
.transition(.3s)
22+
}
23+
.zoom-img-wrap.abs {
24+
position: absolute;
25+
top: 0;
26+
left: 0;
27+
width: 100%;
28+
height: 100%;
29+
}
30+
31+
.zoom-overlay {
32+
position: fixed;
33+
z-index: 888;
34+
background: rgba(0, 0, 0, .6);
35+
opacity: 0;
36+
cursor: pointer;
37+
cursor: -webkit-zoom-out;
38+
.transition(.3s);
39+
&.show {
40+
opacity: 1;
41+
+ .zoom-img-title {
42+
opacity: 1;
43+
}
44+
}
45+
}
46+
47+
.zoom-img-title {
48+
position: fixed;
49+
z-index: 900;
50+
height: 30px;
51+
line-height: 30px;
52+
color: #fff;
53+
background: rgba(0, 0, 0, .3);
54+
opacity: 0;
55+
.transition(.3s);
56+
}
57+
58+
}
59+

source/css/_partial/postlist.less

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
.post-list-item {
88
padding: 0 12px;
9-
margin-bottom: 24px;
9+
margin-bottom: 30px;
1010
}
1111

1212
.post-time {
@@ -94,8 +94,10 @@
9494
padding: 0px 16px;
9595
line-height: 28px;
9696
color: rgba(255, 255, 255, 0.8);
97+
.transition(.2s);
9798
&:hover {
98-
color: #fff
99+
color: #fff;
100+
box-shadow: 0 4px 8px rgba(0, 0, 0, .26);
99101
}
100102
}
101103

source/css/_partial/variable.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
&:hover,
4343
&:active {
44-
box-shadow: 0 5px 11px 0 rgba(0, 0, 0, 0.18), 0 4px 15px 0 rgba(0, 0, 0, 0.15);
44+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 4px 15px rgba(0, 0, 0, 0.2);
4545
}
4646

4747
}

source/css/style.less

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ html {
3737
color: @primaryTextColor;
3838
font-size: @font-size;
3939
line-height: 1.5;
40+
overflow-x: hidden;
4041
}
4142

4243
body {
@@ -399,4 +400,5 @@ hr,
399400
@import '_partial/tags';
400401
@import '_partial/search';
401402
@import '_partial/reward';
403+
@import '_partial/lightbox';
402404
@import '_duoshuo/embed';

source/img/avatar.jpg

4.83 KB
Loading

source/js/main.js

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,133 @@
266266
}
267267
}
268268

269-
})()
269+
})(),
270+
lightbox: function () {
271+
var zoomedImg;
272+
var screenSize = {};
273+
var margin = 0;
274+
var scrollbarWidth = w.innerWidth - docEl.offsetWidth;
275+
276+
function updateScreenSize() {
277+
screenSize.x = w.innerWidth || docEl.clientWidth || body.clientWidth;
278+
screenSize.y = w.innerHeight || docEl.clientHeight || body.clientHeight;
279+
}
280+
updateScreenSize();
281+
282+
function zoom() {
283+
if (!this.isZoomed) {
284+
this.isZoomed = !this.isZoomed;
285+
zoomedImg = this;
286+
287+
if (!this.img)
288+
this.img = this.querySelector('img');
289+
290+
var imgH = this.img.getBoundingClientRect().height;
291+
var imgW = this.img.getBoundingClientRect().width;
292+
var imgL = this.img.getBoundingClientRect().left;
293+
var imgT = this.img.getBoundingClientRect().top;
294+
295+
var realW = this.img.naturalWidth || imgW,
296+
realH = this.img.naturalHeight || imgH;
297+
298+
this.placeholder = this.querySelector('.placeholder');
299+
this.placeholder.style.cssText = 'height: ' + imgH + 'px';
300+
301+
var top = (screenSize.y - imgH) / 2;
302+
var left = (screenSize.x - this.offsetWidth) / 2;
303+
304+
this.img.classList.add('zoom-img');
305+
this.overlay = d.createElement('div');
306+
this.overlay.id = 'the-overlay';
307+
this.overlay.className = 'zoom-overlay';
308+
this.overlay.style.cssText = 'height:' + screenSize.y + 'px; width: ' + screenSize.x + 'px; top: -' + top + 'px; left: -' + left + 'px';
309+
310+
this.wrapper = d.createElement('div');
311+
this.wrapper.id = 'the-wrapper';
312+
this.wrapper.className = 'zoom-img-wrap abs';
313+
this.wrapper.appendChild(this.img);
314+
this.wrapper.appendChild(this.overlay);
315+
this.children[0].appendChild(this.wrapper);
316+
317+
var title = this.img.title || this.img.alt;
318+
if (title) {
319+
this.caption = d.createElement('div');
320+
this.caption.className = 'zoom-img-title';
321+
this.caption.innerHTML = title;
322+
this.caption.style.cssText = 'width: ' + screenSize.x + 'px; top: ' + (screenSize.y - top - 30) + 'px; left: -' + left + 'px';
323+
this.wrapper.appendChild(this.caption);
324+
}
325+
326+
var wrapX = ((screenSize.x - scrollbarWidth) / 2) - imgL - (imgW / 2);
327+
var wrapY = imgT * (-1) + (screenSize.y - imgH) / 2;
328+
var scale = 1;
329+
330+
if (realH > imgH) {
331+
if (imgH === imgW && screenSize.y > screenSize.x) {
332+
scale = screenSize.x / imgW;
333+
} else if (imgH === imgW && screenSize.y < screenSize.x) {
334+
scale = (screenSize.y - margin) / imgH;
335+
} else if (imgH > imgW) {
336+
scale = (screenSize.y - margin) / imgH;
337+
if (scale * imgW > screenSize.x) {
338+
scale = screenSize.x / imgW;
339+
}
340+
} else if (imgH < imgW) {
341+
scale = screenSize.x / imgW;
342+
if (scale * imgH > screenSize.y) {
343+
scale = (screenSize.y - margin) / imgH;
344+
}
345+
}
346+
}
347+
348+
if (scale * imgW > realW) {
349+
scale = realW / imgW;
350+
}
351+
352+
var that = this;
353+
setTimeout(function () {
354+
var wrapTrf = 'translate3d(' + wrapX + 'px, ' + wrapY + 'px, 0)';
355+
var imgTrf = 'scale(' + scale + ')';
356+
357+
that.wrapper.style.cssText = 'transform: ' + wrapTrf + ';-webkit-transform: ' + wrapTrf;
358+
that.img.style.cssText = 'transform: ' + imgTrf + ';-webkit-transform: ' + imgTrf;
359+
that.overlay.className = 'zoom-overlay show';
360+
}, 0);
361+
362+
} else {
363+
this.isZoomed = !this.isZoomed;
364+
zoomedImg = null
365+
this.img.style.cssText = '';
366+
this.wrapper.style.cssText = '';
367+
this.overlay.className = 'zoom-overlay';
368+
369+
var that = this;
370+
setTimeout(function () {
371+
that.placeholder.style.cssText = '';
372+
that.children[0].appendChild(that.img);
373+
that.children[0].removeChild(that.wrapper);
374+
that.img.classList.remove('zoom-img');
375+
}, 300)
376+
}
377+
}
378+
379+
forEach.call($$('.post-content .img-lightbox'), function (el) {
380+
el.addEventListener(even, zoom);
381+
});
382+
383+
return {
384+
updateScreenSize: updateScreenSize,
385+
zoomOut: function () {
386+
if (zoomedImg) {
387+
zoomedImg[even]();
388+
}
389+
}
390+
}
391+
}
270392
};
271393

394+
var lightbox = Blog.lightbox();
395+
272396
w.addEventListener('load', function () {
273397
Blog.fixNavMinH();
274398
Blog.waterfall();
@@ -288,6 +412,7 @@
288412
Blog.fixNavMinH();
289413
Blog.toggleMenu();
290414
Blog.waterfall();
415+
lightbox.updateScreenSize();
291416
});
292417

293418
gotop.addEventListener(even, function () {
@@ -317,6 +442,7 @@
317442
Blog.fixedHeader(top);
318443
Blog.toc.fixed(top);
319444
Blog.toc.actived(top);
445+
lightbox.zoomOut();
320446
}, false);
321447

322448
if (w.BLOG.SHARE) {

0 commit comments

Comments
 (0)