Skip to content

Commit

Permalink
Merge pull request #99 from rwatgg/develop
Browse files Browse the repository at this point in the history
when changing UserInput types, then apply focus/blur events again
  • Loading branch information
Felix Nielsen authored Mar 27, 2017
2 parents f73c716 + 20f6d26 commit 29cda68
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 71 deletions.
216 changes: 150 additions & 66 deletions dist/conversational-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ var cf;
}
}
else {
// tags are manually setup and passed as options.tags.
}
// remove invalid tags if they've sneaked in.. this could happen if tags are setup manually as we don't encurage to use static Tag.isTagValid
var indexesToRemove = [];
Expand Down Expand Up @@ -847,11 +848,16 @@ var cf;
/// <reference path="../../ConversationalForm.ts"/>
/// <reference path="../BasicElement.ts"/>
/// <reference path="../../form-tags/Tag.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand Down Expand Up @@ -2239,6 +2245,7 @@ var cf;
this.domElement.value = valueText;
}
else {
// throw new Error("cf-: value:string is not valid. Value: "+value);
}
return isValid;
};
Expand Down Expand Up @@ -2511,11 +2518,16 @@ var cf;
})(cf || (cf = {}));

/// <reference path="Tag.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand All @@ -2538,6 +2550,7 @@ var cf;
else if (_this.type == "password") {
}
else if (_this.type == "file") {
// check InputFileTag.ts
}
return _this;
}
Expand All @@ -2548,6 +2561,7 @@ var cf;
InputTag.prototype.findAndSetLabel = function () {
_super.prototype.findAndSetLabel.call(this);
if (!this._label) {
// special use cases for <input> tag add here...
}
};
InputTag.prototype.setTagValueAndIsValid = function (value) {
Expand All @@ -2568,11 +2582,16 @@ var cf;
})(cf || (cf = {}));

/// <reference path="Tag.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand All @@ -2592,6 +2611,7 @@ var cf;
_this.optionTags.push(tag);
}
else {
// console.warn((<any>this.constructor).name, 'option tag invalid:', tag);
}
}
return _this;
Expand Down Expand Up @@ -2657,11 +2677,16 @@ var cf;
})(cf || (cf = {}));

/// <reference path="Tag.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand All @@ -2674,6 +2699,7 @@ var cf;
if (_this.domElement.getAttribute("type") == "submit") {
}
else if (_this.domElement.getAttribute("type") == "button") {
// this.onClick = eval(this.domElement.onclick);
}
return _this;
}
Expand All @@ -2683,11 +2709,16 @@ var cf;
})(cf || (cf = {}));

/// <reference path="Tag.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand Down Expand Up @@ -2737,11 +2768,16 @@ var cf;
})(cf || (cf = {}));

/// <reference path="ControlElement.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand Down Expand Up @@ -2816,11 +2852,16 @@ var cf;
})(cf || (cf = {}));

/// <reference path="Button.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand Down Expand Up @@ -2869,11 +2910,16 @@ var cf;
})(cf || (cf = {}));

/// <reference path="Button.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand Down Expand Up @@ -2922,11 +2968,16 @@ var cf;
})(cf || (cf = {}));

/// <reference path="Button.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand Down Expand Up @@ -3082,11 +3133,16 @@ var cf;

/// <reference path="Button.ts"/>
/// <reference path="../../logic/Helpers.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand Down Expand Up @@ -3249,11 +3305,16 @@ var cf;
/// <reference path="BasicElement.ts"/>
/// <reference path="control-elements/ControlElements.ts"/>
/// <reference path="../logic/FlowManager.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand All @@ -3279,8 +3340,8 @@ var cf;
_this.eventTarget = options.eventTarget;
_this.inputElement = _this.el.getElementsByTagName("textarea")[0];
_this.onInputFocusCallback = _this.onInputFocus.bind(_this);
_this.inputElement.addEventListener('focus', _this.onInputFocusCallback, false);
_this.onInputBlurCallback = _this.onInputBlur.bind(_this);
_this.inputElement.addEventListener('focus', _this.onInputFocusCallback, false);
_this.inputElement.addEventListener('blur', _this.onInputBlurCallback, false);
//<cf-input-control-elements> is defined in the ChatList.ts
_this.controlElements = new cf.ControlElements({
Expand Down Expand Up @@ -3447,6 +3508,11 @@ var cf;
var currentType = this.inputElement.getAttribute("type");
var isCurrentInputTypeTextAreaButNewTagPassword = this._currentTag.type == "password" && currentType != "password";
var isCurrentInputTypeInputButNewTagNotPassword = this._currentTag.type != "password" && currentType == "password";
// remove focus and blur events, because we want to create a new element
if (this.inputElement && (isCurrentInputTypeTextAreaButNewTagPassword || isCurrentInputTypeInputButNewTagNotPassword)) {
this.inputElement.removeEventListener('focus', this.onInputFocusCallback, false);
this.inputElement.removeEventListener('blur', this.onInputBlurCallback, false);
}
if (isCurrentInputTypeTextAreaButNewTagPassword) {
// change to input
var input_1 = document.createElement("input");
Expand All @@ -3466,6 +3532,11 @@ var cf;
this.inputElement.parentNode.replaceChild(textarea_1, this.inputElement);
this.inputElement = textarea_1;
}
// add focus and blur events to newly created input element
if (this.inputElement && (isCurrentInputTypeTextAreaButNewTagPassword || isCurrentInputTypeInputButNewTagNotPassword)) {
this.inputElement.addEventListener('focus', this.onInputFocusCallback, false);
this.inputElement.addEventListener('blur', this.onInputBlurCallback, false);
}
if (this.initialInputHeight == 0) {
// initial height not set
this.initialInputHeight = this.inputElement.offsetHeight;
Expand Down Expand Up @@ -3727,11 +3798,16 @@ var cf;
/// <reference path="../BasicElement.ts"/>
/// <reference path="../../logic/Helpers.ts"/>
/// <reference path="../../ConversationalForm.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand Down Expand Up @@ -3846,6 +3922,8 @@ var cf;
// if robot, then check linked response for binding values
// one way data binding values:
innerResponse = innerResponse.split("{previous-answer}").join(this.responseLink.parsedResponse);
// add more..
// innerResponse = innerResponse.split("{...}").join(this.responseLink.parsedResponse);
}
// check if response contains an image as answer
var responseContains = innerResponse.indexOf("contains-image") != -1;
Expand Down Expand Up @@ -3925,11 +4003,16 @@ var cf;
/// <reference path="ChatResponse.ts"/>
/// <reference path="../BasicElement.ts"/>
/// <reference path="../../logic/FlowManager.ts"/>
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// namespace
var cf;
(function (cf) {
Expand Down Expand Up @@ -4104,6 +4187,7 @@ var cf;
setTimeout(function () { return scrollable_1.scrollTop = y_1; }, 100);
}
catch (e) {
// catch errors where CF have been removed
}
};
ChatList.prototype.getTemplate = function () {
Expand Down
Loading

0 comments on commit 29cda68

Please sign in to comment.