//v2.0
if (typeof jQuery != "undefined") {minisiteBuyPrice();} else { console.log("Please Include jQuery 1.x");}
function minisiteBuyBox(d) { return '
Buy now
Please purchase all our products from these authorized dealers only to ensure that you receive full support in Warranty and replacement matters.
'; }
function minisiteBuyPrice(){
loadCSS = function (href) { var cssLink = jQuery(""); jQuery("head").append(cssLink); };
loadCSS("https://www.garmin.com.hk/m/_c/2017/webshopbox.css");
jQuery(document).ready(function() {
var _minisite_event_title = typeof document.title!="undefined" && document.title!="" ? document.title : "event" ;
_minisite_event_title = _minisite_event_title + " | ";
var _buy_country = "hk";
var _buy_icon_url = "https://www.garmin.com.hk/";
_buy_icon_url = _buy_icon_url.replace(/\/$/,"");
var G_locale = "en_HK";
var G_exclude = ""; //"0,1,2";
var G_prices = {};
var G_currencyFormat = "";
var G_exclude = "";
var G_products = [];
var G_type = "cat";
var G_country = {
"jp" : "税别",
"vn" : "Bao gồm VAT"
}
var G_api = "https://www.garmin.com.my/_js/api_minisite-buy-data/hk/";
var G_errors = "- Data cannot be loaded. Please try again later.. :P.";
var G_currency = "HK";
jQuery(".g_products").each(function() {
var _this_sn = jQuery(this).data("sn");
if (_this_sn == "000-00000-00"){jQuery(this).remove();} else {
G_products.push(_this_sn);
jQuery(this).hide();
}
});
jQuery.ajax({
type: "GET",
url: G_api,
dataType: "jsonp",
jsonp: "callback",
jsonpCallback:"callback",
dataType: "jsonp",
data: {
gpns: G_products.toString(),
country: _buy_country,
type: G_type
},
cache: true,
success: function(data) {
var _isOK = data.status;
if (_isOK) {
// Reset/Empty Price;
jQuery('#spec .classic-price').text( jQuery('#model .premium-rose-gold-gray .price').text() );
jQuery('#spec .sports-price').text( jQuery('#model .sport-seafoam-silver .price').text() );
//get All Prices
jQuery.each(data.products, function(i, item) {
var _t = item.title;
var _g = item.gpn;
var _p = item.price;
var _pp = item.pricePromotion;
var _cry = item.currencyFormat;
// Price
if (typeof _g != "undefined" && _g ) {
if (typeof _p != "undefined" && _p) {
if (typeof _pp != "undefined" && _pp ){
G_prices[_g] = parseFloat(_pp).toLocaleString();
} else {
G_prices[_g] = parseFloat(_p).toLocaleString();
}
}
if (typeof _cry != "undefined" ) { G_currencyFormat = _cry; }
} else {
console.log("missing data : " + i);
}
})
jQuery("#device [data-nav]>*").each(function() {
var thisSn = jQuery(this).find(".pd-color-con>*.active").attr("data-sn");
var pPrice = G_currencyFormat + " " + G_prices[thisSn];
var G_suffix = '';
if ( thisSn in G_prices ){
switch (_buy_country) {
case 'jp': G_suffix = G_country.jp; break;
case 'vn': G_suffix = G_country.vn; break;
}
G_suffix = G_suffix ? " ("+G_suffix+")" : "";
jQuery(this).find('p.price').html( pPrice + G_suffix);
} else {jQuery(this).find('p.price').text("");}
})
jQuery("#device .pd-color-con>*").click(function() {
var thisSn = jQuery(this).attr("data-sn");
var pPrice = G_currencyFormat + " " + G_prices[thisSn];
var G_suffix = '';
if ( thisSn in G_prices ){
switch (_buy_country) {
case 'jp': G_suffix = G_country.jp; break;
case 'vn': G_suffix = G_country.vn; break;
}
G_suffix = G_suffix ? " ("+G_suffix+")" : "";
jQuery("#device [data-nav].active>div.active .price").html( pPrice + G_suffix);
} else {jQuery(this).parents().eq(3).find("p.price").text("");}
})
jQuery.each(data.products, function(i, item) {
var _t = item.title;
var _g = item.gpn;
var _u = item.url;
var _p = item.price;
var _pp = item.pricePromotion;
var _cry = item.currencyFormat;
// Distributors
if (typeof item.distributors!="undefined") {
if (item.distributors.length == 1) {
var _t = item.title;
var _g = item.gpn;
var _pt = item.distributors[0].title;
var _pl = item.distributors[0].link;
if (item.buy == true && item.url != "") {
var _this = jQuery(".g_products[data-sn='" + item.gpn + "']");
if (_this.length == 0) {
console.log("No set data-sn!!!")
} else {
jQuery(_this)
.show()
.css("display", "inline-block")
.attr({"href":_pl, "title": _pt, "target":"_blank"})
.on("click", function() {
ga("send","event","Minisite", " | " +_minisite_event_title + _t +" | "+ _g +" | "+ _pt + " | " + _pl);
});
}
}
}
else if (item.distributors.length > 1) {
var _t = item.title;
var _g = item.gpn;
var dealer = "";
for(var j = 0, len = item.distributors.length; j < len; j++){
var product = item.distributors[j];
var _st = product.title;
var _sl = product.link;
var _si = product.img;
var _sil = (!_si.search(/^http[s]?:\/\//)) ? _si : _buy_icon_url+_si;
dealer += '
';
}
if (item.buy == true && item.url != "") {
var _this = jQuery(".g_products[data-sn='" + item.gpn + "']");
if (_this.length == 0) {
console.log("No set data-sn!!!")
} else {
jQuery("body").append(minisiteBuyBox(i));
jQuery(_this)
.show()
.css("display", "inline-block")
.attr("href", "#webshopbox" + i)
.fancybox({
"hideOnContentClick": true
});
}
}
jQuery("#webshopbox"+i+" #dealer").html(dealer);
}
}
});
} else {
console.log("- No Data :P");
}
},
error: function(xhr) {
console.log("- Data cannot be loaded. Please try again later.. :P");
},
timeout: 60000
});
// fancybox
if (typeof jQuery.fancybox == "function") {
// fancy box loaded;
} else {
console.log("Please Include fancy box plugin !");
}
});
}