// vim: et:ts=4:sw=4:sts=4:ft=js /*@ Ox.Input Input Element () -> Input Element (options) -> Input Element (options, self) -> Input Element options Options object arrows if true, and type is 'float' or 'integer', display arrows arrowStep step when clicking arrows autocomplete array of possible values, or function(key, value, callback), returns one or more values autocompleteReplace if true, value is replaced autocompleteReplaceCorrect if true, only valid values can be entered autocompleteSelect if true, menu is displayed autocompleteSelectHighlight if true, value in menu is highlighted autocompleteSelectSubmit if true, submit input on menu selection autocorrect ('email', 'float', 'integer', 'phone', 'url'), or regexp(value), or function(key, value, blur, callback), returns value autovalidate --remote validation-- clear if true, has clear button changeOnKeypress if true, fire change event while typing disabled if true, is disabled height px (for type='textarea' and type='range' with orientation='horizontal') id element id key to be passed to autocomplete and autovalidate functions max max value if type is 'integer' or 'float' min min value if type is 'integer' or 'float' name will be displayed by autovalidate function ('invalid ' + name) overlap '', 'left' or 'right', will cause padding and negative margin picker picker object rangeOptions range options arrows boolean, if true, display arrows //arrowStep number, step when clicking arrows //arrowSymbols array of two strings max number, maximum value min number, minimum value orientation 'horizontal' or 'vertical' step number, step thumbValue boolean, if true, value is displayed on thumb, or array of strings per value, or function(value), returns string thumbSize integer, px trackGradient string, css gradient for track trackImage string, image url, or array of image urls //trackStep number, 0 for 'scroll here', positive for step trackValues boolean serialize function used to serialize value in submit textAlign 'left', 'center' or 'right' type 'float', 'integer', 'password', 'text', 'textarea' value string validate remote validation width px change input changed event submit input submit event @*/ Ox.Input = function(options, self) { var self = self || {}, that = new Ox.Element({}, self) .defaults({ arrows: false, arrowStep: 1, autocomplete: null, autocompleteReplace: false, autocompleteReplaceCorrect: false, autocompleteSelect: false, autocompleteSelectHighlight: false, autocompleteSelectSubmit: false, autovalidate: null, changeOnKeypress: false, clear: false, disabled: false, key: '', min: 0, max: 100, label: '', labelWidth: 64, overlap: 'none', placeholder: '', serialize: null, style: 'rounded', textAlign: 'left', type: 'text', validate: null, value: '', width: 128 }) .options(options) .addClass( 'OxInput OxMedium Ox' + Ox.toTitleCase(self.options.style) /*+ ( self.options.overlap != 'none' ? ' OxOverlap' + Ox.toTitleCase(self.options.overlap) : '' )*/ ) .bindEvent($.extend(self.options.type == 'textarea' ? {} : { key_enter: submit }, { key_control_v: paste, key_escape: cancel })); if ( Ox.isArray(self.options.autocomplete) && self.options.autocompleteReplace && self.options.autocompleteReplaceCorrect && self.options.value === '' ) { self.options.value = self.options.autocomplete[0] } // fixme: set to min, not 0 if (self.options.type == 'float') { $.extend(self.options, { autovalidate: 'float', textAlign: 'right', value: self.options.value || '0.0' }); } else if (self.options.type == 'integer') { $.extend(self.options, { autovalidate: 'integer', textAlign: 'right', value: self.options.value || '0' }); } if (self.options.label) { self.$label = new Ox.Label({ overlap: 'right', textAlign: 'right', title: self.options.label, width: self.options.labelWidth }) .css({ float: 'left', // fixme: use css rule }) .click(function() { // fixme: ??? // that.focus(); }) .appendTo(that); } if (self.options.arrows) { self.arrows = []; self.arrows[0] = [ new Ox.Button({ overlap: 'right', title: 'left', type: 'image' }) .css({ float: 'left' }) .click(function() { clickArrow(0); }) .appendTo(that), new Ox.Button({ overlap: 'left', title: 'right', type: 'image' }) .css({ float: 'right' }) .click(function() { clickArrow(1); }) .appendTo(that) ] } $.extend(self, { bindKeyboard: self.options.autocomplete || self.options.autovalidate || self.options.changeOnKeypress, hasPasswordPlaceholder: self.options.type == 'password' && self.options.placeholder, inputWidth: getInputWidth() }); if (self.options.clear) { self.$button = new Ox.Button({ overlap: 'left', title: 'close', type: 'image' }) .css({ float: 'right' // fixme: use css rule }) .click(clear) .appendTo(that); } self.$input = $(self.options.type == 'textarea' ? '