Skip to content

Commit

Permalink
Correct bug on multilload + add loadbar in example
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Desmaisons committed Jan 7, 2017
1 parent 4585a07 commit c6e0cd0
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 27 deletions.
6 changes: 6 additions & 0 deletions build/webpack.prod.conf.js
Expand Up @@ -34,6 +34,12 @@ var webpackConfig = merge(baseWebpackConfig, {
commonjs2: 'imagesLoaded',
commonjs: 'imagesLoaded',
amd: 'imagesLoaded'
},
"lodash.isequal": {
root: '_',
commonjs2: 'lodash.isequal',
commonjs: 'lodash.isequal',
amd: 'lodash.isequal'
}
},
vue: {
Expand Down
2 changes: 2 additions & 0 deletions debug.log
@@ -0,0 +1,2 @@
[0102/222648:ERROR:tcp_listen_socket.cc(76)] Could not bind socket to 127.0.0.1:6004
[0102/222648:ERROR:node_debugger.cc(86)] Cannot start debugger server
2 changes: 1 addition & 1 deletion dist/vueimagesloaded.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vueimagesloaded.js.map

Large diffs are not rendered by default.

51 changes: 44 additions & 7 deletions example/components/Hello.vue
@@ -1,7 +1,11 @@
<template>
<div class="hello">
<isotope ref="isotope" :options='options' :list="list" v-images-loaded:on.progress="imageProgress">
<div v-for="element in list" :key="element.id">
<div class="status">
<progress-bar v-show="loading" class="progress-half" :type="status" :size="'large'" :value="currentImg" :max="maxImg" :show-label="true"></progress-bar>
</div>

<isotope ref="isotope" :options='options' :list="list" v-images-loaded:on="getLoadingCallBack()">
<div v-for="element in list" :key="element.id" class="item">
{{element.name}}
<img :src="element.src" alt="Not found">
</div>
Expand All @@ -13,6 +17,7 @@

<script>
import imagesLoaded from '../../src/imagesLoadedDirective'
import ProgressBar from 'vue-bulma-progress-bar'
import isotope from 'vueisotope'
const names= ['John', 'Ringo', 'Paul', 'George']
Expand All @@ -23,9 +28,9 @@ function getImageSrc () {
width = Math.round( width * size );
var height = Math.round( 140 * size );
var rando = Math.ceil( Math.random() * 1000 );
// 10% chance of broken image src
// 25% chance of broken image src
// random parameter to prevent cached images
return rando < 100 ? '//foo/broken-' + rando + '.jpg' :
return rando < 250 ? '//foo/broken-' + rando + '.jpg' :
// use lorempixel for great random images
'//lorempixel.com/' + width + '/' + height + '/' + '?' + rando;
}
Expand All @@ -39,11 +44,16 @@ export default {
},
components: {
isotope,
ProgressBar
},
name: 'hello',
data () {
return {
list: names.map((name, id)=>{return {name, id, src : getImageSrc()}}),
loading: false,
maxImg: 0,
currentImg: 0,
status: 'success',
options:{
layoutMode: 'masonry',
masonry: {
Expand All @@ -56,9 +66,24 @@ export default {
}
},
methods:{
imageProgress (imageLoaded, image){
console.log('progress', cpt++, image)
this.$refs.isotope.layout('masonry')
getLoadingCallBack () {
return {
progress: (instance, img ) => {
this.loading = true
this.currentImg++
this.maxImg = instance.images.length
if (!img.isLoaded) {
this.status = 'danger'
}
this.$refs.isotope.layout('masonry')
},
always: (instance) => {
setTimeout(()=> {
this.loading = false
this.currentImg = 0
}, 250);
}
}
},
addItem () {
this.list.push({name: 'Jimmy', id: count++, src : getImageSrc()})
Expand All @@ -79,4 +104,16 @@ export default {
color: #333;
border: 2px solid #b6b5b4;
}
.progress-half{
width: 50%;
justify-content: space-around;
margin: 0 auto;
}
.status {
height: 40px;
display: flex;
align-items: center;
}
</style>
1 change: 1 addition & 0 deletions example/main.js
Expand Up @@ -2,6 +2,7 @@
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import 'bulma/css/bulma.css'

/* eslint-disable no-new */
new Vue({
Expand Down
1 change: 1 addition & 0 deletions example/simple/index.html
Expand Up @@ -12,6 +12,7 @@
<script type="text/javascript" src="bower_components\lodash\dist\lodash.js"></script>
<script type="text/javascript" src="bower_components\isotope\dist\isotope.pkgd.js"></script>
<script type="text/javascript" src="bower_components\vue-isotope\dist\vue_isotope.js"></script>
<script type="text/javascript" src="bower_components\vue-isotope\dist\vue_isotope.js"></script>
<script type="text/javascript" src="bower_components\imagesloaded\imagesloaded.pkgd.min.js"></script>

<script type="text/javascript" src="..\..\dist\vueimagesloaded.js"></script>
Expand Down

0 comments on commit c6e0cd0

Please sign in to comment.