This file contains hidden or 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
//////////////// IS ////////////////// | |
// Check if an object is primitive | |
function isPrimitive (obj) { | |
var type = typeof obj; | |
return obj == null || type === 'boolean' || type === 'number' || type === 'string' || type === 'symbol'; | |
} | |
// Check if an object is primitive | |
function isPrimitive2 (obj) { |
This file contains hidden or 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
// Location replacer | |
addEventListener('click', function (event) { | |
// Create .which property if not exists | |
// As far as I've tested, it exists in all modern browsers | |
if (!event.which && event.button) { | |
if (event.button & 1) { | |
event.which = 1; | |
} else if (event.button & 4) { | |
event.which = 2; | |
} else if (event.button & 2) { |
This file contains hidden or 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
// Always Hashchange | |
addEventListener('click', function (event) { | |
// Create .which property if not exists | |
// As far as I've tested, it exists in all modern browsers | |
if (!event.which && event.button) { | |
if (event.button & 1) { | |
event.which = 1; | |
} else if (event.button & 4) { | |
event.which = 2; | |
} else if (event.button & 2) { |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- | |
Copyright (c) 2018 by Aleksandr Yefremov (https://codepen.io/yesasha/pen/ppdyWL) | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER I |
This file contains hidden or 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
// performance.now() and performance.timing.navigationStart polyfill | |
if (!window.performance) { | |
window.performance = {}; | |
} | |
if (!performance.now) { | |
performance.now = function () { | |
return Date.now() - this.timing.navigationStart; | |
} | |
} |
This file contains hidden or 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
// Helps to attach and then remove event listeners | |
// without having to worry about saving the callback and other arguments, | |
// like the original javascript functions require. | |
// Also allows passing "this" and any amount of arguments | |
// to the callback function | |
// | |
// Copyright (c) 2015 Aleksandr Efremov | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal |
This file contains hidden or 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
// Keeps aspect ratio of an element by listening to window resize event | |
// and setting height = width / aspect ratio | |
// | |
// Copyright (c) 2015 Aleksandr Efremov | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is |
This file contains hidden or 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
// Date.now() polyfill for old browsers (<ie 8) | |
if (!Date.now) { | |
Date.now = function () { | |
return (new Date).getTime(); | |
}; | |
} |
This file contains hidden or 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
// Keeps aspect ratio of an element by listening to window resize event | |
// and setting height = width / aspect ratio | |
// | |
// Copyright (c) 2015 Aleksandr Efremov | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is |
NewerOlder