forked from freakdesign/shopifyFD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopifyFD.min.js
More file actions
138 lines (138 loc) · 77.7 KB
/
shopifyFD.min.js
File metadata and controls
138 lines (138 loc) · 77.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
(function(){if(0>document.URL.indexOf("myshopify.com/admin"))return alert("Error: Shopify Admin not found");if("undefined"===typeof Shopify)return alert("Error: Shopify object not found");if("undefined"===typeof jQuery)return alert("Error: jQuery not found");if(document.getElementById("shopifyfd-css"))"object"===typeof Shopify&&Shopify.Flash&&Shopify.Flash.error?Shopify.Flash.error("Error: ShopifyFD already loaded"):alert("Error: ShopifyFD already loaded");else if("classList"in document.createElement("_")&&
(!document.createElementNS||"classList"in document.createElementNS("http://www.w3.org/2000/svg","g"))){var n=window.shopifyfdTranslation||{save:"Save",edit:"Edit","delete":"Delete",about_shopifyfd:"About ShopifyFD",select_or_create_metafield:"Select or create a metafield",reload_page:"Reload page to check results.",add_new_metafield:"Add New Metafield",edit_metafield:"Edit Metafield",metafield_deleted:"Metafield deleted",hide_from_sitemap:"Hide from Sitemap"},l={alpha:!1,omega:!1,metafields:{},data:{},
cache:{}};(function(){var a=document.createElement("link");a.type="text/css";a.rel="stylesheet";a.id="shopifyfd-css";a.href="//freakdesign-us.s3.amazonaws.com/shopify/shopifyFD/s/shopifyFD.css";document.getElementsByTagName("head")[0].appendChild(a)})();var Z='<label class="metafield-next-label next-label">'+n.add_new_metafield+'</label><input class="ssb" maxlength="20" type="text" id="metafield_namespace" placeholder="namespace" list="fd-dl-namespace"><datalist id="fd-dl-namespace"></datalist><input class="ssb" maxlength="30" type="text" id="metafield_key" placeholder="key" list="fd-dl-key"><datalist id="fd-dl-key"></datalist><textarea class="ssb" id="metafield_value" placeholder="value"></textarea><input type="hidden" id="metafield_id"><a class="btn fd-btn savemymeta" id="shopifyjs_savemetafield">'+
n.save+'</a> <a class="int btn fd-btn savemymeta" id="shopifyjs_savemetafield_int">Save as Integer</a> <a id="shopifyjs_copymetafield" class="btn btn-slim hide btn-primary tooltip tooltip-bottom"><span class="tooltip-container"><span class="tooltip-label">Copy Metafield to Virtual Clipboard</span></span>Copy</a> <a class="btn btn-slim hide delete tooltip tooltip-bottom" id="shopifyjs_deletemetafield"><span class="tooltip-container"><span class="tooltip-label">There is no undo. Be careful...</span></span>'+
n["delete"]+'</a><p style="margin:1em 0;line-height:1"><small><span class="metafield-save-note">Please note: Using the save button top right will NOT save these metafields. Be sure to click '+n.save+' above.<br><br></span><a id="advanced_meta_features" href="#">Toggle helper buttons</a></small></p><div id="advanced_meta" class="hide"><p style="border-bottom: 1px solid #ccc;margin-bottom:.5em">Handle Helper <a id="adv_clear_cache" style="float:right" href="#">Clear cache</a></p><p><a id="adv_get_collections" class="btn fd-btn" href="">Get collections</a></p><p><a id="adv_get_products" class="btn fd-btn" href="">Get 250 products</a></p></div>',
y='<option value="">'+n.select_or_create_metafield+"</option>",J='<div class="vbox fadein"><fieldset><select>'+y+'</select><input id="mv_namespace" placeholder="namespace" /><input id="mv_key" placeholder="key" /><input id="mv_value" placeholder="value" /></fieldset><span class="mybuttons"><a class="save btn btn-slim" href="#">'+n.save+'</a> <a class="btn btn-slim saveinteger" href="#">'+n.save+' as Integer</a> <a title="'+n["delete"]+'" class="delete ico ico-16 ico-delete hidden" href="#">'+n["delete"]+
"</a></span></div>",aa='<div class="vbox-single-card next-card"><div class="next-card__section"><h2 class="next-heading--quarter-margin">Variant Metafields</h2><div id="vrow" class="single-variant">'+J+"</div></div></div>",ba='<li><a id="aboutapp" href="#">'+n.about_shopifyfd+'</a></li><li><a id="bulkmetafields" href="#" class="tooltip tooltip-bottom"><span class="tooltip-container"><span class="tooltip-label">Experimental feature - has limitations</span></span>Bulk Metafields</a></li><li class="view-json-endpoint hidden"><a class="view-json-endpoint-link" href="#" target="_blank">View JSON</a></li><li><a href="//freakdesign-us.s3.amazonaws.com/shopify/shopifyFD/freakdesign-shopifyfd-for-shopify-guide.pdf" target="_blank" class="tooltip tooltip-bottom"><span class="tooltip-container"><span class="tooltip-label">Open the help PDF in new window</span></span>Help</a></li><li class="animated delay bounce support-development"><a href="http://shopifyfd.com/#install" target="_blank" class="tooltip tooltip-bottom"><span class="tooltip-container"><span class="tooltip-label">Your support is appreciated.</span></span>Use this free tool? Tip me! ($)</a></li>',
ca='<p class="warning">This section makes bulk changes to your product metafields. If something goes wrong it may adversely effect all product metafields. There is no undo.</p><table><tr><td>Namespace</td><td><input id="bulk_namespace" placeholder="Namespace" type="text" /></td></tr><tr><td>Key</td><td><input id="bulk_key" placeholder="Key" type="text" /></td></tr><tr><td>Value</td><td><input id="bulk_value" type="text" placeholder="value" /></td></tr><tr><td colspan="2"><p><strong>Note:</strong> Any existing metafield with the same namespace and key will be overwritten.</p></td></tr><tr><td><a class="btn create">'+
n.save+'</a> <a class="btn createint">Save Integer</a></td><td><span style="display:none"><a class="btn delete">Delete</a> <input type="text" style="width:50%" placeholder="Type delete" /></span></td></tr><tr><td colspan="2"><textarea class="debug" placeholder="Data Output (future use only)"></textarea></td></tr></table>',K=function(a){"undefined"===typeof a&&(a=[location.protocol,"//",location.host,location.pathname].join(""));var b=a.split("/");a=b[b.length-2];b=b.pop();return[a,b,location.search.substring(1)]},
B=function(a){return a.replace(/[\\]/g,"\\\\").replace(/[\"]/g,'\\"').replace(/[\/]/g,"\\/").replace(/[\b]/g,"\\b").replace(/[\f]/g,"\\f").replace(/[\n]/g,"\\n").replace(/[\r]/g,"\\r").replace(/[\t]/g,"\\t")},q=function(a){if("undefined"!==typeof a&&"function"===typeof Turbolinks)try{Turbolinks.visit(a)}catch(b){return!1}},L=function(a,b){return a.getAttribute("value")?b.getAttribute("value")?a.innerHTML>b.innerHTML?1:-1:1:-1},f=function(a,b){"function"===typeof Shopify.Flash.error&&"function"===
typeof Shopify.Flash.notice&&(b?Shopify.Flash.error(a):Shopify.Flash.notice(a))},g=function(a,b){if("undefined"===typeof b)return l[a];l[a]=b},da=function(){"undefined"===typeof l.data.themeId&&$.ajax({type:"GET",url:"/admin/themes.json",success:function(a){if(a){l.data.themes=a.themes;for(var b=0,d=a.themes.length;b<d;b++)"main"===a.themes[b].role&&(l.data.themeId=a.themes[b].id)}}})},fa=function(){if(0<$("#shopifyJSbar").length)return!1;var a=$("<div />",{id:"shopifyJSbar","class":"loading noprint fadein"}),
b=$("<div>",{"class":"wrapper clearfix"}),d=$("<ul>",{id:"shopifyJSnav"});d.html(ba).find("a").on("click",function(a){if(!l.cache.content.classList.contains("loading")){a=$(this).prop("id");if("bulkmetafields"===a)return ea(),!1;if("aboutapp"===a)return u(!0,'<p>ShopifyFD is "honor-ware", which means that we trust each other to be nice. As the developer of it, I\'m committed to keep the tool something that\'s actually useful. By releasing new features and correcting possible bugs on a constant basis I can do just that, but I need your support. If you use it and intend to keep it, please sponsor its development by making a small <a target="_blank" href="http://shopifyfd.com/">contribution</a>.</p><p>You can track changes by keeping an eye on the project page or following me on <a target="_blank" href="https://twitter.com/freakdesign">twitter</a>.</p><p><h4 style="margin-top:1em">Resources and links</h4><ul><li><a href="http://freakdesign.com.au/pages/shopifyfd" target="_blank">Project home page</a></li><li><a href="http://goo.gl/OsFK2d" target="_blank">Feature Request</a></li><li><a href="http://bit.ly/shopifyFD_forum" target="_blank">Shopify forum post</a></li></ul></p>',
n.about_shopifyfd,!0),!1}});b.append(d);a.append(b);$("body").append(a);a.removeClass("loading")},M=function(a,b){if("undefined"===typeof a||!a)return!1;var d=$("iframe:first").contents().find("#tinymce:first");if(!d.length)return!1;d=d.html();d={metafield:{namespace:"backups",key:a,value:d,value_type:"string"}};if("undefined"!==typeof b){if(0>window.location.href.indexOf("/admin/products/")||!$("#autosave").hasClass("active"))return!1;$("#autosave").addClass("is-loading").removeClass("active");d.metafield.namespace=
"autosave";d.metafield.key="html"}var c=[location.protocol,"//",location.host,location.pathname,"/metafields.json"].join("");"articles"===g("alpha")&&(c="/admin/articles/"+a+"/metafields.json");$.ajax({type:"POST",url:c,dataType:"json",data:d,success:function(a){r();"undefined"===typeof b?f("Backup saved"):$("#autosave").removeClass("is-loading").addClass("active")},error:function(a){a=JSON.parse(a.responseText);f(a.errors.value[0],!0)}});return!0},C=function(a,b,d){if("undefined"===typeof a||"undefined"===
typeof b)return!1;$.ajax({type:"POST",url:"/admin/products/"+g("products")[b].id+"/metafields.json",dataType:"json",data:a,success:function(c){d&&(c=d.val(),d.val(c+b+": "+g("products")[b].id+": ok\n"));b+1<g("products").length?C(a,b+1,d):("products"==g("alpha")&&r(),f("Bulk changes done!"))}})},z=function(a,b){"undefined"===typeof b&&(b=[location.protocol,"//",location.host,location.pathname].join(""));var d="/metafields.json",c=K(b),e=c[0],c=c[1];"undefined"===typeof a||isNaN(a)||(d="/metafields/"+
a+".json");return"general"===c?"/admin"+d:b=[location.protocol,"//",location.host,"/admin/",e,"/",c,d].join("")},ea=function(){var a=$(ca),b=a.find("a.create"),d=a.find("a.createint"),c=a.find("#bulk_namespace"),e=a.find("#bulk_key"),h=a.find("#bulk_value"),m=a.find("textarea.debug"),p=function(){return 1<c.val().length&&1<e.val().length&&1<h.val().length?!0:!1};b.off("click").on("click",function(){if(p){var a={metafield:{namespace:c.val(),key:e.val(),value:h.val(),value_type:"string"}};C(a,0,m)}else f("No empty fields allowed")});
d.off("click").on("click",function(){if(p)if(isNaN(h.val()))f("Value not an integer",!0);else{m.val(g("products"));var a={metafield:{namespace:c.val(),key:e.val(),value:h.val(),value_type:"integer"}};C(a,0,m)}else f("No empty fields allowed",!0)});$.ajax({type:"GET",url:"/admin/products.json?limit=250&fields=id,title",dataType:"json",success:function(b){b.products&&(b.products.length?(g("products",b.products),u(!0,a,"Bulk Metafield editing (for "+b.products.length+" products)",!0)):f("No products found",
!0))},error:function(a){f("Error getting products",!0)}})},t=function(a,b){var d=z()+"?limit=250",c=$("body");l.cache.fullscreenMetafield=$(".metafield-fullscreen-btn");if(l.cache.fullscreenMetafield.length)l.cache.fullscreenMetafield.on("click",function(){c.hasClass("fullscreen-metafield")?c.removeClass("fullscreen-metafield"):c.addClass("fullscreen-metafield")});$.getJSON(d,function(b){var d="",c=g("datalistNamespace")||["global","test","theme"],p=g("datalistKey")||[];if(b=b.metafields){g("m",b);
g("hasbackup",!1);$("#restorebackup").hide();"products"!==g("alpha")&&"collections"!==g("alpha")&&"pages"!==g("alpha")||ga();var k=$("#metacount");k.text(b.length).removeClass("hide");0===b.length&&k.addClass("hide");for(var k=0,v=b.length;k<v;k++)d+='<option data-type="'+b[k].value_type+'" data-id="'+b[k].id+'">'+b[k].namespace+"."+b[k].key+"</option>",l.metafields[b[k].id]={namespace:b[k].namespace,value:b[k].value,key:b[k].key},"backups"==b[k].namespace&&!1===g("hasbackup")&&($("#restorebackup").show(),
g("hasbackup",!0),N()),"seo"===b[k].namespace&&"hidden"===b[k].key&&1===b[k].value&&D(b[k].id),c.push(b[k].namespace),p.push(b[k].key);c=E(c);p=E(p);g("datalistNamespace",c);g("datalistKey",p);d='<select id="metafieldselect" class="ssb">'+y+d+"</select>"}else d='<select id="metafieldselect" class="ssb">'+y+"</select>";a.html(d).append(Z);for(k=0;k<c.length;k++)d=$("<option />",{value:c[k]}),$("#fd-dl-namespace").append(d);for(k=0;k<p.length;k++)d=$("<option />",{value:p[k]}),$("#fd-dl-key").append(d);
$("#advanced_meta_features").off("click").on("click",function(){$("#advanced_meta").eq(0).toggleClass("hide");return!1});$("#adv_clear_cache").off("click").on("click",function(){$("#advanced_meta").find("select").remove().end().find("a").show();g("products",!1);g("collections",!1);return!1});$("#adv_get_products").off("click").on("click",function(){var a=$(this),b=function(b){for(var d="",c=$("<select />").change(function(){var a=$(this);$("#metafield_value").val(a.val())}).html('<option value="">Add product handle as value</option>'),
e=0,h=b.products.length;e<h;e++)d+='<option value="'+b.products[e].handle+'">'+b.products[e].title+"</option>";c.append(d);a.after(c).hide()};if(g("products")){var d=g("products");b(d)}else $.ajax({type:"GET",url:"/admin/products.json?limit=250",dataType:"json",success:function(a){a.products.length&&(g("products",a),b(a))},fail:function(){f("Failed to load products",!0)}});return!1});$("#adv_get_collections").off("click").on("click",function(){var a=$(this),b=function(b){for(var d="",c=$("<select />",
{}).change(function(){var a=$(this);$("#metafield_value").val(a.val())}).html('<option value="">Add collection handle as value</option>'),e=0,h=b.collections.length;e<h;e++)d+='<option value="'+b.collections[e].handle+'">'+b.collections[e].title+"</option>";c.append(d);a.after(c).hide()};if(g("collections")){var d=g("collections");b(d)}else $.ajax({type:"GET",url:"/admin/collections.json?limit=250",dataType:"json",success:function(a){a.collections.length&&(g("collections",a),b(a))},error:function(){f("Failed to load collections",
!0)}});return!1});$("#metafieldselect").change(function(){var a=$(this).find(":selected");if(a.attr("data-id")){var b=l.metafields[a.attr("data-id")];$(".metafield-next-label").text(n.edit_metafield);$("#metafield_namespace").val(b.namespace).prop("disabled",!0);$("#metafield_key").val(b.key).prop("disabled",!0);$("#metafield_value").val(b.value);$("#metafield_id").val(a.attr("data-id"));$("#shopifyjs_deletemetafield").removeClass("hide")}else Q()});$("#shopifyjs_deletemetafield").on("click",function(a){a.preventDefault();
a=$("#metafield_id").val()||!1;if(!a)return f("Object ID Missing",!0),!1;a=z(a);-1<a.indexOf("?show_all_images")||-1<a.indexOf("products.json")||$.ajax({type:"DELETE",url:a,success:function(a){f(n.metafield_deleted);r()},error:function(a){f("Failed to delete",!0)}})});$(".metafield-content a.savemymeta").off("click").on("click",function(){var a="string";$(this).hasClass("int")&&(a="integer");var b=$("#metafield_namespace").val(),d=$("#metafield_key").val(),c=$("#metafield_value").val(),e=$("#metafield_id").val(),
b={metafield:{namespace:b,key:d,value:c,value_type:a}},a={metafield:{id:e,value:c,value_type:a}};5<e.length?(e=z(e),$.ajax({type:"PUT",url:e,dataType:"json",data:a,success:function(a){r();w(a);f("Metafield updated")}})):(e=z(),$.ajax({type:"POST",url:e,dataType:"json",data:b,success:function(a){r();f("Metafield saved")},error:function(a){a=JSON.parse(a.responseText);var b="";a.errors.namespace&&(b+="Namespace "+B(a.errors.namespace[0])+". ");a.errors.key&&(b+="Key "+B(a.errors.key[0])+". ");a.errors.value&&
(b+="Value "+B(a.errors.value[0])+". ");f("Metafield failed to save: "+b,!0)}}));return!1})})},ha=function(){var a=$("iframe:first").contents().find("#tinymce:first");if(!a.length)return!1;var b=["href","target","class","src"];a.find("*").each(function(a,c){for(a=c.attributes.length-1;0<=a;a--)0>b.indexOf(c.attributes[a].name)&&c.removeAttribute(c.attributes[a].name)})},Q=function(){$(".metafield-next-label").text(n.add_new_metafield);$("#metafield_namespace").val("").prop("disabled",!1);$("#metafield_key").val("").prop("disabled",
!1);$("#metafield_value").val("");$("#metafield_id").val("");$("#shopifyjs_deletemetafield").addClass("hide")},G=function(a){var b=document.getElementsByClassName("view-json-endpoint");if(b.length){var d=document.getElementsByClassName("view-json-endpoint-link");"undefined"!==typeof a?(b[0].classList.remove("hidden"),d[0].href=["//",location.host,location.pathname].join("")+".json"):(b[0].classList.add("hidden"),d[0].href="")}},ja=function(){if(function(){var a=document.createElement("div");return"draggable"in
a||"ondragstart"in a&&"ondrop"in a}()){w("has dnd");var a=document.documentElement;a.ondragover=function(){this.className="dragit";return!1};a.ondragleave=function(){this.className="";return!1};a.ondragend=function(){this.className="";return!1};a.ondrop=function(a){a.preventDefault&&a.preventDefault();var d=a.dataTransfer.files,c=d.length,e=0,h=new FileReader,m={};h.onload=function(a){w("load");a=a.target.result.split(",")[1];m[e]={name:d[e].name,data:a};e++;e<c?(f("Reading file ["+(e+1)+"] contents..."),
h.readAsDataURL(d[e])):ia(m)};c&&(document.documentElement.className="dragit",f("Reading file ["+(e+1)+"] contents..."),h.readAsDataURL(d[e]));return!1}}},ia=function(a){var b=l.data.themeId;if(!b||isNaN(b))return f("Theme ID not found",!0),!1;var d=Object.keys(a).length,c=0;"themes"==g("alpha")&&(b=g("omega"));"settings"!=g("omega")||isNaN(g("alpha"))||(b=g("alpha"));var e=function(){$.ajax({type:"PUT",url:"/admin/themes/"+b+"/assets.json",data:{asset:{key:"assets/"+a[c].name,attachment:a[c].data}},
success:function(){f(a[c].name+" uploaded ("+(c+1)+"/"+d+")");c++;c<d&&e()},error:function(){f("File upload failed",!0)}})};e()},R=function(a,b,d){if("undefined"===typeof a)return!1;f("Updating Variant "+(b+1)+"/"+a.length+"...");"undefined"===typeof b&&(b=0);"undefined"===typeof d&&(d=!1);$.ajax({type:"PUT",url:"/admin/variants/"+a[b].variant.id,dataType:"json",data:a[b],success:function(c){++b;b<a.length?R(a,b,d):(f("Variants updated"),"function"===typeof d&&d())},error:function(){f("Update failed",
!0)}})},S=function(a,b,d,c,e,h){h="undefined"!==typeof h?"integer":"string";var m="post",g="/admin/variants/"+a+"/metafields.json";b={metafield:{namespace:b,key:d,value:c,value_type:h}};if(e.length){if(isNaN(e))return!1;b={metafield:{id:e,value:c,value_type:h}};g="/admin/variants/"+a+"/metafields/"+e+".json";m="put"}$.ajax({type:m,url:g,data:b,success:function(b){w(b);x(a);f("Metafield saved")},error:function(b){x(a);f("Error Saving",!0)}})},ka=function(a,b){var d="/admin/variants/"+a+"/metafields/"+
b+".json";if(-1<d.indexOf("?")||-1<d.indexOf("products.json"))return!1;$.ajax({type:"DELETE",url:d,success:function(b){w(b);x(a);f(n.metafield_deleted)},error:function(b){x(a);f("Failed to delete",!0)}})},x=function(a){if("undefined"===typeof a||isNaN(a)||!a)return f("Could not find ID",!0),!1;$("#mv_namespace").val("").prop("disabled",!1);$("#mv_key").val("").prop("disabled",!1);$("#mv_value").val("");g("current_vid","");var b=function(a){return'<option class="meta" value="'+a.id+'">'+a.namespace+
"."+a.key+"</option>"};$.ajax({type:"GET",url:"/admin/variants/"+a+"/metafields.json",success:function(d){$("#vrow option.meta").remove();if(d=d.metafields)g("vm",d),d.length?$("#vrow select").addClass("active"):$("#vrow select").removeClass("active");for(var c=0,e=d.length;c<e;c++)$("#vrow select").append(b(d[c]));$("#vrow .save").off("click").on("click",function(){g("current_vid")||g("current_vid","");S(a,$("#mv_namespace").val(),$("#mv_key").val(),$("#mv_value").val(),g("current_vid"));return!1});
$("#vrow .saveinteger").off("click").on("click",function(){g("current_vid")||g("current_vid","");S(a,$("#mv_namespace").val(),$("#mv_key").val(),$("#mv_value").val(),g("current_vid"),!0);return!1});$("#vrow .delete").addClass("hidden").off("click").on("click",function(){ka(a,g("current_vid"));return!1});$("#vrow select").eq(0).off("change").change(function(){var a=$(this).val();g("current_vid",a);w(g("vm"));if(a.length){$("#mv_namespace").prop("disabled",!0);$("#mv_key").prop("disabled",!0);$("#vrow .delete").removeClass("hidden");
a:{for(var b,d=0,c=g("vm").length;d<c;d++)if(b=g("vm")[d],parseInt(b.id)==parseInt(a)){a=b;break a}a=!1}a&&($("#mv_namespace").val(a.namespace),$("#mv_key").val(a.key),$("#mv_value").val(a.value))}else $("#mv_namespace").val("").prop("disabled",!1),$("#mv_key").val("").prop("disabled",!1),$("#mv_value").val(""),$("#vrow .delete").addClass("hidden")});$("#vrow .mybuttons").fadeIn()},error:function(a){f("Error grabbing metafields",!0)}});window.dispatchEvent(new Event("resize"))},la=function(){$("td.vid input").on("change",
function(){var a=$(this);a.val(a.attr("data-val"))}).on("click",function(){$(this).select()});var a=$(".edit-variant-metafield");a.on("click",function(b){b.preventDefault();var d=$(this);$("#vrow").remove();if(d.hasClass("active"))d.removeClass("active");else{a.removeClass("active");d.addClass("active");b=d.attr("data-val");g("currentvrow",b);$("tr.variant.active").removeClass("active");var d=d.parent().parent().parent(),c=d.find("td").length+1;d.addClass("active").after('<tr id="vrow"><td colspan="'+
c+'">'+J+"</td></tr>");x(b)}})},ma=function(a){if("product"!==a||null!==document.getElementById("removealltags"))return!0;a=$("ul.js-tag-list").eq(0).parent();a.length?(a.append('<a style="margin-top:.75em" id="removealltags" href="#" class="fd-btn btn delete">Remove all tags</a>'),$("#removealltags").on("click",function(a){a.preventDefault();$("ul.next-token-list").eq(0).find("a").click()})):f("ShopifyFD error : btn_removealltags : target html not found",!0)},w=function(a){g("debug")&&console.log(a)},
u=function(a,b,d,c){w("fdmodal");var e=$("#fdmodal");if(a){e.length&&e.remove();a=$('<div id="fdmodal" class="modalWindow"><div class="main content"><header></header></div></div>');d&&a.find("header").html("<h2>"+d+"</h2>");b&&(b=$("<div/>",{}).append(b),a.find("div.main.content").append(b));if(c)c=$('<a href="#" class="close-modal">×</a>'),c.on("click",function(){u(!1);return!1}),a.find("header").prepend(c).end().fadeIn();else a.fadeIn().on("click",function(){u(!1)});$("body").append(a)}else e.off("click").remove()},
na=function(){var a=$(".header .header__secondary-actions:first");if(!a.length)return f("ShopifyFD error : setup_discounts : target html not found",!0),!1;var b=$("<ul/>",{"class":"segmented",id:"discount_buttons"}),d=$("<li/>"),c=$("<a/>",{"class":"btn btn-separate disabled",href:"#"}).html("Bulk create").on("click",function(a){a.preventDefault()});d.append(c);b.append(d);a.prepend(b)},oa=function(){var a=$(".ui-layout__section--secondary .ui-layout__item:last"),b=$(".header .header__secondary-actions:first");
b.length||(b=$(".header .header__primary-actions:first"));if(a.length){var d=$('<div class="ui-layout__item"><div class="next-card"></div></div>');d.find(".next-card").append('<div class="next-card-metafield next-card next-card--aside fadein"><section class="next-card__section"><h3 class="next-heading">Metafields <svg class="next-icon next-icon--size-16 metafield-fullscreen-btn"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#next-website"></use></svg><span id="metacount" class="hide">0</span></h3><div class="metafield-content content"><i class="ico ico-20 ico-20-loading"></i></div></section></div>');
a.after(d);a=$("div.metafield-content");t(a)}else f("ShopifyFD error : setup_articles : Metafield target HTML not found",!0);if(b.length){var a=$("<ul/>",{"class":"segmented",id:"copy-object"}),d=$("<li/>"),c=$("<a/>",{"class":"fd-btn btn btn-separate",href:"#"}).html("Duplicate").on("click",function(a){a.preventDefault();$(this);$.getJSON(["//",location.host,location.pathname].join("")+".json",function(a){$.ajax({type:"POST",url:"/admin/blogs/"+a.article.blog_id+"/articles.json",dataType:"json",
data:{article:{author:a.article.author,blog_id:a.article.blog_id,body_html:a.article.body_html,summary_html:a.article.summary_html,tags:a.article.tags,template_suffix:a.article.template_suffix,title:a.article.title+" [copy]",published:!1}},success:function(a){q("/admin/blogs/"+a.article.blog_id+"/articles/"+a.article.id)},error:function(a){f("Error saving",!0)}})})});d.append(c);a.append(d);b.prepend(a)}else f("ShopifyFD error : setup_articles : Header button missing",!0);0===$("#rte_extra").length&&
($("#article-content_iframecontainer").eq(0).after('<div class="sst" id="rte_extra"><a class="btn fd-btn tooltip delete tooltip-bottom" id="clearformatting" href="#"><span class="tooltip-container"><span class="tooltip-label">Will remove all HTML on click</span></span>Purge html</a> <a class="btn fd-btn tooltip tooltip-bottom" id="clear-html-attributes" href="#"><span class="tooltip-container"><span class="tooltip-label">Removes HTML attributes except for <br>target,class,href & src</span></span>Clean HTML</a> <a class="btn fd-btn tooltip tooltip-bottom" id="createbackup" href="#"><span class="tooltip-container"><span class="tooltip-label">Save contents as metafield</span></span>Create Backup</a> <a class="btn fd-btn" style="display:none;" id="restorebackup" href="#">Restore Backup</a> <a class="btn fd-btn tooltip tooltip-bottom" id="save_images_to_meta" href="#"><span class="tooltip-container"><span class="tooltip-label">Add image paths to a metafield</span></span>Images to Metafields</a></div>'),
A())},N=function(){$("#restorebackup").show().on("click",function(a){a.preventDefault();a:{g("omega");a=$("iframe").contents().find("#tinymce").eq(0);var b=g("m");if(b)for(var d=0,c=b.length;d<c;d++){if("backups"===b[d].namespace){a.html(b[d].value);f("Backup restored");break a}}else f("Error, nothing to restore",!0)}})},A=function(){var a=$("#restorebackup");a.length&&(g("hasbackup")?N():a.hide());$("#clearformatting").on("click",function(a){a.preventDefault();a=$("iframe:first").contents().find("#tinymce:first");
if(a.length){var d=document.createElement("div");d.innerHTML=a.html();a.text(d.textContent||d.innerText||"")}});$("#clear-html-attributes").on("click",function(a){a.preventDefault();ha()});$("#createbackup").on("click",function(a){a.preventDefault();M(g("omega"))});$("#save_images_to_meta").on("click",function(a){a.preventDefault();pa()})},pa=function(){var a=$("iframe:first").contents().find("#tinymce:first").find("img");if(a&&a.length){var b="";a.each(function(d){var c=$(this).prop("src").replace(/https:/i,
"");b+=c;d<a.length-1&&(b+=",")});var d={metafield:{namespace:"helpers",key:"images",value:b,value_type:"string"}},c=[location.protocol,"//",location.host,location.pathname,"/metafields.json"].join("");"articles"===g("alpha")&&(c="/admin/articles/"+g("omega")+"/metafields.json");$.ajax({type:"POST",url:c,dataType:"json",data:d,success:function(a){r();f("Images saved to metafield")},error:function(a){f("Error saving",!0)}})}else f("No images found",!0)},E=function(a){a=a.concat();for(var b=0;b<a.length;++b)for(var d=
b+1;d<a.length;++d)a[b]===a[d]&&a.splice(d--,1);return a},T=function(){if(!document.getElementsByClassName("sku-count-cell").length){var a=$("div.header-row:first");if(!a.length)return!1;var b=$("<div />",{"class":"row s-none sku-count-cell"});$.ajax({type:"GET",url:"/admin/settings/general.json",dataType:"json",success:function(d){var c=!1;try{g("shop_settings",d.shop_settings),c=d.shop_settings.total_skus,b.html(e)}catch(f){}if(c){var e;e='<div class="box notice header-notice has-ico"><i class="ico next-icon--16 next-icon--notice-blue in-gutter"></i>You are using %1 skus</div>'.replace("%1",
c);b.html(e);a.after(b)}}})}},qa=function(){T();var a=$(".header .header__secondary-actions:first");a.length||(a=$(".header .header__primary-actions:first"));if(!a.length)return f("Error : setup_products_list : html not found",!0),!1;$("#showsku").length&&$("#showsku").remove();var b=$("<ul/>",{"class":"segmented",id:"showsku"}),d=$("<li/>"),c=$("<a/>",{"class":"btn fd-btn",href:"/",title:"Show SKU and Variant IDs"}).html("Show SKUs & ID").on("click",function(a){a.preventDefault();var b=[],d=$("#all-products td.name a[href]");
d.each(function(){b.push($(this).attr("href").split(/[/]+/).pop())});if(b.length){var c=$(this);c.addClass("is-loading disabled");var k=function(a,b){$.ajax({type:"GET",url:"/admin/products/"+a[b]+".json?fields=variants",dataType:"json",success:function(e){var h=e.product.variants[0].sku;e=e.product.variants[0].id;var O="";if(h||e)h&&(O='<span title="SKU" class="sku label badge badge--small badge--left-margin animated fadein">'+h+"</span>"),d.eq(b).before(O+'<span title="VariantID" class="variant-label badge badge--small badge--left-margin animated fadein">'+
e+"</span>");b+1<a.length?k(a,b+1):(f("SKUs and Variant IDs Loaded"),c.removeClass("is-loading").text("Data Loaded"))}})};f("Loading SKUs and Variant IDs, please wait...");k(b,0)}});d.append(c);b.append(d);a.append(b)},U=function(){if("undefined"===typeof l.data.themes)$.ajax({type:"GET",url:"/admin/themes.json",success:function(a){if(a){l.data.themes=a.themes;for(var b=0,d=a.themes.length;b<d;b++)"main"===a.themes[b].role&&(l.data.themeId=a.themes[b].id);U()}}});else{var a=function(a){if("undefined"===
typeof l.data.themes||"undefined"===typeof a)return!1;a=parseInt(a);for(var b=l.data.themes.length-1;0<=b;b--)if(l.data.themes[b].id===a)return l.data.themes[b]},b=$(".published-theme-title");$(".unpublished-theme-title");for(var d=$("div.unpublished-box"),c=[],e=0;e<d.length;e++){var h=d[e].id.split("_").pop();c.push(h);var m=d.eq(e).find(".unpublished-theme-title"),g=a(h),k="";g&&(k+="<br>Created at: "+(new Date(g.created_at)).toString(),k+="<br>Updated at: "+(new Date(g.updated_at)).toString());
m.after('<div style="font-size:90%;opacity:.5" class="theme-data" data-id="'+h+'">Theme ID: '+h+k+"</div>")}b.length&&(d=$(".published-theme .btn-primary").eq(0).attr("href"),"undefined"!==typeof d&&-1<d.indexOf("/admin/themes")&&(h=d.split("/")[3],c.push(h),g=a(h),k="",g&&(k+="<br>Created at: "+(new Date(g.created_at)).toString(),k+="<br>Updated at: "+(new Date(g.updated_at)).toString()),b.after('<div style="font-size:90%;opacity:.5" class="theme-data" data-id="'+h+'">Theme ID: '+h+k+"</div>")));
2>c.length||(a=$(".header .header__secondary-actions:first"),a.length&&(b=$("<a />",{"class":"btn fd-btn"}).text("Export all themes").on("click",function(a){a.preventDefault();for(a=0;a<c.length;a++)$.ajax({type:"POST",data:{_method:"post"},url:"/admin/themes/"+c[a]+"/export"});f(c.length+" export request"+(1<c.length?"s":"")+" sent. Check your inbox")}),a.append(b)))}},ra=function(){var a=$(".header .header__primary-actions:first");if(!a.length)return!1;$.ajax({type:"GET",url:"/admin/link_lists.json",
dataType:"json",success:function(b){if(b){b=b.link_lists;for(var d="",c=0,e=b.length;c<e;c++)g("omega")!==b[c].id.toString()&&(d+='<option value="'+b[c].id+'">'+b[c].title+"</option>");b=$("<select />",{"class":"header-select fadein"}).append("<option>Edit other Menu</option>",d).change(function(){var a=$(this).val();a&&q("/admin/link_lists/"+a)});a.prepend(b)}},error:function(a){f("Error loading linklist data",!0)}})},V=function(){var a=$(".next-card__section .next-grid__cell--no-flex"),b=function(){$.ajax({type:"GET",
url:"/admin/collections.json?limit=250",dataType:"json",success:function(a){for(var b=$.param({utf8:"\u2713","link_list[handle]":"all-collections","link_list[title]":"All Collections"}),d=[],c=0,f=a.collections.length;c<f;++c){d.push({position:c+1,title:a.collections[c].title,link_type:"collection",subject_id:a.collections[c].id});var h={};h["link_list[links][][position]"]=c+1;h["link_list[links][][title]"]=a.collections[c].title;h["link_list[links][][link_type]"]="collection";h["link_list[links][][subject_id]"]=
a.collections[c].id;b+="&"+$.param(h)}e(b)},error:function(){f("Error! Are you sure you have access to collections?",!0)}});return!1},d=function(){$.ajax({type:"GET",url:"/admin/pages.json?limit=250",dataType:"json",success:function(a){for(var b=$.param({utf8:"\u2713","link_list[handle]":"all-pages","link_list[title]":"All Pages"}),c=[],d=0,f=a.pages.length;d<f;++d){c.push({position:d+1,title:a.pages[d].title,link_type:"page",subject_id:a.pages[d].id});var h={};h["link_list[links][][position]"]=d+
1;h["link_list[links][][title]"]=a.pages[d].title;h["link_list[links][][link_type]"]="page";h["link_list[links][][subject_id]"]=a.pages[d].id;b+="&"+$.param(h)}e(b)},error:function(){f("Error! Are you sure you have access to pages?",!0)}});return!1},c=function(){$.ajax({type:"GET",url:"/admin/products/vendors.json",dataType:"json",success:function(a){for(var b=$.param({utf8:"\u2713","link_list[handle]":"all-vendors","link_list[title]":"All Vendors"}),d=[],c=0,h=a.vendors.length;c<h;++c){var f={position:c+
1,title:a.vendors[c],link_type:"http",subject:"/collections/vendors?q="+encodeURIComponent(a.vendors[c].toLowerCase()).replace(/%20/g,"+")},m={};m["link_list[links][][position]"]=c+1;m["link_list[links][][title]"]=a.vendors[c];m["link_list[links][][link_type]"]="http";m["link_list[links][][subject]"]="/collections/vendors?q="+encodeURIComponent(a.vendors[c].toLowerCase()).replace(/%20/g,"+");b+="&"+$.param(m);d.push(f)}e(b)}})},e=function(a){"undefined"!==typeof a&&$.ajax({type:"POST",url:"/admin/link_lists",
data:a,success:function(a,b,c){(b=c.getResponseHeader("X-XHR-Redirected-To"))?(linklistID=b.split("/").pop(),isNaN(linklistID)?f("Error creating linklist - ID not returned",!0):(f("Link list added"),q("/admin/link_lists/"+linklistID))):(linklistID=$(a).find("form").eq(0).attr("action").split("/").pop(),isNaN(linklistID)||(f("Link list added"),q("/admin/link_lists/"+linklistID)))},error:function(){f("Error creating linklist",!0)}})},h=$("<a/>",{href:"#","class":"tooltip-bottom tooltip",style:"margin-right:1.5em"}).html('<span class="tooltip-container"><span class="tooltip-label">Make a copy of this linklist</span></span>Duplicate').on("click",
function(a){a.preventDefault();var b=$(this);a=b.parent().find('a[href^="/admin/link_lists"]').eq(0);a.length?(b.addClass("btn is-loading no-btn"),href=a.attr("href").split("/").pop(),isNaN(href)||$.ajax({type:"GET",url:"/admin/link_lists/"+href,success:function(a){var b=$(a).find("#edit_link_list_"+href);b.length&&(b.find('input[name="_method"]').remove(),b.find('input[name="authenticity_token"]').remove(),a=b.find('input[name="link_list[title]"]'),a.val(a.val()+" [COPY]"),b.find('select[name="link_list[links][][link_type]"]').each(function(a){var c=
$(this).val();"collection"===c?(a=b.find('div[context="collectionPicker'+a+'"]').eq(0),c=a.attr("define").split(","),"undefined"!==typeof c[2]&&(c=parseInt(c[2].replace(/\D/g,"")),a.after('<input name="link_list[links][][subject_id]" value="'+c+'" />'))):"page"===c?(a=b.find('div[context="pagePicker'+a+'"]').eq(0),c=a.attr("define").split(","),"undefined"!==typeof c[2]&&(c=parseInt(c[2].replace(/\D/g,"")),a.after('<input name="link_list[links][][subject_id]" value="'+c+'" />'))):"product"===c&&(a=
b.find('div[context="productPicker'+a+'"]').eq(0),c=a.attr("define").split(","),"undefined"!==typeof c[2]&&(c=parseInt(c[2].replace(/\D/g,"")),a.after('<input name="link_list[links][][subject_id]" value="'+c+'" />')))}),e(b.serialize()))},error:function(a,c,d){b.removeClass("btn is-loading no-btn");f(d,!0)}})):f("Can not copy this linklist. ID was not found",!0)}),m=$("<a />",{href:"#","class":"tooltip-bottom tooltip",style:"margin-right:1.5em"}).html('<span class="tooltip-container"><span class="tooltip-label">Delete Linklist on click</span></span><i class="ico ico-14-svg ico-delete"></i>').on("click",
function(a){a.preventDefault();var b=$(this);a=b.parent().find('a[href^="/admin/link_lists"]').eq(0);a.length&&(b.addClass("btn is-loading no-btn"),href=a.attr("href").split("/").pop(),isNaN(href)||$.ajax({type:"POST",url:"/admin/link_lists/"+href,data:{utf8:"\u2713",_method:"delete"},success:function(a){b.removeClass("btn is-loading no-btn").closest(".next-grid__cell.next-grid__cell--half").addClass("disable").css({opacity:".2","pointer-events":"none"})}}))});1<a.length?(a.prepend(m,h),$.ajax({type:"GET",
url:"/admin/link_lists.json",dataType:"json",success:function(b){b&&(g("link_lists",b),a.each(function(a){$(this).parent().find("h3").append('<span class="fadein" style="color:#ccc;display: block;font-size: 11px;font-family: monospace;">'+b.link_lists[a].handle+"</span>")}))}})):a.prepend(h);var h=$(".ui-annotated-section__description").eq(0),m=$("<a/>",{"class":"btn tooltip-bottom tooltip fd-btn sst",href:"#"}).html('<span class="tooltip-container"><span class="tooltip-label">Create a menu with every collection</span></span>Create Collections menu').on("click",
function(){$(this).addClass("is-loading disabled");b();return!1}),p=$("<a/>",{"class":"btn tooltip-bottom tooltip fd-btn sst",href:"#"}).html('<span class="tooltip-container"><span class="tooltip-label">Create a menu with every page</span></span>Create Pages menu').on("click",function(){$(this).addClass("is-loading disabled");d();return!1}),k=$("<a/>",{"class":"btn tooltip-bottom tooltip fd-btn sst",href:"#"}).html('<span class="tooltip-container"><span class="tooltip-label">Create a menu with all vendors</span></span>Create Vendor menu').on("click",
function(){$(this).addClass("is-loading disabled");c();return!1});h.length&&h.append("<br>",m,"<br>",p,"<br>",k);h=$('.ui-annotated-section__description a[href="/admin/link_lists/new"]');if(h.length&&(m=$("#link_lists .next-grid--no-outside-padding a:last-child"),m.length)){var v="";2<m.length&&(m.each(function(){var a=$(this),b=a.parent().parent().find("h3").text(),a=a.attr("href");b.length&&a.length&&(v+='<option value="'+a+'">'+b+"</option>")}),v.length&&(m=$("<select />",{style:"width: 100%"}).on("change",
function(){var a=$(this).val();a.length&&q(a)}).html('<option value="">Select Menu</option>'+v),p=$("<div />",{"class":"sst"}),p.append('<label class="next-label">Select a menu to quickly edit.</label>',m),h.after(p)))}},H=function(a){if("undefined"!==typeof a&&a.length){var b=a[0];if("object"===typeof b){var d=$('textarea[name="bulk-redirect-log"]'),c=d.val();$.ajax({type:"POST",url:"/admin/redirects.json",dataType:"json",data:b,success:function(b){c+=b.redirect.path+", "+b.redirect.target+", success\n";
d.val(c);a.shift();0<a.length?H(a):f("Bulk redirection additions complete")},error:function(e){c+=b.redirect.path+", "+b.redirect.target+", "+e.responseJSON.errors.path[0]+"\n";d.val(c);a.shift();0<a.length?H(a):f("Bulk redirection additions complete")}})}}},sa=function(){if(!document.getElementsByClassName("bulk-redirect-panel").length){$(".header .header__secondary-actions:first");var a=$(".next-card.has-bulk-actions");a.length||(a=$("#url_redirects"));if(!a.length)return f("Could not add bulk redirect panel",
!0),!1;var b=$('<div class="bulk-redirect-panel next-grid next-grid--outer-grid" style="border-bottom: 1px solid #DADADA;margin-bottom: 1em;padding-bottom: 1em;"><div class="next-grid__cell next-grid__cell--third"><h2 class="next-heading">Bulk Redirects</h2><p>To bulk add redirects manually add the path (old url) and target (new url) separated with a comma to the input box. As with any bulk action, run a small sample first before processing 1000s of items.<br><br></p><ul><li>One redirect per line.</li><li>A log will show progress and any errors</li></ul></div><div class="next-grid__cell"><h2 class="next-heading">Paste URLs</h2><p>An example of the redirect is shown below:<br><code>http://freakdesign.com.au/old-url,http://freakdesign.com.au/new-url</code><br>or<br><code>/old-url,/pages/new-url</code></p><br><textarea name="bulk-redirect-paste"></textarea><br><br><button class="redirect-process btn fd-btn btn-primary">Add Redirects</button> <button class="redirect-reload btn fd-btn">Reload page</button><div class="fadein hide bulk-redirect-log"><br><br><h2 class="next-heading">Activity Log</h2><textarea name="bulk-redirect-log"></textarea></div></div></div>'),
d=b.find(".redirect-process"),c=b.find(".redirect-reload"),e=b.find('textarea[name="bulk-redirect-paste"]'),h=b.find('textarea[name="bulk-redirect-log"]');c.on("click",function(a){a.preventDefault();q("/admin/redirects?"+Math.floor(1E6*Math.random()))});d.on("click",function(a){a.preventDefault();a=e.val().replace(/ /g,"");if(!(4>a.length)&&(a=a.split("\n"),a.length)){for(var b=[],c=0;c<a.length;c++){var d=a[c].split(",");2===d.length&&(d[0]=d[0].trim(),d[1]=d[1].trim(),"/"!==d[1].substring(0,1)&&
"http"!==d[1].substring(0,4)&&(d[1]="/"+d[1]),b.push({redirect:{path:d[0],target:d[1]}}))}b.length&&(h.val("").parent().removeClass("hide"),H(b))}});a.prepend(b)}},ta=function(){T();G(!0);g("collections",!1);var a=$(".header .header__secondary-actions:first");a.length||(a=$(".header .header__primary-actions:first"));if(a.length){var b=$("<ul/>",{"class":"segmented",style:"margin-right: .5em"}),d=$("<li/>"),c=$("<a/>",{"class":"btn fd-btn",style:"margin-left:.5em",href:"#"}).text("Show Product Count").on("click",
function(a){a.preventDefault();$.ajax({type:"GET",url:"/admin/collections.json?limit=250",dataType:"json",success:function(a){if(a.collections.length){g("collections",a);for(var b=a.collections.length-1;0<=b;b--){var c=$("#collections-results").find('a[href="/admin/collections/'+a.collections[b].id+'"]:last');0===c.find("span").length&&c.append('<span class="sku label badge badge--small badge--left-margin">'+a.collections[b].products_count+"</span>")}}}})}),e=$("<a/>",{"class":"btn fd-btn",href:"#",
title:"Add tags to entire collection"}).html("Bulk edit tags").on("click",function(){u(!0,'<div><div class="clearfix em"><div class="half">Choose a collection</div><div class="half"><select data-action="collection"><option value="">Loading, please wait...</option></select></div></div><div class="clearfix em"><div class="half">Choose an action</div><div class="half"><select data-action="action"><option value="add">Add</option><option value="set">Set</option><option value="remove">Remove</option><option disabled value="toggle">Toggle</option><option value="purge" style="background:red;color:#fff">DELETE ALL</option></select></div></div><div class="clearfix em"><div class="half">Set the tag</div><div class="half"><input /></div></div><div class="half"><a class="btn" data-action="update_tags">Update tags</a></div><div class="half"><small>Add: Adds tags to the existing ones<br>Set: Replaces tags with new ones<br>Remove: Removes matching tags<br>Toggle: Future Use, disabled...</small></div></div>',
"Edit tags for all products in a collection",!0);var a=$("#fdmodal"),b=a.find('select[data-action="action"]'),c=a.find("a").eq(1),d=a.find('select[data-action="collection"]'),e=a.find("input").eq(0);b.change(function(a){"purge"==b.val()||"set"==b.val()?("purge"==b.val()&&e.val("").attr("disabled","disabled"),c.addClass("delete")):(e.removeAttr("disabled"),c.removeClass("delete"))});var l=function(a,b,d,e){var f=a.products[b].id,h={product:{id:f,tags:d}};c.text(b+1+"/"+a.products.length);$.ajax({type:"PUT",
url:"/admin/products/"+f+".json",data:h,dataType:"json",success:function(c){++b;b<a.products.length?l(a,b,d,e):"function"===typeof e&&e()}})},n=function(a,b,d,e){if(a.products[b].tags){var f=d.replace(/, /g,",").split(","),h=a.products[b].tags.replace(/, /g,",").split(","),h=$(h).not(f).get()+"",f=a.products[b].id,h={product:{id:f,tags:h}};c.text(b+1+"/"+a.products.length);$.ajax({type:"PUT",url:"/admin/products/"+f+".json",data:h,dataType:"json",success:function(c){++b;b<a.products.length?n(a,b,
d,e):"function"===typeof e&&e()}})}else++b,b<a.products.length?n(a,b,d,e):"function"===typeof e&&e()},P=function(a,b,d,e){var f=d.replace(/, /g,",").split(","),h=a.products[b].tags.split(","),h=E(f.concat(h))+"",f=a.products[b].id,h={product:{id:f,tags:h}};c.text(b+1+"/"+a.products.length);$.ajax({type:"PUT",url:"/admin/products/"+f+".json",data:h,dataType:"json",success:function(c){++b;b<a.products.length?P(a,b,d,e):e()}})};c.on("click",function(){d.val().length?("add"===b.val()&&e.val().length&&
$.ajax({type:"GET",url:"/admin/products.json?collection_id="+d.val()+"&fields=id,tags",dataType:"json",success:function(a){c.addClass("disabled");P(a,0,e.val(),function(){f("Done. Tags have been added");c.text("Update tags").removeClass("disabled")})}}),"purge"!==b.val()&&"set"!==b.val()||$.ajax({type:"GET",url:"/admin/products.json?collection_id="+d.val()+"&fields=id",dataType:"json",success:function(a){c.addClass("disabled");l(a,0,e.val(),function(){f("Done.");c.text("Update tags").removeClass("disabled")})}}),
"remove"===b.val()&&$.ajax({type:"GET",url:"/admin/products.json?collection_id="+d.val()+"&fields=id,tags",dataType:"json",success:function(a){c.addClass("disabled");n(a,0,e.val(),function(){f("Matched tags have been removed.");c.text("Update tags").removeClass("disabled")})}})):f("Choose a collection",!0);return!1});b.hide();$.ajax({type:"GET",url:"/admin/collections.json?limit=250",dataType:"json",success:function(a){if(a.collections.length){g("collections",a);for(var c="",e=0,f=a.collections.length;e<
f;e++)c+='<option value="'+a.collections[e].id+'">'+a.collections[e].title+"</option>";d.append(c).find("option:eq(0)").text("Select a collection");b.show()}}});return!1});d.append(e,c);b.append(d);a.prepend(b)}else f("ShopifyFD error : setup_collections : target html not found")},ga=function(){var a;try{a="localStorage"in window&&null!==window.localStorage}catch(c){a=!1}if(a){a=$('<div class="metafield-copy-paste sst"><a class="fd-btn btn btn-slim" id="fd_copymetafields">Copy All Metafields</a> <a class="fd-btn btn btn-slim" id="fd_pastemetafields">Paste Metafields</a> <a class="btn btn-slim tooltip tooltip-bottom" href="#" id="fd_whatmetafields"><span class="tooltip-container"><span class="tooltip-label">View what is in the clipboard</span></span>?</a></div>');
var b=a.find("#fd_pastemetafields"),d=a.find("#fd_whatmetafields");a.find("#fd_copymetafields").on("click",function(a){a.preventDefault();"undefined"!==typeof g("m")?0<g("m").length?(localStorage.metafieldCopy=JSON.stringify(g("m")),f(g("m").length+" Metafields copied"),b.show(),d.show()):f("No metafields to copy",!0):(b.hide(),d.hide())});d.on("click",function(a){a.preventDefault();if("undefined"!==typeof localStorage.metafieldCopy){a="";var b=!1;try{b=JSON.parse(localStorage.metafieldCopy)}catch(d){return!1}if(b){for(var f=
0,g=b.length;f<g;f++){var p=b[f].value,k=document.createElement("div");k.innerHTML=p;a+="<p><strong>"+b[f].namespace+"."+b[f].key+" ("+b[f].value_type+")</strong><br>"+(k.textContent||k.innerText)+"</p><hr>"}u(!0,a,"In the virtual clipboard...")}}});b.on("click",function(a){a.preventDefault();"undefined"!==typeof localStorage.metafieldCopy?(a=JSON.parse(localStorage.metafieldCopy),a.length?(g("m-copy",a),W(g("m-copy"),0)):f("Nothing to paste",!0)):f("Nothing to paste",!0)});"undefined"===typeof localStorage.metafieldCopy&&
(b.hide(),d.hide());$(".metafield-content").after(a)}},W=function(a,b){if("undefined"===typeof a||"undefined"===typeof b)return!1;f("Pasting metafields...");var d={metafield:{namespace:a[b].namespace,key:a[b].key,value:a[b].value,value_type:a[b].value_type}};$.ajax({type:"POST",url:[location.protocol,"//",location.host,location.pathname,"/metafields.json"].join(""),dataType:"json",data:d,success:function(c){b+1<a.length?W(a,++b):(r(),f("All metafields pasted!"))}})},ua=function(a,b){if("undefined"===
typeof a||isNaN(a))return!1;$.ajax({type:"PUT",url:"/admin/products/"+a+".json",dataType:"json",data:{product:{id:a,images:[""]}},success:function(a){$("#product-images").parent().remove();f("Images deleted. Reload product to check...")}})},va=function(){clearInterval(g("autosave"));G(!0);if(!document.getElementsByClassName("next-card-metafield").length){var a=$(".next-grid__cell--third:first");a.length?(a.prepend('<div class="next-card-metafield next-card next-card--aside fadein"><section class="next-card__section"><h3 class="next-heading">Metafields <svg class="next-icon next-icon--size-16 metafield-fullscreen-btn"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#next-website"></use></svg><span id="metacount" class="hide">0</span></h3><div class="metafield-content content"><i class="ico ico-20 ico-20-loading"></i></div></section></div>'),
a=$("div.metafield-content"),t(a)):f("ShopifyFD error : setup_products : Metafield target HTML not found",!0)}var b=$(".header .header__secondary-actions:first");b.length||(b=$(".header .header__primary-actions:first"));b.length&&!document.getElementsByClassName("product-switcher").length&&$.ajax({type:"GET",url:"/admin/products.json?limit=250&fields=id,title",dataType:"json",success:function(a){if(a){a=a.products;var c="",d=a.length;if(250<d)return!0;for(var e=0;e<d;e++)g("omega")!==a[e].id.toString()&&
(c+='<option value="'+a[e].id+'">'+a[e].title+"</option>");a=$("<select />",{"class":"product-switcher header-select fadein"}).append("<option>Edit other Product</option>",c).change(function(){var a=$(this).val();a&&q("/admin/products/"+a)});a.find("option").sort(L).appendTo(a);b.prepend(a)}},error:function(a){f("Error loading linklist data",!0)}});a=$("#js-collections");if(a.length){var d=a.find(".list-of-added-collections a");if(d.length){var c=$("<a />",{"class":"btn fd-btn delete"}).text("Remove from all").on("click",
function(a){a.preventDefault();d.trigger("click")});a.append(c)}}if(!document.getElementsByClassName("additional-product-actions").length){var a=$("#product-outer-variants"),c=$('<div class="additional-product-actions next-card"><div class="next-card"><div class="next-card__header"><div class="wrappable"><div class="wrappable__item"><h2 class="next-heading">Additional actions</h2></div></div></div><section class="next-card__section additional-product-content"></section></div>'),e=c.find(".additional-product-content");
if(!document.getElementsByClassName("remove-all-images").length){var h=$("<a />",{"class":"btn delete tooltip tooltip-bottom"}).html('Remove all images<span class="tooltip-container"><span class="tooltip-label">Instant, and no undo</span></span>').on("click",function(a){a.preventDefault();$(this);a=window.location.pathname.split("/").pop();ua(a)});e.append(h)}a.after(c)}document.getElementsByClassName("seo-hide-button").length||(a=$(".next-card.visibility .next-card__section:first"),a.length&&(c=
$("<a />",{"class":"btn fd-btn seo-hide-button"}).text(n.hide_from_sitemap).on("click",function(a){a.preventDefault();(a=$(this).attr("data-id"))?$.ajax({type:"DELETE",url:["//",location.host,location.pathname].join("")+"/metafields/"+a+".json",success:function(a){r()},error:function(a){f("Failed to delete",!0)}}):$.ajax({type:"POST",url:["//",location.host,location.pathname].join("")+"/metafields.json",dataType:"json",data:{metafield:{namespace:"seo",key:"hidden",value:1,value_type:"integer"}},success:function(a){r()},
error:function(){f("Failed to save metafield",!0)}})}),a.append('<p style="margin:1em 0">Add metafield to remove this product from the sitemap. It is <b>very</b> important that you <a href="http://docs.shopify.com/api/unlinked/hide-from-search-engines-and-sitemaps" target="_blank">understand</a> what doing this means. If you don\'t, leave it alone.</p>',c)));null===document.getElementById("rte_extra")&&($("#product-description_iframecontainer").eq(0).after('<div class="sst" id="rte_extra"><a class="btn fd-btn tooltip delete tooltip-bottom" id="clearformatting" href="#"><span class="tooltip-container"><span class="tooltip-label">Will remove all HTML on click</span></span>Purge html</a> <a class="btn fd-btn tooltip tooltip-bottom" id="clear-html-attributes" href="#"><span class="tooltip-container"><span class="tooltip-label">Removes HTML attributes except for <br>target,class,href & src</span></span>Clean HTML</a> <a class="btn fd-btn tooltip tooltip-bottom" id="createbackup" href="#"><span class="tooltip-container"><span class="tooltip-label">Save contents as metafield</span></span>Create Backup</a> <a class="btn fd-btn" style="display:none;" id="restorebackup" href="#">Restore Backup</a> <a class="btn fd-btn tooltip tooltip-bottom" id="save_images_to_meta" href="#"><span class="tooltip-container"><span class="tooltip-label">Add image paths to a metafield</span></span>Images to Metafields</a></div>'),
$(".rtetools-buttons ul.segmented:last").append('<li><a id="autosave" tabindex="-1" class="btn btn-slim" href="#">Autosave</a></li>'),A(),$("#autosave").on("click",function(){var a=$(this);a.hasClass("active")?(f("Autosave disabled"),clearInterval(g("autosave")),a.removeClass("active")):(f("Autosave enabled"),a.addClass("active"),g("autosave",setInterval(function(){-1<window.location.href.indexOf("/admin/products/")?M(g("omega"),!0)||clearInterval(g("autosave")):clearInterval(g("autosave"))},3E4)));
return!1}));ma("product");var a=$("#product-outer-variants"),m=m||{};if(!document.getElementsByClassName("bulk-variants-section").length)if(a.length){var p=$("<div />",{"class":"next-card__section fadein hide bulk-variants-section",style:"background: #F5F6F7;"}),k=$("<a />",{"class":"btn fd-btn btn-slim",style:"margin-left:1em;margin-top: -3px;"}).text("Bulk Edits").on("click",function(a){a.preventDefault();p.toggleClass("hide")});p.html('<h2>Edit all variants</h2><p style="margin: .5em 0 1em;font-size: 12px;border-bottom: 1px solid #ccc;padding-bottom: .5em;">Bulk Editing comes with risks. Proceed with caution.</p><label style="margin-top:1.5em">Set Compare at Price<br><small>0 will clear the compare at price</small></label><input type="number" style="width:50%" value="0"> <a class="bulk-compare-save tooltip tooltip-bottom btn fd-btn"><span class="tooltip-container"><span class="tooltip-label">Save Compare at Price for all variants</span></span>Save</a>');
var c=p.find("a.bulk-compare-save"),v=p.find("input");c.on("click",function(a){a.preventDefault();var b=$(this);b.addClass("is-loading").attr("style","margin-left:1em;text-indent: -9999px;");a=function(){b.removeClass("is-loading").attr("style","margin-left:1em")};var c=v.val();if(isNaN(c)||"0"===c||""===c)c=null;if((c||null===c)&&"object"===typeof m)if(1<Object.keys(m).length)if(Object.keys(m).length===$("tr.variant").length){var d=[],e;for(e in m){var h=m[e],g;for(g in h)h.hasOwnProperty(g)&&d.push({variant:{id:h[g],
compare_at_price:c}})}d.length&&R(d,0,a)}else f("Unexpected variant found.",!0);else f("You only have 1 variant. No need to bulk edit",!0)});a.append(p)}else f("ShopifyFD error : setup_products : Inventory target HTML not found",!0);if(!document.getElementsByClassName("edit-variant-metafield").length)if(c=$("#product-inner-variants th:last-child"),c.length){c.before('<th class="variants-table__heading--indent-right tr">ID</th>');c=$("th.tc:first");c.length&&"Inventory"===c.text()&&c.text("#").prop("title",
"Quantity");var l=$("tr.variant");l.each(function(a){var b=l.eq(a).find("td:last a:first").prop("href").split("/").pop(),c=$("input#variant_ids_"+b),d=$("<a />",{"class":"edit-variant-metafield",style:"margin-left:3px","data-val":b}).html('<span><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" width="16" height="16" viewBox="0 0 12 12" enable-background="new 0 0 12 12" xml:space="preserve"><path fill="currentColor" d="M0 0v12h12V0H0zM11 11H1V1h10V11zM5 9h2V7h2V5H7V3H5v2H3v2h2V9z"></path></svg></span>');
m["variant_"+a]={id:b};c.after(d);a='<td class="vid new-variants-table__cell"><input class="mock-edit-on-hover tr" data-action="selectall" data-val="'+b+'" type="text" value="'+b+'" /></td>';$(this).find("td:last-child").before(a)}).promise().done(function(){la();window.dispatchEvent(new Event("resize"))})}else document.getElementsByClassName("vbox-single-card").length||null==document.getElementById("product_variant_id")||(c=document.getElementById("product_variant_id").value,$("#product-outer-variants").after(aa),
x(c));document.getElementsByClassName("set-preferred-collection").length||(c=$("ul.product-collections-list"),c.length&&c.find("li").each(function(){var a=$(this),b=a.find("a").eq(0).attr("href").split("/").pop(),c=$("<a/>",{"class":"tooltip tooltip-bottom set-preferred-collection",href:"#"}).html('<span class="next-icon next-icon--10" style="background:#21C2A8;left: -.5em;"></span><span class="tooltip-container"><span class="tooltip-label">Set a metafield with this collection handle</span></span>').on("click",
function(a){a.preventDefault();"undefined"!==b&&$.ajax({type:"GET",url:"/admin/collections/"+b+".json?fields=handle",dataType:"json",success:function(a){"undefined"!==typeof a&&(a=a.collection.handle,$.ajax({type:"POST",url:["//",location.host,location.pathname].join("")+"/metafields.json",dataType:"json",data:{metafield:{namespace:"collection",key:"preferred",value:a,value_type:"string"}},success:function(a){r();f("Preferred collection metafield saved")},error:function(a){a=JSON.parse(a.responseText);
f(a.errors.value[0],!0)}}))},error:function(){f("Failed to load collection",!0)}})});a.find("div.next-grid:first").prepend(c)}));if(!document.getElementsByClassName("edit-selected-weights").length&&(c=$("div.bulk-actions").eq(0),c.length)){var F=$("<a/>",{href:"#","class":"btn fd-btn btn-slim hide edit-selected-weights",style:"padding-left:.5em"}).text("Edit selected weights").on("click",function(){u(!0,'<label>New weight (grams)</label><input class="half" min="0" type="number" data-action="update-variant-weight" /><a data-action="update-variant-weight" href="#" class="btn btn-slim">Save</a><br><br><small>Note: You may need to reload this page before Shopify will show the new weight in the dashboard.</small>',
"Edit weight",!0);var a=$('a[data-action="update-variant-weight"]'),b=$('input[data-action="update-variant-weight"]');if(a.length&&b.length)a.on("click",function(){var c=$('tr.variant input[type="checkbox"]:checked');if(c.length&&!isNaN(b.val())){var d=[];c.each(function(){var a=$(this).val();isNaN(a)||d.push(parseInt(a))});var e=function(c,d){$.ajax({type:"PUT",url:"/admin/variants/"+d[c],dataType:"json",data:{variant:{id:d[0],grams:b.val()}},success:function(b){++c;c<d.length?e(c,d):(f("Weight updated"),
a.removeClass("is-loading").text(n.save))}})};a.addClass("is-loading").text("");e(0,d)}else f("Did you set a weight?",!0);return!1});return!1});c.append(F);$('tr.variant input[type="checkbox"]').on("change",function(){1<$('tr.variant input[type="checkbox"]:checked').length?F.removeClass("hide"):F.addClass("hide")})}a.length&&"object"===typeof m&&1<Object.keys(m).length&&a.find("header a.btn--plain:last").after(k)},wa=function(){var a=$(".ui-layout__section--secondary .ui-layout__item:last");if(a.length){a.find("a").eq(0).clone(!0);
var b=$('<div class="ui-layout__item"><div class="next-card"></div></div>');b.find(".next-card").append('<div class="next-card-metafield next-card next-card--aside fadein"><section class="next-card__section"><h3 class="next-heading">Metafields <svg class="next-icon next-icon--size-16 metafield-fullscreen-btn"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#next-website"></use></svg><span id="metacount" class="hide">0</span></h3><div class="metafield-content content"><i class="ico ico-20 ico-20-loading"></i></div></section></div>');
a.after(b);t($("div.metafield-content"))}else f("ShopifyFD error : setup_pages : Metafield target HTML not found",!0);0===$("#rte_extra").length&&($("#page-content_iframecontainer").eq(0).after('<div class="sst" id="rte_extra"><a class="btn fd-btn tooltip delete tooltip-bottom" id="clearformatting" href="#"><span class="tooltip-container"><span class="tooltip-label">Will remove all HTML on click</span></span>Purge html</a> <a class="btn fd-btn tooltip tooltip-bottom" id="clear-html-attributes" href="#"><span class="tooltip-container"><span class="tooltip-label">Removes HTML attributes except for <br>target,class,href & src</span></span>Clean HTML</a> <a class="btn fd-btn tooltip tooltip-bottom" id="createbackup" href="#"><span class="tooltip-container"><span class="tooltip-label">Save contents as metafield</span></span>Create Backup</a> <a class="btn fd-btn" style="display:none;" id="restorebackup" href="#">Restore Backup</a> <a class="btn fd-btn tooltip tooltip-bottom" id="save_images_to_meta" href="#"><span class="tooltip-container"><span class="tooltip-label">Add image paths to a metafield</span></span>Images to Metafields</a></div>'),
A());var d=$(".header .header__secondary-actions:first");d.length||(d=$(".header .header__primary-actions:first"));d.length?$.ajax({type:"GET",url:"/admin/pages.json?limit=250&fields=id,title",dataType:"json",success:function(a){if(a){pages=a.pages;a="";for(var b=0,f=pages.length;b<f;b++)g("omega")!==pages[b].id.toString()&&(a+='<option value="'+pages[b].id+'">'+pages[b].title+"</option>");a=$("<select />",{id:"shopifyjs_llselect","class":"header-select fadein"}).append("<option>Edit other Page</option>",
a).change(function(){var a=$(this).val();a&&q("/admin/pages/"+a)});a.find("option").sort(L).appendTo(a);d.prepend(a)}},error:function(a){f("Error loading page data",!0)}}):f("ShopifyFD error : setup_pages : Page switcher target HTML not found",!0)},X=function(a){if("undefined"===typeof a.urls)return!1;f("Copying rates ("+a.urls.length+")");var b=a.urls[0];if(0>b.indexOf("price_based")&&0>b.indexOf("weight_based"))return"function"===typeof a.callback&&a.callback(d,a.urls),!1;var d={};-1<b.indexOf("price_based")?
d.shippingType="price_based":d.shippingType="weight_based";$.ajax({url:b,success:function(b){b=$(b);d.shippingRateName=b.find("#shipping_rate_name").val();d.shippingRatePrice=b.find("#shipping_rate_price").val();"price_based"===d.shippingType?(d.shippingRateMinOrder=b.find("#shipping_rate_min_order_subtotal").val(),d.shippingRateMaxOrder=b.find("#shipping_rate_max_order_subtotal").val()):(d.shippingRateWeightLow=b.find("#shipping_rate_weight_low").val(),d.shippingRateWeightHigh=b.find("#shipping_rate_weight_high").val());
"function"===typeof a.callback&&a.callback(d,a.urls)}})},Y=function(a){"undefined"!==typeof a&&(f("Delete zone ("+a.length+")"),$.ajax({type:"POST",url:"/admin/settings/shipping_zones/"+a[0],data:{utf8:"\u2713",_method:"delete"},success:function(b){$('a[href="/admin/settings/shipping_zones/'+a[0]+'"]').parents(".zone-shipping-rate").addClass("disabled").css({opacity:".3"});a.shift();a.length?Y(a):($(".delete-zones").removeClass("is-loading"),f("Zones deleted. "+n.reload_page))},error:function(a){$(".delete-zones").removeClass("is-loading");
f("Error deleting rates. "+n.reload_page,!0)}}))},I=function(a,b){f("Pasting rates ("+a.length+")");var d=a[0],c={utf8:"\u2713","":[d.shippingType],shipping_rate:{type:d.shippingType,new_type:d.shippingType,display_type:d.shippingType,name:d.shippingRateName,price:d.shippingRatePrice}},e="",h="";if("weight_based"===d.shippingType)c.shipping_rate.weight_low=d.shippingRateWeightLow,c.shipping_rate.weight_high=d.shippingRateWeightHigh,h=d.shippingRateWeightLow||"0",e=d.shippingRateWeightHigh||"and up";
else if("price_based"===d.shippingType)c.shipping_rate.min_order_subtotal=d.shippingRateMinOrder,c.shipping_rate.max_order_subtotal=d.shippingRateMaxOrder,h=d.shippingRateMinOrder||"0",e=d.shippingRateMaxOrder||"and up";else return;var g=function(){f("Pasting complete. "+n.reload_page);$(".paste-zones").removeClass("disabled is-loading")},p='<div class="table-wrapper table-wrapper--scrollable" style="opacity:.5"><table class="table--zone-rates next-table--no-outside-padding"><thead><tr><td>'+d.shippingRateName+
"</td><td></td></tr></thead><tbody><tr><td>"+h+" - "+e+'</td><td class="type--right">'+d.shippingRatePrice+"</td></tr></tbody></table></div>";$.ajax({type:"POST",dataType:"html",url:"/admin/shipping_rates/"+b,data:c,success:function(d){$('a[href="/admin/settings/shipping_zones/'+b+'"]').parents(".zone-shipping-rate").find(".zone-shipping-rates").append(p);a.shift();a.length?I(a,b):g()},error:function(d){f("Error when pasting a rate",!0);a.shift();a.length?I(a,b):g()}})},xa=function(){if(!$(".zone-shipping-rate").length)return!1;
var a=$(".zone-shipping-rate > div").not(".zone-shipping-rates").find("a").parent(),b=$("<a />",{"class":"btn fd-btn delete delete-zones",href:"#"}).text("Delete all zones").on("click",function(a){a.preventDefault();$(this).addClass("is-loading disabled");a=$(".zone-shipping-rate > div").find('a[href^="/admin/settings/shipping_zones/"]');if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d].href.split("/").pop());Y(b)}}),d=$("<a />",{"class":"btn btn--plain disabled paste-zones",style:"border:none",
href:"#"}).text("Paste").on("click",function(a){a.preventDefault();var b=$(this),d=function(){b.removeClass("is-loading");$(".paste-zones").removeClass("disabled")};b.addClass("is-loading");$(".paste-zones").addClass("disabled");a=b.parent().find("a").eq(2)[0].href.split("/").pop();isNaN(a)?(f("Paste failed. ID did not match format expected.",!0),d()):"object"===!typeof g("copiedZones")?d():(d=Object.create(g("copiedZones")),I(d,a))}),c=$("<a />",{"class":"btn btn--plain copy-zones",style:"border:none",
href:"#"}).text("Copy").on("click",function(a){a.preventDefault();var b=$(this);$(".paste-zones").addClass("disabled");a=b.parents(".zone-shipping-rate").eq(0).find(".zone-shipping-rates a");if(a.length){var d=[];a.each(function(){d.push($(this)[0].href)});b.addClass("is-loading");a=b.next("a")[0].href.split("/").pop();if(isNaN(a))f("Copy failed. ID did not match format expected.",!0);else{X({urls:d,callback:function(a,b){k(a,b)}});var c=[],k=function(a,d){a&&c.push(a);1<d.length?(d.shift(),X({urls:d,
callback:function(a,b){k(a,b)}})):(b.removeClass("is-loading"),$(".paste-zones").removeClass("disabled"),f(c.length+" Rates Copied"))};g("copiedZones",c)}}});a.prepend(d,c);$("#settings-shipping > .ui-annotated-section:eq(1) .ui-annotated-section__description").append("<p>The delete function below will immediately attempt to remove all zones and rates. There is no undo.</p>",b)},ya=function(){var a=$(".ui-layout__section--secondary .ui-layout__item:last"),b=$(".header .header__secondary-actions:first");
b.length||(b=$(".header .header__primary-actions:first"));a.length?(a.prepend('<div class="next-card-metafield next-card next-card--aside fadein"><section class="next-card__section"><h3 class="next-heading">Metafields <svg class="next-icon next-icon--size-16 metafield-fullscreen-btn"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#next-website"></use></svg><span id="metacount" class="hide">0</span></h3><div class="metafield-content content"><i class="ico ico-20 ico-20-loading"></i></div></section></div>'),
a=$("div.metafield-content"),t(a),0===$("#rte_extra").length&&($("#collection-description_iframecontainer").eq(0).after('<div class="sst" id="rte_extra"><a class="btn fd-btn tooltip delete tooltip-bottom" id="clearformatting" href="#"><span class="tooltip-container"><span class="tooltip-label">Will remove all HTML on click</span></span>Purge html</a> <a class="btn fd-btn tooltip tooltip-bottom" id="clear-html-attributes" href="#"><span class="tooltip-container"><span class="tooltip-label">Removes HTML attributes except for <br>target,class,href & src</span></span>Clean HTML</a> <a class="btn fd-btn tooltip tooltip-bottom" id="createbackup" href="#"><span class="tooltip-container"><span class="tooltip-label">Save contents as metafield</span></span>Create Backup</a> <a class="btn fd-btn" style="display:none;" id="restorebackup" href="#">Restore Backup</a> <a class="btn fd-btn tooltip tooltip-bottom" id="save_images_to_meta" href="#"><span class="tooltip-container"><span class="tooltip-label">Add image paths to a metafield</span></span>Images to Metafields</a></div>'),
A())):f("ShopifyFD error : setup_custom_collections : target html not found",!0);if(b.length){var a=$("<ul/>",{"class":"segmented",id:"copy-object"}),d=$("<li/>"),c=$("<a/>",{"class":"fd-btn btn btn-separate",href:"#"}).html("Duplicate").on("click",function(a){a.preventDefault();$(this).addClass("disabled is-loading");$.getJSON(["//",location.host,location.pathname].join("")+".json",function(a){delete a.collection.disjunctive;delete a.collection.handle;delete a.collection.id;delete a.collection.products_count;
delete a.collection.published_at;delete a.collection.published_scope;delete a.collection.updated_at;a.collection.published=!1;a.collection.title+=" [copy]";var b={},d="/admin/custom_collections.json",c=a.collection.collection_type;delete a.collection.collection_type;"smart"===c?(b.smart_collection=a.collection,d="/admin/smart_collections.json"):b.custom_collection=a.collection;if("smart"===c)$.ajax({type:"POST",url:d,contentType:"application/json;charset=utf-8",data:JSON.stringify(b),success:function(a){try{var b=
a[Object.keys(a)[0]].id;"undefined"!==b&&q("/admin/collections/"+b)}catch(d){}},error:function(){f("Error duplicating.",!0)}});else{var e=0,g=window.location.pathname.split("/").pop(),l=function(a,c,e,g){"undefined"!==typeof a&&"undefined"!==typeof c&&("undefined"===typeof e&&(e=1),"undefined"===typeof g&&(g=[]),f("Duplicating collection, please wait..."),$.ajax({type:"GET",url:"/admin/collects.json?limit=250&fields=product_id&page="+e+"&collection_id="+a,success:function(h){g=g.concat(h.collects);
250*e>c?(b.custom_collection.collects=g,$.ajax({type:"POST",url:d,contentType:"application/json;charset=utf-8",data:JSON.stringify(b),success:function(a){try{var b=a[Object.keys(a)[0]].id;"undefined"!==b&&q("/admin/collections/"+b)}catch(d){}},error:function(){f("Error duplicating.",!0)}})):l(a,c,++e,g)}}))};(function(){$.ajax({type:"GET",url:"/admin/collects/count.json?collection_id="+g,success:function(a){e=a.count;0<e&&l(g,e,1)}})})()}})});d.append(c);a.append(d);b.prepend(a)}else f("ShopifyFD error : setup_articles : Header button missing",
!0)},za=function(){var a=$(".header .header__primary-actions:first > div");if(a.length){var b=$("<ul/>",{"class":"segmented",id:"get_all_images"}),d=$("<li/>"),c=$("<a/>",{"class":"btn",href:"#",style:"margin-left:1em"}).html("Download file list").on("click",function(){var a=$(this);(function(){var b=[];a.addClass("is-loading").attr("style","margin-left:1em;text-indent: -9999px;");var d=function(c){"undefined"===typeof c&&(c="/admin/settings/files");$.ajax({url:c,success:function(c){c=$(c);for(var g=
c.find(".next-input.next-input--readonly"),l=0;l<g.length;l++)b.push(g[l].value);c=c.find("#assets-table").next(".next-card__section").find("a:last");c=c.length?c[0].href:"";-1<c.indexOf("direction=next")?d(c):(a.removeClass("is-loading").removeAttr("style"),b.length?(c="files-list-"+Math.floor(Date.now()/1E3)+".txt","undefined"===typeof c&&(c="blob-"+Math.floor(Date.now()/1E3)+".txt"),g=document.createElement("a"),document.body.appendChild(g),g.style="display: none",l=new Blob(["\ufeff",b],{type:"text/plain"}),
l=window.URL.createObjectURL(l),g.href=l,g.download=c,g.click(),window.URL.revokeObjectURL(l)):f("No files exist. Nothing to list.",!0))}})};d()})();return!1});d.append(c);b.append(d);a.prepend(b)}},Aa=function(){var a=$(".ui-layout__section--secondary .ui-layout__item:last");if(a.length){var b=$('<div class="ui-layout__item"><div class="next-card"></div></div>');b.find(".next-card").append('<div class="next-card-metafield next-card next-card--aside fadein"><section class="next-card__section"><h3 class="next-heading">Metafields <svg class="next-icon next-icon--size-16 metafield-fullscreen-btn"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#next-website"></use></svg><span id="metacount" class="hide">0</span></h3><div class="metafield-content content"><i class="ico ico-20 ico-20-loading"></i></div></section></div>');
a.after(b);b=$("div.metafield-content");t(b)}else f("ShopifyFD error : setup_single_order : target html not found",!0);b=$(".customer-email:last");if(b.length){var d=$("<input />",{value:b.text(),readonly:"readonly","class":"noprint",style:"margin:1em 0"}).on("click",function(){$(this).select()});b.parent().parent().after(d)}a=$(".header .header__secondary-actions:first");a.length&&"undefined"!==typeof _user_id&&(b=$('.header .header__secondary-actions a.next-list__item[target="_blank"]:first'),b.length&&
-1<b[0].href.indexOf("/checkouts/")?$("<a />",{"class":"btn fd-btn",href:b[0].href,target:"_blank"}).text("Order Status Page").appendTo(a):(b=parseInt(window.location.href.split("/").pop()),$.ajax({type:"GET",url:"/admin/orders/"+b+".json",success:function(b){b.order.checkout_token&&$("<a />",{"class":"btn fd-btn",href:"https://checkout.shopify.com/"+_user_id+"/checkouts/"+b.order.checkout_token+"/thank_you",target:"_blank"}).text("Order Status Page").appendTo(a)}})))},Ba=function(){var a=$(".order.no-wrap a");
if(!a.length)return!1;var b=!1;a.append('<div class="bubble hide fadein"><div class="bubble-content p"><h3 class="large">Orders</h3><div class="pr"><ul class="unstyled"></ul></div></div></div>').css({position:"relative"}).hover(function(){var a=$(this);b=setTimeout(function(){var b=a.find("ul").eq(0),e=a.attr("href");$("div.bubble").addClass("hide");a.data("order")?a.find("div.bubble").removeClass("hide"):$.ajax({type:"GET",url:e+".json",success:function(e){if(e){for(var f=e.order.line_items,g=e.order.fulfillments,
k="",l=0,n=f.length;l<n;l++)k+='<li style="white-space:normal">'+f[l].quantity+" × "+f[l].name+"</li>";e.order.fulfillment_status&&g.length&&(k+='<li style="white-space:normal;border-top: 1px solid #ccc;margin-top: .5em;padding-top: .5em;">Tracking#: <b>'+g[0].tracking_number+"</b></li>");a.data("order",k);b.html(k);a.find("div.bubble").removeClass("hide")}}})},100)},function(){clearTimeout(b);$(this).find("div.bubble").addClass("hide")})},D=function(a){"undefined"!==typeof a?$(".seo-hide-button").addClass("active").attr("data-id",
a).text("Hidden in Sitemap"):$(".seo-hide-button").removeClass("active").removeAttr("data-id").text(n.hide_from_sitemap)},r=function(){var a=z();$.getJSON(a,function(a){var d="";a=a.metafields;D();if(a.length){g("m",a);$("#metacount").text(a.length).removeClass("hide");for(var c=0,e=a.length;c<e;c++)d+='<option data-type="'+a[c].value_type+'" data-id="'+a[c].id+'">'+a[c].namespace+"."+a[c].key+"</option>",l.metafields[a[c].id]={namespace:a[c].namespace,value:a[c].value,key:a[c].key},"backups"===a[c].namespace&&
$("#restorebackup").show(),"seo"===a[c].namespace&&"hidden"===a[c].key&&1===a[c].value&&D(a[c].id);d=y+d}else $("#metacount").text("0").addClass("hide"),g("m",!1),$("#restorebackup").hide(),d=y;$("#metafieldselect").html(d);Q()})};(function(){document.getElementsByTagName("html")[0].className+=" shopifyJSoverride";ja();da();var a=document.querySelectorAll('a[href="/admin/products"]');a.length&&(a[0].href="/admin/products?limit=250");a=document.querySelectorAll('a[href="'+[location.protocol,"//",location.host].join("")+
'/admin/apps"]');a.length&&(a[0].href="/admin/apps/installed");setInterval(function(){l.cache.content=document.getElementById("content");if(!l.cache.content.classList.contains("loading")){fa();var a=K(),d=!1,c=a[0],e=a[1],a=a[2];"next"===e||"prev"===e||c===g("alpha")&&e===g("omega")?"next"!==e&&"prev"!==e&&a!=l.queryString&&("products"!==c||isNaN(e)?"admin"===c&&"products"===e?d=!0:"admin"===c&&"redirects"===e&&(d=!0):d=!0):d=!0;if(d)if(l.alpha=c,l.omega=e,l.queryString=a,"customers"===c&&!isNaN(e))d=
$(".ui-layout__section--secondary .ui-layout__item:last"),d.length?(c=$('<div class="ui-layout__item"><div class="next-card"></div></div>'),c.find(".next-card").append('<div class="next-card-metafield next-card next-card--aside fadein"><section class="next-card__section"><h3 class="next-heading">Metafields <svg class="next-icon next-icon--size-16 metafield-fullscreen-btn"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#next-website"></use></svg><span id="metacount" class="hide">0</span></h3><div class="metafield-content content"><i class="ico ico-20 ico-20-loading"></i></div></section></div>'),
d.after(c),d=$("div.metafield-content"),t(d)):f("ShopifyFD error : setup_customers : target HTML not found");else if("articles"===c&&!isNaN(e))oa();else if("blogs"===c&&!isNaN(e))targetHTML=$(".ui-layout__section--secondary .ui-layout__item:last"),targetHTML.length?(targetHTML.prepend('<div class="next-card-metafield next-card next-card--aside fadein"><section class="next-card__section"><h3 class="next-heading">Metafields <svg class="next-icon next-icon--size-16 metafield-fullscreen-btn"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#next-website"></use></svg><span id="metacount" class="hide">0</span></h3><div class="metafield-content content"><i class="ico ico-20 ico-20-loading"></i></div></section></div>'),
d=$("div.metafield-content"),t(d)):f("ShopifyFD error : setup_blogs : target html not found",!0);else if("collections"===c&&!isNaN(e))ya();else if("link_lists"===c&&!isNaN(e))ra();else if("orders"===c&&!isNaN(e))Aa();else if("pages"===c&&!isNaN(e))wa();else if("products"===c&&!isNaN(e))va();else if("variants"===c&&!isNaN(e))G(!0),d=$(".next-layout__sidebar > div:first"),d.length&&(d.after('<div class="next-card-metafield next-card next-card--aside fadein"><section class="next-card__section"><h3 class="next-heading">Metafields <svg class="next-icon next-icon--size-16 metafield-fullscreen-btn"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#next-website"></use></svg><span id="metacount" class="hide">0</span></h3><div class="metafield-content content"><i class="ico ico-20 ico-20-loading"></i></div></section></div>'),
t($("div.metafield-content")));else if("admin"!==c||"apps"!==e)if("admin"!==c||"channels"!==e)if("admin"===c&&"collections"===e)ta();else if("admin"===c&&"discounts"===e)na();else if("admin"!==c||"draft_orders"!==e)if("admin"===c&&"link_lists"===e)V();else if("admin"===c&&"links"===e)V();else if("admin"===c&&"orders"===e)Ba();else if("admin"===c&&"products"===e)qa();else if("admin"===c&&"redirects"===e)sa();else if("admin"!==c||"reports"!==e)if("admin"===c&&"themes"===e)U();else if("admin"!==c||"transfers"!==
e)if("online_store"!==c||"preferences"!==e)"settings"===c&&"account"===e?$(".ui-annotated-section:last").after('<section class="ui-annotated-section"><div class="ui-annotated-section__annotation"><div class="ui-annotated-section__title"><h2 class="next-heading next-heading--no-margin">Purge / Delete all site content</h2></div><div class="ui-annotated-section__description"><p>Delete all content on the store to start fresh</p></div></div><div class="ui-annotated-section__content"><div class="next-card"><div class="next-card__section"><p>Coming soon...</p></div></div></div></section>'):
"settings"===c&&"files"===e?za():"settings"===c&&"general"===e?(d=$("#settings-general section:first"),d.length&&(c=$("<section />",{"class":"ui-annotated-section"}),e=$("<div>",{"class":"ui-annotated-section__annotation"}),a=$("<div>",{"class":"ui-annotated-section__content"}),e.html('<div class="ui-annotated-section__title"><h2 class="next-heading next-heading--no-margin">Store Metafields</h2></div><div class="ui-annotated-section__description"><p>Edit your shop level metafields here. Review the <a target="_blank" href="http://docs.shopify.com/themes/liquid-documentation/objects/metafield">Shopify documentation</a> for more info on Metafields.</p></div>'),
a.html('<div class="next-card-metafield next-card next-card--aside fadein"><section class="next-card__section"><h3 class="next-heading">Metafields <svg class="next-icon next-icon--size-16 metafield-fullscreen-btn"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#next-website"></use></svg><span id="metacount" class="hide">0</span></h3><div class="metafield-content content"><i class="ico ico-20 ico-20-loading"></i></div></section></div>'),c.append(e,a),d.after(c),d=$("div.metafield-content"),
$(".next-card-metafield").removeClass("next-card--aside"),t(d))):"settings"===c&&"shipping"===e&&xa()}},1E3);f("ShopifyFD loaded")})()}else f("Browser unsupported (classList)")})();