Ox.Input = function(options, self) { /** options arrows boolearn, if true, and type is 'float' or 'integer', display arrows arrowStep number, step when clicking arrows autocomplete array of possible values, or function(key, value, callback), returns one or more values autocompleteReplace boolean, if true, value is replaced autocompleteReplaceCorrect boolean, if true, only valid values can be entered autocompleteSelect boolean, if true, menu is displayed autocompleteSelectHighlight boolean, if true, value in menu is highlighted autocompleteSelectSubmit boolean, if true, submit input on menu selection autocorrect string ('email', 'float', 'integer', 'phone', 'url'), or regexp(value), or function(key, value, blur, callback), returns value autovalidate --remote validation-- clear boolean, if true, has clear button disabled boolean, if true, is disabled height integer, px (for type='textarea' and type='range' with orientation='horizontal') id string, element id key string, to be passed to autocomplete and autovalidate functions max number, max value if type is 'integer' or 'float' min number, min value if type is 'integer' or 'float' name string, will be displayed by autovalidate function ('invalid ' + name) overlap string, '', 'left' or 'right', will cause padding and negative margin picker //rangeOptions 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 textAlign 'left', 'center' or 'right' type 'float', 'integer', 'password', 'text', 'textarea' value string validate function, remote validation width integer, px methods: events: change submit */ var self = self || {}, that = new Ox.Element('div', self) .defaults({ arrows: false, arrowStep: 1, autocomplete: null, autocompleteReplace: false, autocompleteReplaceCorrect: false, autocompleteSelect: false, autocompleteSelectHighlight: false, autocompleteSelectSubmit: false, autovalidate: null, 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, 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' ? '