a zip code crypto-currency system good for red ONLY

base-input.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. (function (factory) {
  12. if (typeof module === "object" && typeof module.exports === "object") {
  13. var v = factory(require, exports);
  14. if (v !== undefined) module.exports = v;
  15. }
  16. else if (typeof define === "function" && define.amd) {
  17. define(["require", "exports", "@angular/core", "./util", "../components/ion", "./debouncer"], factory);
  18. }
  19. })(function (require, exports) {
  20. "use strict";
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. var core_1 = require("@angular/core");
  23. var util_1 = require("./util");
  24. var ion_1 = require("../components/ion");
  25. var debouncer_1 = require("./debouncer");
  26. var BaseInput = (function (_super) {
  27. __extends(BaseInput, _super);
  28. function BaseInput(config, elementRef, renderer, name, _defaultValue, _form, _item, _ngControl) {
  29. var _this = _super.call(this, config, elementRef, renderer, name) || this;
  30. _this._defaultValue = _defaultValue;
  31. _this._form = _form;
  32. _this._item = _item;
  33. _this._ngControl = _ngControl;
  34. _this._isFocus = false;
  35. _this._disabled = false;
  36. _this._debouncer = new debouncer_1.TimeoutDebouncer(0);
  37. _this._init = false;
  38. _this._initModel = false;
  39. /**
  40. * @output {Range} Emitted when the range selector drag starts.
  41. */
  42. _this.ionFocus = new core_1.EventEmitter();
  43. /**
  44. * @output {Range} Emitted when the range value changes.
  45. */
  46. _this.ionChange = new core_1.EventEmitter();
  47. /**
  48. * @output {Range} Emitted when the range selector drag ends.
  49. */
  50. _this.ionBlur = new core_1.EventEmitter();
  51. _form && _form.register(_this);
  52. _this._value = util_1.deepCopy(_this._defaultValue);
  53. if (_item) {
  54. (void 0) /* assert */;
  55. _this.id = name + '-' + _item.registerInput(name);
  56. _this._labelId = _item.labelId;
  57. _this._item.setElementClass('item-' + name, true);
  58. }
  59. // If the user passed a ngControl we need to set the valueAccessor
  60. if (_ngControl) {
  61. _ngControl.valueAccessor = _this;
  62. }
  63. return _this;
  64. }
  65. Object.defineProperty(BaseInput.prototype, "disabled", {
  66. /**
  67. * @input {boolean} If true, the user cannot interact with this element.
  68. */
  69. get: function () {
  70. return this._disabled;
  71. },
  72. set: function (val) {
  73. this.setDisabledState(val);
  74. },
  75. enumerable: true,
  76. configurable: true
  77. });
  78. Object.defineProperty(BaseInput.prototype, "value", {
  79. get: function () {
  80. return this._value;
  81. },
  82. set: function (val) {
  83. if (this._writeValue(val)) {
  84. this.onChange();
  85. this._fireIonChange();
  86. }
  87. },
  88. enumerable: true,
  89. configurable: true
  90. });
  91. // 1. Updates the value
  92. // 2. Calls _inputUpdated()
  93. // 3. Dispatch onChange events
  94. BaseInput.prototype.setValue = function (val) {
  95. this.value = val;
  96. };
  97. /**
  98. * @hidden
  99. */
  100. BaseInput.prototype.setDisabledState = function (isDisabled) {
  101. this._disabled = isDisabled = util_1.isTrueProperty(isDisabled);
  102. this._item && this._item.setElementClass("item-" + this._componentName + "-disabled", isDisabled);
  103. };
  104. /**
  105. * @hidden
  106. */
  107. BaseInput.prototype.writeValue = function (val) {
  108. if (this._writeValue(val)) {
  109. if (this._initModel) {
  110. this._fireIonChange();
  111. }
  112. else if (this._init) {
  113. // ngModel fires the first time too late, we need to skip the first ngModel update
  114. this._initModel = true;
  115. }
  116. }
  117. };
  118. /**
  119. * @hidden
  120. */
  121. BaseInput.prototype._writeValue = function (val) {
  122. (void 0) /* assert */;
  123. if (util_1.isUndefined(val)) {
  124. return false;
  125. }
  126. var normalized = (val === null)
  127. ? util_1.deepCopy(this._defaultValue)
  128. : this._inputNormalize(val);
  129. var notUpdate = util_1.isUndefined(normalized) || !this._inputShouldChange(normalized);
  130. if (notUpdate) {
  131. return false;
  132. }
  133. (void 0) /* console.debug */;
  134. this._value = normalized;
  135. if (this._init) {
  136. this._inputUpdated();
  137. }
  138. return true;
  139. };
  140. /**
  141. * @hidden
  142. */
  143. BaseInput.prototype._fireIonChange = function () {
  144. var _this = this;
  145. if (this._init) {
  146. this._debouncer.debounce(function () {
  147. (void 0) /* assert */;
  148. _this.ionChange.emit(_this._inputChangeEvent());
  149. _this._initModel = true;
  150. });
  151. }
  152. };
  153. /**
  154. * @hidden
  155. */
  156. BaseInput.prototype.registerOnChange = function (fn) {
  157. this._onChanged = fn;
  158. };
  159. /**
  160. * @hidden
  161. */
  162. BaseInput.prototype.registerOnTouched = function (fn) {
  163. this._onTouched = fn;
  164. };
  165. /**
  166. * @hidden
  167. */
  168. BaseInput.prototype._initialize = function () {
  169. if (this._init) {
  170. (void 0) /* assert */;
  171. return;
  172. }
  173. this._init = true;
  174. if (util_1.isPresent(this._value)) {
  175. this._inputUpdated();
  176. }
  177. };
  178. /**
  179. * @hidden
  180. */
  181. BaseInput.prototype._fireFocus = function () {
  182. if (this._isFocus) {
  183. return;
  184. }
  185. (void 0) /* console.debug */;
  186. this._form && this._form.setAsFocused(this);
  187. this._setFocus(true);
  188. this.ionFocus.emit(this);
  189. };
  190. /**
  191. * @hidden
  192. */
  193. BaseInput.prototype._fireBlur = function () {
  194. if (!this._isFocus) {
  195. return;
  196. }
  197. (void 0) /* console.debug */;
  198. this._form && this._form.unsetAsFocused(this);
  199. this._setFocus(false);
  200. this._fireTouched();
  201. this.ionBlur.emit(this);
  202. };
  203. /**
  204. * @hidden
  205. */
  206. BaseInput.prototype._fireTouched = function () {
  207. this._onTouched && this._onTouched();
  208. };
  209. /**
  210. * @hidden
  211. */
  212. BaseInput.prototype._setFocus = function (isFocused) {
  213. (void 0) /* assert */;
  214. (void 0) /* assert */;
  215. (void 0) /* assert */;
  216. this._isFocus = isFocused;
  217. var item = this._item;
  218. if (item) {
  219. item.setElementClass('input-has-focus', isFocused);
  220. item.setElementClass('item-input-has-focus', isFocused);
  221. }
  222. this._inputUpdated();
  223. };
  224. /**
  225. * @hidden
  226. */
  227. BaseInput.prototype.onChange = function () {
  228. this._onChanged && this._onChanged(this._inputNgModelEvent());
  229. };
  230. /**
  231. * @hidden
  232. */
  233. BaseInput.prototype.isFocus = function () {
  234. return this._isFocus;
  235. };
  236. /**
  237. * @hidden
  238. */
  239. BaseInput.prototype.hasValue = function () {
  240. var val = this._value;
  241. if (!util_1.isPresent(val)) {
  242. return false;
  243. }
  244. if (util_1.isArray(val) || util_1.isString(val)) {
  245. return val.length > 0;
  246. }
  247. return true;
  248. };
  249. /**
  250. * @hidden
  251. */
  252. BaseInput.prototype.focusNext = function () {
  253. this._form && this._form.tabFocus(this);
  254. };
  255. /**
  256. * @hidden
  257. */
  258. BaseInput.prototype.ngOnDestroy = function () {
  259. (void 0) /* assert */;
  260. var form = this._form;
  261. form && form.deregister(this);
  262. this._init = false;
  263. };
  264. /**
  265. * @hidden
  266. */
  267. BaseInput.prototype.ngAfterContentInit = function () {
  268. this._initialize();
  269. };
  270. /**
  271. * @hidden
  272. */
  273. BaseInput.prototype.initFocus = function () {
  274. var ele = this._elementRef.nativeElement.querySelector('button');
  275. ele && ele.focus();
  276. };
  277. /**
  278. * @hidden
  279. */
  280. BaseInput.prototype._inputNormalize = function (val) {
  281. return val;
  282. };
  283. /**
  284. * @hidden
  285. */
  286. BaseInput.prototype._inputShouldChange = function (val) {
  287. return this._value !== val;
  288. };
  289. /**
  290. * @hidden
  291. */
  292. BaseInput.prototype._inputChangeEvent = function () {
  293. return this;
  294. };
  295. /**
  296. * @hidden
  297. */
  298. BaseInput.prototype._inputNgModelEvent = function () {
  299. return this._value;
  300. };
  301. /**
  302. * @hidden
  303. */
  304. BaseInput.prototype._inputUpdated = function () {
  305. (void 0) /* assert */;
  306. var item = this._item;
  307. if (item) {
  308. setControlCss(item, this._ngControl);
  309. // TODO remove all uses of input-has-value in v4
  310. var hasValue = this.hasValue();
  311. item.setElementClass('input-has-value', hasValue);
  312. item.setElementClass('item-input-has-value', hasValue);
  313. }
  314. };
  315. BaseInput.propDecorators = {
  316. 'ionFocus': [{ type: core_1.Output },],
  317. 'ionChange': [{ type: core_1.Output },],
  318. 'ionBlur': [{ type: core_1.Output },],
  319. 'disabled': [{ type: core_1.Input },],
  320. };
  321. return BaseInput;
  322. }(ion_1.Ion));
  323. exports.BaseInput = BaseInput;
  324. function setControlCss(element, control) {
  325. if (!control) {
  326. return;
  327. }
  328. element.setElementClass('ng-untouched', control.untouched);
  329. element.setElementClass('ng-touched', control.touched);
  330. element.setElementClass('ng-pristine', control.pristine);
  331. element.setElementClass('ng-dirty', control.dirty);
  332. element.setElementClass('ng-valid', control.valid);
  333. element.setElementClass('ng-invalid', !control.valid);
  334. }
  335. });
  336. //# sourceMappingURL=base-input.js.map