1
0
Fork 0
Browse Source

Update by default upon creation

master
Starbeamrainbowlabs 6 years ago
parent
commit
eb92d05c00
  1. 2
      Makefile
  2. 1
      SnoozeSquad.js
  3. 2
      SnoozeSquad.min.js

2
Makefile

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
### SnoozeSquad Makefile ###
# The target output file
TargetFile = SnoozeSquad.min.js
# Set the default make goal
@ -16,4 +17,5 @@ build: @@ -16,4 +17,5 @@ build:
cat HeaderComment.js >$(TargetFile)
uglifyjs SnoozeSquad.js --mangle --compress --screw-ie8 >>$(TargetFile)
@echo [SnoozeSquad/Build] Minified Snooze Squad to $(TargetFile)
@echo [SnoozeSquad/Build] $$(ls -lh SnoozeSquad.js | cut -d ' ' -f 5) --\> $$(ls -lh SnoozeSquad.min.js | cut -d ' ' -f 5)
@echo '*** Build Complete ***'

1
SnoozeSquad.js

@ -14,6 +14,7 @@ class SnoozeSquad @@ -14,6 +14,7 @@ class SnoozeSquad
this.querySelector = `[${this.attributeName}]`;
this.lastUpdateTime = 0;
this.start();
this.update();
}
start()

2
SnoozeSquad.min.js vendored

@ -5,4 +5,4 @@ @@ -5,4 +5,4 @@
* Licensed under the MIT license.
******************************************************************************/
"use strict";class SnoozeSquad{constructor(t){this.range=1;this.attributeName="data-src";this.updateInterval=250;for(let e in t)this[e]=t[e];this.querySelector=`[${this.attributeName}]`;this.lastUpdateTime=0;this.start()}start(){var t=false;try{var e=Object.defineProperty({},"passive",{get:function(){t=true}});window.addEventListener("test",null,e)}catch(t){}window.addEventListener("scroll",function(t){if(+new Date-this.lastUpdateTime>this.updateInterval)this.update()}.bind(this),t?{passive:true}:false)}update(){this.lastUpdateTime=+new Date;var t=this.getSnoozingElements();for(let e of t){if(this.isElementInRange(e))this.wakeUpElement(e)}}getSnoozingElements(){return document.querySelectorAll(this.querySelector)}isElementInRange(t){var e=t.getBoundingClientRect(),i=this.range*window.innerHeight;if(e.bottom>-i&&e.top<window.innerHeight+i&&e.right>-i&&e.left<window.innerWidth+i){return true}return false}wakeUpElement(t){var e=this.attributeName.replace("data-","");if(t.dataset.hasOwnProperty(e)){t.src=t.dataset[e]}else{}}}
"use strict";class SnoozeSquad{constructor(t){this.range=1;this.attributeName="data-src";this.updateInterval=250;for(let e in t)this[e]=t[e];this.querySelector=`[${this.attributeName}]`;this.lastUpdateTime=0;this.start();this.update()}start(){var t=false;try{var e=Object.defineProperty({},"passive",{get:function(){t=true}});window.addEventListener("test",null,e)}catch(t){}window.addEventListener("scroll",function(t){if(+new Date-this.lastUpdateTime>this.updateInterval)this.update()}.bind(this),t?{passive:true}:false)}update(){this.lastUpdateTime=+new Date;var t=this.getSnoozingElements();for(let e of t){if(this.isElementInRange(e))this.wakeUpElement(e)}}getSnoozingElements(){return document.querySelectorAll(this.querySelector)}isElementInRange(t){var e=t.getBoundingClientRect(),i=this.range*window.innerHeight;if(e.bottom>-i&&e.top<window.innerHeight+i&&e.right>-i&&e.left<window.innerWidth+i){return true}return false}wakeUpElement(t){var e=this.attributeName.replace("data-","");if(t.dataset.hasOwnProperty(e)){t.src=t.dataset[e]}else{}}}

Loading…
Cancel
Save