var iwish_shop = "gelaskins-usa.myshopify.com"; var iWishCnt=0;var iWishlistmain={};var iWishsync=!1;var iWishRemoveMsg='';var noItemsMsg='';getSession();if(typeof iWishSelectClass==='undefined'){var iWishSelectClass="#product-select, .single-option-selector, .single-option-selector__radio, select[id|='product-select'], select[id|='product-variants-option'], select[id|='variant-listbox-option']"} if(typeof iwishWrapperClass==='undefined'){var iwishWrapperClass='form'} var iwishProductWrap='';if(typeof iwish_added_txt==='undefined'){var iwish_added_txt='Added in Wishlist'} if(typeof iwish_add_txt==='undefined'){var iwish_add_txt='Add to Wishlist'} if(typeof iwish_wait_msg==='undefined'){var iwish_wait_msg='Please wait...'} var iWishpId=0;var iWishvarId=0;var iWishvarIdOld=0;function iWishPost(e,t){method="post";var n=document.createElement("form");n.setAttribute("method",method);n.setAttribute("action",e);for(var r in t){if(t.hasOwnProperty(r)){var i=document.createElement("input");i.setAttribute("type","hidden");i.setAttribute("name",r);i.setAttribute("value",t[r]);n.appendChild(i)}}document.head.appendChild(n);n.submit()} function getSession(){if(typeof(Storage)!=="undefined"){if(iwish_cid==''&&localStorage.iWishsync=='true'){console.log('logout! clear storage...');localStorage.removeItem('iWishlistmain');localStorage.removeItem('iWishCnt');localStorage.removeItem('setupTime');localStorage.removeItem('iWishsync')} if(localStorage.iWishlistmain){iWishlistmain=JSON.parse(localStorage.getItem('iWishlistmain'))} if(localStorage.iWishCnt){iWishCnt=localStorage.iWishCnt} if(localStorage.iWishsync){if(parseInt(iwish_cid)>0&&localStorage.iWishsync=='true'){iWishsync=!0}} localStorage.setItem('iWishsync',iWishsync)}} function pushToSession(){if(typeof(Storage)!=="undefined"){if(iWishlistmain){localStorage.setItem("iWishlistmain",JSON.stringify(iWishlistmain))} localStorage.setItem("iWishCnt",iWishCnt)}} function isInWishlist(pId,vId){if(typeof iWishlistmain[pId]==='undefined'){return!1} else{if(iWishlistmain[pId].indexOf(vId)>=0){return!0}else{return!1}}} function iwish_init(){jQuery('.iWishCount').html(iWishCnt);console.log('iWishsync status:: '+iWishsync+' iwish_cid ::'+iwish_cid);if(parseInt(iwish_cid)>0){if(!iWishsync){console.log('Sync Need to be done');syncWithServer()}} if(typeof iwish_qvButton!='undefined'&&typeof iwish_qvWrapper!='undefined'){iwish_onInitqv()} if(typeof iWishinitFn!=='undefined'&&typeof iWishinitFn==='function'){iWishinitFn()}} function syncWithServer(){var dataString=JSON.stringify(iWishlistmain);jQuery.ajax({url:'//iwish.shopapps.in/ajax/syncWishlist.php',data:{shop:iwish_shop,cId:iwish_cid,iwishlist:dataString},dataType:'jsonp',jsonpCallback:'iWishCallback',success:function(json){jQuery.extend(iWishlistmain,json.jsonDt);iWishCnt=json.iwishCnt;pushToSession();jQuery('.iWishCount').html(iWishCnt);console.log('iWishsync done :: '+JSON.stringify(iWishlistmain));iWishsync=!0;localStorage.setItem('iWishsync',iWishsync);if(typeof iWishsyncFn!=='undefined'&&typeof iWishsyncFn==='function'){iWishsyncFn()}},error:function(XMLHttpRequest,textStatus,errorThrown){}})} function iwish_onInitqv(){iCanUseOn=!!jQuery.fn.on;if(iCanUseOn){jQuery("body").on('click',iwish_qvButton,function(){iwish_qvDelay()})} else{jQuery("body").delegate(iwish_qvButton,'click',function(){iwish_qvDelay()})}} function iwish_qvDelay(){setTimeout(function(){if(jQuery(iwish_qvWrapper+':visible').find('.iWishAdd').length>0){iWishvarId=jQuery(iwish_qvWrapper+':visible').find('[name=id]').val();checkIwish(jQuery(iwish_qvWrapper+':visible').find(iwishWrapperClass),iWishvarId);if(typeof iWishQvFn!=='undefined'&&typeof iWishQvFn==='function'){iWishQvFn()}}else{iwish_qvDelay()}},300)} function iWishOnSelectChange(){iCanUseOn=!!jQuery.fn.on;if(iCanUseOn){jQuery(document).on('change',iWishSelectClass,function(){selectedClass=jQuery(this);setTimeout(function(){iWishvarId=selectedClass.parents(iwishWrapperClass).find('[name=id]').val();checkIwish(selectedClass.parents(iwishWrapperClass),iWishvarId)},400)})} else{jQuery(document).delegate(iWishSelectClass,'change',function(){selectedClass=jQuery(this);setTimeout(function(){iWishvarId=selectedClass.parents(iwishWrapperClass).find('[name=id]').val();checkIwish(selectedClass.parents(iwishWrapperClass),iWishvarId)},400)})}} function checkIwish(iwishFrmObj,iWishvId){var iwishCurrObj=iwishFrmObj.find('.iWishAdd');iWishpId=iwishCurrObj.attr('data-product');console.log("checkIwish "+iWishpId+' :: '+iWishvId);iwishCurrObj.html(iwish_wait_msg);var checkAganId=isInWishlist(iWishpId,iWishvId);if(checkAganId){iwishCurrObj.addClass('iwishAdded').html(iwish_added_txt)} else{iwishCurrObj.removeClass('iwishAdded').html(iwish_add_txt)} if(typeof iWishSelectChangeFn!=='undefined'&&typeof iWishSelectChangeFn==='function'){iWishSelectChangeFn(iwishCurrObj)}} function iwish_add(iwishAdd,iWishvId){iWishpId=iwishAdd.attr("data-product");if(iwishAdd.hasClass("iwishAdded")||iWishvId==""||iWishpId==""){return!1} iwishAdd.html(iwish_wait_msg);var iwishpTitle=iwishAdd.attr("data-pTitle");iwish_addOnly(iWishpId,iWishvId,iwishpTitle);if(iWishlistmain[iWishpId].indexOf(iWishvId)>=0){iwishAdd.addClass("iwishAdded").html(iwish_added_txt);if(iwish_cid==''){var iwishFrmObj=iwishAdd.parents(iwishWrapperClass);iwishFrmObj.find(".iWishLoginMsg").fadeIn(500);setTimeout(function(){iwishFrmObj.find('.iWishLoginMsg').fadeOut()},6000)}} if(typeof iWishAddFn!=="undefined"&&typeof iWishAddFn==="function"){iWishAddFn()}} function iwish_addCollection(iwishAdd,iWishvId){iWishpId=iwishAdd.attr("data-product");if(iwishAdd.hasClass("iwishAdded")||iWishvId==""||iWishpId==""){return!1} iwishAdd.html(iwish_wait_msg);var iwishpTitle=iwishAdd.attr("data-pTitle");iwish_addOnly(iWishpId,iWishvId,iwishpTitle);if(iWishlistmain[iWishpId].indexOf(iWishvId)>=0){iwishAdd.addClass("iwishAdded").html(iwish_added_txt)} if(typeof iWishaddCollFn!=="undefined"&&typeof iWishaddCollFn==="function"){iWishaddCollFn()}} function iwish_addOnly(iWishpId,iWishvId,iwishpTitle){if(typeof(iWishlistmain[iWishpId])==="undefined"){iWishlistmain[iWishpId]=[]} console.log("Adding "+iWishpId+" :: "+iWishvId);if(iWishlistmain[iWishpId].indexOf(iWishvId)<0){iWishlistmain[iWishpId].push(iWishvId);iWishCnt++;pushToSession();jQuery(".iWishCount").html(iWishCnt);if(parseInt(iwish_cid)>0){jQuery.ajax({url:'//iwish.shopapps.in/ajax/iwishAdd.php',data:{shop:iwish_shop,cId:iwish_cid,pId:iWishpId,vId:iWishvId,pTitle:iwishpTitle},dataType:"jsonp",jsonpCallback:"iWishCallback",success:function(json){},error:function(XMLHttpRequest,textStatus,errorThrown){}})}}} function iwish_remove(pId,vId){if(typeof iWishlistmain[pId]==='undefined'){return!1} else{var delindex=iWishlistmain[pId].indexOf(vId);if(delindex>=0){iWishlistmain[pId].splice(delindex,1);if(iWishCnt>0){iWishCnt--} pushToSession();jQuery('.iWishCount').html(iWishCnt);jQuery.ajax({url:'//iwish.shopapps.in/ajax/iwishRemove.php',data:{shop:iwish_shop,cId:iwish_cid,pId:pId,vId:vId},dataType:'jsonp',jsonpCallback:'iWishCallback',success:function(json){iWishRemoveMsg=json.pro_remove_msg;noItemsMsg=json.no_items_msg},error:function(XMLHttpRequest,textStatus,errorThrown){console.log(errorThrown)}}).done(function(){if(jQuery(".iwishMsgSuccess").length==0){jQuery(".iwishMsg").append(iWishRemoveMsg)} setTimeout(function(){jQuery(".iwishMsgSuccess").fadeOut().remove();if(iWishCnt==0&&jQuery(".iwishMsgInfo").length==0){jQuery(".iwishMsg").append(noItemsMsg)}},3000)});if(typeof iWishRemoveFn!=='undefined'&&typeof iWishRemoveFn==='function'){iWishRemoveFn()} return!0}else{if(typeof iWishRemoveFn!=='undefined'&&typeof iWishRemoveFn==='function'){iWishRemoveFn()} return!1}}} jQuery(document).ready(function(){console.log('iWishlistmain :: '+JSON.stringify(iWishlistmain));iwishProductWrap=jQuery(".iWishAdd:visible").parents(iwishWrapperClass);if(iwishProductWrap.length==1){iWishpId=iwishProductWrap.find(".iWishAdd").attr('data-product');iWishvarId=iwishProductWrap.find('[name=id]').val();console.log('Wishlist init :: '+iWishpId+' :: '+iWishvarId);checkIwish(iwishProductWrap,iWishvarId); /*var checkAganId=isInWishlist(iWishpId,iWishvarId);if(checkAganId){iwishProductWrap.find('.iWishAdd').addClass('iwishAdded').html(iwish_added_txt)} else{iwishProductWrap.find('.iWishAdd').removeClass('iwishAdded').html(iwish_add_txt).show()}*/} iwish_init();jQuery(".iwishRemoveBtn").click(function(){if(jQuery(this).hasClass('iwishRemoved')){return!1} var currentPid=jQuery(this).attr('data-pid');var currentVid=jQuery(this).attr('data-vidremove');if(iwish_remove(currentPid,currentVid)){jQuery(this).addClass('iwishRemoved');jQuery(this).parents('.iwishItem').remove()} return!1});jQuery("input[name=iwishProQuantity]").change(function(){if(parseInt(iwish_cid)>0){var currentiwishInpQty=jQuery(this);var iwishProQty=parseInt(currentiwishInpQty.val());var iwishUpdateVid=currentiwishInpQty.parents('.iwishItem').find('[name=id]').val();jQuery.ajax({url:'//iwish.shopapps.in/ajax/iwishUpdateQty.php',data:{shop:iwish_shop,cId:iwish_cid,iwishpQty:iwishProQty,vId:iwishUpdateVid},dataType:'jsonp',jsonpCallback:'iWishCallback',success:function(json){if(iwishProQty>0){currentiwishInpQty.parents('.iwishItem').find('[name=quantity]').val(iwishProQty)} currentiwishInpQty.parents('.iwishItem').find('.iwishQtyMsg').html('updated wishlist quantity!').fadeIn().delay(3000).fadeOut()},error:function(XMLHttpRequest,textStatus,errorThrown){}});if(typeof iwishUpdateQtyFn!=='undefined'&&typeof iwishUpdateQtyFn==='function'){iwishUpdateQtyFn()}}})});if(window.addEventListener){window.addEventListener("load",iWishOnSelectChange,!1)} else{window.attachEvent("onload",iWishOnSelectChange)}