Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************Doogma JS*******************/
- (function() {
- // Developer Instructions:
- // To Execute this script in Test environment - Add query paramater "ddtest" in Page's URL. Test script is "doogma-test.js"
- // To Prevent browser caching - Add query parameter "nocache=somevalue"
- // If saving this file as "doogma-test.js" then set isTestScript = true, otherwise false
- var isTestScript = true;
- var productionScript = document.querySelector('script[src*="doogma.js"]');
- // Make Script Singleton
- if(isTestScript) {
- var currentScript = document.querySelector('script[src*="doogma-test.js"]'); // Note: Do not use "document.currentScript" as it is not supported in IE.
- if(!currentScript) { // This is live script. (var isTestScript is assigned "true" by mistake, correct it in source code.)
- isTestScript = false;
- }
- }
- if(!isTestScript) {
- var currentScript = productionScript;
- if(currentScript.hasAttribute('data-dd-executed')) {
- return;
- }
- currentScript.setAttribute('data-dd-executed','');
- }
- // END: Make Script Singleton
- var docUrl = docurl();
- // Load Test version of script if query parameter contains "ddtest" and current script is not test version.
- if(docUrl.hasSearch('ddtest') && !isTestScript) {
- var testSrc = currentScript.src.replace('.js','-test.js');
- var noCache = docUrl.getSearch('nocache');
- if(noCache) {
- testSrc = docurl(testSrc).setSearch('nocache',noCache).href;
- }
- var testScript = document.createElement('script');
- testScript.setAttribute('src', testSrc);
- document.head.appendChild(testScript);
- return;
- }
- // END: Load Test version of script
- // Check if Script should be disabled
- if(docUrl.hasSearch('nodoogma') || docUrl.hasSearch('nodoogmanav')) {
- return;
- }
- // END: Check if Script should be disabled
- docUrl = null;
- // Load jQuery in noConflict mode
- var dg$;
- var serverURL = 'https://bc.doogma.com/';
- var siteURL = window.location.href;
- var script = document.createElement('script');
- script.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js');
- script.addEventListener('load', function() {
- dg$ = $.noConflict(true);
- mainScript(dg$);
- });
- document.head.appendChild(script);
- // Main Script starts here
- function mainScript($) {
- var storehash = 'storeHash=' + docurl(currentScript.src).getSearch('storeHash');
- var isUIReady = false;
- var uiModificationComplete = true;
- var designerDiv;
- $.fn.ignore = function(sel){
- return this.clone().find(sel||">*").remove().end();
- };
- function fetchOptions(productID,storehash) {
- $.ajax({
- url: serverURL+'frontJs/fetchOptions.php'+'?productID='+productID+'&'+storehash,
- crossDomain: true,
- type: 'GET',
- dataType: 'json',
- processData: false,
- header: {
- "Access-Control-Allow-Origin": "*",
- },
- success: function(response) {
- if ($.trim(response)){
- if($('form .form-field[data-product-attribute]').length) {
- $('form .form-field[data-product-attribute]').each(function(index) {
- var _this = $(this);
- if($('.form-field-title',this).length) {
- var name = $.trim($('.form-field-title',this).ignore().text().split(':')[0]);
- } else if($('label.form-label',this).length) {
- var name = $.trim($('label.form-label',this).text().split(':')[0]);
- }
- name = $.trim(name.split('Required')[0]);
- name = $.trim(name.split('required')[0]);
- name = $.trim(name.replace(/[^a-zA-Z 0-9 _ -]+/g, ""));
- $.each(response, function(index, value){
- value.optionName = $.trim(value.optionName.replace(':',''));
- if(name == value.optionName && value.doogmaClass) {
- if((_this).data('product-attribute') == 'input-text' || (_this).data('product-attribute') == 'input-number' || (_this).data('product-attribute') == 'input-checkbox' || (_this).data('product-attribute') == 'input-file') {
- (_this).find('input').addClass('doogma-'+value.doogmaClass)
- } else if((_this).data('product-attribute') == 'textarea' ) {
- (_this).find('textarea').addClass('doogma-'+value.doogmaClass)
- }
- }
- if(name == value.optionName && value.hidefieldClass == 'yes') {
- // Note: It is important to set type="hidden" as this is used as
- // a selector by some client's custom scripts to show/hid options.
- _this.hide().find('input').attr('type', 'hidden');
- }
- });
- });
- }
- if($('form .productAttributeRow').length) {
- $('form .productAttributeRow').each(function(index) {
- var _this = $(this);
- var name = $.trim($('.productAttributeLabel label span.name',this).text().split(':')[0]);
- $.each(response, function(index, value){
- if(name == value.optionName && value.doogmaClass) {
- if((_this).find('.productAttributeValue input').length) {
- (_this).find('input').addClass('doogma-'+value.doogmaClass);
- } else if((_this).find('.productAttributeValue textarea').length) {
- (_this).find('textarea').addClass('doogma-'+value.doogmaClass);
- }
- }
- if(name == value.optionName && value.hidefieldClass == 'yes') {
- _this.hide().find('input').attr('type', 'hidden');
- }
- });
- });
- }
- }
- }
- });
- }
- function fetchOptionValues(productID,storehash) {
- var options = $('form .form-field[data-product-attribute]');
- //var pending = options.length;
- options.each(function(index1) {
- var _this = $(this);
- if($('.form-field-title',this).length) {
- var optionName = $.trim($('.form-field-title',this).ignore().text().split(':')[0]);
- } else if($('label.form-label',this).length) {
- var optionName = $.trim($('label.form-label',this).text().split(':')[0]);
- }
- optionName = $.trim(optionName.split('Required')[0]);
- optionName = $.trim(optionName.split('required')[0]);
- $.ajax({
- url: serverURL+'frontJs/fetchOptionValues.php'+'?optionName='+optionName+'&'+storehash,
- crossDomain: true,
- type: 'GET',
- aysnc: false,
- dataType: 'json',
- processData: false,
- header: {
- "Access-Control-Allow-Origin": "*",
- },
- success: function(response) {
- if ($.trim(response)){
- $.each(response, function(index, value){
- if((_this).data('product-attribute') == 'swatch' || (_this).data('product-attribute') == 'set-rectangle' || (_this).data('product-attribute') == 'set-radio' || (_this).data('product-attribute') == 'product-list') {
- _this.find('input').each(function() {
- var _inthis = $(this);
- if(value.parentClass != '') {
- if(_inthis.val() == value.optionValueID) {
- _inthis.addClass('doogma-'+value.parentClass);
- if(value.parenthidefieldClass == 'yes') {
- _this.hide().find('input').attr('type', 'hidden');
- }
- _inthis.attr('data-doogma-value',value.doogmaClass);
- if(value.defaultValue == 'yes'){
- _inthis.attr('checked','checked');
- } else {
- _inthis.removeAttr('checked');
- }
- if(value.hidefieldClass == 'yes') {
- _inthis.hide().find('input').attr('type', 'hidden');
- }
- }
- }
- });
- } else if((_this).data('product-attribute') == 'set-select') {
- _this.find('select option').each(function() {
- var _inthis = $(this);
- if(value.parentClass != '') {
- if(_inthis.val() == value.optionValueID) {
- _inthis.parent('select').addClass('doogma-'+value.parentClass);
- if(value.parenthidefieldClass == 'yes') {
- _this.hide().find('input').attr('type', 'hidden');
- }
- _inthis.attr('data-doogma-value',value.doogmaClass);
- if(value.defaultValue == 'yes'){
- _inthis.parent('select').val(value.optionValueID).trigger('change');
- } else {
- _inthis.removeAttr('selected');
- }
- if(value.hidefieldClass == 'yes') {
- _inthis.hide().find('input').attr('type', 'hidden');
- }
- }
- }
- });
- }
- });
- }
- }
- });
- });
- options = $('form .productAttributeRow');
- //pending = options.length;
- options.each(function(index1) {
- var _this = $(this);
- var optionName = $.trim($('.productAttributeLabel label span.name',this).text().split(':')[0]);
- $.ajax({
- url: serverURL+'frontJs/fetchOptionValues.php'+'?optionName='+optionName+'&'+storehash,
- crossDomain: true,
- type: 'GET',
- dataType: 'json',
- processData: false,
- header: {
- "Access-Control-Allow-Origin": "*",
- },
- success: function(response) {
- if ($.trim(response)){
- $.each(response, function(index, value){
- if((_this).find('.productAttributeValue ul').length) {
- _this.find('.productAttributeValue ul li').each(function() {
- var _lithis = $(this);
- var _inthis = $('input',this);
- if(value.parentClass != '') {
- if(_inthis.val() == value.optionValueID) {
- _inthis.addClass('doogma-'+value.parentClass);
- if(value.parenthidefieldClass == 'yes') {
- _this.hide().find('input').attr('type', 'hidden');
- }
- _inthis.attr('data-doogma-value',value.doogmaClass);
- if(value.defaultValue == 'yes'){
- _inthis.attr('checked','checked');
- _lithis.addClass('selectedValue');
- } else {
- _inthis.removeAttr('checked');
- }
- if(value.hidefieldClass == 'yes') {
- _inthis.hide().find('input').attr('type', 'hidden');
- }
- }
- }
- });
- } else if((_this).find('.productAttributeValue select').length) {
- _this.find('.productAttributeValue select option').each(function() {
- var _inthis = $(this);
- if(value.parentClass != '') {
- if(_inthis.val() == value.optionValueID) {
- _inthis.parent('select').addClass('doogma-'+value.parentClass);
- if(value.parenthidefieldClass == 'yes') {
- _this.hide().find('input').attr('type', 'hidden');
- }
- _inthis.attr('data-doogma-value',value.doogmaClass);
- if(value.defaultValue == 'yes'){
- _inthis.parent('select').val(value.optionValueID).trigger('change');
- } else {
- _inthis.removeAttr('selected');
- }
- if(value.hidefieldClass == 'yes') {
- _inthis.hide().find('input').attr('type', 'hidden');
- }
- }
- }
- });
- }
- });
- }
- }
- });
- });
- }
- function fetchNewFeatureSetings(storehash) {
- $.ajax({
- url: serverURL+'frontJs/fetchSettings.php?'+storehash,
- crossDomain: true,
- type: 'GET',
- dataType: 'json',
- processData: false,
- header: {
- "Access-Control-Allow-Origin": "*",
- },
- success: function(response) {
- if ($.trim(response)) {
- var getData = response;
- if(getData.mobileImageFloat == 'yes') {
- var script = '<script type="text/javascript" src="//bc.doogma.com/js/mybigcommerce-doogma-test-store-float-designer.js"></script>';
- $('body').append(script);
- }
- }
- }
- });
- }
- function IsThumbs() {
- $('body').on('click', '.productThumbs a', function(){
- var selVal = $(this).data('fullimagelink');
- $('select.doogma-alt-image1').val(selVal);
- if(selVal == '#customizeImage') {
- $('.doogma-customize-now-selected').prop('checked', true);
- } else {
- $('.doogma-customize-now-selected').prop('checked', false);
- }
- });
- }
- function fetchProducts(productID,storehash) {
- $.ajax({
- url: serverURL+'frontJs/fetchProductsddtest.php'+'?productID='+productID+'&'+storehash,
- crossDomain: true,
- type: 'GET',
- dataType: 'json',
- processData: false,
- header: {
- "Access-Control-Allow-Origin": "*",
- },
- success: function(response) {
- if ($.trim(response)){
- var getData = response;
- var designerParentDiv = '';
- function designerParentFun(designerParentDiv) {
- addDesignerElement({
- parentDiv: designerParentDiv,
- uid: getData.doogmaCode
- });
- fetchNewFeatureSetings(storehash);
- if(getData.showProductThumbs && getData.showProductThumbs == 'yes' && getData.image_count > 1) {
- if(getData.customizeImage != '') {
- var imgURL = getData.customizeImage;
- } else {
- var imgURL = serverURL+'upload/customize.png';
- }
- $thumbImagesHtml = '<ul class="productThumbs">';
- $thumbImagesHtml +='<li><a href="javascript:void(0);" class="customizeImage" data-fullImagelink="#customizeImage" ><img src="'+imgURL+'" alt="customizeImage" width="38" /></a></li>';
- $.each(getData.AllImages,function(index,value){
- $thumbImagesHtml +='<li><a href="javascript:void(0);" data-fullImagelink="'+getData.FullsizeImages[index]+'"><img src="'+value+'" alt="thumbImages'+index+'" /></a></li>';
- });
- $thumbImagesHtml += '</ul>';
- $thumbImagesHtml += '<select style="display:none;" class="doogma-alt-image1">';
- $thumbImagesHtml +='<option value="#customizeImage" data-doogma-value="doogma-customize-now-selected" selected>customizeImage</option>';
- $.each(getData.FullsizeImages,function(index,value) {
- var selImageDoogma = value.replace('https:','');
- $thumbImagesHtml +='<option value="'+value+'" data-doogma-value="'+selImageDoogma+'"> Image'+index+' </option>';
- });
- $thumbImagesHtml += '</select>';
- $thumbImagesHtml += '<input type="checkbox" name="doogma-customize-now-selected" class="doogma-customize-now-selected" value="true" style="display:none;" checked>';
- $thumbImagesHtml += '<style> .productThumbs { display: block; margin: 10px; padding: 0; text-align: left; } .productThumbs li { display: inline-block; margin: 10px; } </style>';
- $('.VisualizationContainer').append($thumbImagesHtml);
- IsThumbs();
- } else if(getData.showProductThumbs && getData.showProductThumbs == 'yes') {
- $thumbImagesHtml = '<input type="checkbox" name="doogma-customize-now-selected" class="doogma-customize-now-selected" value="true" style="display:none;" checked>';
- $('.VisualizationContainer').append($thumbImagesHtml);
- }
- }
- if(getData.addDoogma == 'yes') {
- var imgName = getData.image_file;
- $('body img[src*="'+imgName+'"]').each(function(index) {
- if($(this).attr('src').indexOf(imgName) > -1) {
- if($(this).parents('[class*=product][class*=images]').length) {
- if($(this).parents('[class*=product][class*=images][class*=container]').length) {
- var _parent = $(this).parents('[class*=product][class*=images][class*=container]');
- var designerParentDiv = _parent.addClass('VisualizationContainer')[0];
- designerParentFun(designerParentDiv);
- } else {
- var _parent = $(this).parents('[class*=product][class*=images]');
- var designerParentDiv = _parent.addClass('VisualizationContainer')[0];
- designerParentFun(designerParentDiv);
- }
- return false;
- } else if($(this).parents('[class*=thumb][class*=product]').length) {
- var _parent = $(this).parents('[class*=thumb][class*=product]');
- var designerParentDiv = _parent.addClass('VisualizationContainer')[0];
- designerParentFun(designerParentDiv);
- return false;
- } else if($(this).parents('[class*=Thumb][class*=Product][class!=ProductThumbImage]').length) {
- var _parent = $(this).parents('[class*=Thumb][class*=Product][class!=ProductThumbImage]');
- var designerParentDiv = _parent.addClass('VisualizationContainer')[0];
- designerParentFun(designerParentDiv);
- $('#fancy_outer').remove();
- return false;
- }
- }
- });
- $('body form[action*="/cart.php"]').parent().addClass('NavigationContainer');
- if(getData.doogmaProductId) {
- $('input[name=product_id]').after('<input type="hidden" class="doogma-product-id" value="'+getData.doogmaProductId+'">');
- }
- } else {
- $('body .doogma-plugin').remove();
- }
- }
- }
- });
- }
- function scrollToOption() {
- if($('form .form-field').length) {
- var options = $('form .form-field[data-product-attribute]');
- for(var i=0; i<options.length; i++) {
- var divOpt = options[i];
- var _this = $(divOpt);
- var optionName = $.trim($('label.form-label',divOpt).text().split(':')[0]);
- if(optionName == 'doogma-selected-heading') {
- var doogmaSelected = $('input',divOpt).val();
- for(var i=0; i<options.length; i++) {
- divOpt = options[i];
- var _inthis = $(divOpt);
- var seloptionName = divOpt.querySelector('[class*="doogma-"]').className.match(/doogma-\S+/)[0];
- if(seloptionName == doogmaSelected) {
- $('html,body').animate({ scrollTop: $(_inthis).offset().top}, 'slow');
- return;
- }
- }
- }
- }
- }
- if($('form .productAttributeRow').length) {
- var options = $('form .productAttributeRow');
- for(var i=0; i<options.length; i++) {
- var divOpt = options[i];
- var _this = $(divOpt);
- var optionName = $.trim($('.productAttributeLabel label span.name',divOpt).text().split(':')[0]);
- if( optionName == 'doogma-selected-heading') {
- var doogmaSelected = $('.productAttributeValue input',divOpt).val();
- for(var i=0; i<options.length; i++) {
- divOpt = options[i];
- var _inthis = $(divOpt);
- var seloptionName = divOpt.querySelector('[class*="doogma-"]').className.match(/doogma-\S+/)[0];
- if(seloptionName == doogmaSelected) {
- $('html,body').animate({ scrollTop: $(_inthis).offset().top}, 'slow');
- return;
- }
- }
- }
- }
- }
- }
- function createCookie(name,value,days) {
- var expires = "";
- if (days) {
- var date = new Date();
- date.setTime(date.getTime() + (days*24*60*60*1000));
- expires = "; expires=" + date.toUTCString();
- }
- document.cookie = name + "=" + value + expires + "; path=/";
- }
- function readCookie(name) {
- var nameEQ = name + "=";
- var ca = document.cookie.split(';');
- for(var i=0;i < ca.length;i++) {
- var c = ca[i];
- while (c.charAt(0)==' ') c = c.substring(1,c.length);
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
- }
- return null;
- }
- function eraseCookie(name) {
- createCookie(name,"",-1);
- }
- function addDesignerElement(parameters) {
- if(typeof parameters == 'undefined') {
- var param = addDesignerElement.sParameters;
- } else {
- var param = addDesignerElement.sParameters = parameters;
- }
- /* if(!uiModificationComplete) {
- return;
- } */
- param.parentDiv.innerHTML = '';
- designerDiv = document.createElement('div');
- designerDiv.setAttribute('class','doogma-plugin');
- if(param.uid) {
- designerDiv.setAttribute('data-uid',param.uid);
- }
- designerDiv.setAttribute('data-nav-ready', isUIReady);
- param.parentDiv.appendChild(designerDiv);
- var script = document.createElement('script');
- script.setAttribute('src', '//cdne2im.doogma.com/smartmobile-v2/loader.js');
- param.parentDiv.appendChild(script);
- }
- function StenciladdtoCart() {
- if($('.productView-details .productView-info').length) {
- $('.productView-details .productView-info').each(function() {
- if($.trim($('.productView-info-name',this).text()).indexOf('doogma-thumb') > -1) {
- var imageLink = $('.productView-info-value',this).text();
- $('.productView-image img').attr('src',imageLink);
- }
- });
- }
- }
- function getPageParameters() {
- var el = document.querySelector('#doogma');
- if(el) {
- try {
- return JSON.parse(el.textContent);
- } catch(e) {}
- }
- return {};
- }
- $(function() {
- // Delete this if condition after Shahil fixes timing issue in InkityAndCo
- if(window.location.hostname != 'inkityandco.com' || isTestScript) {
- if(getPageParameters().siteNavigationModifier) {
- uiModificationComplete = false;
- document.addEventListener('doogmaNavigationModifyComplete', function onNavModifyComplete() {
- document.removeEventListener('doogmaNavigationModifyComplete', onNavModifyComplete);
- uiModificationComplete = true;
- addDesignerElement();
- });
- }
- }
- if($('input[name=product_id]').length) {
- var productID = $('input[name=product_id]').val();
- fetchProducts(productID,storehash);
- fetchOptions(productID,storehash);
- fetchOptionValues(productID,storehash);
- $('body').on('click', '#swipeTarget', function() {
- scrollToOption(productID);
- });
- }
- if($('form[name=cartForm]').length) {
- if($('form[name=cartForm] .CartContents').length) {
- $('form[name=cartForm] .CartContents tbody tr').each(function() {
- var _tr = $(this);
- if($('td',this).hasClass('ProductName')) {
- var _thisName = $('td.ProductName',this);
- if(_thisName.find('table.productAttributes').length) {
- _thisName.find('table.productAttributes tbody tr').each(function() {
- var _txt = $.trim($(this).text());
- if(_txt.indexOf('doogma') > -1 && _txt.indexOf('thumb') > -1 ) {
- var imageLink = $('td:nth-child(2)',this).text();
- if(_tr.find('td').hasClass('CartThumb')) {
- var _this = _tr.find('td.CartThumb');
- _this.find('img').attr('src',imageLink);
- }
- }
- if(_txt.indexOf('doogma') > -1 && _txt.indexOf('saved') > -1 && _txt.indexOf('design') > -1 ) {
- var productLink = $('td:nth-child(2)',this).text();
- _thisName.find(' a:first').attr('href',productLink);
- if(_tr.find('td').hasClass('CartThumb')) {
- var _this = _tr.find('td.CartThumb');
- _this.find('a').attr('href',productLink);
- }
- }
- });
- }
- }
- });
- }
- if($('form[name=cartForm] .CartList').length) {
- $('form[name=cartForm] .CartList li').each(function() {
- var _tr = $(this);
- if($('.ProductDetails',this).length) {
- var _thisName = $('.ProductDetails',this);
- if(_thisName.find('table.productAttributes').length) {
- _thisName.find('table.productAttributes tbody tr').each(function() {
- var _txt = $.trim($(this).text());
- if(_txt.indexOf('doogma') > -1 && _txt.indexOf('thumb') > -1 ) {
- var imageLink = $('td:nth-child(2)',this).text();
- if(_tr.find('.ProductImage').length) {
- var _this = _tr.find('.ProductImage');
- _this.find('img').attr('src',imageLink);
- }
- }
- if(_txt.indexOf('doogma') > -1 && _txt.indexOf('saved') > -1 && _txt.indexOf('design') > -1 ) {
- var productLink = $('td:nth-child(2)',this).text();
- _thisName.find(' a:first').attr('href',productLink);
- if(_tr.find('.ProductImage').length) {
- var _this = _tr.find('.ProductImage');
- _this.find('a').attr('href',productLink);
- }
- }
- });
- }
- }
- });
- }
- }
- if($('div[data-cart-content]').length) {
- $('div[data-cart-content] .cart-item').each(function(index) {
- var _tr = $(this);
- if($('.cart-item-name',this)) {
- var _thisName = $('.cart-item-name',this);
- _thisName.next('.cart-item-option-item').each(function() {
- _txt = $.trim($('.cart-item-option-label',this).text());
- if(_txt.indexOf('doogma') > -1 && _txt.indexOf('saved') > -1 && _txt.indexOf('design') > -1 ) {
- var productLink = $.trim($('.cart-item-option-value',this).text());
- _thisName.find('a').attr('href',productLink);
- }
- if(_txt.indexOf('doogma') > -1 && _txt.indexOf('thumb') > -1 ) {
- var imageLink = $.trim($('.cart-item-option-value',this).text());
- if(_tr.find('.cart-item-image')) {
- var _this = _tr.find('.cart-item-image');
- _this.html('<img src="'+imageLink+'" />');
- }
- }
- });
- }
- });
- $('body').on('click', 'a[data-cart-item-remove]', function() {
- setTimeout(function(){ location.reload(); }, 2500);
- });
- }
- if($('.cart').length) {
- $('.cart tbody.cart-list tr').each(function(index) {
- var _tr = $(this);
- if($('td',this).hasClass('cart-item-title')) {
- var _thisName = $('td.cart-item-title',this);
- $('td.cart-item-title .definitionList-key',this).each(function() {
- _txt = $.trim($(this).text());
- if(_txt.indexOf('doogma') > -1 && _txt.indexOf('saved') > -1 && _txt.indexOf('design') > -1 ) {
- var productLink = $.trim($(this).next('.definitionList-value').text());
- _thisName.find('.cart-item-name a').attr('href',productLink);
- }
- if(_txt.indexOf('doogma') > -1 && _txt.indexOf('thumb') > -1 ) {
- var imageLink = $.trim($(this).next('.definitionList-value').text());
- if(_tr.find('td').hasClass('cart-item-figure')) {
- var _this = _tr.find('td.cart-item-figure');
- _this.html('<img src="'+imageLink+'" />');
- //_this.find('img').attr('src',imageLink);
- }
- }
- });
- }
- });
- $('body').on('click', '.cart-remove', function() {
- setTimeout(function(){ location.reload(); }, 2500);
- });
- }
- // Cart JSON
- if(siteURL.indexOf('/cart') > -1) {
- host = '/api/storefront/cart?include=lineItems.digitalItems.options,lineItems.physicalItems.options';
- $.ajax({
- type: 'GET',
- url: host,
- dataType: 'json',
- success: function(response){
- var items = response[0]['lineItems']['physicalItems'];
- $.each(items, function(index,value) {
- var thumb , designLink = '';
- $.each(value.options, function(oIndex,oValue) {
- if(oValue.name == 'doogma-thumb') {
- thumb = oValue.value;
- } else if(oValue.name == 'doogma-saveddesignlink') {
- designLink = oValue.value;
- } else if(oValue.name == 'Link To Product Image') {
- thumb = oValue.value;
- } else if(oValue.name == 'Link to Design Page') {
- designLink = oValue.value;
- }
- });
- var proList = $('div[data-cart-content] .cart-item')[index];
- $('img',proList).attr('src',thumb);
- if($('a',proList).attr('href') == value.url) {
- $('a[href="'+value.url+'"]',proList).attr('href',designLink);
- }
- });
- }
- });
- }
- // Customer Logged In or not On Account page
- function parseJwt(token) {
- if(token != '') {
- const base64HeaderUrl = token.split('.')[0];
- const base64Header = base64HeaderUrl.replace('-', '+').replace('_', '/');
- const headerData = JSON.parse(window.atob(base64Header));
- const base64Url = token.split('.')[1];
- const base64 = base64Url.replace('-', '+').replace('_', '/');
- const dataJWT = JSON.parse(window.atob(base64));
- dataJWT.header = headerData;
- return dataJWT;
- }
- }
- function customerOrderitems(value) {
- host = '/api/storefront/order/'+value+'?include=lineItems.digitalItems.options,lineItems.physicalItems.options';
- $.ajax({
- type: 'GET',
- url: host,
- dataType: 'json',
- success: function(response1) {
- var items = response1['lineItems']['physicalItems'];
- $.each(items, function(index,value) {
- var thumb , designLink = '';
- $.each(value.options, function(oIndex,oValue) {
- if(oValue.name == 'doogma-thumb') {
- thumb = oValue.value;
- } else if(oValue.name == 'doogma-saveddesignlink') {
- designLink = oValue.value;
- } else if(oValue.name == 'Link to Product Image') {
- thumb = oValue.value;
- } else if(oValue.name == 'Link to Design Page') {
- designLink = oValue.value;
- }
- });
- var imageUrl = value.imageUrl.split('/');
- imageUrl = imageUrl[imageUrl.length-1];
- imageUrl = imageUrl.split('.')[0];
- if($('input[value="'+value.id+'"]').length) {
- var parentEle = $('input[value="'+value.id+'"]').parents()[1];
- var imgEle = $('img', parentEle);
- imgEle.removeAttr('class');
- imgEle.attr('src',thumb);
- } else if($('body img[src *="'+imageUrl+'"]').length) {
- var imgEle = $('body img[src *="'+imageUrl+'"]');
- imgEle.removeAttr('class');
- imgEle.attr('src',thumb);
- }
- });
- }
- });
- }
- // all Orders page
- if(siteURL.indexOf('action=view_order') > -1 || siteURL.indexOf('action=order_status') > -1) {
- var appClientId = "gq98apmftghdptreh2utos3hs4w0sp0";
- $.ajax({
- url: "/customer/current.jwt?app_client_id="+appClientId,
- crossDomain: true,
- type: 'GET',
- header: {
- "Access-Control-Allow-Origin": "*",
- },
- success: function(response) {
- const jwtDecoded = parseJwt(response);
- if(jwtDecoded) {
- $.ajax({
- url: serverURL+'frontJs/customerOrders.php?customerID='+jwtDecoded.customer.id+'&'+storehash,
- crossDomain: true,
- type: 'GET',
- dataType: 'json',
- processData: false,
- header: {
- "Access-Control-Allow-Origin": "*",
- },
- success: function(response) {
- if(response.length > 0) {
- $.each(response, function(index,value) {
- customerOrderitems(value);
- });
- }
- }
- });
- }
- }
- });
- // Single Order page
- if(siteURL.indexOf('order_id=') > -1) {
- var order_id = siteURL.split('order_id=')[1];
- order_id = order_id.replace( /\D+$/, '');
- customerOrderitems(order_id);
- }
- }
- });
- if($('#form-action-addToCart').length) {
- $('body').on('click', '#form-action-addToCart', function (){
- if($('form .form-field').length) {
- var ProName = $('.productView-title').text();
- $('form .form-field[data-product-attribute]').each(function() {
- var _this = $(this);
- var optionName = $.trim($('label.form-label',this).text().split(':')[0]);
- if( optionName == 'saved design link') {
- var productLink = $('input',this).val();
- createCookie(ProName+'link',productLink,1);
- }
- if( optionName == 'doogma-thumb') {
- var doogmaThumb = $('textarea',this).val();
- createCookie(ProName+'thumb',doogmaThumb,1);
- }
- });
- }
- setTimeout(function(){ StenciladdtoCart(); }, 3000);
- });
- }
- if($('.AddCartButton').length) {
- $('body').on('click', '.AddCartButton', function (){
- if($('form .productAttributeRow').length) {
- var ProName = $('.ProductDetailsGrid h1').text();
- $('form .productAttributeRow').each(function() {
- var optionName = $.trim($('.productAttributeLabel label span.name',this).text().split(':')[0]);
- if( optionName == 'saved design link') {
- var productLink = $('.productAttributeValue input',this).val();
- createCookie('currentProductLink',productLink,1);
- }
- if( optionName == 'doogma-thumb') {
- var doogmaThumb = $('.productAttributeValue textarea',this).val();
- createCookie('currentProductThumb',doogmaThumb,1);
- }
- });
- }
- });
- }
- $('body').on('click', '.quickview', function(){
- setTimeout(function(){
- var productID = $('input[name=product_id]').val();
- fetchProducts(productID,storehash);
- fetchOptions(productID,storehash);
- fetchOptionValues(productID,storehash);
- $('body').on('click', '#form-action-addToCart', function (){
- setTimeout(function(){ StenciladdtoCart(); }, 3000);
- });
- }, 1500);
- });
- $(document).ajaxComplete(function( event, xhr, settings ) {
- if (settings.url.indexOf('/remote.php?w=getproductquickview') > -1) {
- setTimeout(function(){
- var productID = $('input[name=product_id]').val();
- fetchProducts(productID,storehash);
- fetchOptions(productID,storehash);
- fetchOptionValues(productID,storehash);
- }, 1500);
- }
- if (settings.url.indexOf('/cart.php') > -1) {
- $('.fastCartThumb img').attr('src',readCookie('currentProductThumb'));
- $('.fastCartThumb img').attr('width','200px');
- $('.fastCartItemBox div a').attr('href',readCookie('currentProductLink'));
- }
- });
- $(document).ajaxStop(function(){
- isUIReady = true;
- if(designerDiv) {
- designerDiv.setAttribute('data-nav-ready', 'true');
- }
- productionScript.setAttribute('data-navigation-complete', '');
- dispatchCustomEvent(document, 'doogmaNavigationComplete');
- });
- }
- // +---------------------+
- // | Utility Functions |
- // +---------------------+
- /**
- * Manipulates a URL by using "a" (Anchor) DOMElement. If input url is not absolute url then computation is done relative to document's current page.
- * It means if protocol and host in input url is missing then the current document protocol and host is used as protocol and host of input url.
- * If url starts without a forwarding slash then current page's base path is used as base of input url.
- *
- * Important: Do not set a url directly through 'href' property, instead set url through 'setUrl()' function.
- *
- * @param value {String} URL value. If it is missing then document URL is used instead.
- *
- * @returns a {DOMElement} An anchor DOMElement with extended functionalities for URL manipulation
- */
- function docurl(value) {
- var a = document.createElement('a');
- if(typeof value == 'undefined') {
- setUrl(document.location.href);
- } else {
- setUrl(value);
- }
- a.setUrl = setUrl;
- a.hasSearch = hasSearch;
- a.getSearch = getSearch;
- a.setSearch = setSearch;
- a.removeSearch = removeSearch;
- return a;
- function setUrl(value) {
- if(value = value.trim()) {
- a.setAttribute('href',value);
- } else {
- a.removeAttribute('href');
- }
- return this;
- }
- function hasSearch(prop) {
- return typeof getSearch(prop)=='string';
- }
- function getSearch(prop) {
- var s = a.search;
- if(s.length<2) {
- return undefined;
- }
- var m = s.match(new RegExp('[\\?&]'+prop+'(=[^&]*)?(&|$)'));
- if(!m) {
- return undefined;
- }
- m = m[0];
- s = m.slice(1, m[m.length-1]=='&'?-1:m.length);
- m = s.indexOf('=');
- return m == -1? '' : decodeURIComponent(s.slice(m+1));
- }
- function setSearch(prop,val) {
- if(typeof val=='undefined') {
- var val = '';
- } else {
- val = decodeURIComponent(val)==val? encodeURIComponent(val) : val;
- }
- var s = a.search;
- // search
- var f = new RegExp('[\\?&]'+prop+'(=[^&]*)?(&|$)').exec(s);
- if(val) {
- prop += '=' + val;
- }
- if(f) { // replace existing
- var e = f.index+f[0].length;
- e = e==s.length? '' : s.slice(e-1);
- s = s.slice(0, f.index+1) + prop + e;
- } else { // add new
- if(s.length>1) {
- s += '&' + prop;
- } else {
- s += prop;
- }
- }
- a.search = s;
- return this;
- }
- function removeSearch(prop) {
- var s = a.search;
- var f = new RegExp('[\\?&]'+prop+'(=[^&]*)?(&|$)').exec(s);
- if(!f) {
- return this;
- }
- var e = f.index+f[0].length;
- if(f.index>0 && e<s.length) {
- e--;
- }
- a.search = s.slice(0, f.index) + s.slice(e);
- return this;
- }
- }
- function dispatchCustomEvent(elem, type, bubbles, cancelable, detail) {
- if (typeof bubbles == 'undefined')
- var bubbles = false;
- if (typeof cancelable == 'undefined')
- var cancelable = false;
- try {
- var evt = new CustomEvent(type, { bubbles:bubbles, cancelable:cancelable, detail:detail });
- } catch(e) {
- evt = document.createEvent('CustomEvent');
- evt.initCustomEvent(type, bubbles, cancelable, detail);
- }
- elem.dispatchEvent(evt);
- }
- })();
- /********************infothreeg@gmail.com (Suman Bansal) *********************/
Add Comment
Please, Sign In to add comment