vue-picture-preview
Advanced tools
Comparing version 1.2.0 to 1.2.1
91
index.js
@@ -22,69 +22,66 @@ import lgPreview from './vue-picture-preview.vue' | ||
} | ||
}) | ||
}); | ||
window.LOGIC_EVENT_BUS = LOGIC_EVENT_BUS | ||
window.LOGIC_EVENT_BUS = LOGIC_EVENT_BUS; | ||
Vue.component('lg-preview', lgPreview) | ||
Vue.component('lg-preview', lgPreview); | ||
const updateIndex = function (list) { | ||
list.forEach(function (item, index) { | ||
item.index = index + 1 | ||
}) | ||
const updateIndex = (list) => { | ||
list.forEach((item, index) => { | ||
item.index = index + 1; | ||
}); | ||
} | ||
function getImage (src, previewItem) { | ||
return new Promise(function (resolve, reject) { | ||
const img = new window.Image() | ||
img.src = src | ||
img.onload = function () { | ||
previewItem['naturalHeight'] = img.naturalHeight | ||
previewItem['naturalWidth'] = img.naturalWidth | ||
setTimeout(function () { | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.loading = false | ||
},500) | ||
resolve(img) | ||
} | ||
img.error = function (e) { | ||
reject(e) | ||
} | ||
}) | ||
const img = new window.Image(); | ||
img.src = src; | ||
img.onload = function () { | ||
previewItem['naturalHeight'] = img.naturalHeight; | ||
previewItem['naturalWidth'] = img.naturalWidth; | ||
setTimeout(() => { | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.loading = false; | ||
}, 500); | ||
}; | ||
img.error = function (e) { | ||
console.error(e); | ||
}; | ||
} | ||
Vue.directive('preview', { | ||
bind: function (el) { | ||
var previewItem = { | ||
title: '', | ||
bind: function (el, binding) { | ||
let previewItem = { | ||
title: el.alt || '', | ||
el: el, | ||
index: 0, | ||
src: '' | ||
} | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.list.push(previewItem) | ||
updateIndex(LOGIC_EVENT_BUS.LOGIC_PREVIEW.list) | ||
el.addEventListener('click', function (e) { | ||
e.stopPropagation() | ||
src: binding.value | ||
}; | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.list.push(previewItem); | ||
updateIndex(LOGIC_EVENT_BUS.LOGIC_PREVIEW.list); | ||
el.addEventListener('click', (e) => { | ||
e.stopPropagation(); | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.isTitleEnable = el.getAttribute('preview-title-enable')== "false" ? false : true; | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.isHorizontalNavEnable = el.getAttribute('preview-nav-enable')== "false" ? false : true; | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.show = true | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.loading = true | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.current = previewItem | ||
getImage(previewItem.src, previewItem) | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.show = true; | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.loading = true; | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.current = previewItem; | ||
getImage(previewItem.src, previewItem); | ||
}) | ||
}, | ||
update: function (el, oldValue) { | ||
var previewItem = LOGIC_EVENT_BUS.LOGIC_PREVIEW.list.find(function (item) { | ||
return item.el === el | ||
}) | ||
if (!previewItem) return | ||
previewItem.src = oldValue.value | ||
previewItem.title = el.alt | ||
update: (el, oldValue) => { | ||
var previewItem = LOGIC_EVENT_BUS.LOGIC_PREVIEW.list.find((item) => { | ||
return item.el === el; | ||
}); | ||
if (!previewItem) return; | ||
previewItem.src = oldValue.value; | ||
previewItem.title = el.alt; | ||
}, | ||
unbind: function (el) { | ||
unbind: (el) => { | ||
if (el) { | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.list.forEach(function (item, index) { | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.list.forEach((item, index) => { | ||
if (el === item.el) { | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.list.splice(index, 1) | ||
LOGIC_EVENT_BUS.LOGIC_PREVIEW.list.splice(index, 1); | ||
} | ||
}) | ||
}); | ||
} | ||
updateIndex(LOGIC_EVENT_BUS.LOGIC_PREVIEW.list) | ||
updateIndex(LOGIC_EVENT_BUS.LOGIC_PREVIEW.list); | ||
} | ||
@@ -91,0 +88,0 @@ }) |
{ | ||
"name": "vue-picture-preview", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "移动端Vue.js图片预览插件 | Mobile-friendly picture file preview Vue.js plugin with horizontal nav and bottom title.", | ||
"main": "index.js", | ||
"main": "dist/vue-picture-preview.js", | ||
"scripts": { | ||
"build": "node build.js", | ||
"test": "npm run unit" | ||
@@ -25,3 +26,14 @@ }, | ||
}, | ||
"homepage": "https://github.com/xLogic92/vue-picture-preview#readme" | ||
"homepage": "https://github.com/xLogic92/vue-picture-preview#readme", | ||
"devDependencies": { | ||
"babel-core": "^6.22.1", | ||
"babel-preset-es2015-rollup": "^3.0.0", | ||
"rollup": "^0.41.4", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-plugin-commonjs": "^7.0.0", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
"rollup-plugin-uglify": "^1.0.1", | ||
"rollup-plugin-vue": "^4.7.2", | ||
"vue-template-compiler": "^2.6.7" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
48697
9
272
9
1