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
<?php | |
header("Content-Type: text/event-stream"); | |
while(true) { | |
echo "Event: server-time\n"; | |
$time = time(); | |
echo "data: $time\n"; | |
echo "\n"; | |
flush(); | |
sleep(3); | |
} |
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 s = document.body.style; | |
for (var i in s) { | |
s[i] = "url('foo')"; | |
if(s[i]) { | |
console.log(i); | |
s[i] = '' | |
} | |
} |
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 hasKey = {}.hasOwnProperty; | |
Object.prototype.hasOwnProperty = 1; | |
delete Object.prototype.hasOwnProperty; | |
var iframe = document.createElement('iframe'); | |
document.documentElement.appendChild(iframe); | |
Object.prototype.hasOwnProperty = window.frames[0].Object.prototype.hasOwnProperty; | |
document.documentElement.removeChild(iframe); |
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
/* | |
* Algorithm taken from: | |
* http://csswizardry.com/2011/08/building-better-grid-systems/ | |
*/ | |
.row { | |
width: (number of columns * width of one column) + (number of columns * width of one gutter) px; | |
margin-left: -width of one gutter px; | |
overflow: hidden; | |
clear: both; |
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 template(string, data, prop) { | |
for (prop in data) { | |
string = string.replace(new RegExp('{' + prop + '}', 'g'), data[prop]); | |
} | |
return string; | |
} | |
/* | |
String templating engine: |
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
/** | |
* The following method creates a new element or returns a copy of an element already created by this script. | |
* | |
* @param tagname { String } element to be created/copied | |
* @return { Element/Node } the newly created element | |
*/ | |
createElement: (function(){ | |
// Memorize previous elements created | |
var cache = {}; | |
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
/* | |
* http://requirejs.org/docs/optimization.html | |
* | |
* Use NodeJs to execute the r.js optimization script on this build script | |
* node r.js -o app.build.js | |
* | |
* See: https://github.com/jrburke/r.js/blob/master/build/example.build.js for an example build script | |
* | |
* If you specify just the name (with no includes/excludes) then all modules are combined into the "main" file. | |
* You can include/exclude specific modules though if needed |
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
window.onload = function() { | |
var foo = document.getElementById("abc"); | |
var ZOMG = function(e) { | |
alert("zomg"); | |
e.preventDefault(); | |
}; | |
foo.addEventListener("click", ZOMG, 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
It’s possible to analyze the viewport size in JavaScript but it’s a little messy: | |
- Most browsers support `window.innerWidth` and `window.innerHeight`. | |
- But IE6, 7, 8 and 9 in quirks mode require `document.body.clientWidth` and `document.body.clientHeight`. | |
- All the main browsers support `document.documentElement.clientWidth` and `document.documentElement.clientHeight` but it’s inconsistent. | |
Either the window or document dimensions will be returned depending on the browser and mode. |
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
<!doctype html> | |
<html> | |
<head> | |
<title>jQuery Ajax Test</title> | |
<style type="text/css"> | |
#test { | |
background-color:pink; | |
display:none; | |
padding:10px; | |
text-align:center; |