var AdNabuselectizeControl; window.addEventListener('load', function() { do_selectize(); }) function enable_tracker(id, url, nonce) { window.open(url); window.addEventListener('focus',function () { jQuery.post('#', {enable_tracker:id, wp_nonce:nonce}); location.reload(); }) } function toggle(id,nonce) { jQuery.post('#', {toggle:id, wp_nonce: nonce}); location.reload(); } function toggle_display_div(id) { var div = document.getElementById(id); if(div.style.display == "none"){ div.style.display = "" }else{div.style.display= "none"} } var optionsList = [ {text: '{Woocommerce Product ID}'}, {text: '{Site Country}'}, {text: '{Variation ID}'}, {text: '{SKU}'}, {text: '{GTIN}'} ]; function updateItemIDs(){ var IDs = []; jQuery("#products").find("tr").each(function(){ IDs.push(this.id); }); IDs = IDs.filter(Number); if(document.getElementById("input-tags") != null){ var currentExpr = document.getElementById("input-tags").value ; } else{ return; } jQuery.ajax({ type:'POST', url:ajaxurl, dataType: "json", data: { action: 'get_merchant_centre_id', get_item_id : IDs, currentExpr : currentExpr }, success:function(data) { if(data) { for(key in data){ jQuery('#' + key + ' .predicted_item_id').html(data[key]) } } } }); }; function startEditMode() { jQuery('#editButton').hide(); jQuery('#saveItemIDExpression').show(); AdNabuselectizeControl.enable(); jQuery('#predicted_item_id_div').show(); } function do_selectize() { if(jQuery('#input-tags') == null){ return; } updateItemIDs(); var select = jQuery('#input-tags').selectize({ persist: true, delimiter: ',', duplicates: true, valueField: 'text', labelField: 'name', searchField: ['name', 'text'], options: optionsList, render: { item: function(item, escape) { return '