From 872c94e5ef889dde0247f74c025f0073e4cb380e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torstein=20H=C3=B8nsi?= Date: Fri, 27 Mar 2015 11:04:05 +0100 Subject: [PATCH] Highstock: Fixed issue with the range selector input boxes not being able to focus after first focusing, then clicking on the chart outside the input. --- js/highstock.src.js | 40 ++++++++++++++++++++++++++------------- js/parts/RangeSelector.js | 40 ++++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/js/highstock.src.js b/js/highstock.src.js index 1fc4fa48614..e10c8562fa6 100644 --- a/js/highstock.src.js +++ b/js/highstock.src.js @@ -22151,6 +22151,30 @@ RangeSelector.prototype = { this[name + 'DateBox'].attr({ text: dateFormat(options.inputDateFormat || '%b %e, %Y', this[name + 'Input'].HCTime) }); }, + showInput: function (name) { + var inputGroup = this.inputGroup, + dateBox = this[name + 'DateBox']; + + css(this[name + 'Input'], { + left: (inputGroup.translateX + dateBox.x) + PX, + top: inputGroup.translateY + PX, + width: (dateBox.width - 2) + PX, + height: (dateBox.height - 2) + PX, + border: '2px solid silver' + }); + }, + + hideInput: function (name) { + if (document.activeElement === this[name + 'Input']) { // Prevent running again and again + css(this[name + 'Input'], { + border: 0, + width: '1px', + height: '1px' + }); + this.setInputValue(name); + } + }, + /** * Draw either the 'from' or the 'to' HTML input box of the range selector * @param {Object} name @@ -22193,6 +22217,7 @@ RangeSelector.prototype = { color: '#444' }, chartStyle, options.inputStyle)) .on('click', function () { + rangeSelector.showInput(name); // If it is already focused, the onfocus event doesn't fire (#3713) rangeSelector[name + 'Input'].focus(); }) .add(inputGroup); @@ -22219,22 +22244,11 @@ RangeSelector.prototype = { // Blow up the input box input.onfocus = function () { - css(this, { - left: (inputGroup.translateX + dateBox.x) + PX, - top: inputGroup.translateY + PX, - width: (dateBox.width - 2) + PX, - height: (dateBox.height - 2) + PX, - border: '2px solid silver' - }); + rangeSelector.showInput(name); }; // Hide away the input box input.onblur = function () { - css(this, { - border: 0, - width: '1px', - height: '1px' - }); - rangeSelector.setInputValue(name); + rangeSelector.hideInput(name); }; // handle changes in the input boxes diff --git a/js/parts/RangeSelector.js b/js/parts/RangeSelector.js index 6dbc82ab44f..eec0123b8f4 100644 --- a/js/parts/RangeSelector.js +++ b/js/parts/RangeSelector.js @@ -362,6 +362,30 @@ RangeSelector.prototype = { this[name + 'DateBox'].attr({ text: dateFormat(options.inputDateFormat || '%b %e, %Y', this[name + 'Input'].HCTime) }); }, + showInput: function (name) { + var inputGroup = this.inputGroup, + dateBox = this[name + 'DateBox']; + + css(this[name + 'Input'], { + left: (inputGroup.translateX + dateBox.x) + PX, + top: inputGroup.translateY + PX, + width: (dateBox.width - 2) + PX, + height: (dateBox.height - 2) + PX, + border: '2px solid silver' + }); + }, + + hideInput: function (name) { + if (document.activeElement === this[name + 'Input']) { // Prevent running again and again + css(this[name + 'Input'], { + border: 0, + width: '1px', + height: '1px' + }); + this.setInputValue(name); + } + }, + /** * Draw either the 'from' or the 'to' HTML input box of the range selector * @param {Object} name @@ -404,6 +428,7 @@ RangeSelector.prototype = { color: '#444' }, chartStyle, options.inputStyle)) .on('click', function () { + rangeSelector.showInput(name); // If it is already focused, the onfocus event doesn't fire (#3713) rangeSelector[name + 'Input'].focus(); }) .add(inputGroup); @@ -430,22 +455,11 @@ RangeSelector.prototype = { // Blow up the input box input.onfocus = function () { - css(this, { - left: (inputGroup.translateX + dateBox.x) + PX, - top: inputGroup.translateY + PX, - width: (dateBox.width - 2) + PX, - height: (dateBox.height - 2) + PX, - border: '2px solid silver' - }); + rangeSelector.showInput(name); }; // Hide away the input box input.onblur = function () { - css(this, { - border: 0, - width: '1px', - height: '1px' - }); - rangeSelector.setInputValue(name); + rangeSelector.hideInput(name); }; // handle changes in the input boxes