--- /dev/null
+<html>\r
+<head>\r
+ <title>The source code</title>\r
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
+</head>\r
+<body onload="prettyPrint();">\r
+ <pre class="prettyprint lang-js"><div id="method-Ext.ux.form.DateTime-SelectBox"></div>/**\r
+ * Makes a ComboBox more closely mimic an HTML SELECT. Supports clicking and dragging\r
+ * through the list, with item selection occurring when the mouse button is released.\r
+ * When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}\r
+ * on inner elements. Re-enabling editable after calling this will NOT work.\r
+ *\r
+ * @author Corey Gilmore\r
+ * http://extjs.com/forum/showthread.php?t=6392\r
+ *\r
+ * @history 2007-07-08 jvs\r
+ * Slight mods for Ext 2.0\r
+ */\r
+Ext.ux.SelectBox = function(config){\r
+ this.searchResetDelay = 1000;\r
+ config = config || {};\r
+ config = Ext.apply(config || {}, {\r
+ editable: false,\r
+ forceSelection: true,\r
+ rowHeight: false,\r
+ lastSearchTerm: false,\r
+ triggerAction: 'all',\r
+ mode: 'local'\r
+ });\r
+\r
+ Ext.ux.SelectBox.superclass.constructor.apply(this, arguments);\r
+\r
+ this.lastSelectedIndex = this.selectedIndex || 0;\r
+};\r
+\r
+Ext.extend(Ext.ux.SelectBox, Ext.form.ComboBox, {\r
+ lazyInit: false,\r
+ initEvents : function(){\r
+ Ext.ux.SelectBox.superclass.initEvents.apply(this, arguments);\r
+ // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE\r
+ this.el.on('keydown', this.keySearch, this, true);\r
+ this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);\r
+ },\r
+\r
+ keySearch : function(e, target, options) {\r
+ var raw = e.getKey();\r
+ var key = String.fromCharCode(raw);\r
+ var startIndex = 0;\r
+\r
+ if( !this.store.getCount() ) {\r
+ return;\r
+ }\r
+\r
+ switch(raw) {\r
+ case Ext.EventObject.HOME:\r
+ e.stopEvent();\r
+ this.selectFirst();\r
+ return;\r
+\r
+ case Ext.EventObject.END:\r
+ e.stopEvent();\r
+ this.selectLast();\r
+ return;\r
+\r
+ case Ext.EventObject.PAGEDOWN:\r
+ this.selectNextPage();\r
+ e.stopEvent();\r
+ return;\r
+\r
+ case Ext.EventObject.PAGEUP:\r
+ this.selectPrevPage();\r
+ e.stopEvent();\r
+ return;\r
+ }\r
+\r
+ // skip special keys other than the shift key\r
+ if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {\r
+ return;\r
+ }\r
+ if( this.lastSearchTerm == key ) {\r
+ startIndex = this.lastSelectedIndex;\r
+ }\r
+ this.search(this.displayField, key, startIndex);\r
+ this.cshTask.delay(this.searchResetDelay);\r
+ },\r
+\r
+ onRender : function(ct, position) {\r
+ this.store.on('load', this.calcRowsPerPage, this);\r
+ Ext.ux.SelectBox.superclass.onRender.apply(this, arguments);\r
+ if( this.mode == 'local' ) {\r
+ this.calcRowsPerPage();\r
+ }\r
+ },\r
+\r
+ onSelect : function(record, index, skipCollapse){\r
+ if(this.fireEvent('beforeselect', this, record, index) !== false){\r
+ this.setValue(record.data[this.valueField || this.displayField]);\r
+ if( !skipCollapse ) {\r
+ this.collapse();\r
+ }\r
+ this.lastSelectedIndex = index + 1;\r
+ this.fireEvent('select', this, record, index);\r
+ }\r
+ },\r
+\r
+ render : function(ct) {\r
+ Ext.ux.SelectBox.superclass.render.apply(this, arguments);\r
+ if( Ext.isSafari ) {\r
+ this.el.swallowEvent('mousedown', true);\r
+ }\r
+ this.el.unselectable();\r
+ this.innerList.unselectable();\r
+ this.trigger.unselectable();\r
+ this.innerList.on('mouseup', function(e, target, options) {\r
+ if( target.id && target.id == this.innerList.id ) {\r
+ return;\r
+ }\r
+ this.onViewClick();\r
+ }, this);\r
+\r
+ this.innerList.on('mouseover', function(e, target, options) {\r
+ if( target.id && target.id == this.innerList.id ) {\r
+ return;\r
+ }\r
+ this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;\r
+ this.cshTask.delay(this.searchResetDelay);\r
+ }, this);\r
+\r
+ this.trigger.un('click', this.onTriggerClick, this);\r
+ this.trigger.on('mousedown', function(e, target, options) {\r
+ e.preventDefault();\r
+ this.onTriggerClick();\r
+ }, this);\r
+\r
+ this.on('collapse', function(e, target, options) {\r
+ Ext.getDoc().un('mouseup', this.collapseIf, this);\r
+ }, this, true);\r
+\r
+ this.on('expand', function(e, target, options) {\r
+ Ext.getDoc().on('mouseup', this.collapseIf, this);\r
+ }, this, true);\r
+ },\r
+\r
+ clearSearchHistory : function() {\r
+ this.lastSelectedIndex = 0;\r
+ this.lastSearchTerm = false;\r
+ },\r
+\r
+ selectFirst : function() {\r
+ this.focusAndSelect(this.store.data.first());\r
+ },\r
+\r
+ selectLast : function() {\r
+ this.focusAndSelect(this.store.data.last());\r
+ },\r
+\r
+ selectPrevPage : function() {\r
+ if( !this.rowHeight ) {\r
+ return;\r
+ }\r
+ var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);\r
+ this.focusAndSelect(this.store.getAt(index));\r
+ },\r
+\r
+ selectNextPage : function() {\r
+ if( !this.rowHeight ) {\r
+ return;\r
+ }\r
+ var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);\r
+ this.focusAndSelect(this.store.getAt(index));\r
+ },\r
+\r
+ search : function(field, value, startIndex) {\r
+ field = field || this.displayField;\r
+ this.lastSearchTerm = value;\r
+ var index = this.store.find.apply(this.store, arguments);\r
+ if( index !== -1 ) {\r
+ this.focusAndSelect(index);\r
+ }\r
+ },\r
+\r
+ focusAndSelect : function(record) {\r
+ var index = typeof record === 'number' ? record : this.store.indexOf(record);\r
+ this.select(index, this.isExpanded());\r
+ this.onSelect(this.store.getAt(record), index, this.isExpanded());\r
+ },\r
+\r
+ calcRowsPerPage : function() {\r
+ if( this.store.getCount() ) {\r
+ this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();\r
+ this.rowsPerPage = this.maxHeight / this.rowHeight;\r
+ } else {\r
+ this.rowHeight = false;\r
+ }\r
+ }\r
+\r
+});</pre> \r
+</body>\r
+</html>
\ No newline at end of file