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
// http://remysharp.com/2010/07/21/throttling-function-calls/ | |
function throttle(fn, delay) { | |
var timer = null; | |
return function () { | |
var context = this, args = arguments; | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
fn.apply(context, args); | |
}, delay); | |
}; |
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
// http://jsfiddle.net/icodejs/TAVz5/ | |
(function(Highcharts) { | |
var | |
addEvent = Highcharts.addEvent, | |
each = Highcharts.each; | |
/** | |
* Filter by dragMin and dragMax | |
*/ |
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
/* | |
* Too many cool techniques to let this code slip through my fingers | |
* =============================================================== | |
* jQuery Plugin: Tokenizing Autocomplete Text Entry | |
* Version 1.6.0 | |
* | |
* Copyright (c) 2009 James Smith (http://loopj.com) | |
* Licensed jointly under the GPL and MIT licenses, | |
* choose which one suits your project best! | |
* |
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
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () { | |
var Storage = function (type) { | |
function createCookie(name, value, days) { | |
var date, expires; | |
if (days) { | |
date = new Date(); | |
date.setTime(date.getTime()+(days*24*60*60*1000)); | |
expires = "; expires="+date.toGMTString(); |
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
// http://davidwalsh.name/array-sort | |
// If you provide a function expression to the sort method, you can sort | |
// objects within the array using simple logic. Let's say you have an | |
// array of objects representing persons and you want to sort them by age. | |
// Oh yes, it can be done, and quite easily: | |
[ | |
{ name: "Robin Van Persie", age: 28 }, | |
{ name: "Theo Walcott", age: 22 }, | |
{ name: "Bacary Sagna", age: 26 } |
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
//CustomEvent example usage - https://developer.mozilla.org/en-US/docs/DOM/customEvent?redirect=no | |
// add an appropriate event listener | |
obj.addEventListener("cat", function(e) { process(e.detail) }) | |
// create and dispatch the event | |
var event = new CustomEvent("cat", {"detail":{"hazcheeseburger":true}}) | |
obj.dispatchEvent(event) |
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
# Markdown Cheat Sheet | |
# H1 tag | |
## H2 tag | |
### H3 tag | |
#### H4 tag | |
##### H5 tag | |
###### H6 tag | |
*This text will be italic* |
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 pubsub = { | |
sendMessage: function() { | |
message = $("input").val(); | |
$("body").trigger("messageReceived", { message: message}); | |
return false; | |
}, | |
displayMessage: function(data) { | |
$("body").trigger("messageDisplayed"); | |
li = $("<li />").text(data.message).css("display", "none"); | |
$("ul").append(li); |
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 preferred way now of binding events is through delegation. The idea of delegating is that you delegate an event to a parent, and then every time it detects that event, it looks to see if the item clicked on is what we want, and then it triggers that event. This is perhaps easier to see in an example: */ | |
$("table").on("click", "tr", function() { | |
console.log("tr inside table clicked"); | |
}); | |
/* The advantage of this is that it’s much easier work for the browser to bind one click event to one item, and then run a conditional every time that event fires, compared to binding a click event to every single tr. Essentially, with delegate, the process for the above code goes like this: | |
1. Bind 1 click event to table | |
2. Detected a click event on table |
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 MS = MS || {}; | |
MS.ajaxEventListener = ({ | |
init: function(w, d) { | |
w.evt = d.createEvent("Event"); | |
w.evt.initEvent("ajaxLoaded", true, true); | |
return this; | |
}, | |
dispatchEvent: function(w, d) { | |
if (w.evt) { |