Created
March 26, 2017 20:26
-
-
Save Todai88/1005717d9fde8104826643254ac8a4b2 to your computer and use it in GitHub Desktop.
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
/// Index.js | |
"use strict"; | |
var app = { | |
// Application Constructor | |
initialize: function() { | |
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); | |
}, | |
// deviceready Event Handler | |
// | |
// Bind any cordova events here. Common events are: | |
// 'pause', 'resume', etc. | |
onDeviceReady: function() { | |
this.homePage(); | |
}, | |
homePage: function() { | |
var content = document.getElementsByClassName("app")[0]; | |
var html = "<h1 class='title'>Hello World</h1>"; | |
html += "<div class='main'>Hej och välkommen till min första Cordova app."; | |
html += "<button class='otherPage'>Nästa sida</button></div>"; | |
content.innerHTML = html; | |
var button = document.getElementsByClassName("otherPage")[0]; | |
app.addEventListeners(button, this.otherPage); | |
}, | |
otherPage: function() { | |
var title = document.getElementsByClassName("title")[0]; | |
var content = document.getElementsByClassName("main")[0]; | |
console.log("Other page"); | |
title.innerHTML = "Other page"; | |
var html = "Try an alert!<br>"; | |
html += "<button class='alertButton'>Alert</button>"; | |
content.innerHTML = html; | |
var button = document.getElementsByClassName("alertButton")[0]; | |
app.addEventListeners(button, function() { | |
window.alert("hej"); | |
}); | |
}, | |
addEventListeners: function(element, callback) { | |
element.addEventListener("touchend", function(event) { | |
event.preventDefault(); | |
callback(); | |
}); | |
element.addEventListener("click", callback); | |
} | |
}; | |
app.initialize(); | |
Contact GitHub API Training Shop Blog About | |
© 2017 GitHub, Inc. Terms Privacy Security Status Help | |
/// index.html | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;"> | |
<meta name="format-detection" content="telephone=no"> | |
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> | |
<link rel="stylesheet" type="text/css" href="css/index.css"> | |
<title>Hello World</title> | |
</head> | |
<body> | |
<div class="app"> | |
<p>App is loading. Hold on!</p> | |
</div> | |
<script type="text/javascript" src="cordova.js"></script> | |
<script type="text/javascript" src="js/index.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment