var LivePriceService = siteHelper.getComponent('MiComponents.Services.PdsLivePriceService');
jQuery.fn.flash = function (color, duration) {
var current = this.css('backgroundColor');
this.animate({ backgroundColor: 'rgb(' + color + ')' }, duration / 2)
.animate({ backgroundColor: current }, duration / 2);
};
function formatStock(stock) {
var product = miConstants.productList.filter(function (p) { return p.SymbolCode == stock.Symbol })[0];
return $.extend(stock, {
Display: product.DisplayName,
Ask: stock.Ask.toFixed(stock.DecimalCount),
Bid: stock.Bid.toFixed(stock.DecimalCount),
Direction: stock.DirectionBid === 0 ? '' : stock.DirectionBid >= 0 ? '▲' : '▼',
DirectionClass: stock.DirectionBid === 0 ? 'greenIconEqual' : stock.DirectionBid > 0 ? 'greenIconUp' : 'redIconDown'
});
}
function LivePrice(cdnurl) {
var $stockTableBodyFx = $('#mycrawler1');
var $stockTableBodyIndice = $('#mycrawler2');
var $stockTableBodyCommodity = $('#mycrawler3');
var rowTemplate = '
{Display} {Bid} {Ask} ';
var failCount = 0;
var products = miConstants.productList.map(function (p) { return p.SymbolCode; });
var livePriceService = new LivePriceService();
livePriceService.setInitialCallback(livePriceinitialize);
livePriceService.setUpdateCallback(showPriceChanges);
livePriceService.start(products);
livePriceService.setUpdateData(products);
function showPriceChanges(data) {
$.each(data.data, function (key, value) {
updateStockPrice(value);
});
}
function livePriceinitialize(data) {
$stockTableBodyFx.empty();
$stockTableBodyCommodity.empty();
$stockTableBodyIndice.empty();
$.each(data.data, function () {
formatStock(this);
});
$.each(data.data, function () {
var stock = this;
var product = miConstants.productList.filter(function (p) { return p.SymbolCode == stock.Symbol })[0];
if (product.Group == "fx") {
$stockTableBodyFx.append(rowTemplate.supplant(stock));
}
else if (product.Group == "commodity") {
$stockTableBodyCommodity.append(rowTemplate.supplant(stock));
}
else if (product.Group == "indice") {
$stockTableBodyIndice.append(rowTemplate.supplant(stock));
}
});
marqueeInit({
uniqueid: 'mycrawler1',
inc: 3, //speed - pixel increment for each iteration of this marquee's movement
mouse: 'cursor driven', //mouseover behavior ('pause' 'cursor driven' or false)
moveatleast: 1,
neutral: 50,
persist: false,
savedirection: true
});
marqueeInit({
uniqueid: 'mycrawler2',
inc: 3,
mouse: 'cursor driven',
moveatleast: 1,
neutral: 50,
persist: false,
savedirection: true
});
marqueeInit({
uniqueid: 'mycrawler3',
inc: 3,
mouse: 'cursor driven',
moveatleast: 1,
neutral: 50,
persist: false,
savedirection: true
});
var totalWidth = 0
$($('#fXContent ul ul ul')[0])
.children('li')
.each(function (e, i) {
totalWidth += ($(i).outerWidth() + 50)
})
$('#fXContent ul ul ul').css('width', totalWidth < 1800 ? 1800 : totalWidth + "px");
totalWidth = 0;
$($('#indiciesContent ul ul ul')[0])
.children('li')
.each(function (e, i) {
totalWidth += ($(i).outerWidth() + 50)
})
$('#indiciesContent ul ul ul').css('width', totalWidth < 1800 ? 1800 : totalWidth + "px");
totalWidth = 0;
$($('#commodityContent ul ul ul')[0])
.children('li')
.each(function (e, i) {
totalWidth += ($(i).outerWidth() + 50)
})
$('#commodityContent ul ul ul').css('width', totalWidth < 1800 ? 1800 : totalWidth + "px");
$('.StockMarketWrap div.StockMarketMarquee').show();
$('.stockMarketBtnFilter ul li:first').addClass("stockMarketBtnActiveMR");
$('.stockMarketBtnFilter ul li').click(function () {
$('.stockMarketBtnFilter ul li').removeClass("stockMarketBtnActiveMR");
$(this).addClass("stockMarketBtnActiveMR");
var currentTab = $(this).data("symbol");
$('.StockMarketWrap div.StockMarketMarquee').hide();
$(currentTab).show();
return false;
});
$(".stockMarketClose").click(function () {
if (!$(this).hasClass("active")) {
$(this).addClass("active");
$(".StockMarketWrapBackG").stop(true, false).animate({ bottom: -42 }, 700, "easeOutQuart");
} else {
$(this).removeClass("active");
$(".StockMarketWrapBackG").stop(true, false).animate({ bottom: 0 }, 700, "easeOutQuart");
}
});
$(".StockMarketWrap").css("opacity", "0.8");
$(".StockMarketWrap").mouseover(function () {
$(this).stop(true, false).animate({ opacity: 1 }, 700, "easeOutQuart");
}).mouseleave(function () {
$(this).stop(true, false).animate({ opacity: 0.8 }, 700, "easeOutQuart");
});
}
function updateStockPrice(stock) {
var product = miConstants.productList.filter(function (p) { return p.SymbolCode == stock.Symbol })[0];
if (product.Group == "fx") {
var $row = $stockTableBodyFx.find('li[data-symbol=' + stock.Symbol + ']');
var displayStock = formatStock(stock);
$row = $(rowTemplate.supplant(displayStock));
var $row_class = $row.attr("class");
$stockTableBodyFx.find('li[data-symbol=' + stock.Symbol + ']').attr("class", $row_class);
$stockTableBodyFx.find('li[data-symbol=' + stock.Symbol + ']').html($row.html());
}
else if (product.Group == "indice") {
var $row = $stockTableBodyIndice.find('li[data-symbol=' + stock.Symbol + ']');
var displayStock = formatStock(stock);
$row = $(rowTemplate.supplant(displayStock));
var $row_class = $row.attr("class");
$stockTableBodyIndice.find('li[data-symbol=' + stock.Symbol + ']').attr("class", $row_class);
$stockTableBodyIndice.find('li[data-symbol=' + stock.Symbol + ']').html($row.html());
}
else if (product.Group == "commodity") {
var $row = $stockTableBodyCommodity.find('li[data-symbol=' + stock.Symbol + ']');
var displayStock = formatStock(stock);
$row = $(rowTemplate.supplant(displayStock));
var $row_class = $row.attr("class");
$stockTableBodyCommodity.find('li[data-symbol=' + stock.Symbol + ']').attr("class", $row_class);
$stockTableBodyCommodity.find('li[data-symbol=' + stock.Symbol + ']').html($row.html());
}
}
}
function isIE() {
var myNav = navigator.userAgent.toLowerCase();
return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
}