Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 021f43c

Browse files
authored
feat: add imageZoom option (#239)
1 parent eded04a commit 021f43c

File tree

11 files changed

+52
-14
lines changed

11 files changed

+52
-14
lines changed

src/components/ImageZoom.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="ImageZoom" :class="{'with-border': border}">
3-
<img ref="img" :src="url" :alt="alt" :width="width" />
3+
<img ref="img" :src="imageURL" :alt="alt" :width="width" :title="title" />
44
</div>
55
</template>
66

@@ -10,8 +10,10 @@ export default {
1010

1111
props: {
1212
url: {
13-
type: String,
14-
required: true
13+
type: String
14+
},
15+
src: {
16+
type: String
1517
},
1618
alt: {
1719
type: String
@@ -22,6 +24,15 @@ export default {
2224
},
2325
width: {
2426
type: [String, Number]
27+
},
28+
title: {
29+
type: String
30+
}
31+
},
32+
33+
computed: {
34+
imageURL() {
35+
return this.src || this.url
2536
}
2637
},
2738

src/store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ const store = new Vuex.Store({
108108

109109
const env = {
110110
headings: [],
111-
mixins: []
111+
mixins: [],
112+
config: getters.config
112113
}
113114
if (page.markdown) {
114115
page.content = marked(page.content, {

src/utils/marked.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,14 +1123,20 @@ Renderer.prototype.link = function(href, title, text) {
11231123
return out
11241124
}
11251125

1126+
// @modified
11261127
Renderer.prototype.image = function(href, title, text) {
11271128
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
11281129
href = resolveUrl(this.options.baseUrl, href)
11291130
}
1130-
var out = '<img src="' + href + '" alt="' + text + '"'
1131+
var { imageZoom } = this.options.env.config
1132+
var tag = imageZoom ? 'image-zoom' : 'img'
1133+
var out = `<${tag} src="` + href + '" alt="' + text + '"'
11311134
if (title) {
11321135
out += ' title="' + title + '"'
11331136
}
1137+
if (imageZoom) {
1138+
out += ' v-bind:border="false"'
1139+
}
11341140
out += this.options.xhtml ? '/>' : '>'
11351141
return out
11361142
}

website/docs/builtin-components.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Use medium-style zoom effect to display certain image.
88

99
| Prop | Type | Default | Description |
1010
| ------ | --------- | ------- | ------------------------ |
11-
| url | `string` | N/A | URL to image |
11+
| src | `string` | N/A | URL to image |
12+
| title | `string` | N/A | Image title |
1213
| alt | `string` | N/A | Placeholder text |
1314
| border | `boolean` | `false` | Show border around image |
1415
| width | `string` | N/A | Image width |
@@ -19,13 +20,13 @@ Example:
1920

2021
```markdown
2122
<ImageZoom
22-
url="https://i.loli.net/2018/09/24/5ba8e878850e9.png"
23+
src="https://i.loli.net/2018/09/24/5ba8e878850e9.png"
2324
:border="true"
2425
width="300"
2526
/>
2627
```
2728

28-
<ImageZoom url="https://i.loli.net/2018/09/24/5ba8e878850e9.png" :border="true" width="300"/>
29+
<ImageZoom src="https://i.loli.net/2018/09/24/5ba8e878850e9.png" :border="true" width="300"/>
2930

3031
## `<Badge>`
3132

website/docs/guide/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Render offers [free static site hosting](https://render.com/docs/static-sites) w
2222

2323
The easiest way to use GitHub Pages is to populate all your files inside `./docs` folder on the master branch, and then use this folder for GitHub Pages:
2424

25-
<ImageZoom url="https://i.loli.net/2018/06/11/5b1e0da0c173a.png" alt="github pages" :border="true" />
25+
<ImageZoom src="https://i.loli.net/2018/06/11/5b1e0da0c173a.png" alt="github pages" :border="true" />
2626

2727
However you can still use `gh-pages` branch or even `master` branch to serve your docs, it all depends on your needs.
2828

website/docs/guide/plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Example:
3030
{author}
3131
```
3232

33-
<ImageZoom :border="true" url="https://i.loli.net/2018/09/28/5bae278dd9c03.png" />
33+
<ImageZoom :border="true" src="https://i.loli.net/2018/09/28/5bae278dd9c03.png" />
3434

3535
---
3636

website/docs/options.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ new Docute({
249249
})
250250
```
251251

252+
## imageZoom
253+
254+
- Type: `boolean`
255+
- Default: `undefined`
256+
257+
Enable Medium-like image zoom effect to all images.
258+
259+
Alternatively you can use the [`<image-zoom>`](./builtin-components.md#imagezoom) component if you only need this in specific images.
260+
252261
## fetchOptions
253262

254263
- Type: `object`

website/docs/zh/builtin-components.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Docute 附带一些内置的 Vue 组件。
99
|属性|类型|默认值|描述|
1010
|---|---|---|---|
1111
|url|`string`|N/A|Image 的 URL|
12+
| title | `string` | N/A | Image title |
1213
|alt|`string`|N/A|占位文字|
1314
|border|`boolean`|`false`|是否显示图像周围的边框|
1415
|width|`string`|N/A|Image 宽度|
@@ -17,13 +18,13 @@ Docute 附带一些内置的 Vue 组件。
1718

1819
```markdown
1920
<ImageZoom
20-
url="https://i.loli.net/2018/09/24/5ba8e878850e9.png"
21+
src="https://i.loli.net/2018/09/24/5ba8e878850e9.png"
2122
:border="true"
2223
width="300"
2324
/>
2425
```
2526

26-
<ImageZoom url="https://i.loli.net/2018/09/24/5ba8e878850e9.png" :border="true" width="300"/>
27+
<ImageZoom src="https://i.loli.net/2018/09/24/5ba8e878850e9.png" :border="true" width="300"/>
2728

2829

2930
## `<Badge>`

website/docs/zh/guide/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ Make sure to check out Now's [GitHub Integration](https://zeit.co/docs/v2/integr
3636

3737
使用 Github Pages 最简单的方式是在 master 分支上的 `./docs` 文件夹中加入所有文件,然后将此文件夹用于 Github Pages:
3838

39-
<ImageZoom url="https://i.loli.net/2018/06/11/5b1e0da0c173a.png" alt="github pages" :border="true" />
39+
<ImageZoom src="https://i.loli.net/2018/06/11/5b1e0da0c173a.png" alt="github pages" :border="true" />
4040

4141
但是你仍然可以使用 `gh-pages` 分支或者 `master` 分支来为你的文档提供服务,这一切都取决于你的需求。

website/docs/zh/guide/plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ new Docute({
3030
{author}
3131
```
3232

33-
<ImageZoom :border="true" url="https://i.loli.net/2018/09/28/5bae278dd9c03.png" />
33+
<ImageZoom :border="true" src="https://i.loli.net/2018/09/28/5bae278dd9c03.png" />
3434

3535
---
3636

0 commit comments

Comments
 (0)