CS174
Chris Pollett
Dec 5, 2016
<!DOCTYPE html>
<html>
<head>
<title>Hello HTML 5</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script></head>
<body>
<div data-role="page">
<div data-role="header">
<h1>My First HTML APP!</h1>
</div><!-- /header -->
<div data-role="content">
<p>This is an HTML 5 app.</p>
</div><!-- /content -->
</div><!-- /page -->
</body>
</html>
<ul data-role="listview" data-inset="true" data-filter="true">
<li><a href="#">Red</a></li>
<li><a href="#">Green</a></li>
<li><a href="#">Blue</a></li>
<li><a href="#">Violet</a></li>
<li><a href="#">Ultra-Violet</a></li>
</ul>
document.getElementById("yo").onclick = function() {alert("yo");}
in jQuery we could do:
$("#yo").onclick = function() {alert("yo");}
$(document).ready(handler) // or $(handler)
<!DOCTYPE html>
<html>
<head>
<title>Portrait or Landscape</title>
<meta id="myview" name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
$(function(){
// Orientation Change
// When orientation changes event is triggered
// exposing an orientation property of either
// landscape or portrait
$('body').bind('orientationchange', function(event){
changeOrientation(event.orientation)
})
// Change the style depending on orientation
function changeOrientation(ori) {
// Remove all classes
$("#orientation").removeClass('portrait landscape');
$("#orientation").addClass(ori);
$("#orientation").html("<p>"+ori.toUpperCase()+"</p>");
}
$("body").trigger("orientationchange");
})
</script>
<style>
div.portrait {
background-color: blue;
width: 100%;
height: 100%;
}
div.landscape {
background-color: red;
width: 100%;
height: 100%;
}
p {
font-size:24px;
color:white;
}
</style>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Orientation</h1>
</div><!-- /header -->
<div data-role="content">
<div id="orientation" class="portrait" ></div>
</div><!-- /content -->
<div data-role="footer">
<h4>My Footer</h4>
</div><!-- /footer -->
</div><!-- /page -->
</body>
</html>
Which of the following statements is true?
Which of the following statements is true?
<html>
<head>
<title>Local Storage Test</title>
</head>
<body>
<script type="text/javascript">
if (localStorage) {
document.write("<h1>Local Storage is Working!</h1>");
testStorage();
} else {
document.write("<h1>Local Storage is Unavailable!</h1>");
}
function testStorage()
{
myvalue = localStorage.getItem("mykey1");
myvalue2 = localStorage["mykey2"];
if(myvalue) {
document.write("<p>Found stored value for mykey1 ="+
myvalue+"</p>");
localStorage.removeItem("mykey1");
//can use localStorage.clear(); to get rid of everything
} else {
localStorage.setItem("mykey1", "hello");
}
if(myvalue2) {
document.write("<p>Found stored value for mykey2 ="+
myvalue2+"</p>");
} else {
localStorage["mykey2"] = "yo";
}
document.write("<h1>List all that's stored after update</h1>");
for (i=0; i<=localStorage.length-1; i++)
{
key = localStorage.key(i);
value = localStorage.getItem(key);
document.write("<p>("+key+", "+value+")</p>");
}
}
</script>
</body>
</html>
function downloadDelayed()
{
$.ajax({
url : "myscript.php",
success : function (data) {
$("#contentArea").html(data);
}
});
}
setTimeout("downloadDelayed()", 1000);
<canvas id="drawpad" ></canvas>
<style type="text/css">
#drawpad {
width: 200px;
height: 100px;
background-color: light-gray;
}
</style>
<script type="text/javascript"*gt;
drawpad_object = document.getElementById("drawpad");
drawpad_context = drawpad_object.getContext("2d");
drawpad_context.strokeStyle = "blue";
drawpad_context.strokeRect(10,10,50,50);
drawpad_context.fillStyle = "green";
drawpad_context.font = "32pt Arial";
max_width = 100;
drawpad_context.rotate(3.14/3); //pi/3
drawpad_context.fillText("hello", 80, -10, max_width);
</script>
<canvas id="drawpad" ontouchstart="startHandler(event);" ontouchmove="moveHandler(event);" ontouchend="endHandler(event);" ontouchcancel="cancelHandler(event);" ></canvas>
drawpad_object.addEventListener("touchstart", startHandler2, false);
<video id="myvideo" width="320" height="240" controls="controls"> <source src="some_movie.mp4" type="video/mp4" /> <!-- firefox only in the last few years supports mp4--> <source src="some_movie.ogg" type="video/ogg" /> <!-- firefox does support ogg but others don't--> Your browser does not support the video tag. </video>
<?php
/**
* Simple server to allow progressive downloads and http pseudo-streaming
* This code uses the request variable f to determine the file to server
* from the current directory. If a range request is made, it serves it
* appropriately.
*/
// Exit if not requested to server a file
if (empty($_REQUEST['f']) || preg_match("/(\/|\\\)/",$_REQUEST['f'])) {
header('HTTP/1.1 403 Forbidden');
exit("403 Forbidden");
}
// Determine path to file and make sure a unix path
$path = str_replace("\\", "/", realpath(__DIR__)) ."/". $_REQUEST['f'];
if (file_exists($path)) {
$finfo = new \finfo(FILEINFO_MIME);
$mime_type = $finfo->file($path);
$size = filesize($path);
$start = 0;
$end = $size - 1;
/* say the filetype we are server, and say that we accept range requests
and so are capable of pseudo-streaming
*/
header("Content-type: $mime_type");
header("Accept-Ranges: bytes");
// Check for range requests
if (!empty($_SERVER['HTTP_RANGE'])) {
//found range info, try to serve
serveRangeRequest($path);
return;
}
// Serve non-range request
header("Content-Length: " . $size);
header("Content-Range: bytes $start-$end/$size");
readfile($path);
} else {
header('HTTP/1.1 404 Not Found');
exit("404 Not Found");
}
/**
* Handles resource file serving to browser in the range request setting
*
* @param string $file file name to serve from current directory
*/
function serveRangeRequest($file)
{
$size = filesize($file);
$start = 0;
$end = $size - 1;
$current_start = $start;
$current_end = $end;
/*
We first parse the Range: header and see if its valid.
The header for a range request looks like:
Range: bytes=some_start_value-some_end_value
(either of some_start_value or some_end_value might be omitted)
split into at most 2 element with last having rest of string
The $_SERVER['HTTP_RANGE'] variable gets the values of the
Range header. I.e., what's after the word Range:.
*/
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
if (strpos($range, ',') !== false) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $start-$end/$size");
return;
}
if ($range == '-') {
$current_start = $size - 1;
} else {
$range = explode('-', $range);
$current_start = trim($range[0]);
$current_end = (isset($range[1]) && is_numeric(trim($range[1])))
? trim($range[1]) : $size;
if ($current_start === "") {
$current_start = max(0, $size - $range[1] - 1);
}
}
$current_end = ($current_end > $end) ? $end : $current_end;
if ($current_start > $current_end || $current_start > $size - 1 ||
$current_end >= $size) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $start-$end/$size");
return;
}
/*
We've now determined the range to serve was valid, so we output
a 206 partial content header and say the range we are going to send
back. Then we actually send it.
*/
$start = $current_start;
$end = $current_end;
$length = $end - $start + 1;
$fp = @fopen($file, 'rb');
fseek($fp, $start);
header('HTTP/1.1 206 Partial Content');
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: " . $length);
$buffer = 8192;
$position = 0;
/* try to output 8Kb at a time until done range. Use ftell to check if fread
happens to get less than 8Kb and then update current position
appropriately.
*/
while(!feof($fp) && $position <= $end && connection_status() == 0) {
$position = ftell($fp);
if ($position + $buffer > $end) {
$buffer = $end - $position + 1;
}
echo fread($fp, $buffer);
flush();
}
fclose($fp);
}
<!DOCTYPE html>
<html>
<head>
<title>Location Test</title>
</head>
<body>
<h1>Hi There</h1>
<script type="text/javascript">
function mycallback(position)
{
alert("Your latitude is: " + position.coords.latitude);
alert("Your longitude is: " + position.coords.longitude);
alert("The accuracy is:" + position.coords.accuracy);
}
function error(msg)
{
if(msg) {
alert(msg);
if(msg.code) {
alert(msg.code); //PositionError has this
}
} else {
alert("that did not work");
}
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(mycallback, error);
} else {
error('not supported');
}
</script>
</body>
</html>