| <!DOCTYPE html> |
| <!-- |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| --> |
| <html manifest="/cache-manifest.cmf"> |
| <head> |
| <title></title> |
| <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"/> |
| <meta name="apple-mobile-web-app-capable" content="yes"/> |
| <meta name="apple-mobile-web-app-status-bar-style" content="black"/> |
| <link rel="apple-touch-icon" href="/public/touchicon.png"/> |
| <base href="/"/> |
| <script type="text/javascript"> |
| (function() { |
| |
| window.appcache = {}; |
| |
| /** |
| * Get and cache a resource. |
| */ |
| appcache.get = function(uri) { |
| var h = uri.indexOf('#'); |
| var u = h == -1? uri : uri.substring(0, h); |
| |
| // Get resource from local storage first |
| var ls = window.lstorage || localStorage; |
| var item = null; |
| try { item = ls.getItem(u); } catch(e) {} |
| if (item != null && item != '') |
| return item; |
| |
| // Get resource from network |
| //if (window.debug) debug('appcache.get', u); |
| var http = new XMLHttpRequest(); |
| http.open("GET", u, false); |
| http.setRequestHeader("Accept", "*/*"); |
| http.send(null); |
| if (http.status == 200) { |
| if (http.getResponseHeader("X-Login") != null) { |
| if (window.debug) debug('http error', u, 'X-Login'); |
| // Redirect to login page if not signed in |
| document.location = '/login/'; |
| return null; |
| } else if (http.responseText == '' || http.getResponseHeader("Content-Type") == null) { |
| if (window.debug) debug('http error', u, 'No-Content'); |
| return null; |
| } |
| try { ls.setItem(u, http.responseText); } catch(e) {} |
| return http.responseText; |
| } |
| if (window.debug) debug('http error', u, http.status, http.statusText); |
| // Redirect to login page if not signed in |
| if (http.status == 403) |
| document.location = '/login/'; |
| return null; |
| }; |
| |
| appcache.remove = function(uri) { |
| var h = uri.indexOf('#'); |
| var u = h == -1? uri : uri.substring(0, h); |
| var ls = window.lstorage || localStorage; |
| try { ls.removeItem(u); } catch(e) {} |
| return true; |
| }; |
| |
| })(); |
| |
| /** |
| * Load Javascript and CSS. |
| */ |
| (function() { |
| |
| var bootjs = document.createElement('script'); |
| bootjs.type = 'text/javascript'; |
| bootjs.text = appcache.get('/all-min.js'); |
| document.head.appendChild(bootjs); |
| document.head.appendChild(ui.declareCSS(appcache.get('/ui-min.css'))); |
| |
| // Disable cache for testing |
| //lstorage.enabled = false; |
| |
| })(); |
| |
| /** |
| * Redirect to login page if not signed in. |
| */ |
| (function() { |
| |
| if (document.location.protocol == 'https:' && !hasauthcookie()) |
| document.location = '/login/'; |
| |
| })(); |
| </script> |
| </head> |
| <body class="delayed"> |
| <div id="mainbodydiv" class="mainbody"> |
| |
| <div id="headdiv" class="hsection"> |
| <script type="text/javascript"> |
| (function() { |
| |
| $('headdiv').appendChild(ui.declareScript(appcache.get('/config-min.js'))); |
| |
| })(); |
| </script> |
| </div> |
| |
| <div id="menubackground" class="tbarbackground fixed"></div> |
| <div id="menu" class="tbarmenu fixed"></div> |
| |
| <div id="viewheadbackground" class="viewheadbackground fixed"></div> |
| <div id="viewhead" class="viewhead fixed"></div> |
| |
| <div id="viewcontainer"></div> |
| |
| <div id="viewfootbackground" class="viewfootbackground fixed"></div> |
| <div id="viewfoot" class="viewfoot fixed"></div> |
| <div id="status" class="status fixed" style="visibility: hidden;"></div> |
| |
| <script type="text/javascript"> |
| (function() { |
| |
| /** |
| * Init service references. |
| */ |
| var editorComp = sca.component("Editor"); |
| var user= sca.defun(sca.reference(editorComp, "user")); |
| var accounts = sca.reference(editorComp, "accounts"); |
| |
| /** |
| * Set page title. |
| */ |
| document.title = config.windowtitle(); |
| |
| /** |
| * Init div variables. |
| */ |
| var bdiv = $('mainbodydiv'); |
| var mdiv = $('menu'); |
| var hdiv = $('viewhead'); |
| var vcontainer = $('viewcontainer'); |
| vcontainer.className = ui.isMobile()? 'viewcontainer3dm' : 'viewcontainer3d'; |
| var fdiv = $('viewfoot'); |
| |
| /** |
| * The current user name and account entry. |
| */ |
| window.username = 'anonymous'; |
| |
| /** |
| * The current store category. |
| */ |
| var storecat = 'top'; |
| var storeidx = 0; |
| |
| /** |
| * Pre-fetch app resources. |
| */ |
| var appresources = [ |
| ['/all-min.js'], |
| ['/ui-min.css'], |
| ['/account/', 9], |
| ['/clone/', 3], |
| ['/create/', 2], |
| ['/delete/', 3], |
| ['/graph/', 5], |
| ['/config-min.js'], |
| ['/home/', 0], |
| ['/home/home.b64'], |
| ['/page/', 4], |
| ['/public/app.b64'], |
| ['/public/config-min.js'], |
| ['/public/grid72.b64'], |
| ['/public/iframe-min.html'], |
| ['/public/img.b64'], |
| ['/public/user.b64'], |
| ['/stats/', 2], |
| ['/store/', 1] |
| ]; |
| |
| /** |
| * Show a status message. |
| */ |
| window.showStatus = function(s, c) { |
| //debug('status', s); |
| var sdiv = $('status'); |
| if (isNil(sdiv)) |
| return s; |
| sdiv.innerHTML = '<span class="' + (c? c : 'okstatus') + '">' + s + '</span>'; |
| sdiv.className = 'status fixed'; |
| sdiv.style.visibility = 'visible'; |
| |
| function divtransitionend(e) { |
| e.target.style.visibility = 'hidden'; |
| e.target.className = 'status fixed'; |
| } |
| if (!sdiv.addedTransitionEnd) { |
| sdiv.addEventListener('webkitTransitionEnd', divtransitionend, false); |
| sdiv.addEventListener('transitionend', divtransitionend, false); |
| sdiv.addedTransitionEnd = true; |
| } |
| sdiv.className = 'statusout3 fixed'; |
| return s; |
| } |
| |
| /** |
| * Show an error message. |
| */ |
| window.showError = function(s) { |
| //debug('error', s); |
| return showStatus(s, 'errorstatus'); |
| } |
| |
| /** |
| * Show the online/offline status. |
| */ |
| window.showOnlineStatus = function() { |
| return navigator.onLine? showStatus('Online') : showError('Offline'); |
| } |
| |
| /** |
| * Handle application cache events. |
| */ |
| applicationCache.addEventListener('checking', function(e) { |
| //debug('appcache checking', e); |
| showStatus('Checking'); |
| }, false); |
| applicationCache.addEventListener('error', function(e) { |
| //debug('appcache error', e); |
| showOnlineStatus(); |
| }, false); |
| applicationCache.addEventListener('noupdate', function(e) { |
| //debug('appcache noupdate', e); |
| showOnlineStatus(); |
| }, false); |
| applicationCache.addEventListener('downloading', function(e) { |
| //debug('appcache downloading', e); |
| showStatus('Updating'); |
| }, false); |
| applicationCache.addEventListener('progress', function(e) { |
| //debug('appcache progress', e); |
| showStatus('Updating'); |
| }, false); |
| applicationCache.addEventListener('updateready', function(e) { |
| //debug('appcache updateready', e); |
| try { |
| applicationCache.swapCache(); |
| } catch(e) {} |
| showOnlineStatus(); |
| //debug('appcache swapped', e); |
| |
| // Update offline resources in local storage and reload the page |
| map(function(res) { |
| showStatus('Updating'); |
| appcache.remove(res[0]); |
| appcache.get(res[0]); |
| }, append(appresources, config.appresources())); |
| window.location.reload(); |
| }, false); |
| applicationCache.addEventListener('cached', function(e) { |
| //debug('appcache cached', e); |
| showOnlineStatus(); |
| |
| // Install offline resources in local storage |
| map(function(res) { |
| showStatus('Installing'); |
| appcache.remove(res[0]); |
| appcache.get(res[0]); |
| }, append(appresources, config.appresources())); |
| }, false); |
| |
| /** |
| * Handle network offline/online events. |
| */ |
| window.addEventListener('offline', function(e) { |
| //debug('going offline'); |
| showStatus('Offline'); |
| }, false); |
| window.addEventListener('online', function(e) { |
| //debug('going online'); |
| showStatus('Online'); |
| }, false); |
| |
| //debug(navigator.onLine? 'online' : 'offline'); |
| |
| /** |
| * Handle view transitions. |
| */ |
| var viewurl = ''; |
| var viewuri = ''; |
| var viewidx = 0; |
| var viewdiv; |
| |
| /** |
| * Record which transitions should be applied to each resource. |
| */ |
| var apptransitions = {}; |
| map(function(res) { |
| if (res.length > 1) |
| apptransitions[res[0]] = res[1]; |
| }, append(appresources, config.appresources())); |
| |
| /** |
| * Return the transition that should be applied to a resource. |
| */ |
| function viewtransition(ouri, uri) { |
| var ot = apptransitions[ouri]; |
| if (isNil(ot)) |
| return 'left'; |
| var t = apptransitions[uri]; |
| if (isNil(t)) |
| return 'left'; |
| return t < ot? 'right' : 'left'; |
| } |
| |
| /** |
| * Create a new view div. |
| */ |
| function mkviewdiv(cname) { |
| var vdiv = document.createElement('div'); |
| vdiv.className = cname; |
| if (!ui.isMobile()) |
| return vdiv; |
| |
| // Handle view transition end |
| function viewdivtransitionend(e) { |
| if (e.target.className == 'leftviewunloaded3dm' || e.target.className == 'rightviewunloaded3dm') |
| e.target.parentNode.removeChild(e.target); |
| } |
| vdiv.addEventListener('webkitTransitionEnd', viewdivtransitionend, false); |
| vdiv.addEventListener('transitionend', viewdivtransitionend, false); |
| return vdiv; |
| } |
| |
| /** |
| * Return the last visited location. |
| */ |
| function lastvisited() { |
| if (username != lstorage.getItem('ui.lastvisit.user')) |
| return null; |
| return lstorage.getItem('ui.lastvisit.url'); |
| } |
| |
| /** |
| * Build and show the menu bar. |
| */ |
| function showmenu(mdiv, view, appname) { |
| mdiv.innerHTML = ui.menubar( |
| append(mklist(ui.menu('menuhome', 'Home', '/', '_view', view == 'home'), |
| ui.menu('menustore', 'Store', '/#view=store&category=' + storecat + '&idx=' + storeidx, '_view', view === 'store')), |
| (isNil(appname) || appname == 'undefined')? |
| mklist() : |
| mklist( |
| ui.menu('menustats', 'Stats', '/#view=stats&app=' + appname, '_view', view == 'stats'), |
| ui.menu('menupage', 'Page', '/#view=page&app=' + appname, '_view', view == 'page'), |
| ui.menu('menulogic', config.logic(), '/#view=graph&app=' + appname, '_view', view == 'graph'), |
| ui.menu('menurun', '<span class="greentext" style="font-weight: bold">Run!</span>', '/' + appname + '/', '_blank', false))), |
| (isNil(appname) || appname == 'undefined')? mklist( |
| hasauthcookie()? ui.menufunc('menusignout', 'Sign out', 'return logout();', false) : ui.menu('menusignin', 'Sign in', '/login/', '_self', false), |
| ui.menu('menuaccount', 'Account', '/#view=account', '_view', view == 'account')) : |
| mklist()); |
| |
| if (fdiv.innerHTML == '') |
| fdiv.innerHTML = config.viewfoot(); |
| } |
| |
| /** |
| * Get the current user's account. |
| */ |
| function getaccount() { |
| var doc = accounts.get(); |
| |
| // Stop now if we didn't get an account |
| if (doc == null) |
| return false; |
| |
| var accountentry = car(elementsToValues(atom.readATOMEntry(mklist(doc)))); |
| username = cadr(assoc("'id", cdr(accountentry))); |
| return true; |
| } |
| |
| /** |
| * Show a view. |
| */ |
| function showview(url) { |
| //debug('showview', url); |
| |
| // Save last visited location |
| lstorage.setItem('ui.lastvisit.user', username); |
| lstorage.setItem('ui.lastvisit.url', url); |
| |
| // Determine the view to show |
| var params = ui.fragmentParams(url); |
| var view = isNil(params['view'])? 'home' : params['view'];; |
| var uri = '/' + view + '/'; |
| var idx = isNil(params['idx'])? 0 : parseInt(params['idx']); |
| |
| // Track store category view |
| if (view == 'store') { |
| storecat = isNil(params['category'])? 'top' : params['category']; |
| storeidx = idx; |
| } |
| |
| // Determine the transition to use |
| var vtransition = uri == viewuri? (idx >= viewidx? 'left' : 'right') : viewtransition(viewuri, uri); |
| |
| // Track current view url and uri |
| viewurl = url; |
| viewuri = uri; |
| viewidx = idx; |
| |
| // Show the menu bar |
| var appname = params['app']; |
| showmenu(mdiv, view, appname); |
| |
| // Scroll to the top and hide the address bar |
| window.scrollTo(0, 0); |
| |
| // Start to unload the front view and create a new view |
| if (ui.isMobile()) { |
| // Prepare current view for transition out |
| var ovdiv = viewdiv; |
| if (!isNil(ovdiv)) { |
| ovdiv.skipNode = true; |
| ovdiv.className = 'viewunloading3dm'; |
| } |
| |
| // Load the requested doc into a new view |
| var vdiv = mkviewdiv(vtransition + 'viewloading3dm'); |
| var vdoc = appcache.get(uri); |
| vdiv.innerHTML = vdoc; |
| vcontainer.appendChild(vdiv); |
| map(ui.evalScript, ui.innerScripts(vdiv)); |
| |
| // Make sure the top document is visible |
| if (document.body.style.visibility != 'visible') |
| document.body.style.visibility = 'visible'; |
| |
| setTimeout(function() { |
| // Transition the old view out |
| if (!isNil(ovdiv)) |
| ovdiv.className = vtransition + 'viewunloaded3dm'; |
| |
| // Transition the new view in |
| vdiv.className = 'viewloaded3dm'; |
| }, 100); |
| |
| } else { |
| // Prepare current view for transition out |
| var ovdiv = viewdiv; |
| if (!isNil(ovdiv)) |
| ovdiv.skipNode = true; |
| |
| // Load the requested doc into the view |
| var vdiv = mkviewdiv('viewloading3d'); |
| var vdoc = appcache.get(uri); |
| vdiv.innerHTML = vdoc; |
| vcontainer.appendChild(vdiv); |
| map(ui.evalScript, ui.innerScripts(vdiv)); |
| |
| // Make sure the top document is visible |
| if (document.body.style.visibility != 'visible') |
| document.body.style.visibility = 'visible'; |
| |
| setTimeout(function() { |
| // Transition the new view in |
| vdiv.className = 'viewloaded3d'; |
| |
| // Transition the old view out |
| if (!isNil(ovdiv)) |
| ovdiv.parentNode.removeChild(ovdiv); |
| }, 100); |
| } |
| |
| // Track the current visible view |
| viewdiv = vdiv; |
| |
| return true; |
| } |
| |
| /** |
| * Update the browser window location. |
| */ |
| function updatelocation(url) { |
| //debug('updatelocation', url); |
| |
| // Add url to the history if necessary |
| if (url != ui.pathandparams(location)) { |
| history.pushState(null, null, url); |
| //debug('pushstate', history.length); |
| |
| // Update the location hash if necessary |
| var f = ui.fragment(url); |
| if (f != '' && f != location.hash) { |
| location.hash = f; |
| //debug('hash', f); |
| } |
| } |
| return url; |
| } |
| |
| /** |
| * Handle navigations. |
| */ |
| window.onnavigate = function(url) { |
| //debug('onnavigate', url); |
| |
| // Update the browser window location |
| updatelocation(url); |
| |
| // Show the specified view |
| if (url == viewurl) |
| return true; |
| return showview(url); |
| }; |
| |
| /** |
| * Handle login redirect. |
| */ |
| window.onloginredirect = function(e) { |
| document.location = '/login/'; |
| }; |
| |
| /** |
| * Log the current user out. |
| */ |
| window.logout = function() { |
| // Clear session cookie and user-specific local storage entries |
| clearauthcookie(); |
| lstorage.removeItem('/r/Editor/accounts'); |
| lstorage.removeItem('/r/Editor/dashboards'); |
| document.location = '/login/'; |
| return false; |
| } |
| |
| /** |
| * Handle history. |
| */ |
| window.addEventListener('popstate', function(e) { |
| //debug('onpopstate', history.length); |
| var furl = ui.fragment(location); |
| var url = location.pathname + (furl == ''? '' : '#' + furl); |
| |
| // Show the current view |
| if (url == viewurl) |
| return true; |
| return showview(url); |
| |
| }, false); |
| |
| window.addEventListener('hashchange', function(e) { |
| //debug('onhashchange'); |
| var furl = ui.fragment(location); |
| var url = location.pathname + (furl == ''? '' : '#' + furl); |
| |
| // Show the current view |
| if (url == viewurl) |
| return true; |
| return showview(url); |
| |
| }, false); |
| |
| /** |
| * Handle orientation change. |
| */ |
| document.body.onorientationchange = function(e) { |
| //debug('onorientationchange'); |
| ui.onorientationchange(e); |
| |
| // Resize menu and view header |
| mdiv.style.width = ui.pixpos(document.documentElement.clientWidth); |
| hdiv.style.width = ui.pixpos(document.documentElement.clientWidth); |
| return true; |
| }; |
| |
| /** |
| * Initialize the document. |
| */ |
| function onload() { |
| //debug('onload', history.length); |
| ui.onload(); |
| |
| // Get the current user account |
| getaccount(); |
| |
| // Show the view specified in the given url fragment |
| var furl = ui.fragment(location); |
| if (furl != '') { |
| var url = location.pathname + '#' + furl; |
| if (url == viewurl) |
| return true; |
| return showview(url); |
| } |
| |
| // Show the last visited view |
| if (ui.isMobile() && (document.referrer == null || document.referrer == '' || |
| document.referrer.indexOf('//' + location.hostname + '/login/') != -1 || |
| document.referrer.indexOf('//accounts.google.com/ServiceLogin') != -1 || |
| document.referrer.indexOf('//www.facebook.com/login.php') != -1)) { |
| var lv = lastvisited(); |
| var url = isNil(lv)? location.pathname : lv; |
| updatelocation(url); |
| if (url == viewurl) |
| return true; |
| return showview(url); |
| } |
| |
| // Show the main home view |
| var url = location.pathname; |
| if (url == viewurl) |
| return true; |
| return showview(url); |
| } |
| |
| onload(); |
| |
| })(); |
| </script> |
| |
| <div id="footdiv" class="fsection"> |
| </div> |
| |
| </div> |
| </body> |
| </html> |