/* Remove scroller variables at the begining and scroller functions and put the new one. Some conditions if data available + if open, high, low, .... chart.php -> now GET parameter + global var in Symex... -> includes proper feeder file lib.js chart.php - define SymexChartGlobals.values_type + proper feeder file include interactive,js new feeder file kernel_17.php -> set GET['values_type'], .labelsY_txt:nowrap(IE negative sign bug), set lang_array[36] */ jQuery(document).ready(function() { if (data_close_0.length == 0) { $('#no_data_message').show(); $('#loader').hide(); return; } $('#loader').hide(); // Coef => set period to be selected initially if ( SymexChartGlobals.show_last_coef != '' ) { var help_1 = eval( SymexChartGlobals.show_last_coef.split('*')[0] ); var help_2 = eval( SymexChartGlobals.show_last_coef.split('*')[1] ); var leftScInit = parseInt(data_date.length / help_1 * help_2 ); // jQuery('#left_scroll').css('left', parseInt(SymexChartGlobals.chart_width / help_1 * help_2 ) ); } else { var leftScInit = 0; } //check if last year we have quotes => case no => select hall period (3 years) if ( leftScInit > 0) { var no_empty_period = 0; for ( var z = leftScInit; z < SymexChartGlobals.points_qty; z++ ) { if (data_close_0[z]) { no_empty_period++; break; } } if ( no_empty_period == 0 ) leftScInit = 0; } // Price graph drawLine( leftScInit, SymexChartGlobals.points_qty ); labels_X( leftScInit, SymexChartGlobals.points_qty ); labels_Y( leftScInit, SymexChartGlobals.points_qty ); if (SymexChartGlobals.display_news == 1) { news( leftScInit, SymexChartGlobals.points_qty ); } // Indicator graph if (SymexChartGlobals.display_volume > 0) { drawVolumes( leftScInit, SymexChartGlobals.points_qty ); labels_volume_Y( leftScInit, SymexChartGlobals.points_qty ); } show_period( leftScInit, SymexChartGlobals.points_qty ); // Summary Graph if ( SymexChartGlobals.chart_sum_height > 5 ) { drawLine_2(); labels_X_summary(); } // Prevent move back precission cell after `touchmove` event finish! // It seems if we touch screen without moving for some miliseconds - it is `click` event for iPad. jQuery('#ie_mousemove_bug').live('touchstart', function(e){ e.preventDefault(); return; }); jQuery('#ie_mousemove_bug, #precCell').live('mousemove touchmove', function(e) { // google.bg: jquery touchmove // http://www.devinrolsen.com/basic-jquery-touchmove-event-setup/ if (e.originalEvent.touches) { // Case touch screen device e.preventDefault(); var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; var elm = jQuery('#ie_mousemove_bug').offset(); var x = touch.pageX - elm.left; var x_orig = x; // Need for precission cell pointer var y = touch.pageY - elm.top; // Prevent touch devices bug -> touchmove event is keep outside the element! if(x > jQuery('#ie_mousemove_bug').width() || x < 0 || y > jQuery('#ie_mousemove_bug').height() || y < 0){ return; } } else { // Case PC var x = e.pageX - jQuery('#ie_mousemove_bug').offset().left; //*new* this.offsetLeft; var x_orig = x; // Need for precission cell pointer var y = e.pageY - jQuery('#ie_mousemove_bug').offset().top;//*new* this.offsetTop; } //size of precission cell var precCellH = jQuery('#precCell').height(); var precCellW = jQuery('#precCell').width(); if (x > SymexChartGlobals.chart_width || y > SymexChartGlobals.chart_height) return; var next = 0; // if (SymexChartGlobals.begin == 0) next = 1; var curr_date = parseInt( x / SymexChartGlobals.stepX ) + next + SymexChartGlobals.begin; if (curr_date > SymexChartGlobals.points_qty - 1) curr_date = SymexChartGlobals.points_qty - 1; if ( x > (SymexChartGlobals.chart_width / 2) ) x = x - precCellW - 10; else x += 10; if ( y > (SymexChartGlobals.chart_height / 2) ) y = y - precCellH - 10; else y += 10; // Only for Coteboursiere Mobile Version !!! if (y < -15) y = -15; // -15px - precission cell over price graph's margin top space (period info) var y_max = SymexChartGlobals.chart_height + 20; // +20px - over labels X if (y + precCellH > y_max) y = y_max - precCellH; // if no quotations on current day if (typeof data_close_0[curr_date] == "undefined") { jQuery('#precCell').hide(); // jQuery('#precCellPointer').hide(); } else { if (SymexChartGlobals.tickers_qty == 1) { /* ===== Manage news ===== */ // If infobox pointer is over a triangle - imitate triangle's mouseover event! var flagClear = true; for (var itn = parseInt(x_orig); itn > parseInt(x_orig) - 10; itn--) { // `-10` - width of triangle if ($('.left_' + itn).length > 0) { $('.left_' + itn).trigger('mouseover'); flagClear = false; break; } } if (flagClear) $('#news-info').html(' '); var full = 0; var closeWord = SymexChartGlobals.pays_main != 'SC' ? SymexChartSettings.lang_array[31] : 'NAV: '; closeWord = SymexChartGlobals.values_type == "variation" ? SymexChartSettings.lang_array[36] : closeWord; var closeSign = SymexChartGlobals.values_type == "variation" ? "%" : ""; var text_precCell = SymexChartSettings.lang_array[30] + date_eu(data_date[curr_date]); text_precCell += '
' + closeWord + data_close_0[curr_date].toFixed(2) + closeSign; if ( SymexChartGlobals.tickers_qty == 1 && typeof data_open_0 != "undefined" && data_open_0[curr_date]) // && SymexChartGlobals.pays_main != 'SC' // && SymexChartGlobals.pays_main != 'OR' ) { text_precCell += '
' + SymexChartSettings.lang_array[33] + data_open_0[curr_date].toFixed(2); text_precCell += '
' + SymexChartSettings.lang_array[34] + data_high_0[curr_date].toFixed(2); text_precCell += '
' + SymexChartSettings.lang_array[35] + data_low_0[curr_date].toFixed(2); full += 3; } if (typeof data_vol_0 && data_vol_0[curr_date] > 0) { text_precCell += '
' + SymexChartSettings.lang_array[32] + data_vol_0[curr_date]; full += 1; } jQuery('#precCell').css('height', 30 + ( parseInt(jQuery('#precCell_txt').css('line-height')) * full) ); } else { var text_precCell = SymexChartSettings.lang_array[30] + date_eu(data_date[curr_date]); var full = 0; for( var b = 0; b < SymexChartGlobals.tickers_qty; b++ ) { if (typeof eval('data_close_' + b + '[curr_date]') == "undefined") continue; text_precCell += '
' + SymexChartGlobals.ticker_symbol[b]+ ': ' + eval('data_close_' + b + '[curr_date]').toFixed(2); full++; } jQuery('#precCell').css('height', 30 + ( parseInt(jQuery('#precCell_txt').css('line-height')) * full) ); } jQuery('#precCell').show(); jQuery('#precCell_txt').show(); //jQuery('#precCellPointer').show(); jQuery('#precCellPointer').css('left', x_orig); //*new* this.offsetLeft jQuery('#precCell').css('left', x); jQuery('#precCell').css('top', y); jQuery('#precCell_txt').html(text_precCell); } }); var Scroller = { data: { id: '#scroller', posLeft: 0, posRight: 0, width: jQuery('#summaryGraph').width(), parentWidth: jQuery('#summaryGraph').width() }, is_moving: { left: false, right: false, all: false }, clickX: 0, // Last `click` or `touch` point in Scroller stopMoving: function() { var this_ = Scroller; this_.is_moving['left'] = false; this_.is_moving['right'] = false; this_.is_moving['all'] = false; this_.clickX = 0; Scroller.data['posLeft'] = parseInt( $(Scroller.data['id']).css('left') ); Scroller.data['posRight'] = Scroller.data['parentWidth'] - (Scroller.data['posLeft'] + Scroller.data['width']); }, getElementX: function(e) { if (e.originalEvent.touches) { var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; var scrollPosX = touch.pageX;// - jQuery(Scroller.data.id).offset().left; } else { var scrollPosX = e.pageX;// - jQuery(Scroller.data.id).offset().left; } return scrollPosX; } }; jQuery('#left-scroller').live('mousedown touchstart', function(e) { e.preventDefault(); e.stopPropagation(); Scroller.is_moving['left'] = true; }); jQuery('#right-scroller').live('mousedown touchstart', function(e) { e.preventDefault(); e.stopPropagation(); Scroller.is_moving['right'] = true; }); jQuery(Scroller.data['id']).live('mousedown touchstart', function(e) { e.preventDefault(); e.stopPropagation(); Scroller.is_moving['all'] = true; Scroller.clickX = Scroller.getElementX(e); }); jQuery(document).bind('mouseup touchend', function(e) { e.preventDefault(); if (Scroller.is_moving['all'] || Scroller.is_moving['left'] || Scroller.is_moving['right']) { Scroller.stopMoving(); // Original step 'X' => when show all points var step_zoom = (SymexChartGlobals.chart_width - 1) / (data_date.length - 1); // Remove from stage elements which will be redraw clearLine(); // Stay in range of data array var ls_ = parseInt( Scroller.data['posLeft'] / step_zoom ); // !NOTE: +1 -> round up var rs_ = parseInt( (Scroller.data['posLeft'] + Scroller.data['width']) / step_zoom ) + 1; if ( ls_ < 0 ) { ls_ = 0; } if ( rs_ > SymexChartGlobals.points_qty) { rs_ = SymexChartGlobals.points_qty; } // If switch handles if ( rs_ < ls_ ) { var help = rs_; rs_ = ls_; ls_ = help; } // Redraw stage => if have quotes for selected period var no_data = array_max( data_close_0, ls_, rs_ ); if ( no_data != -100000 ) //-100000 => set in fuction array_max { // Price graph drawLine( ls_, rs_ ); labels_X( ls_, rs_ ); labels_Y( ls_, rs_ ); if (SymexChartGlobals.display_news == 1) { news( ls_, rs_ ); } // Indicator graph if (SymexChartGlobals.display_volume > 0) { drawVolumes( ls_, rs_ ); labels_volume_Y( ls_, rs_ ); } jQuery('#no_data_message').hide(); } else { jQuery('#no_data_message').show(); } show_period( ls_, rs_ ); } }); jQuery('#summaryGraph').live('mousemove touchmove', function(e) { e.preventDefault(); e.stopPropagation(); // Prevent marup elements document.body.focus(); document.onselectstart = function () { return false; }; if (e.originalEvent.touches) { var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; var elm = jQuery(this).offset(); var scrollPosX = touch.pageX - elm.left; } else { var scrollPosX = e.pageX - jQuery(this).offset().left; } // Stay in summary graph! if (scrollPosX < 0) { scrollPosX = 0; } else if (scrollPosX > Scroller.data['parentWidth']) { scrollPosX = Scroller.data['parentWidth']; } /* Manage scroller's width + left */ /* Moving left scroller - change scroller's position and width! */ /* Moving right scroller - change scroller's width only! */ /* Moving all scroller - change scroller's left only! */ if (Scroller.is_moving.left) { Scroller.data['posLeft'] = scrollPosX; Scroller.data['width'] = Scroller.data['parentWidth'] - Scroller.data['posRight'] - scrollPosX; // Prevent switch handles if (Scroller.data['width'] < 20) { Scroller.data['width'] = 20; return; } jQuery(Scroller.data['id']).css({ left: Scroller.data['posLeft'], width: Scroller.data['width'] }); } else if (Scroller.is_moving.right) { Scroller.data['posRight'] = Scroller.data['parentWidth'] - scrollPosX; Scroller.data['width'] = scrollPosX - Scroller.data['posLeft']; // Prevent switch handles if (Scroller.data['width'] < 20) { Scroller.data['width'] = 20; return; } jQuery(Scroller.data['id']).css({ width: Scroller.data['width'] }); } else if (Scroller.is_moving.all) { var deltaX = scrollPosX - Scroller.clickX; /* IMPORTANT! - Scroller.data['posLeft'] / Scroller.data['posLeft'] */ /* will be update on document `mouseup` or `touchend` */ var lp = Scroller.data['posLeft'] + deltaX; // Stay in summary graph! if (lp < 0) { return; } else if ( (lp + Scroller.data['width']) > Scroller.data['parentWidth']) { return; } jQuery(Scroller.data['id']).css({ left: lp }); } }); });