(function() { window.SP = (function() { function SP() {} SP.api_url = document.currentScript.src.split('js/')[0]; SP.default_timeout = 12000; SP.poll_time = 2000; SP.displayMessage = function(html) { var div, selector, styles; // console.log("message"); div = SP.$('.SP-checkout-wrapper'); if (div.length === 0) { styles = ''; div = SP.$('
'); selector = SP.checkout_legacy ? SP.$('#content .group p:eq(1)') : SP.$('.section--thank-you p').first(); if (SP.$('.section--thank-you p').length === 0 && SP.checkout_legacy == false) selector = SP.$('.thank-you'); // selector = SP.checkout_legacy ? SP.$('.thank-you') : SP.$('.section--thank-you p').first(); // console.log(SP.$('.thank-you')); if (SP.$('.thank-you').length > 0 || SP.$('.section--thank-you p').length > 0) selector.after(div).after('

You will receive an email with download links for your digital purchase.

'); else { selector = SP.$('.main__content .section:eq(1)'); // console.log(selector); selector.find('.content-box:eq(0)').after('
'); selector.find('.content-box:eq(1)').html(div).append('

You will receive an email with download links for your digital purchase.

'); } } return div.html(html).before(styles); }; SP.displayLinks = function(links) { // console.log(links); var content, link, node, _i, _len; node = SP.$('
'); for (_i = 0, _len = links.length; _i < _len; _i++) { link = links[_i]; content = '
' + link.file_name; if (link.file_size > 0) content += ' (' + link.file_size + 'kb)'; content += 'Download'; node.append(content); } return SP.displayMessage(node.html()); }; SP.no_link = function() { var content; content = 'There was a delay with your digital downloads'; return SP.displayMessage(content); }; SP.fetchDlLinks = function() { return SP.$.ajax ({ url: "" + SP.api_url + "index.php?p=fetch_links", type: "GET", dataType: "jsonp", data: { shop: Shopify.shop, checkout_token: SP.checkout_token, ctoken: SP.ctoken }, success: SP.received_links }); }; SP.received_links = function(data, status, jxhr) { if (!data.ready) { SP.time_remaining -= SP.poll_time; if (SP.time_remaining > 0) setTimeout(SP.fetchDlLinks, SP.poll_time); else SP.no_link(); } if (data.links) return SP.displayLinks(data.links); }; SP.receivedOrderInfo = function(data, status, jxhr) { // console.log(data); var content; if (!(data.has_attachments && data.is_downloadable)) return; content = 'LOADING'; SP.time_remaining = SP.default_timeout; SP.displayMessage(content); return SP.fetchDlLinks(); // console.log(data); }; SP.check_dl_link = function() { return SP.$.ajax ({ url: "" + SP.api_url + "index.php?p=check_order", type: "GET", // async: false, // jsonpCallback: 'jsonCallback', // contentType: "application/json", dataType: "jsonp", data: { shop: Shopify.shop, checkout_token: SP.checkout_token, ctoken: SP.ctoken }, success: SP.receivedOrderInfo, error: function(error) { console.log(error); } }); }; SP.loadjQuery = function(afterLoad) { return SP.loadScript("//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js", function() { SP.$ = jQuery.noConflict(true); return afterLoad(); }); }; SP.loadScript = function(url, callback) { var script; script = document.createElement("script"); script.type = "text/javascript"; if (script.readyState) { script.onreadystatechange = function() { if (script.readyState === "loaded" || script.readyState === "complete") { script.onreadystatechange = null; return callback(); } }; } else { script.onload = function() { return callback(); }; } script.src = url; return document.getElementsByTagName("head")[0].appendChild(script); }; return SP; })(); SP.path = window.location.pathname.split('/'); // SP.checkout_legacy = SP.path[1] === 'orders'; // SP.checkout_next = SP.path[2] === 'checkouts' && SP.path[4] === 'thank_you'; SP.checkout_legacy = SP.path[2]; if(SP.checkout_legacy != "checkouts" && SP.checkout_legacy != "orders"){ SP.checkout_legacy = SP.path[1]; } SP.checkout_token = SP.path[3]; if (SP.checkout_legacy === 'orders' || SP.checkout_legacy === 'checkouts') { SP.loadjQuery(function() { SP.$.ajaxSetup({ cache: false }); if (SP.checkout_legacy === 'orders') SP.ctoken = 0; else if (SP.checkout_legacy === 'checkouts') SP.ctoken = 1; return SP.check_dl_link(); }); } }).call(this);