Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
113 lines (73 loc) · 2.34 KB
/
Copy pathscript.js
File metadata and controls
113 lines (73 loc) · 2.34 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
$( '#index' ).live( 'pageinit',function(event){
$.getJSON('../devices.json', function(data) {
$.each(data.devices, function(key, value) {
$("#indexList").append('<li><a href="#controlPage?deviceId='+value.id+'">'+value.name+'</a></li>');
});
$('#indexList').listview('refresh');
});
$(document).bind( "pagebeforechange", function( e, data ) {
if ( typeof data.toPage === "string" ) {
var u = $.mobile.path.parseUrl( data.toPage ),
re = /^#controlPage/;
if ( u.hash.search(re) !== -1 ) {
showDevice( u, data.options );
e.preventDefault();
}
}
});
$( '#controlPage' ).live( 'pagehide',function(event, ui){
// Hide all controllers when exiting the controll page
hideControllers();
});
function showDevice( urlObj, options )
{
var deviceId = urlObj.hash.replace( /.*deviceId=/, "" )
var pageSelector = urlObj.hash.replace( /\?.*$/, "" );
$.getJSON('../devices/'+deviceId+'.json', function(device) {
if ( device ) {
var $page = $( pageSelector );
var $header = $page.children( ":jqmData(role=header)" );
var $content = $page.children( ":jqmData(role=content)" );
$.each(device.supportedMethods, function(index, supportedMethod) {
if(supportedMethod.name == "TELLSTICK_TURNON" ){
$('#on').show();
} else if(supportedMethod.name == "TELLSTICK_TURNOFF"){
$('#off').show();
} else if(supportedMethod.name == "TELLSTICK_DIM"){
$('#dimmerContainer').show();
}
});
$header.find( "h1" ).html( device.name );
$page.page();
options.dataUrl = urlObj.href;
$.mobile.changePage( $page, options );
}
});
}
function hideControllers(){
$('#on').hide();
$('#off').hide();
$('#dimmerContainer').hide();
}
function turnOn(){
$.getJSON('../devices/'+getId()+'/on.json');
}
function turnOff(){
$.getJSON('../devices/'+getId()+'/off.json');
}
function getId(){
var id = jQuery(location).attr('href').split("=")[1];
return id
}
$("#off").click(function() {
turnOff();
});
$("#on").click(function() {
turnOn();
});
$("#dim").live("change", function() {
var dim_value = $(this).val();
$.getJSON('../devices/'+getId()+'/dim/'+dim_value+'.json');
console.log(dim_value);
});
});