HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
If the stylesheet you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fetch Tiles into PPouchDB</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script src="http://cdn.kendostatic.com/2013.1.514/js/kendo.all.min.js"></script>
<script src="https://googledrive.com/host/0B2Ay-nw1QSW2SHhjR0VBZXE2bUU/PouchTest/xhr2lib.js"></script>
<script src="https://googledrive.com/host/0B2Ay-nw1QSW2SHhjR0VBZXE2bUU/PouchTest/pouchdb-nightly.js"></script>
<link href="http://cdn.kendostatic.com/2013.1.514/styles/kendo.common.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2013.1.514/styles/kendo.metroblack.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2013.1.514/styles/kendo.dataviz.metroblack.min.css" rel="stylesheet" />
</head>
<body>
<div id="deleteDB" class="shadow k-button ">Delete Database</div>
<div class="gap"> </div>
<div id="downloadButton" class="k-button shadow ">Download Tiles</div>
<div class="gap"> </div>
<div class="CSSTableGenerator">
<table>
<tr>
<td>Item
</td>
<td>Value
</td>
</tr>
<tr>
<td>Status
</td>
<td data-bind="text: status">xxx
</td>
</tr>
<tr>
<td>XHR2 Support
</td>
<td data-bind="text: xhr">xxx
</td>
</tr>
<tr>
<td>Base64 blobs
</td>
<td data-bind="text: b64Flag">xxx
</td>
</tr>
<tr>
<td>DB Manifest
</td>
<td data-bind="text: dbManifest">xxx
</td>
</tr>
<tr>
<td>Tile Count
</td>
<td data-bind="text: tileCount">xxx
</td>
</tr>
<tr>
<td>Start Time
</td>
<td data-bind="text: startTime">xxx
</td>
</tr>
<tr>
<td>Fetch Time
</td>
<td data-bind="text: fetchTime">xxx
</td>
</tr>
<tr>
<td>Blob Count
</td>
<td data-bind="text: blobCount">xxx
</td>
</tr>
<tr>
<td>Total Time
</td>
<td data-bind="text: totalTime">xxx
</td>
</tr>
<tr>
<td>Blobs/sec
</td>
<td data-bind="text: blobRate">xxx
</td>
</tr>
</table>
</div>
<h1>Sample Image Fetched From PouchDB</h1>
<div class="gap"> </div>
<div id="imgBox">
<img id="imgTile" alt="MAP not loaded YET">
</div>
</body>
</html>
html
{
font: 14px "Verdana", "Helvetica", sans-serif;
margin-left: 8px;
height: 100%;
background-image: linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
background-image: -o-linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
background-image: -moz-linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
background-image: -webkit-linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
background-image: -ms-linear-gradient(bottom, rgb(83,181,217) 17%, rgb(147,208,219) 59%);
background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0.17, rgb(83,181,217)), color-stop(0.59, rgb(147,208,219)) );
}
body {
height: 100%;
wdith: 100%;
}
.gap
{
display: block;
height: 10px;
}
.shadow
{
box-shadow: 0 1px 7px rgba(0, 0, 0, 0.65);
}
#imgBox
{
padding: 4px;
width: 256px;
height: 256px;
box-shadow: 0 1px 7px rgba(0, 0, 0, 0.65);
}
#imgTile
{
width: 100%;
height: 100%;
}
.CSSTableGenerator
{
margin: 0px;
padding: 0px;
width: 80%;
box-shadow: 0 1px 7px rgba(0, 0, 0, 0.65);
border: 1px solid #000000;
-moz-border-radius-bottomleft: 0px;
-webkit-border-bottom-left-radius: 0px;
border-bottom-left-radius: 0px;
-moz-border-radius-bottomright: 0px;
-webkit-border-bottom-right-radius: 0px;
border-bottom-right-radius: 0px;
-moz-border-radius-topright: 0px;
-webkit-border-top-right-radius: 0px;
border-top-right-radius: 0px;
-moz-border-radius-topleft: 0px;
-webkit-border-top-left-radius: 0px;
border-top-left-radius: 0px;
}
.CSSTableGenerator table
{
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
.CSSTableGenerator tr:last-child td:last-child
{
-moz-border-radius-bottomright: 0px;
-webkit-border-bottom-right-radius: 0px;
border-bottom-right-radius: 0px;
}
.CSSTableGenerator table tr:first-child td:first-child
{
-moz-border-radius-topleft: 0px;
-webkit-border-top-left-radius: 0px;
border-top-left-radius: 0px;
}
.CSSTableGenerator table tr:first-child td:last-child
{
-moz-border-radius-topright: 0px;
-webkit-border-top-right-radius: 0px;
border-top-right-radius: 0px;
}
.CSSTableGenerator tr:last-child td:first-child
{
-moz-border-radius-bottomleft: 0px;
-webkit-border-bottom-left-radius: 0px;
border-bottom-left-radius: 0px;
}
.CSSTableGenerator tr:hover td
{
}
.CSSTableGenerator tr:nth-child(odd)
{
background-color: #aad4ff;
}
.CSSTableGenerator tr:nth-child(even)
{
background-color: #ffffff;
}
.CSSTableGenerator td
{
vertical-align: middle;
border: 1px solid #000000;
border-width: 0px 1px 1px 0px;
text-align: left;
padding: 8px;
font-size: 14px;
font-family: Verdana;
font-weight: normal;
color: #000000;
}
.CSSTableGenerator tr:last-child td
{
border-width: 0px 1px 0px 0px;
}
.CSSTableGenerator tr td:last-child
{
border-width: 0px 0px 1px 0px;
}
.CSSTableGenerator tr:last-child td:last-child
{
border-width: 0px 0px 0px 0px;
}
.CSSTableGenerator tr:first-child td
{
background: -o-linear-gradient(bottom, #005fbf 5%, #003f7f 100%);
background: -webkit-gradient( linear, left top, left bottom, color-stop(0.05, #005fbf), color-stop(1, #003f7f) );
background: -moz-linear-gradient( center top, #005fbf 5%, #003f7f 100% );
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#005fbf", endColorstr="#003f7f");
background: -o-linear-gradient(top,#005fbf,003f7f);
background-color: #005fbf;
border: 0px solid #000000;
text-align: center;
border-width: 0px 0px 1px 1px;
font-size: 16px;
font-family: Verdana;
font-weight: bold;
color: #ffffff;
}
.CSSTableGenerator tr:first-child:hover td
{
background: -o-linear-gradient(bottom, #005fbf 5%, #003f7f 100%);
background: -webkit-gradient( linear, left top, left bottom, color-stop(0.05, #005fbf), color-stop(1, #003f7f) );
background: -moz-linear-gradient( center top, #005fbf 5%, #003f7f 100% );
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#005fbf", endColorstr="#003f7f");
background: -o-linear-gradient(top,#005fbf,003f7f);
background-color: #005fbf;
}
.CSSTableGenerator tr:first-child td:first-child
{
border-width: 0px 0px 1px 0px;
}
.CSSTableGenerator tr:first-child td:last-child
{
border-width: 0px 0px 1px 1px;
}
1px 1px;
}
var baseURL = "https://googledrive.com/host/0B2Ay-nw1QSW2SHhjR0VBZXE2bUU/TinyBlueMarble/";
var DBNAME = "MapTiles";
var DB = null;
var manifest = null;
var vm = null;
var showID = "4-9-6";
var fetchCnt = 0;
var imageType = "jpg";
var maxTiles = 999999;
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
if (!window.indexedDB) {
window.alert("Your browser doesn't support a stable version of IndexedDB.");
}
// executed when all js and css is loaded (i.e. document ready event)
$(function () {
makeVM();
vm.set("status", "Initializing");
testXHR();
testBase64();
openDB();
setup();
});
function makeVM() {
vm = kendo.observable({
status: "",
xhr: false,
b64Flag: false,
dbManifest: false,
tileCount: 0,
startTime: "",
fetchTime: "0",
blobCount: 0,
totalTime: "0",
blobRate: 0
});
kendo.bind(document.body, vm);
}
function testXHR() {
vm.set("xhr", $xhr.supported());
}
function testBase64() {
var b64Flag = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
vm.set("b64Flag", b64Flag);
}
function setup() {
$("#deleteDB").click(deleteDB);
$("#downloadButton").click(download);
$xhr.defaultError(function (text, code) {
console.error("xhr2 error: ", text, " code: ", code, " url: ", this.xhr2data.url);
});
}
function openDB() {
DB = Pouch(DBNAME);
DB.get("MANIFEST", function (err, doc) {
if (err) {
console.error("Manifest fetch error: ", err.error, " reason: ", err.reason, " status: ", err.status);
manifest = null;
vm.set("dbManifest", false);
getManifest();
} else {
manifest = doc.data;
vm.set("dbManifest", true);
vm.set("tileCount", manifest.files.length);
vm.set("status", "Ready");
}
});
}
function deleteDB() {
Pouch.destroy(DBNAME, function (err, info) {
if (err) {
console.error("Could not Delete DB: ", info);
} else {
console.log("db deleted");
vm.set("dbManifest", false);
}
});
manifest = null;
vm.set("tileCount", 0);
vm.set("status", "Reload");
}
function getManifest() {
$xhr.ajax({
url: baseURL + "manifest.json",
dataType: "json",
success: parseManifest
});
}
function parseManifest(data) {
data.files = data.files.slice(0, maxTiles - 1);
manifest = data;
DB.put({ _id: "MANIFEST", data: data }, function (err, response) {
if (err) {
console.error("Could store MANIFEST: error: " + err.error + " reason: " + err.reason + " status: " + err.status);
} else {
console.log("saved: ", response.id + " rev: " + response.rev);
vm.set("dbManifest", true);
}
});
vm.set("tileCount", manifest.files.length);
vm.set("status", "Ready");
}
function download() {
if (manifest == null) {
alert("No Manifest, reload");
return;
}
fetchCnt = 0;
vm.set("blobCount", 0);
vm.set("startTime", new Date());
vm.set("fetchTime", "0");
getBlobs(manifest.files);
}
function getBlobs(fileList) {
console.log("starting to fetch blobs");
$.each(fileList, function (i, val) {
var path = baseURL + val.id + "." + imageType;
$xhr.ajax({
url: path,
dataType: "blob",
success: function (data) { saveBlob(data, val.size, val.id); }
});
});
}
function saveBlob(blob, length, id) {
if (blob.size != length) {
console.error("Blob Length found: ", blob.size, " expected: ", length);
}
putBlob(blob, id);
++fetchCnt;
if (fetchCnt == manifest.files.length) {
setTimeout(fetchComplete, 0);
}
}
function fetchComplete() {
var startTime = vm.get("startTime");
var elapsed = new Date() - startTime;
var fetchTime = ms2Time(elapsed);
vm.set("fetchTime", fetchTime);
console.log("Done Fetching Tiles");
}
function putBlob(blob, id) {
var cnt;
var type = blob.type;
DB.putAttachment(id + "/pic", blob, type, function (err, response) {
if (err) {
console.error("Could store blob: error: " + err.error + " reason: " + err.reason + " status: " + err.status);
} else {
console.log("saved: ", response.id + " rev: " + response.rev);
cnt = vm.get("blobCount");
vm.set("blobCount", ++cnt);
if (cnt == manifest.files.length) {
setTimeout(storeComplete, 0);
}
}
});
}
function storeComplete() {
console.log("Done Storing Tiles");
var startTime = vm.get("startTime");
var elapsed = new Date() - startTime;
var totalTime = ms2Time(elapsed);
vm.set("totalTime", totalTime);
var rate = manifest.files.length * 1000 / elapsed;
vm.set("blobRate", rate);
setImage();
}
function setImage() {
var id = showID;
var blob;
DB.getAttachment(id + "/pic", function (err, response) {
if (err) {
console.error("Could find blob id: ", id, " error: ", err.error, " reason: ", err.reason, " status: ", err.status);
} else {
blob = response;
var imgURL = URL.createObjectURL(blob);
// Set img src to ObjectURL
$("#imgTile").attr("src", imgURL);
// Revoking ObjectURL
URL.revokeObjectURL(imgURL);
}
});
}
function ms2Time(ms) {
var secs = ms / 1000;
ms = Math.floor(ms % 1000);
var minutes = secs / 60;
secs = Math.floor(secs % 60);
var hours = minutes / 60;
minutes = Math.floor(minutes % 60);
hours = Math.floor(hours % 24);
return hours + ":" + minutes + ":" + secs + "." + ms;
}
Also see: Tab Triggers