Skip to content

Instantly share code, notes, and snippets.

View emphaticsunshine's full-sized avatar

Mohit Seth emphaticsunshine

View GitHub Profile
@emphaticsunshine
emphaticsunshine / gist:3790614
Created September 26, 2012 21:11 — forked from remy/gist:350433
Storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
// older way in jquery
$('ul').delegate('li','click',function(){
// do something
});
//newer way
$("ul").on("click","li",function(){
// do something
});
var employees = [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Anna",
"lastName": "Smith"
},
{
@emphaticsunshine
emphaticsunshine / with-js.js
Created August 13, 2012 23:15
With block javascript
var person ={
"employee":{
"name": "Mohit Seth",
"role": "Javascript Developer"
}
}
/*this should be avoided*/
@emphaticsunshine
emphaticsunshine / script-blocks.html
Created August 10, 2012 02:59
Reduce number of script blocks
/* This should be avoided
<script>
// block A javascript code
</script>
<script>
//block B javascript code
</script>
@emphaticsunshine
emphaticsunshine / inline-vs-external.html
Created August 10, 2012 02:46
Inline vs external js
/*This should be avoided */
<input type="button" id="click-button" onclick="doSomething();" />
/* Better way to add javascript */
<input type="button" id="click-button" />
<script>
@emphaticsunshine
emphaticsunshine / Global vs namespacing
Created August 10, 2012 02:30
Global vs namespacing
/*This is a global variable*/
var name = "Mohit Seth";
var role = "UI Developer";
/*It is how namespacing can be done*/
var NS = {
name: "Mohit Seth",
role: "UI Developer"
@emphaticsunshine
emphaticsunshine / Logger.js
Created August 4, 2012 14:53
Console wrapper
var Logger = {
log : function( msg ) {
if( console ) {
console.log(msg);
}
}
};
<script>
document.domain="parentdomain.com";
</script>
@emphaticsunshine
emphaticsunshine / cross-sub-domain.js
Created August 4, 2012 02:14
Cross sub domain solution
/*
Author:Mohit Seth
Version : 1.1
Date : '02/10/2012'
Performs sub domain call using an iframe.
Usage:
Create new object of CrossDomain object passing the initial parameters
E.g:
var cd = new CrossDomain($("#frameID"),$("#targetDivID"),"xyz.com","http://xyz.com",callbackFunction);