var stockSpans = []; var stockSpansBuzz = []; var stockListId = []; function showStocksInfo() { var current_feeder = '' var ig_counter =0; $('span.stockInfo').each(function (ind,itm) { var name = $(itm).attr('name'); if (name.match(/^stockInfo\.\d+/)) { var r = name.split('\.'); stock_id=r[1]; stockListId.push(stock_id); if (r.length>2) { display_type = r[2]; if (display_type == 'buzz') { stockSpansBuzz[stockSpansBuzz.length]=itm; } } else { stockSpans.push(itm); } } }); fetch_group(); } function fetch_group() { var length = stockListId.length; var itmPerPage=6; var loops = parseInt(length/itmPerPage); for (i=0;i<=loops;i++) { var from=i*itmPerPage; var to=(i+1)*itmPerPage; var tempList=stockListId.slice(from,to); if (tempList.length>0) { var tempList=tempList.join('-'); var myURL = "/Ext/I-Invest/StockInfo/CmmApiIinvest_getStockInfoJson/0,16471,stockListId,00.html" myURL = myURL.replace('stockListId',tempList); $.ajax({ type: 'GET', url:myURL, success: function(data) { var data = ($.parseJSON(data)); fillSpans(data); } }); } } } var toDisplay; function fillSpans(aRes) { $(aRes).each(function (ind,itm) { var aStock=itm var stock_id=itm.id // making sure that the paper is only stock or teudat-sal: var stock_type = itm.type if (stock_type == 1 || stock_type == 15 || stock_type == 28 || stock_type == 12) { toDisplay = true; } else { toDisplay = false; } var buzz_span_name ='stockInfo.' + stock_id + '.buzz'; var te_stockHTML = getStockHTML(aStock); var te_span_name ='stockInfo.' + stock_id; $(stockSpans).each(function (ind,itm) { if ($(itm).attr('name') == te_span_name && $(itm).attr('stockData')!=1) { $(itm).append($(te_stockHTML).clone(true)); $(itm).attr('stockData',1); } }); }); } function getStockHTML(aStock) { var stock_id=aStock.id var stock_value=aStock.lastShaar; var stock_percent=aStock.dailyChgPercent; var float_percentageChange = parseFloat(stock_percent); siInfoClass = 'si-info-normal'; arrow = '/images/pixel.gif' if (float_percentageChange > 0) {siInfoClass='si-info-positive'; arrow = '/images/1280/stocks/green_arrow.png'} if (float_percentageChange < 0) {siInfoClass='si-info-negative'; arrow = '/images/1280/stocks/red_arrow.png'} if (toDisplay) { var article_id = CalcS.articleId; var message='הוסף לתיק האישי'; } else { var stockAddLink = ""; } var siWrp=$('',{'class':'si-wrp'}); var siBrOpen=$('',{'class':'si-brk-open'}).text('('); var siBrClose=$('',{'class':'si-brk-close'}).text(')'); var siInfoIcn=$('',{'class':'si-info-img'}).attr({'src':'/images/1280/stocks/graph.png'}); var siValue=$('',{'class':'si-value'}).text(stock_value); var siInfoArrow=$('',{'class':'si-info-img-upDown'}).attr({'src':arrow}); var siPercent=$('',{'class':'si-value-percent ' + siInfoClass}).text(formated_number(stock_percent,'',2,'%')); siWrp.append(siBrOpen,siInfoIcn,siValue,siInfoArrow,siPercent,$(stockAddLink),siBrClose); return $(siWrp); } function formated_number(n,s,decimalpoints,a) { function with_comma(n,r) {return (n >= r) ? with_comma(Math.floor(n / r),r) + "," + (r + (n % r)).toString().replace(/^1/,'') : n} try { var n = parseFloat(n.replace(/,/g,"")) if (isNaN(n) || n == 0) {return "---"} var sign = n < 0 ? '-' : s var p = 1 for(var i=0; i < decimalpoints ;i++) {p *= 10} var sn = Math.abs(new String(Math.round(n * p))).toString() while(sn.length < decimalpoints + 1) {sn = "0" + sn} return with_comma(parseInt(sn.substring(0,sn.length - 2)),1000) + "." + sn.substring(sn.length - 2) + a } catch(ex) { console.log("formated_number",ex); } } $(document).ready(function () { try {showStocksInfo()} catch(ex) {alert(ex.description);} });