Skip to content

Instantly share code, notes, and snippets.

@bloodyowl
Created April 24, 2013 21:51
Show Gist options
  • Save bloodyowl/5455880 to your computer and use it in GitHub Desktop.
Save bloodyowl/5455880 to your computer and use it in GitHub Desktop.
Micro jQuery-like starter-kit for mobile development
;(function(){
var owns = {}.hasOwnProperty
, toString = {}.toString
, emptyArray = []
function arrayify(self, arr){
var i = 0, l = arr.length >> 0
for(;i < l; i++) self[i] = arr[i]
self.length = l
return self
}
function $(str, ctx){ return new init(str, ctx) }
function init(str, ctx){
if(ctx === null) return arrayify(this, [])
if(typeof ctx == "string" || toString.call(ctx) == "[object String]") ctx = document.querySelector(ctx)
return arrayify(this, (ctx || document).querySelectorAll(str))
}
var proto = {
init : init
, find : function(str){return new init(str, this[0] || null)}
, push : emptyArray.push
, splice : emptyArray.splice
, length : 0
}
$.prototype = proto.init.prototype = $.fn = proto
window.$ = $
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment