Rev 2145 | Rev 2147 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2051 | linlun | 1 | <?php |
| 2068 | runge | 2 | require_once("backend.php"); |
| 3 | require_once("config.php"); |
||
| 4 | ?> |
||
| 5 | <!DOCTYPE HTML> |
||
| 6 | <html> |
||
| 7 | <head> |
||
| 8 | <meta charset="utf-8"> |
||
| 9 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
||
| 10 | <title>Home Automation Control Center</title> |
||
| 11 | <link rel="stylesheet" href="jquery.mobile-1.1.1.min.css" /> |
||
| 12 | <script src="jquery-1.7.2.min.js"></script> |
||
| 13 | <script src="jquery.mobile-1.1.1.min.js"></script> |
||
| 14 | <script src="jquery.tmpl.min.js"></script> |
||
| 1872 | runge | 15 | |
| 2068 | runge | 16 | <style> |
| 17 | <?php |
||
| 18 | foreach ($pages as $page) |
||
| 19 | { |
||
| 20 | include("pages/" . $page . "/style.css"); |
||
| 21 | } |
||
| 22 | ?> |
||
| 2096 | runge | 23 | |
| 24 | .ui-li-heading { |
||
| 25 | white-space: normal; |
||
| 26 | } |
||
| 2068 | runge | 27 | </style> |
| 2060 | linlun | 28 | |
| 2068 | runge | 29 | <?php |
| 30 | foreach ($pages as $page) |
||
| 31 | { |
||
| 32 | include("pages/" . $page . "/template.html"); |
||
| 33 | } |
||
| 34 | ?> |
||
| 1872 | runge | 35 | |
| 2068 | runge | 36 | <script id="page-template" type="text/x-jquery-tmpl" data-enhance="false"> |
| 2102 | runge | 37 | <div id="page-${name}" data-role="page" data-theme="a" id="page-{name}"> |
| 2145 | runge | 38 | <div data-id="PersistentFooter" data-role="header" data-position="fixed"> |
| 39 | <div data-role="navbar"> |
||
| 40 | <ul class="navbar-container"></ul> |
||
| 41 | </div> |
||
| 2070 | runge | 42 | </div> |
| 2068 | runge | 43 | <div data-role="content"></div> |
| 44 | </div> |
||
| 45 | </script> |
||
| 1872 | runge | 46 | |
| 2068 | runge | 47 | <script id="pagelink-template" type="text/x-jquery-tmpl" data-enhance="false"> |
| 48 | <span> |
||
| 2070 | runge | 49 | <a href="#" data-role="button">${title}</a> |
| 2068 | runge | 50 | </span> |
| 51 | </script> |
||
| 2054 | linlun | 52 | |
| 2068 | runge | 53 | <script> |
| 54 | $.mobile.ignoreContentEnabled = true; |
||
| 2102 | runge | 55 | $.mobile.transitionFallbacks.pop = "none"; |
| 56 | $.mobile.transitionFallbacks.flip = "none"; |
||
| 57 | $.mobile.transitionFallbacks.turn = "none"; |
||
| 58 | $.mobile.transitionFallbacks.flow = "none"; |
||
| 59 | $.mobile.transitionFallbacks.slidefade = "none"; |
||
| 60 | $.mobile.transitionFallbacks.slide = "none"; |
||
| 61 | $.mobile.transitionFallbacks.slideup = "none"; |
||
| 62 | $.mobile.transitionFallbacks.slidedown = "none"; |
||
| 63 | $.mobile.defaultPageTransition = "none"; |
||
| 64 | $.mobile.ajaxEnabled = false; |
||
| 1872 | runge | 65 | |
| 2102 | runge | 66 | var commandActive = false; |
| 67 | var commandQueue = []; |
||
| 68 | |||
| 2068 | runge | 69 | function sendCommand(command, callback) |
| 70 | { |
||
| 2102 | runge | 71 | if (commandActive) |
| 72 | { |
||
| 73 | commandQueue.push({ command: command, callback: callback }); |
||
| 74 | } |
||
| 75 | else |
||
| 76 | { |
||
| 77 | commandActive = true; |
||
| 78 | |||
| 79 | jQuery.getJSON("backend.php?ajax", { command: command }, function(jsonData) |
||
| 80 | { |
||
| 2105 | runge | 81 | handleCommandResponse(true, jsonData, callback); |
| 82 | }).error(function() |
||
| 83 | { |
||
| 84 | handleCommandResponse(false, {}, callback); |
||
| 85 | }); |
||
| 86 | } |
||
| 87 | } |
||
| 2102 | runge | 88 | |
| 2105 | runge | 89 | function handleCommandResponse(success, jsonData, callback) |
| 90 | { |
||
| 91 | commandActive = false; |
||
| 2102 | runge | 92 | |
| 2105 | runge | 93 | if (commandQueue.length > 0) |
| 94 | { |
||
| 95 | var commandItem = commandQueue.shift(); |
||
| 2102 | runge | 96 | |
| 2105 | runge | 97 | sendCommand(commandItem.command, commandItem.callback); |
| 98 | } |
||
| 99 | |||
| 100 | if (success) |
||
| 101 | { |
||
| 102 | if (callback) |
||
| 103 | { |
||
| 2102 | runge | 104 | callback(jsonData); |
| 2105 | runge | 105 | } |
| 2102 | runge | 106 | } |
| 2105 | runge | 107 | else |
| 108 | { |
||
| 109 | console.log("command failed!"); |
||
| 110 | } |
||
| 2068 | runge | 111 | } |
| 112 | </script> |
||
| 1872 | runge | 113 | |
| 2068 | runge | 114 | <script> |
| 115 | var pages = {}; |
||
| 1872 | runge | 116 | |
| 2068 | runge | 117 | <?php |
| 118 | foreach ($pages as $page) |
||
| 1872 | runge | 119 | { |
| 2068 | runge | 120 | include("pages/" . $page . "/script.js"); |
| 1872 | runge | 121 | } |
| 122 | ?> |
||
| 2068 | runge | 123 | </script> |
| 1872 | runge | 124 | |
| 2068 | runge | 125 | <script> |
| 126 | |||
| 2080 | runge | 127 | var aliasNames = <?php echo json_encode($aliasNames); ?>; |
| 2068 | runge | 128 | var pageConfigurations = <?php echo json_encode($pageConfiguration); ?>; |
| 2146 | runge | 129 | var pageInstances = { }; |
| 2102 | runge | 130 | var serverTimeOffset = 0; |
| 2068 | runge | 131 | |
| 2102 | runge | 132 | function getServerTimestamp() |
| 133 | { |
||
| 134 | return ((new Date()).getTime()) - serverTimeOffset |
||
| 135 | } |
||
| 136 | |||
| 2068 | runge | 137 | $(document).ready(function(event) |
| 1872 | runge | 138 | { |
| 2111 | runge | 139 | sendCommand("(new Date()).getTime();", function(timestamp) |
| 2102 | runge | 140 | { |
| 2111 | runge | 141 | serverTimeOffset = ((new Date()).getTime()) - parseInt(timestamp, 10); |
| 2102 | runge | 142 | }); |
| 143 | |||
| 2068 | runge | 144 | jQuery.each(pageConfigurations, function(n, configuration) |
| 1872 | runge | 145 | { |
| 2068 | runge | 146 | var pageName = configuration.page + "_" + n; |
| 2054 | linlun | 147 | |
| 2068 | runge | 148 | pageInstances[pageName] = configuration; |
| 2054 | linlun | 149 | |
| 2068 | runge | 150 | pageInstances[pageName].name = pageName; |
| 2054 | linlun | 151 | |
| 2068 | runge | 152 | pageInstances[pageName].pageElement = $("#page-template").tmpl(pageInstances[pageName]).appendTo($("body")).page(); |
| 153 | pageInstances[pageName].pageContentElement = pageInstances[pageName].pageElement.find(":jqmData(role=content)"); |
||
| 2054 | linlun | 154 | |
| 2068 | runge | 155 | if (pages[configuration.page] && pages[configuration.page].init) |
| 156 | { |
||
| 157 | pages[configuration.page].init(pageInstances[pageName]); |
||
| 158 | } |
||
| 159 | }); |
||
| 2054 | linlun | 160 | |
| 2145 | runge | 161 | |
| 162 | jQuery.each(pageInstances, function(pageName, pageInstance) |
||
| 2068 | runge | 163 | { |
| 2145 | runge | 164 | var navbarContainerElement = pageInstances[pageName].pageElement.find("ul.navbar-container"); |
| 165 | |||
| 166 | jQuery.each(pageInstances, function(pageName2, pageInstance2) |
||
| 167 | { |
||
| 168 | if (pageInstance === pageInstance2) |
||
| 169 | { |
||
| 170 | $("<li class=''><a href='#page-" + pageName2 + "' class='ui-btn-active ui-state-persist'>" + pageInstance2.title + "</a></li>").appendTo(navbarContainerElement); |
||
| 171 | } |
||
| 172 | else |
||
| 173 | { |
||
| 174 | $("<li class=''><a href='#page-" + pageName2 + "'>" + pageInstance2.title + "</a></li>").appendTo(navbarContainerElement); |
||
| 175 | } |
||
| 176 | }); |
||
| 177 | }); |
||
| 178 | |||
| 179 | $(":jqmData(role=header)").navbar(); |
||
| 180 | |||
| 181 | |||
| 182 | /*$(".ui-page").on("swipeleft", function() |
||
| 183 | { |
||
| 2070 | runge | 184 | var nextpage = $(this).nextAll(":jqmData(role=page)"); |
| 2054 | linlun | 185 | |
| 2070 | runge | 186 | if (nextpage.length > 0) |
| 2068 | runge | 187 | { |
| 2133 | runge | 188 | $.mobile.changePage("#" + nextpage[0].id, { transition: "none", changeHash: true }); |
| 2070 | runge | 189 | } |
| 2133 | runge | 190 | else |
| 191 | { |
||
| 192 | nextpage = $(":jqmData(role=page)"); |
||
| 193 | |||
| 194 | $.mobile.changePage("#" + nextpage[0].id, { transition: "none", changeHash: true }); |
||
| 195 | } |
||
| 2070 | runge | 196 | }); |
| 197 | |||
| 198 | $(".ui-page").on("swiperight", function() |
||
| 199 | { |
||
| 200 | var prevpage = $(this).prevAll(":jqmData(role=page)"); |
||
| 2054 | linlun | 201 | |
| 2070 | runge | 202 | if (prevpage.length > 0) |
| 203 | { |
||
| 2133 | runge | 204 | $.mobile.changePage("#" + prevpage[0].id, { transition: "none", reverse: true, changeHash: true }); |
| 2068 | runge | 205 | } |
| 2133 | runge | 206 | else |
| 207 | { |
||
| 208 | prevpage = $(":jqmData(role=page)"); |
||
| 209 | |||
| 210 | $.mobile.changePage("#" + prevpage[prevpage.length - 1].id, { transition: "none", reverse: true, changeHash: true }); |
||
| 211 | } |
||
| 2145 | runge | 212 | });*/ |
| 213 | |||
| 214 | $(":jqmData(role=navbar)").delegate("a", "vclick", function(event) |
||
| 215 | { |
||
| 216 | if(!$(event.target).hasClass("ui-disabled")) |
||
| 217 | { |
||
| 218 | $(":jqmData(role=navbar)").find("a").not(".ui-state-persist").removeClass($.mobile.activeBtnClass); |
||
| 219 | $(this).addClass($.mobile.activeBtnClass); |
||
| 220 | } |
||
| 2070 | runge | 221 | }); |
| 2146 | runge | 222 | |
| 223 | if (document.location.hash === "" || document.location.hash === "#") |
||
| 224 | { |
||
| 225 | document.location.hash = "#" + $(":jqmData(role=page)").attr("id"); |
||
| 226 | } |
||
| 227 | |||
| 228 | $.mobile.changePage($(document.location.hash)); |
||
| 229 | |||
| 1872 | runge | 230 | }); |
| 231 | |||
| 2102 | runge | 232 | var dialogCloseTimer = null; |
| 233 | var dialogCloseCallback = null; |
||
| 234 | |||
| 235 | function openDialog(titleText, contentsHtml, autoCloseTimeout, closeCallback) |
||
| 236 | { |
||
| 237 | closeDialog(); |
||
| 238 | |||
| 239 | $("#dialog .dialog-title").text(titleText); |
||
| 240 | $("#dialog .dialog-contents").html(contentsHtml); |
||
| 241 | $("#dialog a").on("click", function(event) |
||
| 242 | { |
||
| 243 | closeDialog(); |
||
| 244 | event.preventDefault(); |
||
| 245 | return false; |
||
| 246 | }); |
||
| 247 | |||
| 248 | dialogCloseCallback = closeCallback; |
||
| 249 | |||
| 250 | $.mobile.changePage($("#dialog"), { role: "dialog"}); |
||
| 251 | |||
| 252 | $("#dialog").dialog({ close: function(event) |
||
| 253 | { |
||
| 254 | var callback = dialogCloseCallback; |
||
| 255 | |||
| 256 | closeDialog(); |
||
| 257 | |||
| 258 | if (callback) |
||
| 259 | { |
||
| 260 | callback(); |
||
| 261 | } |
||
| 262 | }}); |
||
| 263 | |||
| 264 | |||
| 265 | if (autoCloseTimeout) |
||
| 266 | { |
||
| 267 | dialogCloseTimer = setTimeout(closeDialog, autoCloseTimeout); |
||
| 268 | } |
||
| 269 | } |
||
| 270 | |||
| 271 | function closeDialog() |
||
| 272 | { |
||
| 273 | if (dialogCloseTimer) |
||
| 274 | { |
||
| 275 | clearTimeout(dialogCloseTimer); |
||
| 276 | dialogCloseTimer = null; |
||
| 277 | } |
||
| 278 | |||
| 279 | if ($("#dialog").is(":visible")) |
||
| 280 | { |
||
| 281 | $("#dialog").dialog("close"); |
||
| 282 | |||
| 283 | if (dialogCloseCallback) |
||
| 284 | { |
||
| 285 | dialogCloseCallback(); |
||
| 286 | } |
||
| 287 | } |
||
| 288 | |||
| 289 | dialogCloseCallback = null; |
||
| 290 | } |
||
| 291 | |||
| 292 | |||
| 2068 | runge | 293 | </script> |
| 294 | </head> |
||
| 295 | |||
| 296 | <body> |
||
| 2102 | runge | 297 | <div data-role="dialog" id="dialog"> |
| 298 | <div data-role="content"> |
||
| 299 | <h3 class="dialog-title"></h3> |
||
| 300 | <p class="dialog-contents"></p> |
||
| 301 | <a href="#" data-role="button" data-theme="c">Close</a> |
||
| 302 | </div> |
||
| 303 | </div> |
||
| 304 | |||
| 2068 | runge | 305 | </body> |
| 306 | </html> |