123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- /**
- * jQuery ligerUI 1.1.9
- *
- * http://ligerui.com
- *
- * Author daomi 2012 [ gd_star@163.com ]
- *
- */
- (function ($)
- {
- $.fn.ligerTextBox = function ()
- {
- return $.ligerui.run.call(this, "ligerTextBox", arguments);
- };
- $.fn.ligerGetTextBoxManager = function ()
- {
- return $.ligerui.run.call(this, "ligerGetTextBoxManager", arguments);
- };
- $.ligerDefaults.TextBox = {
- onChangeValue: null,
- width: null,
- disabled: false,
- value: null, //初始化值
- nullText: null, //不能为空时的提示
- digits: false, //是否限定为数字输入框
- number: false //是否限定为浮点数格式输入框
- };
- $.ligerui.controls.TextBox = function (element, options)
- {
- $.ligerui.controls.TextBox.base.constructor.call(this, element, options);
- };
- $.ligerui.controls.TextBox.ligerExtend($.ligerui.controls.Input, {
- __getType: function ()
- {
- return 'TextBox'
- },
- __idPrev: function ()
- {
- return 'TextBox';
- },
- _init: function ()
- {
- $.ligerui.controls.TextBox.base._init.call(this);
- var g = this, p = this.options;
- if (!p.width)
- {
- p.width = $(g.element).width();
- }
- if ($(this.element).attr("readonly"))
- {
- p.disabled = true;
- }
- },
- _render: function ()
- {
- var g = this, p = this.options;
- g.inputText = $(this.element);
- //外层
- g.wrapper = g.inputText.wrap('<div class="l-text"></div>').parent();
- g.wrapper.append('<div class="l-text-l"></div><div class="l-text-r"></div>');
- if (!g.inputText.hasClass("l-text-field"))
- g.inputText.addClass("l-text-field");
- this._setEvent();
- g.set(p);
- g.checkValue();
- },
- _getValue: function ()
- {
- return this.inputText.val();
- },
- _setNullText: function ()
- {
- this.checkNotNull();
- },
- checkValue: function ()
- {
- var g = this, p = this.options;
- var v = g.inputText.val();
- if (p.number && !/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(v) || p.digits && !/^\d+$/.test(v))
- {
- g.inputText.val(g.value || 0);
- return;
- }
- g.value = v;
- },
- checkNotNull: function ()
- {
- var g = this, p = this.options;
- if (p.nullText && !p.disabled)
- {
- if (!g.inputText.val())
- {
- g.inputText.addClass("l-text-field-null").val(p.nullText);
- }
- }
- },
- _setEvent: function ()
- {
- var g = this, p = this.options;
- g.inputText.bind('blur.textBox', function ()
- {
- g.trigger('blur');
- g.checkNotNull();
- g.checkValue();
- g.wrapper.removeClass("l-text-focus");
- }).bind('focus.textBox', function ()
- {
- g.trigger('focus');
- if (p.nullText)
- {
- if ($(this).hasClass("l-text-field-null"))
- {
- $(this).removeClass("l-text-field-null").val("");
- }
- }
- g.wrapper.addClass("l-text-focus");
- })
- .change(function ()
- {
- g.trigger('changeValue', [this.value]);
- });
- g.wrapper.hover(function ()
- {
- g.trigger('mouseOver');
- g.wrapper.addClass("l-text-over");
- }, function ()
- {
- g.trigger('mouseOut');
- g.wrapper.removeClass("l-text-over");
- });
- },
- _setDisabled: function (value)
- {
- if (value)
- {
- this.inputText.attr("readonly", "readonly");
- this.wrapper.addClass("l-text-disabled");
- }
- else
- {
- this.inputText.removeAttr("readonly");
- this.wrapper.removeClass('l-text-disabled');
- }
- },
- _setWidth: function (value)
- {
- if (value > 20)
- {
- this.wrapper.css({ width: value });
- this.inputText.css({ width: value - 4 });
- }
- },
- _setHeight: function (value)
- {
- if (value > 10)
- {
- this.wrapper.height(value);
- this.inputText.height(value - 2);
- }
- },
- _setValue: function (value)
- {
- if (value != null)
- this.inputText.val(value);
- },
- _setLabel: function (value)
- {
- var g = this, p = this.options;
- if (!g.labelwrapper)
- {
- g.labelwrapper = g.wrapper.wrap('<div class="l-labeltext"></div>').parent();
- var lable = $('<div class="l-text-label" style="float:left;">' + value + ': </div>');
- g.labelwrapper.prepend(lable);
- g.wrapper.css('float', 'left');
- if (!p.labelWidth)
- {
- p.labelWidth = lable.width();
- }
- else
- {
- g._setLabelWidth(p.labelWidth);
- }
- lable.height(g.wrapper.height());
- if (p.labelAlign)
- {
- g._setLabelAlign(p.labelAlign);
- }
- g.labelwrapper.append('<br style="clear:both;" />');
- g.labelwrapper.width(p.labelWidth + p.width + 2);
- }
- else
- {
- g.labelwrapper.find(".l-text-label").html(value + ': ');
- }
- },
- _setLabelWidth: function (value)
- {
- var g = this, p = this.options;
- if (!g.labelwrapper) return;
- g.labelwrapper.find(".l-text-label").width(value);
- },
- _setLabelAlign: function (value)
- {
- var g = this, p = this.options;
- if (!g.labelwrapper) return;
- g.labelwrapper.find(".l-text-label").css('text-align', value);
- },
- updateStyle: function ()
- {
- var g = this, p = this.options;
- if (g.inputText.attr('disabled') || g.inputText.attr('readonly'))
- {
- g.wrapper.addClass("l-text-disabled");
- g.options.disabled = true;
- }
- else
- {
- g.wrapper.removeClass("l-text-disabled");
- g.options.disabled = false;
- }
- if (g.inputText.hasClass("l-text-field-null") && g.inputText.val() != p.nullText)
- {
- g.inputText.removeClass("l-text-field-null");
- }
- g.checkValue();
- }
- });
- })(jQuery);
|