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 getJSONP(url, success) { | |
var ud = 'callback_' + + Math.floor(Math.random()*1000000), | |
script = document.createElement('script'), | |
head = document.getElementsByTagName('head')[0] | |
|| document.documentElement; | |
window[ud] = function(data) { | |
head.removeChild(script); | |
window[ud] = null; | |
success && success(data); |
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 xmlhttp = new XMLHttpRequest(); | |
xmlhttp.open("POST", url, true); | |
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
xmlhttp.onreadystatechange = function() { | |
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { | |
alert(xmlhttp.responseText); | |
} | |
} | |
xmlhttp.send("param=bla¶m=bla"); |
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
$window.load(function() { | |
var scrollOffset = ; // Do some padding calculations etc. - this will be substracted from the target item top position | |
// Assign to any links/buttons with '#something' in their href. | |
$('#nav a').on('click',function(e) { | |
var $href = $(this).attr('href'), | |
hi = $href.indexOf('#'); | |
// If no hash part return; | |
if (hi==-1) return true; | |
e.preventDefault(); | |
// The double decodeURI is to support non-english |
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 http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<meta name="description" content="[description here]" /> | |
<meta name="apple-mobile-web-app-capable" content="yes"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>[title here]</title> | |
<link rel="stylesheet" href="css/normalize.css" /> | |
<link rel="stylesheet" href="css/style.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
NOTE: This document is OLD - and most of the tips here are probably outdated, since newer versions of Javascript have been | |
released over the years - with newer optimizations and more emphasis on optimizing newly supported syntax. | |
// Array literal (= []) is faster than Array constructor (new Array()) | |
// http://jsperf.com/new-array-vs-literal/15 | |
var array = []; | |
// Object literal (={}) is faster than Object constructor (new Object()) | |
// http://jsperf.com/new-array-vs-literal/26 |
NewerOlder