Skip to content

Commit de2e85e

Browse files
authored
Merge pull request vuejs#273 from phanan/revamp
Lazy load the GitHub badges
2 parents 8053007 + 071f4a5 commit de2e85e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

app/site/src/App.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@
3535

3636
<script>
3737
import _ from 'lodash'
38+
import Blazy from 'blazy'
3839
import { event } from './utils'
3940
import group from './components/Group.vue'
4041
import explore from './components/Explore.vue'
4142
import mainHeader from './components/Header.vue'
4243
import mainFooter from './components/Footer.vue'
4344
45+
let blazy = null
46+
4447
export default {
4548
components: { group, explore, mainHeader, mainFooter },
4649
@@ -63,8 +66,15 @@ export default {
6366
6467
this.debounceFilter()
6568
})
69+
},
70+
71+
mounted() {
72+
// Register lazyloading for the GitHub badges
73+
blazy = new Blazy({
74+
container: '.right'
75+
})
6676
67-
// Also, upon page load, tf there's a hash, we filter the awesome list
77+
// Also, upon page load, if there's a hash, we filter the awesome list
6878
// right away.
6979
if (window.location.hash) {
7080
this.q = /^#(.*)/.exec(window.location.hash)[1].toLowerCase()
@@ -92,6 +102,11 @@ export default {
92102
}
93103
94104
this.groups = this.filter(_.cloneDeep(window.data), q)
105+
106+
// Force Blazy to revalidate the images for lazy loading
107+
this.$nextTick(() => {
108+
blazy.revalidate()
109+
})
95110
}, 100),
96111
97112
/**

app/site/src/components/Item.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
<template v-else>{{ item.author.name }}</template>
99
</span>
1010
<a v-if="githubBadgeUrl" :href="item.url" class="github-badge">
11-
<img :src="githubBadgeUrl">
11+
<img class="b-lazy"
12+
src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
13+
:data-src="githubBadgeUrl">
1214
</a>
1315
</h1>
1416
<div class="thin" v-if="item.description" v-html="item.description"></div>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"babel-core": "^6.0.0",
1717
"babel-loader": "^6.0.0",
1818
"babel-preset-es2015": "^6.0.0",
19+
"blazy": "^1.6.2",
1920
"chalk": "^1.1.3",
2021
"copy-webpack-plugin": "^3.0.1",
2122
"cross-env": "^1.0.6",

0 commit comments

Comments
 (0)