Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 21st, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // doesn't work: when keyboard is shown, back button hides keyboard. hitting back button again exits app w/o triggering this event
  2.  
  3.     $(document).on('backbutton', function () {
  4.       console.log('back pressed');
  5.      
  6.       if ($.mobile.activePage.find('.suggestions').children().length > 0) {
  7.         console.log('hide suggestions');
  8.         var $input = $.mobile.activePage.find('input');
  9.         $input.val('');
  10.         $input.autocomplete('clear');
  11.         return;
  12.       }
  13.  
  14.       if ($.mobile.urlHistory.activeIndex > 0) {
  15.         console.log('go back');
  16.         window.history.back();
  17.         return;
  18.       }
  19.  
  20.       console.log('exit app');
  21.       navigator.app.exitApp();
  22.     });
  23.  
  24. // better solution
  25.  
  26. $(window).resize(function () {
  27.   if ($.mobile.activePage) {
  28.     var $input = $.mobile.activePage.find('.search-form input');
  29.     $input.val('');
  30.     $input.autocomplete('clear');
  31.   }
  32. });