(function(){
var tomitProductTagger = {
productsAdded: [],
blogProducts : "",
jQuery : "",
modalTemplate : '
',
getProductGridItem : function(product){
var Current = product.price.split(" ");
if(parseInt(product.oldPrice) > parseInt(Current[1]) && !isNaN(product.oldPrice)){
return ' \
\
\
£'+product.oldPrice+' '+product.price+'
\
';
}else{
return ' \
\
\
'+ product.price +'
\
';
}
},
addCss : function(filename) {
var head = document.getElementsByTagName('head')[0];
var style = document.createElement('link');
style.href = filename;
style.type = 'text/css';
style.rel = 'stylesheet';
head.append(style);
},
addCustomCss : function(styles){
var styleSheet = document.createElement("style")
styleSheet.type = "text/css"
styleSheet.innerText = styles
document.head.appendChild(styleSheet)
},
init : function($){
var res = window.location.href.split("/");
if(res.length < 6 && (window.location.href.indexOf('products') <= 0)){
console.log("skip");
return false;
}
tomitProductTagger.addCss('https://blogproducts.checkmyapp.net/limelight.css');
$('head').append("");
tomitProductTagger.addCss('https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.min.css');
$('body').append(this.modalTemplate);
this.jQuery = $;
var tomitProductIds = [];
var tomitCollectionIds = [];
$('a[data-tomit-product-id]').each(function(r){
tomitProductIds.push($(this).data('tomit-product-id'));
});
tomitProductIds = [... new Set(tomitProductIds)];
$('a[data-tomit-collection-id]').each(function(r){
tomitCollectionIds.push($(this).data('tomit-collection-id'));
});
tomitCollectionIds = [... new Set(tomitCollectionIds)];
var url = 'https://blogproducts.checkmyapp.net/products/silvermans.myshopify.com/' + JSON.stringify(tomitProductIds) + '/' + JSON.stringify(tomitCollectionIds);
tomitProductTagger.loadJson(url).then(function(res){
tomitProductTagger.blogProducts = res;
tomitProductTagger.addToProductLinks();
});
},
loadJson : (url) => new Promise((resolve, reject) =>{
var e = url,
r = new XMLHttpRequest;
r.open("GET", e, !0), r.onload = function ()
{
if (200 === r.status)
{
var t = JSON.parse(r.responseText);
resolve(t)
}
else reject("error")
}, r.send()
}),
searchProduct : function(nameKey, myArray){
for (var i=0; i < myArray.products.length; i++) {
if(typeof(myArray.products[i].product) == 'undefined'){
continue;
}
if (nameKey == myArray.products[i].product.id) {
return myArray.products[i].product;
}
}
},
searchCollection : function(nameKey, myArray){
for (var i=0; i < myArray.collections.length; i++) {
if (nameKey == myArray.collections[i].collection.id) {
return myArray.collections[i].collection;
}
}
},
showProductPopup :function (link, e){
a = this;
var linkPos = a.jQuery(link).offset();
var currProdId = a.jQuery(link).data('tomit-product-id');
var neededPopup;
if(typeof currProdId != 'undefined') {
neededPopup = a.jQuery('body .TomITProductPopup[data-tomit-product-id="'+currProdId+'"]');
}else{
neededPopup = a.jQuery('body .TomITProductPopup[data-tomit-collection-id="'+a.jQuery(link).data('tomit-collection-id')+'"]');
}
neededPopup.css("visibility","visible");
neededPopup.css('z-index','10001');
if (a.jQuery(window).width() < 960) {
neededPopup.css("position","fixed");
neededPopup.offset({bottom:-210, left:90});
neededPopup.animate({bottom:0}, 500);
}else{
neededPopup.offset({left:linkPos.left-((neededPopup.width() /2 - a.jQuery(link).width() /2)),top:linkPos.top+20});
neededPopup.css("visibility","visible");
}
},
hideProductPopup : function (link) {
a = this;
var linkPos = a.jQuery(link).offset();
var currProdId = a.jQuery(link).data('tomit-product-id');
var neededPopup;
if(typeof currProdId != 'undefined') {
neededPopup = a.jQuery('body .TomITProductPopup[data-tomit-product-id="'+currProdId+'"]');
}else{
neededPopup = a.jQuery('body .TomITProductPopup[data-tomit-collection-id="'+a.jQuery(link).data('tomit-collection-id')+'"]');
}
if (a.jQuery(window).width() > 960) {
neededPopup.css('visibility','hidden');
neededPopup.offset({left:0,top:0});
neededPopup.css('z-index','0');
}else{
neededPopup.animate({bottom:-210}, 500, function(){
neededPopup.css('visibility','hidden');
neededPopup.css('z-index','0');
});
}
},
addClickHandler : function(link){
var main = this;
main.jQuery(link).click(function(e){
tomitProductTagger.addStat(main.jQuery(this).data('tomit-product-id'), 'view');
e.preventDefault();
e.stopPropagation();
modalWidth = '40%';
if(main.isMobile()) {
modalWidth = '90%';
}
var res = main.searchProduct(main.jQuery(this).data('tomit-product-id'), main.blogProducts);
if("£" == "JPY") {
price = parseFloat(res.price).toFixed(2);
}else{
price = parseFloat(res.price / 100).toFixed(2);
}
main.jQuery('#TomITProductTitle').html(""+res.title+"");
main.jQuery('#TomITProductPrice').html('£ ' + price);
if(parseInt(res.variants[0].oldPrice) > parseFloat(res.variants[0].price) && !isNaN(res.variants[0].oldPrice)){
oldPrice = parseFloat(res.variants[0].oldPrice).toFixed(2)
main.jQuery('#TomITProductOldPrice').html('£ ' + oldPrice);
}else{
main.jQuery('#TomITProductOldPrice').html('');
}
var StrippedString = res.description.replace(/(<([^>]+)>)/ig,"");
if(StrippedString.length > 500){
var substring = res.description.substring(0,500);
main.jQuery('#TomITProductDescription').html(substring+"...read more");
}
else{
main.jQuery('#TomITProductDescription').html(res.description);
}
variantSelector = false;
if(res.variants.length > 1)
{
variantSelector = document.createElement("select");
variantSelector.id = "tomItVariantSelector";
variantSelector.style="width:100%;margin-bottom:3px;";
for(var i = 0; i < res.variants.length;i++)
{
price = res.variants[i]. price
var opt = document.createElement('option');
opt.innerHTML = res.variants[i].title + ' - ' + price;
opt.value = res.variants[i].id;
variantSelector.appendChild(opt);
}
}
main.jQuery('#TomITProductLink').empty();
if(res.available == true){
if(variantSelector != false){
main.jQuery('#TomITProductLink').append(variantSelector);
main.jQuery('#TomITProductLink').append(document.createElement('br'));
}
main.jQuery('#TomITProductLink').append(
'\
');
}
else{
}
//Add this item to cart
main.jQuery('.tomit_add_to_cart').click(function(e){
let tomItVariantId = (main.jQuery(this).data('variantId'));
if(main.jQuery('#tomItVariantSelector').length > 0){
tomItVariantId = $('#tomItVariantSelector').val();
}
let tomItQuantity = $(this).parent().find('.tomit_quantity_atc').val();
if(tomItQuantity > 0) {
let prodData = {};
prodData.quantity = tomItQuantity;
prodData.id = tomItVariantId;
tomitProductTagger.addStat($(this).data('productId'), 'atc');
tomitProductTagger.addToCart({'items' : [prodData]});
}
});
main.jQuery('#closeModal').click(function(){
main.jQuery("#TomITProductView").dialog('close');
})
if(res.images != null){
main.jQuery('#TomITProductImageHolder').html('');
}
main.jQuery("#TomITProductView").dialog({
width: modalWidth,
modal: true,
});
main.jQuery(".ui-dialog-titlebar").hide()
});
},
addStat(prodId, type) {
a = this;
a.jQuery.get('https://blogproducts.checkmyapp.net/stat/silvermans.myshopify.com/'+prodId+'/' + type);
},
addToCart(prod) {
//stats/{customerId}/{productId}/{eventType}
//main.jQuery.get('url naar mijn server/stats/customerid/prodId/atc');
var main = this;
//Add to cart
main.jQuery.post('/cart/add.js', prod).always(function(e){
main.jQuery('.tomItAddedToCart').remove();
main.jQuery('#TomITProductLink').append('');
});
},
isMobile : function(e) {
var isMobile = false; //initiate as false
// device detection
if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
|| /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) {
isMobile = true;
}
return isMobile;
},
addHoverHandler : function(link){
var a = this;
a.jQuery(link).hover(function(e){
a.showProductPopup(this, e);
}, function(e){
a.hideProductPopup(this);
});
a.jQuery(link).on('touchstart', function(e){
a.showProductPopup(this, e);
});
a.jQuery(link).on('touchend', function(e){
a.hideProductPopup(this);
});
},
addToProductLinks : function() {
var a = this;
prods = [];
a.jQuery('a[data-tomit-collection-id]').each(function(e){
var collectionId = a.jQuery(this).data('tomit-collection-id');
var res = a.searchCollection(collectionId, a.blogProducts);
if(res) {
imageTag = "";
if(typeof(res.image) != undefined && res.image != null) {
imageTag = '';
}
a.jQuery('body').append('');
a.addHoverHandler(this);
}
});
a.productsAdded = [];
a.jQuery('a[data-tomit-product-id]').each(function(e){
var prodId = a.jQuery(this).data('tomit-product-id');
var res = a.searchProduct(prodId, a.blogProducts);
if(res) {
if(a.productsAdded.indexOf(prodId) == -1){
a.productsAdded.push(prodId);
price = String(parseFloat(res.variants[0].price).toFixed(2));
oldPrice = String(parseFloat(res.variants[0].oldPrice).toFixed(2));
imageTag = "";
if(typeof(res.images) != undefined && res.images != null) {
imageTag = '';
}
var prodTitle = res.title;
if(res.available == false) {
prodTitle = "(product not available)
" + res.title;
}
if(parseInt(oldPrice) > parseInt(price) && !isNaN(oldPrice)){
a.jQuery('body').append('');
}else{
a.jQuery('body').append('');
}
}
a.addClickHandler(this);
a.addHoverHandler(this);
}
});
}
}
var loadScript = function(url, callback){
var script = document.createElement("script");
script.type = "text/javascript";
// If the browser is Internet Explorer.
if (script.readyState){
script.onreadystatechange = function(){
if (script.readyState == "loaded" || script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
};
// For any other browser.
} else {
script.onload = function(){
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
};
if ((typeof jQuery === 'undefined') || (parseFloat(jQuery.fn.jquery) < 1.9)) {
loadScript('//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js', function(){
loadScript('//code.jquery.com/ui/1.12.1/jquery-ui.min.js', function(){
jQuery331 = jQuery.noConflict(true);
tomitProductTagger.init(jQuery331);
});
});
} else {
loadScript('//code.jquery.com/ui/1.12.1/jquery-ui.min.js', function(){
tomitProductTagger.init(jQuery);
});
}
var css = `
@media only screen and (max-width: 600px) {
.tomit_quantity_atc{
width: 100%!important;
margin-bottom: 3px;
}
.tomit_add_to_cart{
width: 100%!important;
margin-bottom: 3px;
}
}
`,
head = document.head || document.getElementsByTagName('head')[0];
if(!document.getElementById('product-tagger-information-modal-style')) {
var style = document.createElement('style');
head.appendChild(style);
style.type = 'text/css';
style.id = 'product-tagger-information-modal-style';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
var url = window.location.href.replace(window.location.search, '') + '.json';
var res = url.split("/");
var storeurl = res[2];
if(res[res.length-2] == "products"){
tomitProductTagger.loadJson(url).then(function(res){
url = "https://blogproducts.checkmyapp.net/articles/" +res.product.id;
console.log(url);
tomitProductTagger.loadJson(url).then(function(res){
if(res.length > 0){
articlesHolder = document.getElementById("tomITArticlesHolder");
if(!articlesHolder) {
console.log('no div to append to');
return false;
}
var strong = document.createElement("strong");
var text = document.createTextNode("Related Articles");
strong.appendChild(text);
articlesHolder.appendChild(strong);
var ul = document.createElement("ul");
ul.id = "TomITarticlesUL";
articlesHolder.appendChild(ul);
for (i = 0; i < res.length; i++)
{
var a = document.createElement("a");
a.href = "/blogs/" + res[i].handle;
a.target="_blank";
var li = document.createElement("li");
li.classList.add("TomITproductGridItem");
ul.appendChild(li);
li.appendChild(a)
var div = document.createElement("div");
div.classList.add("TomITProductTitle");
a.appendChild(div);
div.innerHTML = res[i].title;
var div = document.createElement("div");
div.classList.add("TomITProductImage");
a.appendChild(div);
var img = document.createElement("img");
img.src = res[i].img;
div.appendChild(img);
}
}})})
}
})();