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
// relies on Date.now() which has been supported everywhere modern for years. | |
// as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values | |
// if you want values similar to what you'd get with real perf.now, place this towards the head of the page | |
// but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed | |
(function(){ | |
// prepare base perf object | |
if (typeof window.performance === 'undefined') { | |
window.performance = {}; |
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 groupCardNumber(cardNumber, digits) { | |
const re = new RegExp('\\d{'+ digits + '}', 'g'); | |
return bankNumber.replace(re, function (match, offset, string) { | |
if((offset + digits - 1) !== string.length - 1) { | |
match = match + ' '; | |
} | |
return match; | |
}); |
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() { | |
let lastTime = 0; | |
const vendors = ['ms', 'moz', 'webkit', 'o']; | |
for(let x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { | |
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; | |
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; | |
} | |
if (!window.requestAnimationFrame) { | |
window.requestAnimationFrame = (callback, element) => { | |
var currTime = new Date().getTime(); |
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
/** | |
* Code copyright Dustin Diaz and Ross Harmes, Pro JavaScript Design Patterns. | |
*/ | |
// Constructor. | |
var Interface = function(name, methods) { | |
if (arguments.length != 2) { | |
throw new Error("Interface constructor called with " + arguments.length + "arguments, but expected exactly 2."); | |
} | |
this.name = 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
function isPopWindowBlocked() { | |
const win = window.open(url, '', ''); | |
return win === 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
const loadImage = (url, callback) => { | |
const image = new Image(); | |
image.onload = () => { | |
callback(null, image); | |
}; | |
image.onerror = () => { | |
callback(new Error('Could not load image at ' + url)); | |
}; | |
image.src = url; | |
} |
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 blobToDataURL(blob) { | |
return new Promise((fulfill, reject) => { | |
let reader = new FileReader(); | |
reader.onerror = reject; | |
reader.onload = (e) => fulfill(reader.result); | |
reader.readAsDataURL(blob); | |
}); | |
} |
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 urlB64ToUint8Array(base64String) { | |
const padding = '='.repeat((4 - base64String.length % 4) % 4); | |
const base64 = (base64String + padding) | |
.replace(/\-/g, '+') | |
.replace(/_/g, '/'); | |
const rawData = window.atob(base64); | |
const outputArray = new Uint8Array(rawData.length); | |
for (let i = 0; i < rawData.length; ++i) { |
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 requestPermission() { | |
return new Promise((resolve, reject) => { | |
const permissionResult = Notification.requestPermission((result) => { | |
// Handling deprecated version with callback. | |
resolve(result); | |
}); | |
if (permissionResult) { | |
permissionResult.then(resolve, reject); | |
} |
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
$.ajax({ | |
type: 'GET', | |
url: {url}, | |
success: function(data) { | |
alert('Success'); | |
}, | |
error: function(xhr, textStatus, errorThrown) { | |
if (xhr.readyState == 4) { | |
// HTTP error (can be checked by XMLHttpRequest.status and XMLHttpRequest.statusText) | |
} else if (xhr.readyState == 0) { |
OlderNewer