Ext.ux.InfoPanel.GoogleSearch extension class code:
1 // vim: ts=2:sw=2:nu:fdc=4:nospell
2 /**
3 * Ext.ux.InfoPanel Extension Class
4 *
5 * @author Ing. Jozef Sakalos
6 * @version $Id: Ext.ux.InfoPanel.GoogleSearch.js 65 2007-06-23 22:30:06Z jozo $
7 *
8 * @class Ext.ux.InfoPanel
9 * @extends Ext.ux.InfoPanel
10 * @constructor
11 * @cfg {String} searchBtnText text to display on search button (defaults to 'Search')
12 * @cfg {String} searchBtnIcon icon path to display on search button (defaults to null)
13 * @cfg {Integer} searchTextSize search text size (defaults to 25)
14 * @cfg {String/HTMLElement/Element} searchResultIframe iframe to display search results in (defaults to null)
15 */
16 Ext.ux.InfoPanel.GoogleSearch = function(el, config, content) {
17
18 if(Ext.isGecko) {
19 this.autoScroll = true;
20 }
21
22 // call parent constructor
23 Ext.ux.InfoPanel.GoogleSearch.superclass.constructor.call(this, el, config);
24
25 // create nicer Ext form
26 var gsForm = this.body.select('form').item(0);
27
28 // beautify search text input
29 var gsText = gsForm.select('input[type=text]').item(0);
30 gsText.addClass('x-form-text x-form-field');
31 gsText.dom.size = this.searchTextSize;
32 gsText.on('click', function(e) {e.stopEvent();});
33
34 // remove original google button
35 this.body.select('input[type=submit]').remove();
36
37 // create new nicer button
38 this.searchButton = new Ext.Button(gsForm, {
39 text: this.searchBtnText
40 , icon: this.searchBtnIcon
41 , cls: this.searchBtnIcon ? 'x-btn-text-icon' : null
42 , type: 'submit'
43 , scope: this
44 , handler: function() {
45
46 if(this.searchResultIframe) {
47 // disable submit
48 gsForm.dom.onsubmit = function() { return false };
49
50 // create google search URL
51 var inputs = gsForm.select('input');
52 var getPars = [];
53 inputs.each(function(el) {
54 if('radio' === el.dom.type && !el.dom.checked) {
55 return;
56 }
57 getPars.push(el.dom.name + '=' + encodeURIComponent(el.dom.value));
58 });
59 var gsURL = gsForm.dom.action + '?' + getPars.join('&');
60
61 // set iframe src attribute
62 Ext.get(this.searchResultIframe).dom.src = gsURL;
63 }
64 else {
65 gsForm.dom.submit();
66 }
67
68 } // end of handler
69 });
70 };
71
72 // extend
73 Ext.extend(Ext.ux.InfoPanel.GoogleSearch, Ext.ux.InfoPanel, {
74 // defaults
75 searchBtnText: 'Search'
76 , searchTextSize: 25
77 , searchBtnIcon: null
78 , searchResultIframe: null
79
80 });
81
82 // end of file