Skip to content

Instantly share code, notes, and snippets.

@unknownuser88
unknownuser88 / gist:8284734
Created January 6, 2014 15:47
.live -> .on
jQuery.fn.extend({
live: function(types, data, fn) {
jQuery(this.context).on(types, this.selector, data, fn);
return this;
},
die: function(types, fn) {
jQuery(this.context).off(types, this.selector || "**", fn);
return this;
},
});
@unknownuser88
unknownuser88 / gist:8284724
Created January 6, 2014 15:47
$_GET javascript
function populateGet() {
var obj = {}, params = location.search.slice(1).split('&');
for (var i = 0, len = params.length; i < len; i++) {
var keyVal = params[i].split('=');
obj[decodeURIComponent(keyVal[0])] = decodeURIComponent(keyVal[1]);
}
return obj;
}
@unknownuser88
unknownuser88 / gist:8284721
Created January 6, 2014 15:46
JQUERY CHECK IF DIV SCROLLED TO END
$(document).ready(function(){
$('div').bind('scroll',chk_scroll);
});
function chk_scroll(e)
{
var elem = $(e.currentTarget);
@unknownuser88
unknownuser88 / gist:8284709
Created January 6, 2014 15:46
JQUERY ENCODE/DECODE URL STRING
var url = $(location).attr('href'); //get current url
//OR
var url = 'folder%2Findex.html%3Fparam%3D%2323dd%26noob%3Dyes'; //or specify one
var decodedUrl = decodeURIComponent(url);
console.log(decodedUrl);
//outputs folder/index.html?param=#23dd&amp;noob=yes
----------------------------------------------------------------------------------
@unknownuser88
unknownuser88 / gist:8284699
Created January 6, 2014 15:45
Center element on screen
jQuery.fn.center = function() {
return this.each(function() {
var t = $(this);
t.css({
'position': 'absolute',
'top': (t.parent().height() - t.height()) / 2 + t.parent().scrollTop() + "px",
'left': (t.parent().width() - t.width()) / 2 + t.parent().scrollLeft() + "px"
}).parent().css('position', 'relative');
});
};
@unknownuser88
unknownuser88 / gist:8284684
Created January 6, 2014 15:45
JQUERY ADD DRAG/TOUCH SUPPORT FOR IPAD
//iPAD Support
$.fn.addTouch = function(){
this.each(function(i,el){
$(el).bind('touchstart touchmove touchend touchcancel',function(){
//we pass the original event object because the jQuery event
//object is normalized to w3c specs and does not provide the TouchList
handleTouch(event);
});
});
@unknownuser88
unknownuser88 / gist:8284680
Created January 6, 2014 15:44
DOM CACHING
MY_OBJECT =
{
cache: {},
init: function()
{
this.cache.c = $('#container');
this.cache.n = this.cache.c.find('.nested');
this.cache.s = this.cache.c.find('#status');
}
@unknownuser88
unknownuser88 / gist:8284673
Created January 6, 2014 15:44
Check if an image has been fully loaded
$('#theImage').attr('src', 'image.jpg').load(function() {
alert('This Image Has Been Loaded');
});
@unknownuser88
unknownuser88 / gist:8284624
Created January 6, 2014 15:41
Stripping HTML from Element
(function($) {
$.fn.stripHtml = function() {
var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
this.each(function() {
$(this).html(
$(this).html().replace(regexp,"")
);
});
return $(this);
}
@unknownuser88
unknownuser88 / gist:8284599
Created January 6, 2014 15:39
jQuery.browser.mobile
if(jQuery.browser.mobile)
{
console.log('You are using a mobile device!');
}
else
{
console.log('You are not using a mobile device!');
}
var isiPad = /ipad/i.test(navigator.userAgent.toLowerCase());