Skip to content

Instantly share code, notes, and snippets.

@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: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: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:8284572
Created January 6, 2014 15:37
OnBeforeUnload
var OnBeforeUnload = (function(){
var
FDUM = new Function,
AFFIRM = function(){ return true; };
var _reg = function(msg,opts){
opts = opts || {};
var
@unknownuser88
unknownuser88 / gist:8284568
Created January 6, 2014 15:37
color convert RGB<==>HEX
function hex2rgb( $colour ) {
if ( $colour[0] == '#' ) {
$colour = substr( $colour, 1 );
}
if ( strlen( $colour ) == 6 ) {
list( $r, $g, $b ) = array( $colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5] );
} elseif ( strlen( $colour ) == 3 ) {
list( $r, $g, $b ) = array( $colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2] );
} else {
return false;
@unknownuser88
unknownuser88 / gist:8284556
Created January 6, 2014 15:37
JQUERY CHECK IF DIV SCROLLED TO END
$(document).ready(function(){
$('div').bind('scroll',chk_scroll);
});
function chk_scroll(e)
{
var elem = $(e.currentTarget);
if (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight())
@unknownuser88
unknownuser88 / gist:8284541
Created January 6, 2014 15:36
$.debug extend function
$.extend({
debug:function(text, dir){
var dir = dir || false;
    if (window.console && window.console.log) {
(dir === true && window.console.dir) ? window.console.dir(text) : window.console.log(text);
    }
}
})
// $.debug('console.log test');
@unknownuser88
unknownuser88 / gist:8284525
Created January 6, 2014 15:36
function debug
function debug(text) {
    if (window.console && window.console.log) {
        window.console.log(text);
    }
    if (window.opera) {
@unknownuser88
unknownuser88 / gist:8284518
Created January 6, 2014 15:35
namespace for function
;q = {
w : 'www',
myFunction: function()
{
var a = arguments[0] || "q";
// alert('running MYNAMESPACE.myFunction...'+a+q.w);
}
}
q.myFunction(); //function call
@unknownuser88
unknownuser88 / gist:8284506
Created January 6, 2014 15:34
array to json javascript
var myarray = [];
var myJSON = "";
$.each(data.data,function(i,val) {
var item = {
"name": val.name,
"facebookId": val.id,
"picture": val.picture.data.url
};
myarray.push(item);
})