Rev 2096 | Rev 2104 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2096 | Rev 2102 | ||
|---|---|---|---|
| Line 32... | Line 32... | ||
| 32 | include("pages/" . $page . "/template.html"); |
32 | include("pages/" . $page . "/template.html"); |
| 33 | } |
33 | } |
| 34 | ?> |
34 | ?> |
| 35 | 35 | ||
| 36 | <script id="page-template" type="text/x-jquery-tmpl" data-enhance="false"> |
36 | <script id="page-template" type="text/x-jquery-tmpl" data-enhance="false"> |
| 37 | <div id="page-${name}" data-role="page" data-theme="a"> |
37 | <div id="page-${name}" data-role="page" data-theme="a" id="page-{name}"> |
| 38 | <div data-role="header"> |
38 | <div data-role="header"> |
| 39 | <a href=" |
39 | <a href="#home" data-icon="home" data-direction="reverse">Home</a> |
| 40 | <h1> |
40 | <h1>${title} - Home Automation Control Center</h1> |
| 41 | </div> |
41 | </div> |
| 42 | <div data-role="content"></div> |
42 | <div data-role="content"></div> |
| 43 | </div> |
43 | </div> |
| 44 | </script> |
44 | </script> |
| 45 | 45 | ||
| Line 49... | Line 49... | ||
| 49 | </span> |
49 | </span> |
| 50 | </script> |
50 | </script> |
| 51 | 51 | ||
| 52 | <script> |
52 | <script> |
| 53 | $.mobile.ignoreContentEnabled = true; |
53 | $.mobile.ignoreContentEnabled = true; |
| 54 | $.mobile.transitionFallbacks.pop = "none" |
54 | $.mobile.transitionFallbacks.pop = "none"; |
| 55 | $.mobile.transitionFallbacks.flip = "none" |
55 | $.mobile.transitionFallbacks.flip = "none"; |
| 56 | $.mobile.transitionFallbacks.turn = "none" |
56 | $.mobile.transitionFallbacks.turn = "none"; |
| 57 | $.mobile.transitionFallbacks.flow = "none" |
57 | $.mobile.transitionFallbacks.flow = "none"; |
| 58 | $.mobile.transitionFallbacks.slidefade = "none" |
58 | $.mobile.transitionFallbacks.slidefade = "none"; |
| 59 | $.mobile.transitionFallbacks.slide = "none" |
59 | $.mobile.transitionFallbacks.slide = "none"; |
| 60 | $.mobile.transitionFallbacks.slideup = "none" |
60 | $.mobile.transitionFallbacks.slideup = "none"; |
| 61 | $.mobile.transitionFallbacks.slidedown = "none" |
61 | $.mobile.transitionFallbacks.slidedown = "none"; |
| 62 | $.mobile.defaultPageTransition = "none" |
62 | $.mobile.defaultPageTransition = "none"; |
| - | 63 | $.mobile.ajaxEnabled = false; |
|
| - | 64 | ||
| - | 65 | var commandActive = false; |
|
| - | 66 | var commandQueue = []; |
|
| 63 | 67 | ||
| 64 | function sendCommand(command, callback) |
68 | function sendCommand(command, callback) |
| 65 | { |
69 | { |
| - | 70 | if (commandActive) |
|
| - | 71 | { |
|
| - | 72 | commandQueue.push({ command: command, callback: callback }); |
|
| - | 73 | } |
|
| - | 74 | else |
|
| - | 75 | { |
|
| - | 76 | commandActive = true; |
|
| - | 77 | ||
| 66 | jQuery.getJSON |
78 | jQuery.getJSON("backend.php?ajax", { command: command }, function(jsonData) |
| - | 79 | { |
|
| - | 80 | commandActive = false; |
|
| - | 81 | ||
| - | 82 | if (commandQueue.length > 0) |
|
| - | 83 | { |
|
| - | 84 | var commandItem = commandQueue.shift(); |
|
| - | 85 | ||
| - | 86 | sendCommand(commandItem.command, commandItem.callback); |
|
| - | 87 | } |
|
| - | 88 | ||
| - | 89 | callback(jsonData); |
|
| - | 90 | }); |
|
| - | 91 | } |
|
| 67 | } |
92 | } |
| 68 | </script> |
93 | </script> |
| 69 | 94 | ||
| 70 | <script> |
95 | <script> |
| 71 | var pages = {}; |
96 | var pages = {}; |
| Line 81... | Line 106... | ||
| 81 | <script> |
106 | <script> |
| 82 | 107 | ||
| 83 | var aliasNames = <?php echo json_encode($aliasNames); ?>; |
108 | var aliasNames = <?php echo json_encode($aliasNames); ?>; |
| 84 | var pageConfigurations = <?php echo json_encode($pageConfiguration); ?>; |
109 | var pageConfigurations = <?php echo json_encode($pageConfiguration); ?>; |
| 85 | var pageInstances = {}; |
110 | var pageInstances = {}; |
| - | 111 | var serverTimeOffset = 0; |
|
| - | 112 | ||
| - | 113 | function getServerTimestamp() |
|
| - | 114 | { |
|
| - | 115 | return ((new Date()).getTime()) - serverTimeOffset |
|
| - | 116 | } |
|
| 86 | 117 | ||
| 87 | $(document).ready(function(event) |
118 | $(document).ready(function(event) |
| 88 | { |
119 | { |
| - | 120 | document.location.hash = ""; |
|
| - | 121 | ||
| - | 122 | sendCommand("timestampRaw", function(jsonData) |
|
| - | 123 | { |
|
| - | 124 | serverTimeOffset = ((new Date()).getTime()) - jsonData.timestamp; |
|
| - | 125 | }); |
|
| - | 126 | ||
| 89 | jQuery.each(pageConfigurations, function(n, configuration) |
127 | jQuery.each(pageConfigurations, function(n, configuration) |
| 90 | { |
128 | { |
| 91 | var pageName = configuration.page + "_" + n; |
129 | var pageName = configuration.page + "_" + n; |
| 92 | 130 | ||
| 93 | pageInstances[pageName] = configuration; |
131 | pageInstances[pageName] = configuration; |
| 94 | 132 | ||
| 95 | pageInstances[pageName].name = pageName; |
133 | pageInstances[pageName].name = pageName; |
| 96 | 134 | ||
| 97 | pageInstances[pageName].pageElement = $("#page-template").tmpl(pageInstances[pageName]).appendTo($("body")).page(); |
135 | pageInstances[pageName].pageElement = $("#page-template").tmpl(pageInstances[pageName]).appendTo($("body")).page(); |
| 98 | pageInstances[pageName].pageContentElement = pageInstances[pageName].pageElement.find(":jqmData(role=content)"); |
136 | pageInstances[pageName].pageContentElement = pageInstances[pageName].pageElement.find(":jqmData(role=content)"); |
| 99 | 137 | ||
| 100 | pageInstances[pageName].pageElement.find(":jqmData(rel=back)").on("click", function(event) |
138 | pageInstances[pageName].pageElement.find(":jqmData(rel=back)").on("click", function(event) |
| 101 | { |
139 | { |
| 102 | $.mobile.changePage( |
140 | $.mobile.changePage("#home", { transition: "slide", reverse: true }); |
| 103 | event.preventDefault(); |
141 | event.preventDefault(); |
| 104 | }); |
142 | }); |
| 105 | 143 | ||
| 106 | pageInstances[pageName].pageLinkElement = $("#pagelink-template").tmpl(pageInstances[pageName]).appendTo($("#home").find(":jqmData(role=content)")).trigger("create").on("click", function(event) |
144 | pageInstances[pageName].pageLinkElement = $("#pagelink-template").tmpl(pageInstances[pageName]).appendTo($("#home").find(":jqmData(role=content)")).trigger("create").on("click", function(event) |
| 107 | { |
145 | { |
| 108 | $.mobile.changePage(pageInstances |
146 | $.mobile.changePage("#" + pageInstances[pageName].pageElement.attr("id"), "slide"); |
| 109 | event.preventDefault(); |
147 | event.preventDefault(); |
| 110 | }); |
148 | }); |
| 111 | 149 | ||
| 112 | 150 | ||
| 113 | if (pages[configuration.page] && pages[configuration.page].init) |
151 | if (pages[configuration.page] && pages[configuration.page].init) |
| 114 | { |
152 | { |
| 115 | pages[configuration.page].init(pageInstances[pageName]); |
153 | pages[configuration.page].init(pageInstances[pageName]); |
| 116 | } |
154 | } |
| 117 | }); |
155 | }); |
| 118 | 156 | ||
| 119 | $(".ui-page").on("swipeleft", function() |
157 | $(".ui-page").on("swipeleft", function() |
| 120 | { |
158 | { |
| 121 | var nextpage = $(this).nextAll(":jqmData(role=page)"); |
159 | var nextpage = $(this).nextAll(":jqmData(role=page)"); |
| 122 | 160 | ||
| 123 | if (nextpage.length > 0) |
161 | if (nextpage.length > 0) |
| 124 | { |
162 | { |
| 125 | $.mobile.changePage( |
163 | $.mobile.changePage("#" + nextpage[0].id, { transition: "slide", changeHash: true }); |
| 126 | } |
164 | } |
| 127 | }); |
165 | }); |
| 128 | 166 | ||
| 129 | $(".ui-page").on("swiperight", function() |
167 | $(".ui-page").on("swiperight", function() |
| 130 | { |
168 | { |
| 131 | var prevpage = $(this).prevAll(":jqmData(role=page)"); |
169 | var prevpage = $(this).prevAll(":jqmData(role=page)"); |
| 132 | 170 | ||
| 133 | if (prevpage.length > 0) |
171 | if (prevpage.length > 0) |
| 134 | { |
172 | { |
| - | 173 | $.mobile.changePage("#" + prevpage[0].id, { transition: "slide", reverse: true, changeHash: true }); |
|
| - | 174 | } |
|
| - | 175 | }); |
|
| - | 176 | }); |
|
| - | 177 | ||
| - | 178 | var dialogCloseTimer = null; |
|
| - | 179 | var dialogCloseCallback = null; |
|
| - | 180 | ||
| - | 181 | function openDialog(titleText, contentsHtml, autoCloseTimeout, closeCallback) |
|
| - | 182 | { |
|
| - | 183 | closeDialog(); |
|
| - | 184 | ||
| - | 185 | $("#dialog .dialog-title").text(titleText); |
|
| - | 186 | $("#dialog .dialog-contents").html(contentsHtml); |
|
| - | 187 | $("#dialog a").on("click", function(event) |
|
| - | 188 | { |
|
| - | 189 | closeDialog(); |
|
| - | 190 | event.preventDefault(); |
|
| - | 191 | return false; |
|
| - | 192 | }); |
|
| - | 193 | ||
| - | 194 | dialogCloseCallback = closeCallback; |
|
| - | 195 | ||
| 135 |
|
196 | $.mobile.changePage($("#dialog"), { role: "dialog"}); |
| - | 197 | ||
| - | 198 | $("#dialog").dialog({ close: function(event) |
|
| - | 199 | { |
|
| - | 200 | var callback = dialogCloseCallback; |
|
| - | 201 | ||
| - | 202 | closeDialog(); |
|
| - | 203 | ||
| - | 204 | if (callback) |
|
| - | 205 | { |
|
| - | 206 | callback(); |
|
| - | 207 | } |
|
| - | 208 | }}); |
|
| - | 209 | ||
| - | 210 | ||
| - | 211 | if (autoCloseTimeout) |
|
| - | 212 | { |
|
| - | 213 | dialogCloseTimer = setTimeout(closeDialog, autoCloseTimeout); |
|
| - | 214 | } |
|
| - | 215 | } |
|
| - | 216 | ||
| - | 217 | function closeDialog() |
|
| - | 218 | { |
|
| - | 219 | if (dialogCloseTimer) |
|
| - | 220 | { |
|
| - | 221 | clearTimeout(dialogCloseTimer); |
|
| - | 222 | dialogCloseTimer = null; |
|
| - | 223 | } |
|
| - | 224 | ||
| - | 225 | if ($("#dialog").is(":visible")) |
|
| - | 226 | { |
|
| - | 227 | $("#dialog").dialog("close"); |
|
| - | 228 | ||
| - | 229 | if (dialogCloseCallback) |
|
| - | 230 | { |
|
| - | 231 | dialogCloseCallback(); |
|
| - | 232 | } |
|
| - | 233 | } |
|
| - | 234 | ||
| - | 235 | dialogCloseCallback = null; |
|
| 136 | } |
236 | } |
| 137 | }); |
- | |
| 138 | }); |
237 | |
| 139 | 238 | ||
| 140 | </script> |
239 | </script> |
| 141 | </head> |
240 | </head> |
| 142 | 241 | ||
| 143 | <body> |
242 | <body> |
| 144 | <div id="home" data-role="page" data-theme="a"> |
243 | <div id="home" data-role="page" data-theme="a"> |
| 145 | <div data-role="header"><h1>Home Automation Control Center</h1></div> |
244 | <div data-role="header"><h1>Home Automation Control Center</h1></div> |
| 146 | <div data-role="content"></div> |
245 | <div data-role="content"></div> |
| 147 | </div> |
246 | </div> |
| - | 247 | ||
| - | 248 | <div data-role="dialog" id="dialog"> |
|
| - | 249 | <div data-role="content"> |
|
| - | 250 | <h3 class="dialog-title"></h3> |
|
| - | 251 | <p class="dialog-contents"></p> |
|
| - | 252 | <a href="#" data-role="button" data-theme="c">Close</a> |
|
| - | 253 | </div> |
|
| - | 254 | </div> |
|
| - | 255 | ||
| 148 | </body> |
256 | </body> |
| 149 | </html> |
257 | </html> |