| 1 | /** |
|---|
| 2 | * Add a search bar to the player |
|---|
| 3 | **/ |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | import com.jeroenwijering.players.*; |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | class com.jeroenwijering.players.SearchView extends AbstractView { |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | /** Save the focus state (to capture enters) **/ |
|---|
| 13 | public static var focussed:Boolean = false; |
|---|
| 14 | |
|---|
| 15 | /** Constructor **/ |
|---|
| 16 | function SearchView(ctr:AbstractController,cfg:Object,fed:Object) { |
|---|
| 17 | super(ctr,cfg,fed); |
|---|
| 18 | Key.addListener(this); |
|---|
| 19 | setDimensions(); |
|---|
| 20 | }; |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | /** Setup the dimensions of the search bar **/ |
|---|
| 24 | private function setDimensions() { |
|---|
| 25 | var ref = this; |
|---|
| 26 | var tgt = config['clip'].search; |
|---|
| 27 | if(config["displayheight"] == config["height"] - config["searchbar"]) { |
|---|
| 28 | tgt._y = config['displayheight']; |
|---|
| 29 | } else { |
|---|
| 30 | tgt._y = config['displayheight'] + config['controlbar']; |
|---|
| 31 | } |
|---|
| 32 | tgt.ipt._width = config['width'] - 95; |
|---|
| 33 | tgt.ipt.onSetFocus = function() { |
|---|
| 34 | SearchView.focussed = true; |
|---|
| 35 | }; |
|---|
| 36 | tgt.ipt.onKillFocus = function() { |
|---|
| 37 | SearchView.focussed = false; |
|---|
| 38 | }; |
|---|
| 39 | tgt.bck._width = config['width']; |
|---|
| 40 | tgt.box._width = config['width'] - 95; |
|---|
| 41 | tgt.btn._x = config['width'] - 86; |
|---|
| 42 | tgt.btn.col = new Color(tgt.btn.icn); |
|---|
| 43 | tgt.btn.col.setRGB(config['frontcolor']); |
|---|
| 44 | tgt.btn.onRollOver = function() { |
|---|
| 45 | this.col.setRGB(ref.config['lightcolor']); |
|---|
| 46 | }; |
|---|
| 47 | tgt.btn.onRollOut = function() { |
|---|
| 48 | this.col.setRGB(ref.config['frontcolor']); |
|---|
| 49 | }; |
|---|
| 50 | tgt.btn.onRelease = function() { |
|---|
| 51 | ref.doSearch(); |
|---|
| 52 | } |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | /** start the search function **/ |
|---|
| 57 | private function doSearch() { |
|---|
| 58 | var txt = escape(config['clip'].search.ipt.text); |
|---|
| 59 | getURL(config['searchlink']+txt,config['linktarget']); |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | /** KeyDown handler, forwarded by Key object **/ |
|---|
| 64 | public function onKeyDown() { |
|---|
| 65 | if(Key.getCode() == 13 && SearchView.focussed == true) { doSearch(); } |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | } |
|---|