Skip to content
This repository has been archived by the owner on Mar 19, 2023. It is now read-only.

Clear out the search box when tab switching #12

Open
GoogleCodeExporter opened this issue Mar 15, 2015 · 0 comments
Open

Clear out the search box when tab switching #12

GoogleCodeExporter opened this issue Mar 15, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

From an email:

I've made a local modification to SearchBox Sync that I think would be useful 
in the mainstream 
version.  I modified the code to _clear_ the search box when switching to a tab 
that does not 
have search information.  The current version you provide leaves the search box 
populated with 
information not relevant to the active tab.  This modification clears that 
information out.  It's a 
relatively minor change to the update method.  It can certainly be done much 
more cleanly than 
this but this was the proof of concept I wrote and it works well enough.  The 
new version of 
update is below:

 this.update = function(aUrl) {
   if (!this.searchbox) {
     return;
   }

   var empty = true;
   var rules = searchboxsync.RuleService.rules;
   if (rules != null) {
     for (var i = 0; i < rules.length; i++) {
       if (rules[i].disabled == true) {
         continue;
       }

       var regex = searchboxsync.RuleService.makeUrlRegex(rules[i]);
       if (regex == null) {
         continue;
       }

       var terms = searchboxsync.Util.extractTerms(regex, aUrl);
       if (terms && terms != "") {
         this.searchbar.removeAttribute("empty");
         this.searchbox.value = terms;

         var evt = document.createEvent("Events");
         evt.initEvent("oninput", true, true);
         this.searchbar.dispatchEvent(evt);

         empty = false;
         break;
       }
     }
   }
   if (empty == true)
   {
       if (this.searchbox.value != "")
       {
           this.searchbox.value = "";

           var evt = document.createEvent("Events");
           evt.initEvent("oninput", true, true);
           this.searchbar.dispatchEvent(evt);
       }
   }
 }

Original issue reported on code.google.com by legege on 31 Jul 2009 at 2:15

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant