Skip to content

Commit

Permalink
fix: issue#112
Browse files Browse the repository at this point in the history
  • Loading branch information
hilongjw committed Feb 6, 2017
1 parent 216cdcc commit 8b2e16c
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 909 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"presets": [
["es2015", { "modules": false }]
],
"plugins": [
"external-helpers"
]
}
10 changes: 7 additions & 3 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@ var fs = require('fs')
var path = require('path')
var rollup = require('rollup')
var babel = require('rollup-plugin-babel')
var uglify = require('rollup-plugin-uglify')
var version = process.env.VERSION || require('./package.json').version

var banner =
'/*!\n' +
' * Vue-Lazyload.js v' + version + '\n' +
' * (c) ' + new Date().getFullYear() + ' Awe <hilongjw@gmail.com>\n' +
' * Released under the MIT License.\n' +
' */'
' */\n'

rollup.rollup({
entry: path.resolve(__dirname, 'src/index.js'),
plugins: [ babel() ]
plugins: [
babel(),
uglify()
]
})
.then(bundle => {
return write(path.resolve(__dirname, 'vue-lazyload.js'), bundle.generate({
format: 'umd',
banner: banner,
moduleName: 'VueLazyload'
}).code)
})
Expand All @@ -37,6 +40,7 @@ function blue (str) {

function write (dest, code) {
return new Promise(function (resolve, reject) {
code = banner + code
fs.writeFile(dest, code, function (err) {
if (err) return reject(err)
console.log(blue(dest) + ' ' + getSize(code))
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-lazyload",
"version": "1.0.0-rc9",
"version": "1.0.0-rc10",
"description": "Vue module for lazy-loading images in your vue.js applications.",
"main": "vue-lazyload.js",
"scripts": {
Expand All @@ -24,10 +24,12 @@
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-polyfill": "^6.13.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-es2015-rollup": "^1.2.0",
"rollup": "^0.35.10",
"rollup-plugin-babel": "^2.6.1"
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-uglify": "^1.0.1"
}
}
63 changes: 33 additions & 30 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@ import Lazy from './lazy'
import LazyComponent from './lazy-component'
import { assign } from './util'

export default (Vue, options = {}) => {
const lazy = new Lazy(options)
const isVueNext = Vue.version.split('.')[0] === '2'
export default {
install (Vue, options = {}) {
const LazyClass = Lazy(Vue)
const lazy = new LazyClass(options)
const isVueNext = Vue.version.split('.')[0] === '2'

Vue.prototype.$Lazyload = lazy
Vue.component('lazy-component', LazyComponent(lazy))
Vue.prototype.$Lazyload = lazy
Vue.component('lazy-component', LazyComponent(lazy))

if (isVueNext) {
Vue.directive('lazy', {
bind: lazy.add.bind(lazy),
update: lazy.update.bind(lazy),
componentUpdated: lazy.lazyLoadHandler.bind(lazy),
unbind : lazy.remove.bind(lazy)
})
} else {
Vue.directive('lazy', {
bind: lazy.lazyLoadHandler.bind(lazy),
update (newValue, oldValue) {
assign(this.vm.$refs, this.vm.$els)
lazy.add(this.el, {
modifiers: this.modifiers || {},
arg: this.arg,
value: newValue,
oldValue: oldValue
}, {
context: this.vm
})
},
unbind () {
lazy.remove(this.el)
}
})
if (isVueNext) {
Vue.directive('lazy', {
bind: lazy.add.bind(lazy),
update: lazy.update.bind(lazy),
componentUpdated: lazy.lazyLoadHandler.bind(lazy),
unbind : lazy.remove.bind(lazy)
})
} else {
Vue.directive('lazy', {
bind: lazy.lazyLoadHandler.bind(lazy),
update (newValue, oldValue) {
assign(this.vm.$refs, this.vm.$els)
lazy.add(this.el, {
modifiers: this.modifiers || {},
arg: this.arg,
value: newValue,
oldValue: oldValue
}, {
context: this.vm
})
},
unbind () {
lazy.remove(this.el)
}
})
}
}
}
Loading

0 comments on commit 8b2e16c

Please sign in to comment.