Created
March 8, 2014 19:50
-
-
Save timothyclemans/9437883 to your computer and use it in GitHub Desktop.
[wearscript]
This file contains hidden or 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
<!-- checklistsforglass.com --> | |
<html style="width:100%; height:100%; overflow:hidden"> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<script src="https://raw.github.com/Glench/fuzzyset.js/master/lib/fuzzyset.js"></script> | |
<link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700' rel='stylesheet' type='text/css'> | |
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>--> | |
<style> | |
/* recover from old-browser styling */ | |
.oldbl {display: block !important;} | |
.oldin {display: inline !important;} | |
img.pic {display: block !important;} | |
.ahem, .skipper, #aboutsite, #aboutsite * {display: none !important;} | |
/* NS6.x-specific fix(es) */ | |
*|*:-moz-list-bullet, *|*:-moz-list-number {font-size: 1em;} | |
/* IE image scaling fix */ | |
img {-ms-interpolation-mode: bicubic;} | |
/* misc */ | |
#present {z-index: 100000 !important;} | |
/* | |
http://meyerweb.com/eric/tools/css/reset/ | |
v2.0 | 20110126 | |
License: none (public domain) | |
*/ | |
html, body, div, span, applet, object, iframe, | |
h1, h2, h3, h4, h5, h6, p, blockquote, pre, | |
a, abbr, acronym, address, big, code, | |
del, dfn, img, ins, kbd, q, s, samp, | |
small, strike, sub, sup, tt, var, | |
b, u, i, center, | |
dl, dt, dd, ol, ul, li, | |
fieldset, form, label, legend, | |
table, caption, tbody, tfoot, thead, tr, th, td, | |
article, aside, canvas, details, embed, | |
figure, figcaption, footer, header, hgroup, | |
menu, nav, output, ruby, section, summary, | |
time, mark, audio, video { | |
margin: 0; | |
padding: 0; | |
border: 0; | |
font-size: 100%; | |
font: inherit; | |
vertical-align: baseline; | |
} | |
/* HTML5 display-role reset for older browsers */ | |
article, aside, details, figcaption, figure, | |
footer, header, hgroup, menu, nav, section { | |
display: block; | |
} | |
body { | |
line-height: 1; | |
font-family:roboto; | |
font-weight:100; | |
color:#FFF; | |
} | |
ol, ul { | |
list-style: none; | |
} | |
blockquote, q { | |
quotes: none; | |
} | |
blockquote:before, blockquote:after, | |
q:before, q:after { | |
content: ''; | |
content: none; | |
} | |
table { | |
border-collapse: collapse; | |
border-spacing: 0; | |
} | |
h1 {font-size:30px; padding:10px; font-weight:300;} | |
li {font-size:30px; border-top:1px solid #FFF;padding:10px;} | |
.current {background:red;font-size:50px;font-weight:500;} | |
#message {padding:40px;font-size:40px;} | |
img { | |
position:absolute;top:0;left:0;display:none; | |
} | |
</style> | |
</head> | |
<body style="background:#000; color:#FFF; width:100%; height:100%; overflow:hidden; margin:0"> | |
<div id="message"></div> | |
<div id="checklist"> | |
<h1></h1> | |
<ul> | |
</ul> | |
</div> | |
<script> | |
String.prototype.capitalize = function() { | |
return this.charAt(0).toUpperCase() + this.slice(1); | |
} | |
var current_todo = 1; | |
var names; | |
var checklists; | |
var done = false; | |
function onGesture(name) { | |
if (name == 'SWIPE_RIGHT' || name == 'WINK') { | |
WS.sound('SUCCESS'); | |
$('#todo_'+current_todo).removeClass('current'); | |
$('#todo_'+(current_todo-1)).hide(); | |
if (current_todo == $('li').size()) { | |
WS.shutdown(); | |
//WS.say($('h1').text()+' complete'); | |
//setTimeout(function () { WS.log('shutdown'); WS.activityCreate(); WS.shutdown(); }, 2000); | |
} else { | |
current_todo += 1; | |
$('#todo_'+current_todo).addClass('current'); | |
WS.say($('#todo_'+current_todo+' span').text()); | |
$('img').hide(); | |
$('#todo_'+current_todo+' img').show(); | |
} | |
} else if (name == 'SWIPE_LEFT' || name == 'DOUBLE_BLINK') { | |
//$('#todo_'+(current_todo-1)).remove(); | |
if (current_todo != 1) { | |
WS.sound('SUCCESS'); | |
$('#todo_'+current_todo).removeClass('current'); | |
current_todo -= 1; | |
$('#todo_'+current_todo).show(); | |
$('#todo_'+current_todo).addClass('current'); | |
WS.say($('#todo_'+current_todo+' span').text()); | |
$('img').hide(); | |
$('#todo_'+current_todo+' img').show(); | |
} | |
} | |
} | |
function onEyeGesture(name){ | |
onGesture(name); | |
} | |
function server() { | |
WS.log('connected'); | |
} | |
function getChecklist(data) { | |
var fuzzy_names = FuzzySet(names); | |
var fuzzy_match = fuzzy_names.get(data)[0][1]; | |
var checklist_index = names.indexOf(fuzzy_match); | |
var checklist = checklists[checklist_index]; | |
$('h1').text(checklist['name']); | |
$('ul').html(''); | |
$('#message').hide(); | |
$('#checklist').show(); | |
WS.log(JSON.stringify(elements)); | |
var elements = checklist['elements']; | |
for (var i = 0; i<elements.length;i++) { | |
if (elements[i]['image']) { | |
if (i == 0) { | |
var img = '<img src="http://checklistsforglass.com'+elements[i]['image']+'" style="display:block" />'; | |
} else { | |
var img = '<img src="http://checklistsforglass.com'+elements[i]['image']+'" />'; | |
} | |
WS.log(img); | |
} else { | |
var img = ''; | |
} | |
if (i == 0) { | |
$('ul').append('<li id="todo_'+(i+1)+'" class="current">'+(i+1)+'. <span>'+elements[i]['text']+'</span>'+img+'</li>'); | |
} else { | |
$('ul').append('<li id="todo_'+(i+1)+'">'+(i+1)+'. <span>'+elements[i]['text']+'</span>'+img+'</li>'); | |
} | |
} | |
WS.say(elements[0]['text']); | |
} | |
function isRegistered() { | |
var is_registered; | |
//WS.say(WS.serialNumber()); | |
$.get('http://checklistsforglass.com/is_registered/'+WS.serialNumber()+'/', function (data) { | |
if (data == 'True') { | |
WS.log('http://checklistsforglass.com/get_checklists/'+WS.serialNumber()+'/'); | |
$.get('http://checklistsforglass.com/get_checklists/'+WS.serialNumber()+'/', function (data) { | |
if (data.length == 0) { | |
var error = 'You have no checklists. In your account either create or buy a checklist.'; | |
WS.say(error); | |
$('#message').text(error); | |
} else if (data.length == 1) { | |
var elements = data[0]['elements']; | |
$('h1').text(data[0]['name']); | |
$('ul').html(''); | |
//$('#message').hide(); | |
$('#checklist').show(); | |
WS.log(JSON.stringify(elements)); | |
for (var i = 0; i<elements.length;i++) { | |
if (elements[i]['image']) { | |
var img = '<img src="http://checklistsforglass.com'+elements[i]['image']+'" />'; | |
WS.log(img); | |
} else { | |
var img = ''; | |
} | |
if (i == 0) { | |
$('ul').append('<li id="todo_'+(i+1)+'" class="current">'+(i+1)+'. <span>'+elements[i]['text'].capitalize()+'</span>'+img+'</li>'); | |
} else { | |
$('ul').append('<li id="todo_'+(i+1)+'">'+(i+1)+'. <span>'+elements[i]['text'].capitalize()+'</span>'+img+'</li>'); | |
} | |
} | |
WS.say(elements[0]['text']); | |
} else { | |
names = []; | |
checklists = data; | |
for (var i=0;i<data.length;i++) { | |
names.push(data[i]['name']); | |
} | |
if (done != true) { | |
done = true; | |
//WS.say('prompt'); | |
WS.speechRecognize('What checklist do you want to show?', 'getChecklist'); | |
} | |
} | |
}); | |
} else { | |
$('#message').text("Device not registered. Your serial number is "+WS.serialNumber()); | |
setTimeout(function () {isRegistered();}, 10000); | |
} | |
}); | |
} | |
function main() { | |
function supports_html5_storage() { | |
try { | |
var local = 'localStorage' in window && window['localStorage'] !== null; | |
localStorage.setItem("lastname", "Smith"); | |
$('#message').text(localStorage.getItem("lastname")); | |
} catch (e) { | |
$('#message').text('No support for local storage'); | |
} | |
} | |
//supports_html5_storage(); | |
$.ajaxSetup({ | |
error: function(jqXHR, exception) { | |
if (jqXHR.status === 0) { | |
WS.log('Not connect. Verify Network.'); | |
} else if (jqXHR.status == 404) { | |
WS.log('Requested page not found. [404]'); | |
} else if (jqXHR.status == 500) { | |
WS.log('Internal Server Error [500].'); | |
} else if (exception === 'parsererror') { | |
WS.log('Requested JSON parse failed.'); | |
} else if (exception === 'timeout') { | |
WS.log('Time out error.'); | |
} else if (exception === 'abort') { | |
WS.log('Ajax request aborted.'); | |
} else { | |
WS.log('Uncaught Error.' + jqXHR.responseText); | |
} | |
} | |
}); | |
WS.gestureCallback('onGesture', 'onGesture'); | |
WS.gestureCallback('onEyeGesture', 'onGesture'); | |
WS.liveCardCreate(false, .2); | |
//WS.serverConnect('{{WSUrl}}', 'server'); | |
WS.activityCreate(); | |
//WS.say($('#todo_'+current_todo+' span').text()); | |
var is_registered = 'False'; | |
isRegistered() | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment