Skip to content

Commit

Permalink
Fixing clear atom to work with <input type="range"> for IE
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Mar 19, 2018
1 parent 56f210e commit edbc914
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 7 additions & 1 deletion javascript/atoms/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ bot.action.clear = function(element) {

if (element.value) {
bot.action.LegacyDevice_.focusOnElement(element);
element.value = '';
if (goog.userAgent.IE && bot.dom.isInputType(element, 'range')) {
var min = element.min ? element.min : 0;
var max = element.max ? element.max : 100;
element.value = (max < min) ? min : min + (max - min) / 2;
} else {
element.value = '';
}
bot.events.fire(element, bot.events.EventType.CHANGE);
bot.events.fire(element, bot.events.EventType.BLUR);
var body = bot.getDocument().body;
Expand Down
19 changes: 18 additions & 1 deletion javascript/atoms/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,21 @@ bot.dom.isFileInput = function(element) {
};


/**
* @param {!Element} element The element to check.
* @param {string} inputType The type of input to check.
* @return {boolean} Whether the element is an input with specified type.
*/
bot.dom.isInputType = function(element, inputType) {
if (bot.dom.isElement(element, goog.dom.TagName.INPUT)) {
var type = element.type.toLowerCase();
return type == inputType;
}

return false;
};


/**
* @param {!Element} element The element to check.
* @return {boolean} Whether the element is contentEditable.
Expand Down Expand Up @@ -331,7 +346,9 @@ bot.dom.isContentEditable = function(element) {
* @return {boolean} Whether the element accepts user-typed text.
*/
bot.dom.isEditable = function(element) {
return (bot.dom.isTextual(element) || bot.dom.isFileInput(element)) &&
return (bot.dom.isTextual(element) ||
bot.dom.isFileInput(element) ||
bot.dom.isInputType(element, 'range')) &&
!bot.dom.getProperty(element, 'readOnly');
};

Expand Down

0 comments on commit edbc914

Please sign in to comment.