Skip to content

Instantly share code, notes, and snippets.

/**
* FUNCTIONS
**/
/**
* Functions create closures; variables defined
* inside of them are accessible inside the
* function, and to any functions that were
* defined within the same scope.
**/
@balupton
balupton / README.md
Last active February 10, 2025 05:38
Ajaxify a Website with the HTML5 History API using History.js, jQuery and ScrollTo
@andrew8088
andrew8088 / oop.js
Created December 12, 2010 02:15
OOP in JS
var tooltip_button = {
show : function () {
this.panel.show();
},
hide : function () {
this.panel.hide();
},
bind_events : function () {
var that = this;
this.button.bind("mouseover.Tooltip_Button", function () { that.show.call(that); });
@thingsinjars
thingsinjars / gist:636030
Created October 20, 2010 08:33
Quick summary of some Touch Events
document.ontouchstart = function(e) {
//This will alert coordinates where you touch the screen
alert(e.touches[0].pageX+', '+e.touches[0].pageY);
//This will alert coordinates if you touch with a second finger at the same time
if(e.touches[1]) {
alert(e.touches[1].pageX+', '+e.touches[1].pageY);
}
}
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
bar[foo?'doSomething':'doSomethingElse'](el);
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@davidvanvickle
davidvanvickle / Javascript utility funcs
Created May 8, 2010 05:27
Javascript utility funcs
/* Javascript utility funcs */
function valueInArray (val,arr) {
for (var i = 0; i < arr.length; i++) {
if (val==arr[i]) {
return true;
}
}
return false;
<!DOCTYPE html>
<html>
<head>
<title>jQuery Templating Demo</title>
<style type="text/css">
html {
background:#f3f3f3;
font: 13px/1.5 helvetica, arial, san-serif;
}
ul {
var array = ["one", "two", "three", "four", "five"];
document.writeln(array + "<br />");
var newArray = shuffle(array);
document.writeln(newArray);
function shuffle (arr) {
var copy = arr.concat(),