Skip to content

Instantly share code, notes, and snippets.

View remy's full-sized avatar
🐹
Always hacking

Remy Sharp remy

🐹
Always hacking
View GitHub Profile
// Attempt to make a drop-and-forget bunch of scripts that mimick some missing html5 goodies automatically
// Example:
// $(document).ready(function() {
// ProvideHtml5.autofocus()
// ProvideHtml5.datepicker()
// ProvideHtml5.forcenumber()
// })
var ProvideHtml5 = {
autofocus = function() {
// Attempt to make a drop-and-forget bunch of scripts that mimick some missing html5 goodies automatically
// Example:
// $(document).ready(function() {
// ProvideHtml5.autofocus()
// ProvideHtml5.datepicker()
// ProvideHtml5.forcenumber()
// })
var ProvideHtml5 = {
autofocus = function() {
<!-- either: -->
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- or -->
<!--[if IE]>
<script>
// actual representation of snow in Brighton - dirty code, but small :)
// run in your console
a=document.createElement("b");document.body.appendChild(a);with(a.style){position="fixed";left=top=0;height=width="100%";background="#fff"};
find: function(q, context) {
var ele = [], list, i, j, x;
this.cache = context;
// this doesn't feel quite right, we should be able to do [#foo,bar].querySelectorAll (or something) - TODO add loop
if (context == undefined && this.length == 1) {
return xui(q, this[0]); // results = [].slice.call(this)
} else if (context == undefined && this.length > 1) {
// do some sort of loop - maybe this:
/*
(function () {
function detectMutation() {
mutationSupported = true;
this.removeEventListener('DOMAttrModified', detectMutation, false);
}
var forEach = [].forEach,
regex = /^data-(.+)/,
el = document.createElement('div'),
mutationSupported = false;
@remy
remy / gist:287106
Created January 26, 2010 19:00
attrMutationDetection
var mutationSupported = (function () {
var el = document.createElement('div'),
mutationSupported = false;
function detectMutation() {
mutationSupported = true;
this.removeEventListener('DOMAttrModified', detectMutation, false);
}
el.addEventListener('DOMAttrModified', detectMutation, false);
@remy
remy / geolocation.js
Created January 29, 2010 00:22
Adds geolocation support via JavaScript and a service from maxmind.com to add the lat/long - perfect :)
if (!navigator.geolocation) {
navigator.geolocation = (function (window, document) {
function getCurrentPosition(callback) {
var geourl = 'http://www.google.com/jsapi?' + Math.random(),
iframe = document.createElement('iframe'),
doc, win;
iframe.style.display = 'none';
window.document.body.appendChild(iframe);
@remy
remy / gist:296785
Created February 6, 2010 16:12 — forked from kangax/gist:296114
// original (http://html5shiv.googlecode.com/svn/trunk/html5.js)
(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,canvas,datalist,details,figure,figcaption,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,summary,time,video".split(','),i=e.length;while(i--){document.createElement(e[i])}})()
// @rem version - 68 characters less, and much more maintainable than @pornelski - how do you like /them/ apples? :-)
// that said - change @pornelski's version so it uses spaces and it's easy maintainable, and still the shortest. /hattip to @pornelski
/*@cc_on(function(e){for(;e[0];document.createElement(e.pop())){}})('abbr article aside audio canvas details figure footer header hgroup mark menu meter nav output progress section time video'.split(' '))@*/
"string" instanceof String; // false.
// 'course it isn't not a string, it may look like a string
// but actually it's masquerading as a banana.