Ext.ns('DJIndexes'); DJIndexes.Home = function(){ var loadLookup = {}; function setIsLoaded(url) { loadLookup[url] = true; } function getIsLoaded(url) { return loadLookup[url]? true : false; } var _init = function(){; if(!searchPage()){ attachListeners(); setActivePage(0,0); loadContent($('#page_0'),0); createTemplates(); setupScrollBar(); } }; function attachListeners () { $('#intraday-home-tabs li').click(tabCallBack); $('#pressroom h3').click(function(){window.location='http://press.djindexes.com'}); $('#pressroom h2').click(function(){window.location='http://press.djindexes.com'}) } function createTemplates() { indexTmpl = new JTMLTemplate( $( "#index-tmpl" ) ); } function setupScrollBar() { $('.scroller').jScrollPane( {autoReinitialise:true,showArrows:true} ); } function tabCallBack(event) { var tgt = $(event.currentTarget); $('#intraday-home-tabs li').removeClass('active-tab'); $(tgt).addClass('active-tab'); var idx = $(tgt).attr('id').split('_')[1]; var familyId = $(tgt).attr('id').split('_')[2]; setActivePage(idx,familyId); var container = $('#page_' + idx); loadContent(container,familyId); } function setActivePage(idx,familyId){ var pages = $('.intraday-page'); $('.intraday-page').removeClass('active-page'); var page = $(pages).get(idx); $(page).addClass('active-page'); var tgt = $('#page_' + idx); } function loadContent(tgt,familyId) { startRefresh(tgt,familyId); $.ajax({ type: "POST", url:"/DataService/v2/Intraday.cfc", data:{method:'getIndexes',familyId:familyId}, success: function (feed) { renderTickers(feed['data'],tgt) }, error: function (msg){ } }); } function renderTickers(data,tgt){ tgt.html('') $.each(data,function(idx,item){ item['lasttime'] = new Date(item['lasttime']).format('d M H:i'); item['last'] = parseFloat(item['last']).toFixed(2); item['netchange'] = parseFloat(item['netchange']).toFixed(2); item['percentagechange'] = parseFloat(item['percentagechange']).toFixed(2); item['direction'] = (item['netchange'] > 0)? 'up':'down'; var content = indexTmpl.render(item); tgt.append(content); }); attachChartLinks(tgt); } function attachChartLinks(tgt){ $('.chart-btn').unbind(); $('.chart-btn').click(function(tgt){ showChart(tgt.currentTarget.id); }); } function showChart(id) { var data = id.split('-'); var ticker = data[0]; var realtime = (data[1] == 1)?true:false; var title = $('#' + ticker + '-title').text().trim(); new DJIndexes.widget.WindowedChart({ id: 'windowed-chart', ticker: ticker, title: title, numberFormat: '0.00', chartLabels: [], realtime: realtime }); } function startRefresh(feed,tgt) { if (!getIsLoaded(tgt)) { setInterval(function(){ loadContent(feed,tgt) },120000); setIsLoaded(tgt); } } function searchPage(){ var serchPanelDiv='search-result'; if(Ext.get(serchPanelDiv)){ var serchPanel = new DJIndexes.SearchPanel({ container:serchPanelDiv, height: 635 }); return true; } return false; } return { init: function(){ _init(); } } }(); Ext.onReady(DJIndexes.Home.init, DJIndexes.Home);