Source : Learn to combine RxJs sequences with super intuitive interactive diagrams
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 removeProperties = ({ | |
password, | |
blockExpires, | |
loginAttempts, | |
...rest | |
}) => rest; |
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
$('p.descr').attr('unselectable', 'on') | |
.css('user-select', 'none') | |
.on('selectstart', false); |
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
// You want to parse this address into parts: | |
var url = 'http://tutorialzine.com/books/jquery-trickshots?trick=12#comments'; | |
// The trick; create a new link with the url as its href: | |
var a = $('<a>',{ href: url }); | |
console.log('Host name: ' + a.prop('hostname')); | |
console.log('Path: ' + a.prop('pathname')); | |
console.log('Query: ' + a.prop('search')); | |
console.log('Protocol: ' + a.prop('protocol')); | |
console.log('Hash: ' + a.prop('hash')); |
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
// Old way | |
console.log($('#elem').length == 1 ? "exists!" : "doesn't exist!"); | |
// The trick: | |
jQuery.fn.exists = function(){ return this.length > 0; } | |
console.log($('#elem').exists() ? "exists!" : "doesn't exist!"); |
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 route = { | |
_routes : {}, // The routes will be stored here | |
add : function(url, action){ | |
this._routes[url] = action; | |
}, | |
run : function(){ | |
jQuery.each(this._routes, function(pattern){ | |
if(location.href.match(pattern)){ | |
// "this" points to the function to be executed | |
this(); |
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
// with jQuery | |
$(document).ready(function(){ /* ... */ }); | |
// shorter jQuery version | |
$(function(){ /* ... */ }); | |
// without jQuery (doesn't work in older IEs) | |
document.addEventListener('DOMContentLoaded', function(){ | |
// your code goes here | |
}, false); | |
// and here's the trick (works everywhere): | |
r(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
var equalizeHeights = function () { | |
$(".equalizer").each(function(ix, el) { | |
var heights = $(el).find('.eq-watch').map(function() { | |
return $(this).height(); | |
}).get(); | |
maxHeight = Math.max.apply(null, heights); | |
$(el).find('.eq-watch').height(maxHeight); | |
}); | |
}; |
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() { | |
var results; | |
this.assert = function assert(value, desc) { | |
var li = document.createElement("li"); | |
li.className = value ? "pass" : "fail"; | |
li.appendChild(document.createTextNode(desc)); | |
results.appendChild(li); | |
if (!value) { | |
li.parentNode.parentNode.className = "fail"; | |
} |
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 getAjaxPromise (url) { | |
return new Promise(function (resolve, reject) { | |
var xhttp = new XMLHttpRequest(); | |
xhttp.open('GET', url, true); | |
xhttp.onload = function () { | |
if (xhttp.status == 200) { | |
resolve(JSON.parse(xhttp.response)); | |
} else { | |
reject(xhttp.statusText); | |
} |
NewerOlder