var iwish_shop = "poppyandpeonies.myshopify.com"; var iWishCnt=0; var iWishlistmain={}; var iWishsync=false; 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'; } 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('iWishsync'); } if (localStorage.iWishlistmain) {iWishlistmain = JSON.parse(localStorage.getItem('iWishlistmain'));} if (localStorage.iWishCnt && !isNaN(localStorage.iWishCnt)) {iWishCnt = parseInt(localStorage.iWishCnt);} if(localStorage.iWishsync) { if(parseInt(iwish_cid)>0 && localStorage.iWishsync == 'true') {iWishsync = true;} } 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 false;} else {if(iWishlistmain[pId].indexOf(vId)>=0) {return true;} else {return false;}} } getSession(); function syncWithServer() { var dataString = JSON.stringify(iWishlistmain); jQuery.ajax({ url: 'https://iwish.shopapps.in/ajax/syncWishlist.php', data: { shop:iwish_shop, cId:iwish_cid, iwishlist:dataString }, dataType: 'jsonp', jsonpCallback: 'iWishSyncCallback', success: function(json) { jQuery.extend( iWishlistmain, json.jsonDt ); iWishCnt = json.iwishCnt; pushToSession(); jQuery('.iWishCount').html(iWishCnt); console.log('iWishsync done :: '+JSON.stringify(iWishlistmain)); iWishsync=true; localStorage.setItem('iWishsync',iWishsync); if (typeof iWishsyncFn !== 'undefined' && typeof iWishsyncFn === 'function') { iWishsyncFn();} }, error: function(XMLHttpRequest, textStatus, errorThrown) {} }); } function checkIwish(iwishFrmObj, iWishvId) { var iwishCurrObj = iwishFrmObj.find('.iWishAdd'); iWishpId = iwishCurrObj.attr('data-product'); console.log("checkIwish "+iWishpId+ ' :: ' + iWishvId); 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_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: 'https://iwish.shopapps.in/ajax/iwishAdd.php', data: { shop:iwish_shop, cId:iwish_cid, pId:iWishpId, vId:iWishvId, pTitle:iwishpTitle }, dataType: "jsonp", jsonpCallback: "iWishAddCallback", success: function(json) {}, error: function(XMLHttpRequest, textStatus, errorThrown) {} }); } } } function iwish_add(iwishAdd, iWishvId) { iWishpId = iwishAdd.attr("data-product"); if(iwishAdd.hasClass("iwishAdded") || iWishvId=="" || iWishpId==""){return false;} 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 false;} 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_remove(iwishRemove, vId, iwishProxy) { var returnTp = false; pId = iwishRemove.attr("data-product"); if(typeof iWishlistmain[pId] === 'undefined') { return returnTp; } var delindex = iWishlistmain[pId].indexOf(vId); if(delindex>=0){ iWishlistmain[pId].splice(delindex, 1); if(iWishCnt>0){ iWishCnt--; } jQuery('.iWishCount').html(iWishCnt); pushToSession(); if(parseInt(iwish_cid)>0){ var iwishProxy = iwishProxy || false; jQuery.ajax({ url: 'https://iwish.shopapps.in/ajax/iwishRemove.php', data: { shop:iwish_shop, cId:iwish_cid, pId:pId, vId:vId}, dataType: 'jsonp', jsonpCallback: 'iWishRemoveCallback', success: function(json) { iwishRemove.removeClass("iwishAdded"); if (iwishProxy == false) { iwishRemove.html(iwish_add_txt); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { } }); } returnTp = true; } if (typeof iWishRemoveFn !== 'undefined' && typeof iWishRemoveFn === 'function'){ iWishRemoveFn();} return returnTp; } 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 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 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_init() { jQuery('.iWishCount').html(iWishCnt); 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();} } /* Let Rock-n-Roll*/ 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); } iwish_init(); /* Proxy page calls */ jQuery(".iwishRemoveBtn").click(function() { console.log('iwishRemove called'); if(jQuery(this).hasClass('iwishRemoved')){return false;} var currentVid=jQuery(this).attr('data-variant'); if(iwish_remove(jQuery(this), currentVid, true)){ console.log('iwish remove :: '+currentVid); jQuery(this).addClass('iwishRemoved'); jQuery(this).parents('.iwishItem').remove(); jQuery(".iwishMsgSuccess").show(); setTimeout(function(){ jQuery(".iwishMsgSuccess").fadeOut(); if(iWishCnt==0){ jQuery(".iwishMsgInfo").fadeIn(); } }, 3000); } return false; }); 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(); if(iwishProQty>0) { jQuery.ajax({ url: 'https://iwish.shopapps.in/ajax/iwishUpdateQty.php', data: { shop:iwish_shop, cId:iwish_cid, iwishpQty:iwishProQty, vId:iwishUpdateVid }, dataType: 'jsonp', jsonpCallback: 'iWishUpdateQtyCallback', success: function(json) { currentiwishInpQty.parents('.iwishItem').find('[name=quantity]').val(iwishProQty); currentiwishInpQty.addClass('iwishProQtyAdded'); setTimeout(function () { currentiwishInpQty.removeClass('iwishProQtyAdded'); }, 2000); currentiwishInpQty.parents('.iwishItem').find('.iwishQtyMsg').fadeIn().delay(3000).fadeOut(); if (typeof iwishUpdateQtyFn !== 'undefined' && typeof iwishUpdateQtyFn === 'function') { iwishUpdateQtyFn();} }, error: function(XMLHttpRequest, textStatus, errorThrown) {} }); } else{ currentiwishInpQty.val(1).addClass('iwishProQtyError'); setTimeout(function () { currentiwishInpQty.removeClass('iwishProQtyError'); }, 1000); } } }); }); if (window.addEventListener) { window.addEventListener("load", iWishOnSelectChange, false); } else { window.attachEvent("onload", iWishOnSelectChange) }