Input: submit when doubleclicking clear button; + some reformatting

This commit is contained in:
rlx 2012-06-16 13:36:03 +00:00
parent 7c7f97066e
commit 77f0c762a3

View file

@ -252,7 +252,10 @@ Ox.Input = function(options, self) {
.css({ .css({
float: 'right' // fixme: use css rule float: 'right' // fixme: use css rule
}) })
.click(clear) .bindEvent({
click: clear,
doubleclick: submit
})
.appendTo(that); .appendTo(that);
} }
@ -641,9 +644,7 @@ Ox.Input = function(options, self) {
self.options.validate && validate(); self.options.validate && validate();
self.bindKeyboard && Ox.UI.$document.off('keydown', keydown); self.bindKeyboard && Ox.UI.$document.off('keydown', keydown);
if (!self.cancelled && !self.submitted) { if (!self.cancelled && !self.submitted) {
that.triggerEvent('blur', { that.triggerEvent('blur', {value: self.options.value});
value: self.options.value
});
self.options.value !== self.originalValue && that.triggerEvent('change', { self.options.value !== self.originalValue && that.triggerEvent('change', {
value: self.options.value value: self.options.value
}); });
@ -679,18 +680,21 @@ Ox.Input = function(options, self) {
function clear() { function clear() {
// fixme: set to min, not zero // fixme: set to min, not zero
// fixme: make this work for password // fixme: make this work for password
if (!self.clearTimeout) {
that.triggerEvent('clear'); that.triggerEvent('clear');
self.options.value = ''; self.options.value = '';
if (self.options.type == 'float') { self.options.value = self.options.type == 'float' ? '0.0'
self.options.value = '0.0'; : self.options.type == 'int' ? '0'
} else if (self.options.type == 'int') { : '';
self.options.value = '0'
}
self.$input.val(self.options.value); self.$input.val(self.options.value);
cursor(0, self.options.value.length); cursor(0, self.options.value.length);
self.options.changeOnKeypress && that.triggerEvent({ self.options.changeOnKeypress && that.triggerEvent({
change: {value: self.options.value} change: {value: self.options.value}
}); });
self.clearTimeout = setTimeout(function() {
self.clearTimeout = 0;
}, 500);
}
} }
function clickArrow(i) { function clickArrow(i) {
@ -785,8 +789,9 @@ Ox.Input = function(options, self) {
var oldCursor = cursor(), var oldCursor = cursor(),
oldValue = self.options.value, oldValue = self.options.value,
newValue = oldValue.toString().slice(0, oldCursor[0] - 1), newValue = oldValue.toString().slice(0, oldCursor[0] - 1),
hasDeletedSelectedEnd = (event.keyCode == 8 || event.keyCode == 46) && hasDeletedSelectedEnd = (event.keyCode == 8 || event.keyCode == 46)
oldCursor[0] < oldCursor[1] && oldCursor[1] == oldValue.length; && oldCursor[0] < oldCursor[1]
&& oldCursor[1] == oldValue.length;
if ( if (
event.keyCode != 9 // tab event.keyCode != 9 // tab
&& (self.options.type == 'textarea' || event.keyCode != 13) // enter && (self.options.type == 'textarea' || event.keyCode != 13) // enter
@ -883,9 +888,7 @@ Ox.Input = function(options, self) {
self.$input.blur(); self.$input.blur();
self.submitted = false; self.submitted = false;
//self.options.type == 'textarea' && self.$input.blur(); //self.options.type == 'textarea' && self.$input.blur();
that.triggerEvent('submit', { that.triggerEvent('submit', {value: self.options.value});
value: self.options.value
});
} }
function validate() { function validate() {