Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
callmecavs committed Jan 8, 2017
1 parent 0c1e6a4 commit 4e2bb5f
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/layzr.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,33 @@ export default (options = {}) => {

// location helper

function getLoc() {
function getLoc () {
return window.scrollY || window.pageYOffset
}

// debounce helpers

function requestScroll() {
function requestScroll () {
prevLoc = getLoc()
requestFrame()
}

function requestFrame() {
if(!ticking) {
requestAnimationFrame(() => check())
function requestFrame () {
if (!ticking) {
window.requestAnimationFrame(() => check())
ticking = true
}
}

// offset helper

function getOffset(node) {
function getOffset (node) {
return node.getBoundingClientRect().top + prevLoc
}

// in viewport helper

function inViewport(node) {
function inViewport (node) {
const viewTop = prevLoc
const viewBot = viewTop + windowHeight

Expand All @@ -75,20 +75,18 @@ export default (options = {}) => {

const offset = (settings.threshold / 100) * windowHeight

return nodeBot >= viewTop - offset
&& nodeTop <= viewBot + offset
return (nodeBot >= viewTop - offset) && (nodeTop <= viewBot + offset)
}

// source helper

function setSource(node) {
function setSource (node) {
instance.emit('src:before', node)

// prefer srcset, fallback to pixel density
if(srcset && node.hasAttribute(settings.srcset)) {
if (srcset && node.hasAttribute(settings.srcset)) {
node.setAttribute('srcset', node.getAttribute(settings.srcset))
}
else {
} else {
const retina = dpr > 1 && node.getAttribute(settings.retina)
node.setAttribute('src', retina || node.getAttribute(settings.normal))
}
Expand All @@ -102,7 +100,7 @@ export default (options = {}) => {

// API

function handlers(flag) {
function handlers (flag) {
const action = flag
? 'addEventListener'
: 'removeEventListener'
Expand All @@ -111,7 +109,7 @@ export default (options = {}) => {
return this
}

function check() {
function check () {
windowHeight = window.innerHeight

nodes.forEach(node => inViewport(node) && setSource(node))
Expand All @@ -120,8 +118,8 @@ export default (options = {}) => {
return this
}

function update() {
nodes = Array.prototype.slice.call(document.querySelectorAll(`[${ settings.normal }]`))
function update () {
nodes = Array.prototype.slice.call(document.querySelectorAll(`[${settings.normal}]`))
return this
}
}

0 comments on commit 4e2bb5f

Please sign in to comment.