Navigation Menu

Skip to content

Commit

Permalink
changing JS invoked from native to work with modular js
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil Maj authored and infil00p committed Feb 20, 2012
1 parent 390fe53 commit 8a13739
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion framework/src/org/apache/cordova/CordovaWebViewClient.java
Expand Up @@ -218,7 +218,7 @@ public void onPageFinished(WebView view, String url) {
// not loaded yet then just set a flag so that the onNativeReady can be fired
// from the JS side when the JS gets to that code.
if (!url.equals("about:blank")) {
ctx.appView.loadUrl("javascript:try{ Cordova.onNativeReady.fire();}catch(e){_nativeReady = true;}");
ctx.appView.loadUrl("javascript:try{ require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}");
}

// Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly
Expand Down
12 changes: 6 additions & 6 deletions framework/src/org/apache/cordova/DroidGap.java
Expand Up @@ -849,7 +849,7 @@ protected void onPause() {
}

// Send pause event to JavaScript
this.appView.loadUrl("javascript:try{Cordova.fireDocumentEvent('pause');}catch(e){};");
this.appView.loadUrl("javascript:try{require('cordova/channel').onPause.fire();}catch(e){console.log('exception firing pause event from native');};");

// Forward to plugins
this.pluginManager.onPause(this.keepRunning);
Expand Down Expand Up @@ -890,7 +890,7 @@ protected void onResume() {
}

// Send resume event to JavaScript
this.appView.loadUrl("javascript:try{Cordova.fireDocumentEvent('resume');}catch(e){};");
this.appView.loadUrl("javascript:try{require('cordova/channel').onResume.fire();}catch(e){console.log('exception firing resume event from native');};");

// Forward to plugins
this.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning);
Expand Down Expand Up @@ -920,7 +920,7 @@ public void onDestroy() {


// Send destroy event to JavaScript
this.appView.loadUrl("javascript:try{Cordova.onDestroy.fire();}catch(e){};");
this.appView.loadUrl("javascript:try{require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");

// Load blank page so that JavaScript onunload is called
this.appView.loadUrl("about:blank");
Expand Down Expand Up @@ -1082,7 +1082,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {

// If back key is bound, then send event to JavaScript
if (this.bound) {
this.appView.loadUrl("javascript:Cordova.fireDocumentEvent('backbutton');");
this.appView.loadUrl("javascript:require('cordova').fireDocumentEvent('backbutton');");
return true;
}

Expand All @@ -1104,13 +1104,13 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {

// If menu key
else if (keyCode == KeyEvent.KEYCODE_MENU) {
this.appView.loadUrl("javascript:Cordova.fireDocumentEvent('menubutton');");
this.appView.loadUrl("javascript:require('cordova').fireDocumentEvent('menubutton');");
return super.onKeyDown(keyCode, event);
}

// If search key
else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
this.appView.loadUrl("javascript:Cordova.fireDocumentEvent('searchbutton');");
this.appView.loadUrl("javascript:require('cordova').fireDocumentEvent('searchbutton');");
return true;
}

Expand Down

0 comments on commit 8a13739

Please sign in to comment.