Skip to content

Instantly share code, notes, and snippets.

@mig1098
Last active August 19, 2016 21:56
Show Gist options
  • Save mig1098/8b8eb2f222be9264baa3696315e54a40 to your computer and use it in GitHub Desktop.
Save mig1098/8b8eb2f222be9264baa3696315e54a40 to your computer and use it in GitHub Desktop.
var mg_brand={
ckname:'mgprod',
getCookie:function( name ) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ';', len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
},
setCookie:function( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+'='+escape( value ) +
( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
( ( path ) ? ';path=' + path : '' ) +
( ( domain ) ? ';domain=' + domain : '' ) +
( ( secure ) ? ';secure' : '' );
},
deleteCookie:function( name, path, domain ) {
if ( mg_brand.getCookie( name ) ){
document.cookie = name + '=' +
( ( path ) ? ';path=' + path : '') +
( ( domain ) ? ';domain=' + domain : '' ) +
';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
},
getUri:function(){
return location.href;
},
getPathname:function(){
return location.pathname;
},
events:function(){
var mgfunc1=function(e,event,uri){
event.preventDefault();
//var uri = mg_brand.getUri();
mg_brand.setCookie(mg_brand.ckname,uri,false,'/');
var _getck = mg_brand.getCookie(mg_brand.ckname);
console.log('is:'+_getck);
$(document).unbind('brand-event');
setTimeout(function(){
$(document).find('a.mg-brand-btn')[0].click();
},100);
};
//click on button brand
$(document).bind('brand-event',mgfunc1);
$(document).on('click','a.mg-brand-btn',function(event){
var uri = $(this).attr('data-uri');
$(document).trigger('brand-event',[event,uri]);
});
},
onlogged(){
var _path = mg_brand.getPathname();
if(/account$/g.test(_path)){
var _getck = mg_brand.getCookie(mg_brand.ckname);
mg_brand.deleteCookie(mg_brand.ckname);
if(typeof _getck != undefined && _getck != null && _getck != ''){
//on logged redirect
window.location.href = _getck;
}
}
},
test:function(){
//console.log('brand intialized');
var _getck = mg_brand.getCookie(mg_brand.ckname);
console.log('cookie is:'+_getck);
},
init:function(){
this.events();
this.onlogged();
//this.test();
}
};
$(function(){
mg_brand.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment