Skip to content

Commit

Permalink
feat: add imageZoom option (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist authored Jun 10, 2019
1 parent eded04a commit 021f43c
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 14 deletions.
17 changes: 14 additions & 3 deletions src/components/ImageZoom.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="ImageZoom" :class="{'with-border': border}">
<img ref="img" :src="url" :alt="alt" :width="width" />
<img ref="img" :src="imageURL" :alt="alt" :width="width" :title="title" />
</div>
</template>

Expand All @@ -10,8 +10,10 @@ export default {
props: {
url: {
type: String,
required: true
type: String
},
src: {
type: String
},
alt: {
type: String
Expand All @@ -22,6 +24,15 @@ export default {
},
width: {
type: [String, Number]
},
title: {
type: String
}
},
computed: {
imageURL() {
return this.src || this.url
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ const store = new Vuex.Store({

const env = {
headings: [],
mixins: []
mixins: [],
config: getters.config
}
if (page.markdown) {
page.content = marked(page.content, {
Expand Down
8 changes: 7 additions & 1 deletion src/utils/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,14 +1123,20 @@ Renderer.prototype.link = function(href, title, text) {
return out
}

// @modified
Renderer.prototype.image = function(href, title, text) {
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
href = resolveUrl(this.options.baseUrl, href)
}
var out = '<img src="' + href + '" alt="' + text + '"'
var { imageZoom } = this.options.env.config
var tag = imageZoom ? 'image-zoom' : 'img'
var out = `<${tag} src="` + href + '" alt="' + text + '"'
if (title) {
out += ' title="' + title + '"'
}
if (imageZoom) {
out += ' v-bind:border="false"'
}
out += this.options.xhtml ? '/>' : '>'
return out
}
Expand Down
7 changes: 4 additions & 3 deletions website/docs/builtin-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Use medium-style zoom effect to display certain image.

| Prop | Type | Default | Description |
| ------ | --------- | ------- | ------------------------ |
| url | `string` | N/A | URL to image |
| src | `string` | N/A | URL to image |
| title | `string` | N/A | Image title |
| alt | `string` | N/A | Placeholder text |
| border | `boolean` | `false` | Show border around image |
| width | `string` | N/A | Image width |
Expand All @@ -19,13 +20,13 @@ Example:

```markdown
<ImageZoom
url="https://i.loli.net/2018/09/24/5ba8e878850e9.png"
src="https://i.loli.net/2018/09/24/5ba8e878850e9.png"
:border="true"
width="300"
/>
```

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

## `<Badge>`

Expand Down
2 changes: 1 addition & 1 deletion website/docs/guide/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Render offers [free static site hosting](https://render.com/docs/static-sites) w

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:

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

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

Expand Down
2 changes: 1 addition & 1 deletion website/docs/guide/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Example:
{author}
```

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

---

Expand Down
9 changes: 9 additions & 0 deletions website/docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ new Docute({
})
```

## imageZoom

- Type: `boolean`
- Default: `undefined`

Enable Medium-like image zoom effect to all images.

Alternatively you can use the [`<image-zoom>`](./builtin-components.md#imagezoom) component if you only need this in specific images.

## fetchOptions

- Type: `object`
Expand Down
5 changes: 3 additions & 2 deletions website/docs/zh/builtin-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Docute 附带一些内置的 Vue 组件。
|属性|类型|默认值|描述|
|---|---|---|---|
|url|`string`|N/A|Image 的 URL|
| title | `string` | N/A | Image title |
|alt|`string`|N/A|占位文字|
|border|`boolean`|`false`|是否显示图像周围的边框|
|width|`string`|N/A|Image 宽度|
Expand All @@ -17,13 +18,13 @@ Docute 附带一些内置的 Vue 组件。

```markdown
<ImageZoom
url="https://i.loli.net/2018/09/24/5ba8e878850e9.png"
src="https://i.loli.net/2018/09/24/5ba8e878850e9.png"
:border="true"
width="300"
/>
```

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


## `<Badge>`
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/guide/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ Make sure to check out Now's [GitHub Integration](https://zeit.co/docs/v2/integr

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

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

但是你仍然可以使用 `gh-pages` 分支或者 `master` 分支来为你的文档提供服务,这一切都取决于你的需求。
2 changes: 1 addition & 1 deletion website/docs/zh/guide/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ new Docute({
{author}
```

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

---

Expand Down
9 changes: 9 additions & 0 deletions website/docs/zh/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ new Docute({
})
```

## imageZoom

- Type: `boolean`
- Default: `undefined`

Enable Medium-like image zoom effect to all images.

Alternatively you can use the [`<image-zoom>`](./builtin-components.md#imagezoom) component if you only need this in specific images.

## fetchOptions

- Type: `object`
Expand Down

0 comments on commit 021f43c

Please sign in to comment.