Created
March 24, 2014 04:05
-
-
Save timothyclemans/9733960 to your computer and use it in GitHub Desktop.
[wearscript] Checklist
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;} | |
#serialnumber {padding:40px;font-size:40px;} | |
</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> | |
var current_todo = 1; | |
var names; | |
var checklists; | |
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.say($('h1').text()+' complete'); | |
setTimeout(function () { WS.shutdown(); }, 2000); | |
} else { | |
current_todo += 1; | |
$('#todo_'+current_todo).addClass('current'); | |
WS.say($('#todo_'+current_todo+' span').text()); | |
} | |
} 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()); | |
} | |
} | |
} | |
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 (i == 0) { | |
$('ul').append('<li id="todo_'+(i+1)+'" class="current">'+(i+1)+'. <span>'+elements[i]['text']+'</span></li>'); | |
} else { | |
$('ul').append('<li id="todo_'+(i+1)+'">'+(i+1)+'. <span>'+elements[i]['text']+'</span></li>'); | |
} | |
} | |
WS.say(elements[0]['text']); | |
} | |
function isRegistered() { | |
var is_registered; | |
$.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) { | |
$('div').text('You have no checklists.'); | |
} 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 (i == 0) { | |
$('ul').append('<li id="todo_'+(i+1)+'" class="current">'+(i+1)+'. <span>'+elements[i]['text']+'</span></li>'); | |
} else { | |
$('ul').append('<li id="todo_'+(i+1)+'">'+(i+1)+'. <span>'+elements[i]['text']+'</span></li>'); | |
} | |
} | |
WS.say(elements[0]); | |
} else { | |
names = []; | |
checklists = data; | |
for (var i=0;i<data.length;i++) { | |
names.push(data[i]['name']); | |
} | |
WS.speechRecognize('What checklist do you want to show?', 'getChecklist'); | |
} | |
}); | |
} else { | |
$('div').text("Device not registered. Your serial number is "+WS.serialNumber()); | |
setTimeout(function () {isRegistered();}, 10000); | |
} | |
}); | |
} | |
function main() { | |
$.ajaxSetup({ | |
error: function(jqXHR, exception) { | |
if (jqXHR.status === 0) { | |
WS.log('Not connect.\n 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.\n' + 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