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 76 2007-06-28 11:35:41Z 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   // call parent constructor
   19   Ext.ux.InfoPanel.GoogleSearch.superclass.constructor.call(this, el, config);
   20 
   21   // create nicer Ext form
   22   var gsForm = this.body.select('form').item(0);
   23 
   24   // handle firefox cursor bug
   25   if(Ext.isGecko) {
   26     gsForm.setStyle('overflow', 'auto');
   27 
   28     this.on('beforeexpand', function() {
   29       gsForm.setStyle('overflow', 'hidden');
   30     });
   31 
   32     this.on('beforecollapse', function() {
   33       gsForm.setStyle('overflow', 'hidden');
   34     });
   35 
   36     this.on('animationcompleted', function() {
   37       gsForm.setStyle('overflow', 'auto');
   38     });
   39   }
   40 
   41 
   42   // beautify search text input
   43   var gsText = gsForm.select('input[type=text]').item(0);
   44   gsText.addClass('x-form-text x-form-field');
   45   gsText.dom.size = this.searchTextSize;
   46 //  gsText.on('click', function(e) {e.stopEvent();});
   47 
   48   // remove original google button
   49   this.body.select('input[type=submit]').remove();
   50 
   51   // create new nicer button
   52   this.searchButton = new Ext.Button(gsForm, {
   53     text: this.searchBtnText
   54     , icon: this.searchBtnIcon
   55     , cls: this.searchBtnIcon ? 'x-btn-text-icon' : null
   56     , type: 'submit'
   57     , scope: this
   58     , handler: function() {
   59 
   60       if(this.searchResultIframe) {
   61         // disable submit
   62         gsForm.dom.onsubmit = function() { return false };
   63 
   64         // create google search URL
   65         var inputs = gsForm.select('input');
   66         var getPars = [];
   67         inputs.each(function(el) {
   68           if('radio' === el.dom.type && !el.dom.checked) {
   69             return;
   70           }
   71           getPars.push(el.dom.name + '=' + encodeURIComponent(el.dom.value));
   72         });
   73         var gsURL = gsForm.dom.action + '?' + getPars.join('&');
   74 
   75         // set iframe src attribute
   76         Ext.get(this.searchResultIframe).dom.src = gsURL;
   77       }
   78       else {
   79         gsForm.dom.submit();
   80       }
   81 
   82     } // end of handler
   83   });
   84 };
   85 
   86 // extend
   87 Ext.extend(Ext.ux.InfoPanel.GoogleSearch, Ext.ux.InfoPanel, {
   88   // defaults
   89   searchBtnText: 'Search'
   90   , searchTextSize: 25
   91   , searchBtnIcon: null
   92   , searchResultIframe: null
   93 
   94 });
   95 
   96 // end of file