Skip to content

Instantly share code, notes, and snippets.

View getify's full-sized avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
function xdomainajax() {
var win;
if (document.location == "otcsandbox.com") {
var content = "<html><body><scr"+"ipt>document.domain='otcsandbox.com';</scr"+"ipt><scr"+"ipt src='http://wheretogetjqueryfrom.com/jquery.js'></scr"+"ipt></body></html>";
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
win = iframe.contentDocument ? iframe : iframe.contentWindow ? iframe.contentWindow : iframe;
var doc = iframe.contentDocument ? iframe.contentDocument ? iframe.contentWindow ? iframe.contentWindow.document ? win.document;
doc.open();
@getify
getify / gist:940603
Created April 25, 2011 14:41
`window.vendor`
(function(){
if (window.vendor) return;
var _browsers = ["chrome","opera","safari","firefox","ie"];
for (var i=0; i<_browsers.length; i++) {
if (_browsers[i] in window) {
window.vendor = window[_browsers[i]];
break;
}
}
})();
@getify
getify / bench-LABjs-parallel.html
Created May 24, 2011 05:53
comparing LABjs and $script.js when parallel loading with execution order dependencies
<script src="../vendor/lab2.min.js"></script>
<script type="text/javascript">
var start = (+new Date);
// load some scripts dependent on each other (in parallel but preserving execution order)
$LAB
.setOptions({AlwaysPreserveOrder:true})
.script('a.js')
.script('b-needs-a.js')
.script('c-needs-b.js')
@getify
getify / gist:1048881
Created June 27, 2011 13:45
how to not miss window.onload in dynamic script loading case
<html>
<head>
<script src="LAB.js"></script>
...
<script>
function do_something() { /* ... */ }
@getify
getify / gist:1061887
Created July 3, 2011 02:13
howto: resumable chains with LABjs
<!DOCTYPE html>
<html>
<head>
<style>#link1, #link2 { display:none; }</style>
<script src="lab.js"></script>
<script>
$LAB.script("jquery.js").wait(function(){
var ready = false,
@getify
getify / gist:1108046
Created July 26, 2011 21:07
document.write() vs. DOM manipulation
document.write("<div id='foo'></div>");
// OR
var div = document.createElement("div");
div.id = "foo";
document.body.appendChild(div);
// keep in mind, body.appendChild will put this <div> at the end of the body, whereas document.write() will put it wherever it's called (probably in the middle of an element.
// SO....
@getify
getify / gist:1110207
Created July 27, 2011 19:46
ugly hack to figure out the actual viewport dimensions (sans scrollbars)
// do the hack
document.childNodes[1].style.width = "100%"; // set the HTML to 100%/100%
document.childNodes[1].style.height = "100%";
document.body.style.width = "100%"; // set the <body> to 100%/100%
document.body.style.height = "100%";
var viewportDimsHack = this.treeBrowserDocument.createElement("div");
viewportDimsHack.style.position = "fixed";
viewportDimsHack.style.left = "0px";
viewportDimsHack.style.top = "0px";
@getify
getify / .htaccess
Created August 24, 2011 18:07
maybe one way to serve images only to non-js browsers
RewriteEngine on
RewriteRule ^kitty.jpg /nothing [R=204,L]
@getify
getify / gist:1171666
Created August 25, 2011 19:50
break down (and counts) of user-agents seen so far in golook.at logs
LABEL LABEL2 UNIQUE UA's # OF USES
(empty) - 1 20553
(unrecognized) - 740 10789
(bots) - 354 111898
Clients - 513 1727
Windows (other) 39 166
Windows IE 12301 94162
Windows Chrome 770 23069
Windows Safari 99 541
Windows Opera 553 3645
@getify
getify / bar.js
Created August 26, 2011 19:27
how to use LABjs to load nested resources serially, with callbacks
// look ma, I have no dependencies, no need for any wrappers!
alert("bar.js is loaded!");