/** * This file is the key in establishing a functional basis of services. * Due to its links are converted into asynchronous request calls. * This class (cAjax) is responsible for all types and sizes of charts plotting. * * @author Viachaslau Lyskouski * @copyright Copyright (c) 2012 Interactive Data Managed Solutions Ltd. */ /** * Function extends the base class "document" to searching items by class name */ document.getElementsByClassName = function(cl) { var retnode = []; var myclass = new RegExp('\\b'+cl+'\\b'); var elem = this.getElementsByTagName('*'); for(var i = 0; i < elem.length; i++) { var classes = elem[i].className; if(myclass.test(classes)) retnode.push(elem[i]); } return retnode; }; /** * Function that formats number * * @param number c - the number of decimal points * @param string d - the separator for the decimal point * @param string t - the thousands separator * @return string - The function returns a formatted version of number */ Number.prototype.formatMoney = function(c, d, t){ var n = this, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; c = isNaN(c = Math.abs(c)) ? 2 : c; d = d === undefined ? "," : d; t = t === undefined ? "." : t; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); }; /** * Function that collapse/expand content * * @param string clip - the selector of the content * @param string icon - the selector of the image * @return void */ function toggleBody(clip, icon) { var tbody = $(clip); var img = $(icon); if (tbody.css('display') == 'none') { tbody.show(); $(icon).attr('src','images/nzz_collapse.gif'); if (navigator.userAgent.indexOf("MSIE")==-1) tbody.css('display') = 'table-row-group'; else tbody.css('display') = 'block'; } else { tbody.hide(); $(icon).attr('src','images/nzz_expand.gif'); tbody.css('display') = 'none'; } } /** * Function prepares the numbers in accordance with the special format: * N.NNNN, NNNN, NN'NNN * * @param number val - the specified number * @param number sz - the number of decimal points * @return string - the function returns a formatted version of number */ function fFloat(val, sz){ if(val == undefined) return 0; try{var i = val.split("'").join('').split(',').join('.');val = i;} catch(e){} sz = sz || 1; sz = Math.pow(10, sz); val = Math.round(val*sz)/sz; return val != NaN ? val : 0; } /** * Statistical function * */ function NETMX(){ //var trackingPath = parent.location.pathname; //if (trackingPath) { //trackingPath = document.referrer; //if (trackingPath) { // trackingPath = trackingPath.replace(/http:\/\/[\w\.]*/gi, ""); //} else { trackingPath = "/finanzen/charts"; //} //} var sNETMX="http://nzz.wemfbox.ch/cgi-bin/ivw/CP/nzzonline" + trackingPath; $('#metrix').append("\"\""); } /** * Class implementation with different modules for navigation and style formation. * oAjax = new cAjax(); * It sets the values of environment variables to default states * * @param boolean vInit - the option for initialization function cAjax.init(), defalt - true * @return void */ function cAjax(vInit){ if(vInit == undefined) vInit = true; this.ini_type = ''; this.o; this.vScrollStep = 21; this.vScrollHeight = 100; this.bScroll = false; this.vToScroll = ''; this.gScrollIni = false; if(vInit) this.init(); if($('.segel').length) this.showTooltip(); } /** * Function from cAjax class for buttons formation (conversion links into buttons with asynchronous requests) * * @param string cType - the class name of block with links for menu navigation */ cAjax.prototype.init = function(cType){ cType = cType || '.menu'; // links reconfiguring var obj = $(cType+" a"); for(var i in obj) if(obj[i].href && obj[i].href.indexOf('#') == -1) obj[i].href="#"+obj[i].href; // -elements preparing $(cType+" a").click(function(e) { NETMX(); if(this.href.indexOf('#') != -1){ // button colorizing if(this.href.indexOf('notch=hold') == -1){ $(cType+" .notch").remove(); this.innerHTML = ' ' + this.innerHTML; } if(this.innerHTML.indexOf('Kapitalschutz') != -1) this.className = 'active blue0'; else if(this.innerHTML.indexOf('Renditeoptimierungs') != -1 || this.innerHTML.indexOf('Renditeopt.') != -1) this.className = 'active green0'; else if(this.innerHTML.indexOf('Partizipation') != -1) this.className = 'active orange0'; else if(this.innerHTML.indexOf('Hebel') != -1) this.className = 'active red0'; else this.className = 'active'; var obj = $(cType+" a"); for(var i in obj) if(this != obj[i]) obj[i].className = ''; // content loading // // from hidden div if(this.href.indexOf('##') != -1){ $('#Content div').css('z-index', '1'); $('#'+this.href.split('##')[1]).css('z-index', '2'); if(this.href.indexOf('/ajax/') != -1 && $('#'+this.href.split('##')[1].replace('pnC', 'idC')).html().length < 60){ $('#'+this.href.split('##')[1].replace('pnC', 'idC')).html('
'); var el = document.createElement("script"); el.src = this.href.split('#')[1]; //el.charset = 'UTF-8'; el.type="text/javascript"; document.getElementsByTagName('head')[0].appendChild(el); } // // from file }else{ $('#Content').fadeOut('slow'); setTimeout('oAjax.stillHidden();', 3000); var url = this.href.split('#')[1]; $('#Content').load(url+'&'+Math.random()+' #ContentTB', function() { $('#Content').fadeIn('slow'); if(oAjax) oAjax.reinit(); else oAjax = new cAjax(); if(document.getElementById('InfoLine')) $('.InfoLine').html($('#InfoLine').html()); if(document.getElementById('scripts')){ eval(document.getElementById('scripts').innerHTML.replace('(und)','&')); } }); } return false;//e.preventDefault(); }else return true; }); this.ini_type += 'this.init(\''+cType+'\');'; } /** * Function for loading image visualization until the page wasn't loaded (initialisation after 3 seconds from cAjax.init) * */ cAjax.prototype.stillHidden = function(){ if($('#Content').is(":hidden")){ $('#Content').html('
'); $('#Content').show(); } } /** * Function for re initialisation all required functionality after each asyncronium request* */ cAjax.prototype.reinit = function(){ var cl = ['menu','menu2','top_menu','top_menu2','pages','links','bottom_list','buttons']; for(var i in cl) $('.'+cl[i]+' a').unbind('click'); $('#'+this.vToScroll).unbind('mousewheel'); i = this.ini_type; this.ini_type = ''; eval(i); } /** * Function prepares content into limited block with scroll * * @param string id_content - id of an div-element */ cAjax.prototype.asScroll = function(id_content){ if($('#'+id_content)){ this.vToScroll = id_content; // near data mouse scrolling $('#'+id_content).mousewheel(function(event, delta) { oAjax.moveScroll(delta); return false; }); // handing scroll if(!oAjax.gScrollIni){ $('body').mousemove(function(e){ if(oAjax.bScroll){ var i = parseInt($('#'+oAjax.vToScroll+' div.scroll div:last').offset().top) - e.pageY; oAjax.moveScroll(parseInt(i/21)); } }); $('body').bind('mouseup',function(e){oAjax.bScroll = false;return true;}); oAjax.gScrollIni = true; } $('#'+id_content+' div.scroll').mousedown(function(e){ var obj = document.getElementById(oAjax.vToScroll); var i = parseInt($('#'+oAjax.vToScroll+' div.scroll div:last').offset().top) - e.pageY; i += (i > 0 ? 1 : -1)*parseInt($('#'+oAjax.vToScroll+' div.scroll div:last').css('height')); i = (parseInt(obj.parentNode.offsetHeight)*i)/parseInt(obj.offsetHeight); oAjax.moveScroll(parseInt(i)); return false; }); $('#'+id_content+' div.scroll div').mousedown(function(){oAjax.bScroll = true;return false;}); // size of scroll var scr = parseInt(document.getElementById(this.vToScroll).parentNode.offsetHeight); this.vScrollHeight = parseInt(document.getElementById(this.vToScroll).offsetHeight); this.vScrollStep = scr/this.vScrollHeight; $('#'+id_content+' div.scroll div').css('height', parseInt(scr*this.vScrollStep)+'px'); // function buffering this.ini_type += 'this.asScroll(\''+id_content+'\');'; } } /** * Function prepares text-content into limited block with scroll * * @param string id_content - id of an div-element */ cAjax.prototype.TextScroll = function(id){ hs = $('#'+id).height(); if(hs > 800){ $('#'+id).css('display','table').attr('class','XL_a'); $('#'+id+'TB').css('display','table-cell').css('vertical-align','top'); $('#'+id+'TB div').css('overflow','hidden').css('width', $('#'+id+'TB div').width()-20); $('#'+id+'TB div div').css('overflow-y','scroll').css('width', $('#'+id+'TB div').width()).css('padding-right','30px').css('height', '720px'); $('#'+id+'Scroll').attr('class','scroll'); h = $('#'+id).height(); $('#'+id+'Scroll b').css('height',(h*h/hs)+'px'); $('#'+id+'TB div div').scroll(function(){ var s = $(this).scrollTop(); $('#'+id+'Scroll b').css('top',(s*(h+10)/hs)+'px'); }); $('#'+id+'Scroll b').mousedown(function(){oAjax.bScroll = 1;}); $('#'+id+'Scroll b').mousemove(function(e){ if(oAjax.bScroll){ if(oAjax.bScroll == 1) oAjax.bScroll = e.pageY; var delta = (e.pageY - oAjax.bScroll)*hs/h; document.title = parseInt(delta)+','+e.pageY; $('#'+id+'TB div div').scrollTop($('#'+id+'TB div div').scrollTop()+delta); oAjax.bScroll = e.pageY; if (window.getSelection) window.getSelection().removeAllRanges(); else if (document.selection && document.selection.clear) document.selection.clear(); } }); $('body').bind('mouseup',function(e){oAjax.bScroll = 0;return true;}); } } /** * Function controls scroll which was created by the function asScroll * * @param number delta - greater than zero - move scroll down, otherwise - move scroll up */ cAjax.prototype.moveScroll = function(delta){ //$('#'+this.vToScroll+' div').css('top', delta < 0 ? '-=21' : '+=21'); obj = document.getElementById(this.vToScroll).getElementsByTagName('div'); var j = parseInt(obj[2].style.top) ? parseInt(obj[2].style.top) : 0; for(var i in obj){ if(i > 1 && j > 0) obj[i].style.top = '0px'; else if(i > 1 && !(j >= 0 && delta > 0) && (j >= this.vScrollHeight*this.vScrollStep-this.vScrollHeight || delta > 0)) obj[i].style.top = (j + 21*delta)+'px'; else if(i > 1 && j < this.vScrollHeight*this.vScrollStep-this.vScrollHeight) obj[i].style.top = (this.vScrollHeight*this.vScrollStep-this.vScrollHeight-21)+'px'; } $('#'+this.vToScroll+' div.scroll div').css('top', parseInt(-parseInt(obj[2].style.top)*this.vScrollStep)+'px'); return false; } /** * Function fills the empty block content from an asynchronous request * * @param number id - number of the required layer */ cAjax.prototype.showHiddenLayer = function(id){ if(document.getElementById(id)){ var html = document.getElementById(id).innerHTML; if(this.ini_type.indexOf('asScroll') != -1) html = '
 
'+html; document.getElementById('ContentTB').innerHTML = html; this.reinit(); } return true; } /** * Function is responsible for displaying the user-selected layer and hiding the rest * * @param string menu_cl - class of the menu block * @param string cl - class of the content block * @param number num - number of current block */ cAjax.prototype.changingLayers = function(menu_cl, cl, num){ this.init('.'+menu_cl); var i = 1, obj; if(menu_cl != ''){ $('.'+menu_cl+' a').attr({'class': ''}); $('.'+menu_cl+' a:eq('+num+')').attr({'class': 'active'}); }else{ $('.'+cl+' select').attr('disabled',true); $('.'+cl+':eq('+num+') select').removeAttr('disabled'); } $('.'+cl).attr({'style': 'visibility:hidden;display:none;'}); $('.'+cl+':eq('+num+')').attr({'style': 'visibility:visible;'}); return false; } /** * Function adjusts the frame size from the charts * * @param string id - id of an iframe * @param number size - number of the iframe size in pixels */ cAjax.prototype.sizeFrame = function(id, size){ if(size == 1 || size == 0) size = size ? 413 : 264; if(document.getElementById(id)){ if(size == -1) $('#'+id).hide(); else{ $('#'+id).show(); $('#'+id).attr('height', size+'px'); if(id == 'allcharts' && size == 413){ var doc, IFrame = document.getElementById(id); if( IFrame.contentDocument ) // NS6 doc = IFrame.contentDocument; else if( IFrame.contentWindow ) // IE5.5, IE6 doc = IFrame.contentWindow.document; else doc = IFrame.document; doc = doc.getElementById("ContentTB").getElementsByTagName('b'); if(doc.length == 0){ $('#'+id).attr('height', '264px'); } } } } return true; } /** * Function changes links in accodance with async. request * * @param string val - new link * @param string obj - localization of group links */ cAjax.prototype.syncLinks = function(val, obj){ val = val.split('='); $(obj).attr('href', function(i, v) { v = v.split(val[0]+'='); v[1] = v[1].slice(v[1].indexOf('&')); return v.join(val[0]+'='+val[1]); }); } /** * Function constructs required chart * * @param string i - id of the target div * @param string color - color for the chart background * @param array spacing - size of different paddings * @param string vGridMin - minimum value on y-axis * @param string vGridMax - maximum value on y-axis * @param string aSeries - chart-dots coordinates * @param boolean aCateg - special charts with non-linear grid * @param boolean bBubble - special charts with bubbles */ cAjax.prototype.newChart = function(i, color, spacing, vGridMin, vGridMax, aSeries, aCateg, bBubble){ aCateg = aCateg || false; bBubble = bBubble || false; return new Highcharts.Chart({ chart: { renderTo: 'idChart_'+i, spacingTop: spacing[0],// 24, spacingRight: spacing[1],//18, spacingBottom: spacing[2],//18, spacingLeft: spacing[3],//11, style: { fontFamily: 'Arial, sans-serif', fontSize: '14px', color: '#4c4c4c' }, events: { redraw: function(){ if (bBubble) {updateLegend();} } }, backgroundColor: color, zoomType: 'xy' }, title: {text: null}, credits: {enabled: false}, legend: {enabled: false}, subtitle: { text: bBubble ? 'Risiko' : '', floating: true, align: 'right', verticalAlign: 'bottom', style: { color: '#4c4c4c', fontFamily: 'Arial, sans-serif', fontSize: '12px' }, y: -20, x: -5 }, xAxis: { lineColor: '#212121', gridLineColor: '#f2f2f2', gridLineWidth: bBubble ? 1 : 0, endOnTick: true, //tickInterval: bBubble ? 10 : null, type: (aCateg || bBubble) ? 'linear' : 'datetime', dateTimeLabelFormats: { minute: '%H:%M', hour: '%H:%M', day: '%e. %b', week: '%e. %b', month: '%b \'%y', year: '%Y' }, labels: bBubble ? { formatter: function() {return this.value+'%';} } : {}, categories: aCateg, events: { setExtremes: function(){ $('#button').show(); } } }, yAxis: { gridLineColor: '#f2f2f2', lineWidth: 0, gridLineWidth: 1, title: { text: bBubble ? 'Performance' : null, align:"high", //rotation: 0, style: { color: '#4c4c4c', fontFamily: 'Arial, sans-serif', fontSize: '12px', fontWeight: 500 }, x: 25+spacing[1], y: 0, margin:-25 }, labels: { align: 'right', x: -8, y: 0, formatter: function() { var val = 0; if(this.value < 10) val = this.value.formatMoney((aCateg ? 2 : 4), '.', '')+(aCateg ? '%' : ''); else if(this.value < 1000) val = this.value.formatMoney(2, '.', ''); else if(this.value < 10000) val = this.value.formatMoney(0, '.', ''); else val = this.value.formatMoney(0, '.', '\''); return bBubble ? this.value+'%' : val; } }, min: vGridMin, max: vGridMax, startOnTick: false, maxPadding: 0 //tickInterval: (vGridMax - vGridMin + 0.2*(vGridMax - vGridMin))/5 }, plotOptions: { pie: { dataLabels: { connectorWidth: 0, enabled: false, softConnector: false }, showInLegend: false }, line: { zIndex: 2, lineWidth: 2, color: '#212121', shadow: false, marker: { enabled: true, fillColor: '#1e1e1e', states: { hover: { enabled: true, symbol: 'circle', radius: 4 } } }, cursor: 'pointer', events: { click: function(event) { if(event.point.name != undefined){ oAjax.showHiddenLayer(event.point.name.split(':')[1]); oAjax.sizeFrame('allcharts', 1); }else if(!bBubble && event.point.id && event.point.tp){ var sType; switch(event.point.tp){ case 'WAR': case 'STO': case 'FUT': case 'OPT': sType = 'aktien'; break; case 'BON': sType = 'obligationen'; break; case 'CUR': sType = 'devisen'; break; case 'IND': sType = 'indizes'; break; case 'COM': sType = 'rohstoffe'; case 'FUN': default: sType = 'fonds'; break; } window.top.location.href = 'http://'+sURL+'/finanzen/'+sType+'/_detail?SECURITY_TYPE='+event.point.tp+'&ID_NOTATION='+event.point.id; } return true; } }, select: {enabled: false} }, column: { zIndex: 1, lineWidth: 2, color: '#f2f2f2', borderWidth: 0, shadow: false, pointWidth: 2 }, scatter: { events: { click: function(event) { if(bBubble && event.point.fillColor == 'rgba(0,147,204,.2)'){ window.top.location.href = 'http://'+sURL+'/finanzen/fonds/_suchergebnis?CLIP_TYPE=fund_searchresult&FUND_CATEGORY='+event.point.id; return true; } } } } }, tooltip: { borderRadius: 0, backgroundColor: '#f9f9f9', borderColor: '#c6c6c6', borderWidth: 0, style: { color: '#1e1e1e', fontFamily: 'Arial, sans-serif', fontSize: '13px', padding: '11px 10px' }, shared: aCateg ? true : false, crosshairs: aCateg ? true: false, formatter: function() { if(aCateg){ if(this.x == '') return false; var s = ''+ this.x +''; $.each(this.points, function(i, point) { if(point.series.name.indexOf('Series') == -1) s += '
'+ point.series.name +': '+ point.y.formatMoney(4, '.', '\'') +'%'; }); return s; }else if(bBubble){ return ''+this.point.name+'
Volatilität: '+ this.x+'%
Performance: '+this.y+'%
Anzahl Fonds: '+this.point.z; }else if(this.x == undefined){ return ''+ this.point.name.replace('ü', String.fromCharCode(252)) +': '+this.y+'%'; } switch(this.series.name.split('.')[0]){ case '1Y': case '5Y': case '1M': case '6M': tm = Highcharts.dateFormat('Datum: %e. %B %Y', this.x); break; case '10D': tm = Highcharts.dateFormat('%e. %B um %H:%M Uhr', this.x); break; default: tm = Highcharts.dateFormat('%H:%M Uhr', this.x); } return ""+ (this.y < 10000 ? this.y : this.y.formatMoney(2, '.', '\'')) +'
'+tm+ (this.series.name.indexOf('news') != -1 && parseInt(this.point.name) > 0 ? '
Anzahl News: '+parseInt(this.point.name)+'
Klicken f'+String.fromCharCode(252)+'r Details!' : ''); } }, series: aSeries }); } /** * Function constructs required little chart * * @param string id - id of the target div * @param array arr - chart-dots coordinates */ cAjax.prototype.CanvasChart = function(id, arr){ this.o = document.getElementById(id); if(this.o.getContext){ this.o = this.o.getContext('2d'); for(var i in arr) this.Canvas(arr[i].split(':')); }else{ var ad = id.split('_'); document.getElementById(id.substr(1)).innerHTML = ''; } } /** * Function checks whether an input parameter in the array * * @param string v - verified value * @param array a - verified array */ cAjax.prototype.isArr = function(v, a){ for(var i in a) if(v == a[i]) return true; return false; } /** * Function with canvas functionality realisation * * @param string a - input parameters for plotting */ cAjax.prototype.Canvas = function(a){ if(this.isArr(a[0], ['b','','c', 'a','v','m','-'])) a[1] = a[1].split(','); switch(a[0]){ case 's':this.o.strokeStyle = a[1];break; case 'f':this.o.fillStyle = a[1];break; case 'w':this.o.lineWidth = a[1];break; case 'b':this.o.beginPath();if(a[1][0]!='') this.o.moveTo(a[1][0],a[1][1]);break; case 'm':this.o.moveTo(a[1][0],a[1][1]);break; case '' :this.o.lineTo(a[1][0],a[1][1]);break; case 'c':this.o.closePath();if(a[1][0]) this.o.stroke();if(a[1][1]) this.o.fill();break; case 'st':this.o.stroke();break; case 'a':this.o.arc(a[1][0],a[1][1],a[1][2],a[1][3],eval(a[1][4]),a[1][5]);break; case 'v':this.o.bezierCurveTo(a[1][0],a[1][1],a[1][2],a[1][3],a[1][4],a[1][5]);break; case '-':this.o.clearRect(a[1][0],a[1][1],a[1][2],a[1][3],a[1][4]);break; case 't':this.o.globalCompositeOperation = a[1];break; } } /** * Function provide tooltip for Credit Suisse * */ cAjax.prototype.showTooltip = function(){ $('#metrix').html('
Passende Produkte von Credit Suisse
'); $('.segel').mouseover(function(e){ var x = x0 = e.pageX, y = y0 = e.pageY, tp = 'Down', h = $('#cTContent').height(), w = $('#cTContent').width(); x = ((x+w+50) > $(document).width()) ? x - w + 30 : x - 30; if((y+h+20) > $(document).height()){ y = y - h - 27; y0 -= 16; tp = 'Up'; }else{ y += 17; y0 += 10; } x = x < 0 ? 5 : x; $('#cTContent').css('top', y+'px').css('left',x+'px').show(); $('#cTMarker'+tp).css('top', y0+'px').css('left',x0+'px').show(); }); $('.segel').mouseout(function(){ $('#cTContent').hide(); $('#cTMarkerUp').hide(); $('#cTMarkerDown').hide(); }); this.ini_type += 'this.showTooltip();'; }