Skip to content

Commit

Permalink
add: dom dispatchEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
hilongjw committed Jun 18, 2017
1 parent fe2dce0 commit 6978fe4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
12 changes: 8 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ rollup.rollup({
]
})
.then(bundle => {
return write(path.resolve(__dirname, 'vue-lazyload.js'), bundle.generate({
format: 'umd',
moduleName: 'VueLazyload'
}).code)
return write(path.resolve(__dirname, 'vue-lazyload.js'), rewriteVersion(bundle.generate({
format: 'umd',
moduleName: 'VueLazyload'
}).code))
})
.then(() => {
console.log('Vue-Lazyload.js v' + version + ' builded')
})
.catch(console.log)

function rewriteVersion (code) {
return code.replace('__VUE_LAZYLOAD_VERSION__', version)
}

function getSize (code) {
return (code.length / 1024).toFixed(2) + 'kb'
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-lazyload",
"version": "1.0.4",
"version": "1.0.5",
"description": "Vue module for lazy-loading images in your vue.js applications.",
"main": "vue-lazyload.js",
"scripts": {
Expand Down
11 changes: 10 additions & 1 deletion src/lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ const DEFAULT_EVENTS = ['scroll', 'wheel', 'mousewheel', 'resize', 'animationend

export default function (Vue) {
return class Lazy {
constructor ({ preLoad, error, preLoadTop, loading, attempt, silent, scale, listenEvents, hasbind, filter, adapter }) {
constructor ({ preLoad, error, preLoadTop, dispatchEvent, loading, attempt, silent, scale, listenEvents, hasbind, filter, adapter }) {
this.version = '__VUE_LAZYLOAD_VERSION__'
this.ListenerQueue = []
this.TargetIndex = 0
this.TargetQueue = []
this.options = {
silent: silent || true,
dispatchEvent: !!dispatchEvent,
preLoad: preLoad || 1.3,
preLoadTop: preLoadTop || 0,
error: error || DEFAULT_URL,
Expand Down Expand Up @@ -313,6 +315,13 @@ export default function (Vue) {

this.$emit(state, listener, cache)
this.options.adapter[state] && this.options.adapter[state](listener, this.options)

if (this.options.dispatchEvent) {
const event = new CustomEvent(state, {
detail: listener
})
el.dispatchEvent(event)
}
}

/**
Expand Down
Loading

0 comments on commit 6978fe4

Please sign in to comment.