Skip to content

Instantly share code, notes, and snippets.

@unknownuser88
unknownuser88 / gist:8284582
Created January 6, 2014 15:38
html5 new tags
<!-- html5 new tags -->
<article> New - Defines an article
<aside> New - Defines content aside from the page content
<audio> New - Defines sound content
<canvas> New - Defines graphics
<command> New - Defines a command button
<datalist> New - Defines a dropdown list
<details> New - Defines details of an element
<embed> New - Defines external interactive content or plugin
<figcaption> New - Defines the caption of a figure element
@unknownuser88
unknownuser88 / gist:8284583
Created January 6, 2014 15:38
getSelectionHtml()
function getSelectionHtml() {
var html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;
@unknownuser88
unknownuser88 / gist:8284587
Created January 6, 2014 15:39
function loadScript(path, callback)
function loadScript(path, callback) {
var done = false;
var scr = document.createElement('script');
scr.onload = handleLoad;
@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());
@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: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: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: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: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: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
----------------------------------------------------------------------------------