1
0
Fork 0
mirror of https://github.com/vuejs/awesome-vue.git synced 2025-08-07 22:04:10 -04:00

Merge pull request #273 from phanan/revamp

Lazy load the GitHub badges
This commit is contained in:
Phan An 2016-06-24 14:15:03 +07:00 committed by GitHub
commit de2e85e537
3 changed files with 20 additions and 2 deletions

View file

@ -35,12 +35,15 @@
<script> <script>
import _ from 'lodash' import _ from 'lodash'
import Blazy from 'blazy'
import { event } from './utils' import { event } from './utils'
import group from './components/Group.vue' import group from './components/Group.vue'
import explore from './components/Explore.vue' import explore from './components/Explore.vue'
import mainHeader from './components/Header.vue' import mainHeader from './components/Header.vue'
import mainFooter from './components/Footer.vue' import mainFooter from './components/Footer.vue'
let blazy = null
export default { export default {
components: { group, explore, mainHeader, mainFooter }, components: { group, explore, mainHeader, mainFooter },
@ -63,8 +66,15 @@ export default {
this.debounceFilter() this.debounceFilter()
}) })
},
// Also, upon page load, tf there's a hash, we filter the awesome list mounted() {
// Register lazyloading for the GitHub badges
blazy = new Blazy({
container: '.right'
})
// Also, upon page load, if there's a hash, we filter the awesome list
// right away. // right away.
if (window.location.hash) { if (window.location.hash) {
this.q = /^#(.*)/.exec(window.location.hash)[1].toLowerCase() this.q = /^#(.*)/.exec(window.location.hash)[1].toLowerCase()
@ -92,6 +102,11 @@ export default {
} }
this.groups = this.filter(_.cloneDeep(window.data), q) this.groups = this.filter(_.cloneDeep(window.data), q)
// Force Blazy to revalidate the images for lazy loading
this.$nextTick(() => {
blazy.revalidate()
})
}, 100), }, 100),
/** /**

View file

@ -8,7 +8,9 @@
<template v-else>{{ item.author.name }}</template> <template v-else>{{ item.author.name }}</template>
</span> </span>
<a v-if="githubBadgeUrl" :href="item.url" class="github-badge"> <a v-if="githubBadgeUrl" :href="item.url" class="github-badge">
<img :src="githubBadgeUrl"> <img class="b-lazy"
src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
:data-src="githubBadgeUrl">
</a> </a>
</h1> </h1>
<div class="thin" v-if="item.description" v-html="item.description"></div> <div class="thin" v-if="item.description" v-html="item.description"></div>

View file

@ -16,6 +16,7 @@
"babel-core": "^6.0.0", "babel-core": "^6.0.0",
"babel-loader": "^6.0.0", "babel-loader": "^6.0.0",
"babel-preset-es2015": "^6.0.0", "babel-preset-es2015": "^6.0.0",
"blazy": "^1.6.2",
"chalk": "^1.1.3", "chalk": "^1.1.3",
"copy-webpack-plugin": "^3.0.1", "copy-webpack-plugin": "^3.0.1",
"cross-env": "^1.0.6", "cross-env": "^1.0.6",