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
// functional additions to the Object prototype | |
Object.prototype.extend = function() { | |
if (arguments.length === 0) | |
return this; | |
for (var i = 0; i < arguments.length; i++) { | |
for (var property in arguments[i]) { | |
if (arguments[i].hasOwnProperty(property)) |
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
function PoolFactory() { | |
var createPool = function (options) { | |
var wrkrs = [], freeWrkrs = [], | |
opts = options || {}, | |
wCnt = options.maxWorkers || 4, | |
wrkrPth = options.path || 'whateveryouwant.js'; |
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
/* | |
The arguments against this practice will be (1) concatenating into existing JS and CSS to save on the number of requests and (2) flash of content style changes. The first argument needs to be judged on a per-case basis; if the required CSS and JS is small, it should be concatenated to a file used throughout the site or site subsection. The second argument can always be hushed with a bit of transition magic! | |
*/ | |
$('article pre').length && (function() { | |
var mediaPath = '/assets/'; | |
$('<link>').attr({ | |
type: 'text/css', | |
rel: 'stylesheet', | |
href: mediaPath + 'css/syntax.css' |
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
// session storage caching | |
define(function() { | |
var cacheObj = window.sessionStorage || { | |
getItem: function(key) { | |
return this[key]; | |
}, | |
setItem: function(key, value) { |
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
/* | |
The debounce method returns a function which wraps your callback, | |
limiting its execution rate to the limit specified in the second argument. | |
Now your frequent callbacks can't brick the user's browser! | |
*/ | |
function debounce(func, wait, immediate) { | |
var timeout; | |
return function() { | |
var context = this, args = arguments; |
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
var frag = document.createDocumentFragment(); | |
ajaxResult.items.forEach(function(item) { | |
// Create the LI element | |
var li = document.createElement('li'); | |
li.innerHTML = item.text; | |
// Do some normal node operations on the LI here, | |
// like add classes, modify attributes, | |
// add event listeners, add child nodes, etc. |
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> | |
<head> | |
<title>Dialog Test</title> | |
<style> | |
dialog::backdrop { | |
background: rgba(255, 0, 255, 0.25); | |
} | |
</style> | |
</head> |
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
<dialog> | |
<p>This is da dialog!</p> | |
<button id="close">Close</button> | |
</dialog> | |
<button id="show">Open Dialog!</button> | |
<script> | |
var dialog = document.querySelector('dialog'); | |
document.querySelector('#show').onclick = function() { | |
dialog.show(); | |
}; |
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
// Require our emitter | |
var Emitter = require('events').EventEmitter; | |
// Our main constructor | |
var myEmitter = function (config) { | |
// extend with emitter | |
Emitter.call(this); | |
}; |
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
var r = new XMLHttpRequest(); | |
r.open("POST", "webservice", true); | |
r.onreadystatechange = function () { | |
if (r.readyState != 4 || r.status != 200) return; | |
console.log(r.responseText); | |
}; | |
r.send("a=1&b=2&c=3"); |