Skip to content

Instantly share code, notes, and snippets.

@rjcorwin
Created March 8, 2018 17:45
Show Gist options
  • Save rjcorwin/673a003ae18a07dcab2e76bac36ebd45 to your computer and use it in GitHub Desktop.
Save rjcorwin/673a003ae18a07dcab2e76bac36ebd45 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
Some notes:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<!--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="viewport" content="width=device-width, initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="width=device-width, initial-scale=.5, maximum-scale=12.0, minimum-scale=.25, user-scalable=yes"/>
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
<style>
select {
font-size: 30px;
}
body {
font-size: 30px;
}
</style>
<script type="text/javascript" src="cordova.js"></script>
<script>
document.addEventListener('deviceready', onDeviceReady, false);
var httpd = null;
function onDeviceReady() {
httpd = ( cordova && cordova.plugins && cordova.plugins.CorHttpd ) ? cordova.plugins.CorHttpd : null;
if (!httpd) {
window.location = window.location.basepath + 'lesson-plan-viewer.html'
}
startServer('/')
}
function updateStatus() {
document.getElementById('location').innerHTML = "document.location.href: " + document.location.href;
if( httpd ) {
/* use this function to get status of httpd
* if server is up, it will return http://<server's ip>:port/
* if server is down, it will return empty string ""
*/
httpd.getURL(function(url){
if(url.length > 0) {
document.getElementById('url').innerHTML = "server is up: <a href='" + url + "' target='_blank'>" + url + "</a>";
} else {
document.getElementById('url').innerHTML = "server is down.";
}
});
// call this function to retrieve the local path of the www root dir
httpd.getLocalPath(function(path){
document.getElementById('localpath').innerHTML = "<br/>localPath: " + path;
});
} else {
alert('CorHttpd plugin not available/ready.');
}
}
function startServer( wwwroot ) {
if ( httpd ) {
// before start, check whether its up or not
httpd.getURL(function(url){
if(url.length > 0) {
document.getElementById('url').innerHTML = "server is up: <a href='" + url + "' target='_blank'>" + url + "</a>";
} else {
/* wwwroot is the root dir of web server, it can be absolute or relative path
* if a relative path is given, it will be relative to cordova assets/www/ in APK.
* "", by default, it will point to cordova assets/www/, it's good to use 'htdocs' for 'www/htdocs'
* if a absolute path is given, it will access file system.
* "/", set the root dir as the www root, it maybe a security issue, but very powerful to browse all dir
*/
httpd.startServer({
'www_root' : wwwroot,
'port' : 8080,
'localhost_only' : false
}, function( url ){
// if server is up, it will return the url of http://<server ip>:port/
// the ip is the active network connection
// if no wifi or no cell, "127.0.0.1" will be returned.
document.getElementById('url').innerHTML = "server is started: <a href='" + url + "' target='_blank'>" + url + "</a>";
}, function( error ){
document.getElementById('url').innerHTML = 'failed to start server: ' + error;
});
}
});
} else {
alert('CorHttpd plugin not available/ready.');
}
}
function stopServer() {
if ( httpd ) {
// call this API to stop web server
httpd.stopServer(function(){
document.getElementById('url').innerHTML = 'server is stopped.';
},function( error ){
document.getElementById('url').innerHTML = 'failed to stop server' + error;
});
} else {
alert('CorHttpd plugin not available/ready.');
}
}
setTimeout(function() {
}, 4000)
</script>
</head>
<body>
<form id="selector" onchange="window.lessonplan.src = this.subject.value + '_c' + this.class.value + '_w' + this.week.value + '_d' + this.day.value + '.png'">
<label for="subject">Subject:</label>
<select name="subject">
<option value="english">english</option>
<option value="kiswahili">kiswahili</option>
<option value="maths">maths</option>
</select>
<label for="class">Class:</label>
<select name="class">
<option value="1">1</option>
<option value="2">2</option>
</select>
<br>
<label for="week">Week:</label>
<select name="week">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">20</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
<label for="day">Day:</label>
<select name="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</form>
<img id="lessonplan" style="width: 100%" src="english_c1_w1_d1.png">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment