This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
navigator.serviceWorker.register('/sw.js').then(function(reg) { | |
//page has loaded from the network and not sw | |
if (!navigator.serviceWorker.controller) { | |
return; | |
} | |
//if sw is in waiting state | |
if (reg.waiting) { | |
//call the update function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import idb from 'idb'; | |
var dbPromise = idb.open('test-db', 1, function(upgradeDb) { | |
switch (upgradeDb.oldVersion) { | |
case 0: | |
upgradeDb.createObjectStore('keyval'); | |
case 1: | |
//name would be the primary key | |
upgradeDb.createObjectStore('people', { | |
keyPath: 'name' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var concat = require('gulp-concat'); | |
var order = require('gulp-order'); | |
var uglify = require('gulp-uglify'); | |
var autopolyfiller = require('gulp-autopolyfiller'); | |
var merge = require('event-stream').merge; | |
gulp.task('default', function () { | |
// Concat all required js files | |
var all = gulp.src('js/*.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let _Http = obj => { | |
return new Promise((resolve, reject) => { | |
let xhr = new XMLHttpRequest(); | |
xhr.open(obj.method || "GET", obj.url); | |
if (obj.headers) { | |
Object.keys(obj.headers).forEach(key => { | |
xhr.setRequestHeader(key, obj.headers[key]); | |
}); | |
} | |
xhr.onload = () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadScript(url, callback){ | |
var script = document.createElement("script") | |
script.type = "text/javascript"; | |
if (script.readyState){ //IE | |
script.onreadystatechange = function(){ | |
if (script.readyState == "loaded" || | |
script.readyState == "complete"){ | |
script.onreadystatechange = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadScript(src) { | |
return new Promise(function(resolve, reject) { | |
let script = document.createElement('script'); | |
script.src = src; | |
script.onload = () => resolve(script); | |
script.onerror = () => reject(new Error("Script load error: " + src)); | |
document.head.append(script); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.filter('dateFilter', function() { | |
return function(date) { | |
let oneSec = 1000; | |
let oneMin = 60 * oneSec; | |
let oneHour = 60 * oneMin; | |
let oneDay = 24 * oneHour; | |
let now = new Date().getTime(); | |
let transactionTime = new Date(date).getTime(); | |
let transactionDate = new Date(date); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let css = `h1{ font-size : 14px;}`; | |
let head = document.head || document.getElementsByTagName('head')[0]; | |
let style = document.createElement('style'); | |
style.type = 'text/css'; | |
if (style.styleSheet) { | |
// This is required for IE8 and below. | |
style.styleSheet.cssText = css; | |
} else { | |
style.appendChild(document.createTextNode(css)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// String | |
function isString (value) { | |
return typeof value === 'string' || value instanceof String; | |
} | |
// Number | |
function isNumber (value) { | |
return typeof value === 'number' && isFinite(value); | |
} |
OlderNewer