forked from pebble-hacks/js-configure-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configurable.html
93 lines (81 loc) · 3.48 KB
/
configurable.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<title>Configurable</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>
<div data-role="page" id="main">
<div data-role="header" class="jqm-header">
<h1>Configurable Pebble App</h1>
</div>
<div data-role="content">
<div data-role="fieldcontain">
<label for="name">Name:</label>
<textarea cols="40" rows="8" name="name" id="name"></textarea>
</div>
<div data-role="fieldcontain">
<label for="special-feature">Activate special feature:</label>
<select name="special-feature" id="special-feature" data-role="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>Choose as many snacks as you'd like:</legend>
<input type="checkbox" name="checkbox-cheetos" id="checkbox-cheetos" class="custom" />
<label for="checkbox-cheetos">Cheetos</label>
<input type="checkbox" name="checkbox-doritos" id="checkbox-doritos" class="custom" />
<label for="checkbox-doritos">Doritos</label>
<input type="checkbox" name="checkbox-fritos" id="checkbox-fritos" class="custom" />
<label for="checkbox-fritos">Fritos</label>
<input type="checkbox" name="checkbox-sunchips" id="checkbox-sunchips" class="custom" />
<label for="checkbox-sunchips">Sun Chips</label>
</fieldset>
</div>
</div>
<div class="ui-body ui-body-b">
<fieldset class="ui-grid-a">
<div class="ui-block-a"><button type="submit" data-theme="d" id="b-cancel">Cancel</button></div>
<div class="ui-block-b"><button type="submit" data-theme="a" id="b-submit">Submit</button></div>
</fieldset>
</div>
</div>
</div>
</div>
<script>
function saveOptions() {
var options = {}
//Add all textual values
$('textarea, select, [type="hidden"], [type="password"], [type="text"]').each(function(){options[$(this).attr('id')] = $(this).val();})
//Add all checkbox type values
$('[type="radio"], [type="checkbox"]').each(function(){options[$(this).attr('id')] = $(this).is(':checked');})
return options;
}
$().ready(function() {
$("#b-cancel").click(function() {
console.log("Cancel");
document.location = "pebblejs://close";
});
$("#b-submit").click(function() {
console.log("Submit");
var location = "pebblejs://close#" + encodeURIComponent(JSON.stringify(saveOptions()));
console.log("Warping to: " + location);
console.log(location);
document.location = location;
});
//Set form values to whatever is passed in.
var obj = jQuery.parseJSON(decodeURIComponent(window.location.search.substring(1)));
for(key in obj) {
$("#"+[key]).val(obj[key]);
$("#"+[key]).val(obj[key]).slider("refresh");
}
});
</script>
</body>
</html>