este-library-oldschool
Version:
Library for github.com/steida/este.git
110 lines (99 loc) • 2.87 kB
JavaScript
// Generated by github.com/steida/coffee2closure 900.1.18
/**
@fileoverview este.ui.FieldReset.
*/
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.superClass_ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
goog.provide('este.ui.FieldReset');
goog.require('este.mobile');
goog.require('goog.dom.classlist');
goog.require('goog.events.InputHandler');
goog.require('goog.string');
goog.require('este.ui.Component');
/**
@param {Element} element
@constructor
@extends {este.ui.Component}
*/
este.ui.FieldReset = function(element) {
this.inputHandler = new goog.events.InputHandler(element);
this.resetBtn = goog.dom.createDom('div', 'e-ui-fieldreset');
this.resetBtn.setAttribute('touch-action', 'none');
this.decorate(element);
}
extend(este.ui.FieldReset, superClass);
/**
@type {string}
*/
este.ui.FieldReset.CLASS_NAME = 'e-ui-fieldreset-empty';
/**
@enum {string}
*/
este.ui.FieldReset.EventType = {
INPUT: 'input'
};
/**
@type {goog.events.InputHandler}
@protected
*/
este.ui.FieldReset.prototype.inputHandler = null;
/**
@type {Element}
@protected
*/
este.ui.FieldReset.prototype.resetBtn = null;
/**
@override
*/
este.ui.FieldReset.prototype.enterDocument = function() {
este.ui.FieldReset.superClass_.enterDocument.call(this);
this.on(this.inputHandler, 'input', this.onInputHandlerInput);
this.on('.e-ui-fieldreset', 'tap', this.onResetBtnTap);
this.update();
};
/**
@override
*/
este.ui.FieldReset.prototype.canDecorate = function(element) {
var ref;
return (ref = element.tagName) === 'INPUT' || ref === 'TEXTAREA';
};
/**
@param {goog.events.BrowserEvent} e
@protected
*/
este.ui.FieldReset.prototype.onInputHandlerInput = function(e) {
this.update();
return this.dispatchEvent(este.ui.FieldReset.EventType.INPUT);
};
/**
@param {goog.events.BrowserEvent} e
@protected
*/
este.ui.FieldReset.prototype.onResetBtnTap = function(e) {
e.preventDefault();
this.getElement().value = '';
this.update();
this.getElement().focus();
return this.dispatchEvent(este.ui.FieldReset.EventType.INPUT);
};
/**
@protected
*/
este.ui.FieldReset.prototype.update = function() {
var isEmpty;
isEmpty = !goog.string.trim(this.getElement().value).length;
goog.dom.classlist.enable(this.getElement(), este.ui.FieldReset.CLASS_NAME, isEmpty);
if (isEmpty) {
return goog.dom.removeNode(this.resetBtn);
} else {
return goog.dom.insertSiblingAfter(this.resetBtn, this.getElement());
}
};
/**
@override
*/
este.ui.FieldReset.prototype.disposeInternal = function() {
this.inputHandler.dispose();
este.ui.FieldReset.superClass_.disposeInternal.call(this);
};