123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /*
- Copyright (c) 2013 Mapo developers and contributors <mapo.tizen@gmail.com>
- This file is part of Mapo.
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- var backEventListener = null;
- var unregister = function() {
- if ( backEventListener !== null ) {
- document.removeEventListener( 'tizenhwkey', backEventListener );
- backEventListener = null;
- window.tizen.application.getCurrentApplication().exit();
- }
- }
- //Initialize function
- var init = function () {
- // register once
- if ( backEventListener !== null ) {
- return;
- }
-
- // TODO:: Do your initialization job
- console.log("init() called");
-
- var backEvent = function(e) {
- if ( e.keyName == "back" ) {
- try {
- if ( $.mobile.urlHistory.activeIndex <= 0 ) {
- quit();
- // if first page, terminate app
- unregister();
- } else {
- // move previous page
- $.mobile.urlHistory.activeIndex -= 1;
- $.mobile.urlHistory.clearForward();
- window.history.back();
- }
- } catch( ex ) {
- unregister();
- }
- } else if ( e.keyName == "menu") {
- $.mobile.changePage("#settings");
- }
- }
-
- // add eventListener for tizenhwkey (Back Button)
- document.addEventListener( 'tizenhwkey', backEvent );
- backEventListener = backEvent;
-
- start();
- };
- $(document).bind( 'pageinit', init );
- $(document).unload( unregister );
|