Skip to content

Instantly share code, notes, and snippets.

@robnyman
robnyman / gist:1821580
Created February 13, 2012 23:55
Serializing dates with JSON
var date = new Date();
console.log(date);
var dateAsString = JSON.stringify(date);
console.log(dateAsString);
var dateAsObj = new Date(JSON.parse(dateAsString));
console.log(dateAsObj);
@robnyman
robnyman / Create-IndexedDB-objectStore.js
Created February 23, 2012 16:08
Create IndexedDB objectStore
// Create an objectStore
console.log("Creating objectStore")
dataBase.createObjectStore("elephants");
@robnyman
robnyman / Put-blob-into-IndexedDB-database.js
Created February 23, 2012 16:32
Put blob into IndexedDB database
// Put the blob into the dabase
transaction.objectStore("elephants").put(blob, "image");
@robnyman
robnyman / WebTelephony-API.js
Created March 1, 2012 17:32
WebTelephony API
// Telephony object
var tel = navigator.mozTelephony;
// Check if the phone is muted (read/write property)
console.log(tel.muted);
// Check if the speaker is enabled (read/write property)
console.log(tel.speakerEnabled);
// Place a call
@robnyman
robnyman / json-localstorage.js
Created February 21, 2012 08:14
JSON and localStorage
var cast = {
"Adm. Adama" : "Edward James Olmos",
"President Roslin" : "Mary McDonnell",
"Captain Adama" : "Jamie Bamber",
"Gaius Baltar" : "James Callis",
"Number Six" : "Tricia Helfer",
"Kara Thrace" : " Katee Sackhoff"
};
// Stores the JavaScript object as a string
@robnyman
robnyman / image-noscript.html
Created February 21, 2012 08:35
Image with noscript fallback
<figure>
<img id="elephant" src="about:blank" alt="A close up of an elephant">
<noscript>
<img src="elephant.png" alt="A close up of an elephant">
</noscript>
<figcaption>A mighty big elephant, and mighty close too!</figcaption>
</figure>
@robnyman
robnyman / localStorage-canvas-data-url.js
Created February 21, 2012 08:39
Use localStorage and canvas to same image as a Data URL
// localStorage with image
var storageFiles = JSON.parse(localStorage.getItem("storageFiles")) || {},
elephant = document.getElementById("elephant"),
storageFilesDate = storageFiles.date,
date = new Date(),
todaysDate = (date.getMonth() + 1).toString() + date.getDate().toString();
// Compare date and create localStorage if it's not existing/too old
if (typeof storageFilesDate === "undefined" || storageFilesDate < todaysDate) {
// Take action when the image has loaded
@robnyman
robnyman / Open-IndexedDB-transaction.js
Created February 23, 2012 16:29
Open IndexedDB transaction
// Open a transaction to the database
var transaction = db.transaction(["elephants"], IDBTransaction.READ_WRITE);
@robnyman
robnyman / WebSMS-API.js
Created March 1, 2012 17:41
WebSMS API
// SMS object
var sms = navigator.mozSMS;
// Send a message
sms.send("123456789", "Hello world!");
// Recieve a message
sms.onrecieved = function (event) {
// Read message
console.log(event.message);
@robnyman
robnyman / Fullscreen API.js
Last active February 12, 2018 23:42
Fullscreen API
var docElm = document.documentElement;
if (docElm.requestFullscreen) {
docElm.requestFullscreen();
}
else if (docElm.mozRequestFullScreen) {
docElm.mozRequestFullScreen();
}
else if (docElm.webkitRequestFullScreen) {
docElm.webkitRequestFullScreen();
}