123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- goog.provide('goog.ui.BidiInput');
- goog.require('goog.dom');
- goog.require('goog.dom.InputType');
- goog.require('goog.dom.TagName');
- goog.require('goog.events');
- goog.require('goog.events.InputHandler');
- goog.require('goog.i18n.bidi');
- goog.require('goog.ui.Component');
- goog.ui.BidiInput = function(opt_domHelper) {
- goog.ui.Component.call(this, opt_domHelper);
- };
- goog.inherits(goog.ui.BidiInput, goog.ui.Component);
- goog.tagUnsealableClass(goog.ui.BidiInput);
- goog.ui.BidiInput.prototype.inputHandler_ = null;
- goog.ui.BidiInput.prototype.decorateInternal = function(element) {
- goog.ui.BidiInput.superClass_.decorateInternal.call(this, element);
- this.init_();
- };
- goog.ui.BidiInput.prototype.createDom = function() {
- this.setElementInternal(
- this.getDomHelper().createDom(
- goog.dom.TagName.INPUT, {'type': goog.dom.InputType.TEXT}));
- this.init_();
- };
- goog.ui.BidiInput.prototype.init_ = function() {
-
- this.setDirection_();
-
- this.inputHandler_ = new goog.events.InputHandler(this.getElement());
- goog.events.listen(
- this.inputHandler_, goog.events.InputHandler.EventType.INPUT,
- this.setDirection_, false, this);
- };
- goog.ui.BidiInput.prototype.setDirection_ = function() {
- var element = this.getElement();
- if (element) {
- var text = this.getValue();
- goog.i18n.bidi.setElementDirByTextDirectionality(element, text);
- }
- };
- goog.ui.BidiInput.prototype.getDirection = function() {
- var dir = this.getElement().dir;
- if (dir == '') {
- dir = null;
- }
- return dir;
- };
- goog.ui.BidiInput.prototype.setValue = function(value) {
- var element = this.getElement();
- if (goog.isDefAndNotNull(element.value)) {
- element.value = value;
- } else {
- goog.dom.setTextContent(element, value);
- }
- this.setDirection_();
- };
- goog.ui.BidiInput.prototype.getValue = function() {
- var element = this.getElement();
- return goog.isDefAndNotNull(element.value) ?
- element.value :
- goog.dom.getRawTextContent(element);
- };
- goog.ui.BidiInput.prototype.disposeInternal = function() {
- if (this.inputHandler_) {
- goog.events.removeAll(this.inputHandler_);
- this.inputHandler_.dispose();
- this.inputHandler_ = null;
- goog.ui.BidiInput.superClass_.disposeInternal.call(this);
- }
- };
|