Created
May 23, 2013 22:03
-
-
Save shazron/5639820 to your computer and use it in GitHub Desktop.
RequireJS with Cordova example (app.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requirejs(['cordova.js'], | |
function () { | |
// start of require | |
// cordova is now available globally | |
var exec = cordova.require('cordova/exec'); | |
var app = { | |
// Application Constructor | |
initialize: function() { | |
this.bindEvents(); | |
}, | |
// Bind Event Listeners | |
// | |
// Bind any events that are required on startup. Common events are: | |
// 'load', 'deviceready', 'offline', and 'online'. | |
bindEvents: function() { | |
document.addEventListener('deviceready', this.onDeviceReady, false); | |
}, | |
// deviceready Event Handler | |
// | |
// The scope of 'this' is the event. In order to call the 'receivedEvent' | |
// function, we must explicity call 'app.receivedEvent(...);' | |
onDeviceReady: function() { | |
app.receivedEvent('deviceready'); | |
}, | |
// Update DOM on a Received Event | |
receivedEvent: function(id) { | |
var parentElement = document.getElementById(id); | |
var listeningElement = parentElement.querySelector('.listening'); | |
var receivedElement = parentElement.querySelector('.received'); | |
listeningElement.setAttribute('style', 'display:none;'); | |
receivedElement.setAttribute('style', 'display:block;'); | |
console.log('Received Event: ' + id); | |
} | |
}; | |
app.initialize(); | |
// end of require | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying too... but not really easy.....
require.min.js:1 Uncaught Error: Mismatched anonymous define() module: function (){var define,module,e
I can't understand how can i load RequireJS, with my CommonJS(configs) after device is ready =/
Some can help me?