| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/lang", |
| 4 |
"dojo/_base/window", |
| 5 |
"dijit/form/_SearchMixin", |
| 6 |
"dojox/mobile/TextBox", |
| 7 |
"dojo/dom-class", |
| 8 |
"dojo/keys", |
| 9 |
"dojo/touch", |
| 10 |
"dojo/on", |
| 11 |
"./sniff" |
| 12 |
], function(declare, lang, win, SearchMixin, TextBox, domClass, keys, touch, on, has){ |
| 13 |
|
| 14 |
return declare("dojox.mobile.SearchBox", [TextBox, SearchMixin], { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
baseClass: "mblTextBox mblSearchBox", |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
type: "search", |
| 26 |
|
| 27 |
placeHolder: "", |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
incremental: true, |
| 33 |
|
| 34 |
_setIncrementalAttr: function(val){ |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
this.incremental = val; |
| 40 |
}, |
| 41 |
|
| 42 |
_onInput: function(e){ |
| 43 |
|
| 44 |
|
| 45 |
if(e.charOrCode == keys.ENTER){ |
| 46 |
e.charOrCode = 229; |
| 47 |
}else if(!this.incremental){ |
| 48 |
e.charOrCode = 0; |
| 49 |
} |
| 50 |
this.inherited(arguments); |
| 51 |
}, |
| 52 |
|
| 53 |
postCreate: function(){ |
| 54 |
this.inherited(arguments); |
| 55 |
this.textbox.removeAttribute('incremental'); |
| 56 |
if(!this.textbox.hasAttribute('results')){ |
| 57 |
this.textbox.setAttribute('results', '0'); |
| 58 |
} |
| 59 |
if(has("ios") < 5){ |
| 60 |
domClass.add(this.domNode, 'iphone4'); |
| 61 |
this.connect(this.textbox, "onfocus", |
| 62 |
function(){ |
| 63 |
if(this.textbox.value !== ''){ |
| 64 |
this.defer( |
| 65 |
function(){ |
| 66 |
if(this.textbox.value === ''){ |
| 67 |
this._onInput({ charOrCode: keys.ENTER }); |
| 68 |
} |
| 69 |
} |
| 70 |
); |
| 71 |
} |
| 72 |
} |
| 73 |
); |
| 74 |
} |
| 75 |
this.connect(this.textbox, "onsearch", |
| 76 |
function(){ |
| 77 |
this._onInput({ charOrCode: keys.ENTER }); |
| 78 |
} |
| 79 |
); |
| 80 |
|
| 81 |
|
| 82 |
var _this = this; |
| 83 |
var touchStartX, touchStartY; |
| 84 |
var handleRelease; |
| 85 |
if(has("ios")){ |
| 86 |
this.on(touch.press, function(evt){ |
| 87 |
var rect; |
| 88 |
touchStartX = evt.touches ? evt.touches[0].pageX : evt.pageX; |
| 89 |
touchStartY = evt.touches ? evt.touches[0].pageY : evt.pageY; |
| 90 |
|
| 91 |
handleRelease = on(win.doc, touch.release, |
| 92 |
function(evt){ |
| 93 |
var rect, dx, dy; |
| 94 |
if(_this.get("value") != ""){ |
| 95 |
dx = evt.pageX - touchStartX; |
| 96 |
dy = evt.pageY - touchStartY; |
| 97 |
|
| 98 |
|
| 99 |
if(Math.abs(dx) <= 4 && Math.abs(dy) <= 4){ |
| 100 |
evt.preventDefault(); |
| 101 |
_this.set("value", ""); |
| 102 |
_this._onInput({ charOrCode: keys.ENTER }); |
| 103 |
} |
| 104 |
} |
| 105 |
if(handleRelease){ |
| 106 |
handleRelease.remove(); |
| 107 |
handleRelease = null; |
| 108 |
} |
| 109 |
} |
| 110 |
); |
| 111 |
rect = _this.domNode.getBoundingClientRect(); |
| 112 |
|
| 113 |
if(rect.right - (evt.touches ? evt.touches[0].pageX : evt.pageX) >= 30){ |
| 114 |
|
| 115 |
if(handleRelease){ |
| 116 |
handleRelease.remove(); |
| 117 |
handleRelease = null; |
| 118 |
} |
| 119 |
} |
| 120 |
}); |
| 121 |
} |
| 122 |
} |
| 123 |
}); |
| 124 |
}); |