📄 ui.js
字号:
// when used with Google Gears pre-release in Firefox/Mac OS X, // the browser would crash when testing in Moxie // if we set the message this way for some reason. // Brad Neuberg, bkn3@columbia.edu //syncMessage.innerHTML = message; while(syncMessage.firstChild){ syncMessage.removeChild(syncMessage.firstChild); } syncMessage.appendChild(document.createTextNode(message)); } }, _clearSyncMessage: function(){ this._setSyncMessage(""); }, _initImages: function(){ var onlineImg = dojo.byId("dot-widget-network-indicator-online"); if(onlineImg){ onlineImg.setAttribute("src", this.onlineImagePath); } var offlineImg = dojo.byId("dot-widget-network-indicator-offline"); if(offlineImg){ offlineImg.setAttribute("src", this.offlineImagePath); } var roller = dojo.byId("dot-roller"); if(roller){ roller.setAttribute("src", this.rollerImagePath); } var checkmark = dojo.byId("dot-success-checkmark"); if(checkmark){ checkmark.setAttribute("src", this.checkmarkImagePath); } }, _showDetails: function(evt){ // cancel the button's default behavior evt.preventDefault(); evt.stopPropagation(); if(!dojox.off.sync.details.length){ return; } // determine our HTML message to display var html = ""; html += "<html><head><title>Sync Details</title><head><body>"; html += "<h1>Sync Details</h1>\n"; html += "<ul>\n"; for(var i = 0; i < dojox.off.sync.details.length; i++){ html += "<li>"; html += dojox.off.sync.details[i]; html += "</li>"; } html += "</ul>\n"; html += "<a href='javascript:window.close()' " + "style='text-align: right; padding-right: 2em;'>" + "Close Window" + "</a>\n"; html += "</body></html>"; // open a popup window with this message var windowParams = "height=400,width=600,resizable=true," + "scrollbars=true,toolbar=no,menubar=no," + "location=no,directories=no,dependent=yes"; var popup = window.open("", "SyncDetails", windowParams); if(!popup){ // aggressive popup blocker alert("Please allow popup windows for this domain; can't display sync details window"); return; } popup.document.open(); popup.document.write(html); popup.document.close(); // put the focus on the popup window if(popup.focus){ popup.focus(); } }, _cancel: function(evt){ // cancel the button's default behavior evt.preventDefault(); evt.stopPropagation(); dojox.off.sync.cancel(); }, _needsBrowserRestart: function(){ var browserRestart = dojo.byId("dot-widget-browser-restart"); if(browserRestart){ dojo.addClass(browserRestart, "dot-needs-browser-restart"); } var appName = dojo.byId("dot-widget-browser-restart-app-name"); if(appName){ appName.innerHTML = ""; appName.appendChild(document.createTextNode(this.appName)); } var status = dojo.byId("dot-sync-status"); if(status){ status.style.display = "none"; } }, _showNeedsOfflineCache: function(){ var widgetContainer = dojo.byId("dot-widget-container"); if(widgetContainer){ dojo.addClass(widgetContainer, "dot-needs-offline-cache"); } }, _hideNeedsOfflineCache: function(){ var widgetContainer = dojo.byId("dot-widget-container"); if(widgetContainer){ dojo.removeClass(widgetContainer, "dot-needs-offline-cache"); } }, _initMainEvtHandlers: function(){ var detailsButton = dojo.byId("dot-sync-details-button"); if(detailsButton){ dojo.connect(detailsButton, "onclick", this, this._showDetails); } var cancelButton = dojo.byId("dot-sync-cancel-button"); if(cancelButton){ dojo.connect(cancelButton, "onclick", this, this._cancel); } }, _setOfflineEnabled: function(enabled){ var elems = []; elems.push(dojo.byId("dot-sync-status")); for(var i = 0; i < elems.length; i++){ if(elems[i]){ elems[i].style.visibility = (enabled ? "visible" : "hidden"); } } }, _syncFinished: function(){ this._updateSyncUI(); var checkmark = dojo.byId("dot-success-checkmark"); var details = dojo.byId("dot-sync-details"); if(dojox.off.sync.successful == true){ this._setSyncMessage("Sync Successful"); if(checkmark){ checkmark.style.display = "inline"; } }else if(dojox.off.sync.cancelled == true){ this._setSyncMessage("Sync Cancelled"); if(checkmark){ checkmark.style.display = "none"; } }else{ this._setSyncMessage("Sync Error"); var messages = dojo.byId("dot-sync-messages"); if(messages){ dojo.addClass(messages, "dot-sync-error"); } if(checkmark){ checkmark.style.display = "none"; } } if(dojox.off.sync.details.length && details){ details.style.display = "inline"; } }, _onFrameworkEvent: function(type, saveData){ if(type == "save"){ if(saveData.status == dojox.storage.FAILED && !saveData.isCoreSave){ alert("Please increase the amount of local storage available " + "to this application"); if(dojox.storage.hasSettingsUI()){ dojox.storage.showSettingsUI(); } // FIXME: Be able to know if storage size has changed // due to user configuration } }else if(type == "coreOperationFailed"){ console.log("Application does not have permission to use Dojo Offline"); if(!this._userInformed){ alert("This application will not work if Google Gears is not allowed to run"); this._userInformed = true; } }else if(type == "offlineCacheInstalled"){ // clear out the 'needs offline cache' info this._hideNeedsOfflineCache(); // check to see if we need a browser restart // to be able to use this web app offline if(dojox.off.hasOfflineCache == true && dojox.off.browserRestart == true){ this._needsBrowserRestart(); return; }else{ var browserRestart = dojo.byId("dot-widget-browser-restart"); if(browserRestart){ browserRestart.style.display = "none"; } } // update our sync UI this._updateSyncUI(); // register our event listeners for our main buttons this._initMainEvtHandlers(); // if offline is disabled, disable everything this._setOfflineEnabled(dojox.off.enabled); // try to go online this._testNet(); } }, _onSync: function(type){ //console.debug("ui, onSync="+type); switch(type){ case "start": this._updateSyncUI(); break; case "refreshFiles": this._setSyncMessage("Downloading UI..."); break; case "upload": this._setSyncMessage("Uploading new data..."); break; case "download": this._setSyncMessage("Downloading new data..."); break; case "finished": this._syncFinished(); break; case "cancel": this._setSyncMessage("Canceling Sync..."); break; default: dojo.warn("Programming error: " + "Unknown sync type in dojox.off.ui: " + type); break; } }, _onNetwork: function(type){ // summary: // Called when we go on- or off-line // description: // When we go online or offline, this method is called to update // our UI. Default behavior is to update the Offline // Widget UI and to attempt a synchronization. // type: String // "online" if we just moved online, and "offline" if we just // moved offline. if(!this._initialized){ return; } // update UI this._updateNetIndicator(); if(type == "offline"){ this._setSyncMessage("You are working offline"); // clear old details var details = dojo.byId("dot-sync-details"); if(details){ details.style.display = "none"; } // if we fell offline during a sync, hide // the sync info this._updateSyncUI(); }else{ // online // synchronize, but pause for a few seconds // so that the user can orient themselves if(dojox.off.sync.autoSync){ if(dojo.isAIR){ window.setTimeout(function(){dojox.off.sync.synchronize();}, 1000); }else{ window.setTimeout(dojox._scopeName + ".off.sync.synchronize()", 1000); } } } }});// register ourselves for low-level framework eventsdojo.connect(dojox.off, "onFrameworkEvent", dojox.off.ui, "_onFrameworkEvent");// start our magic when the Dojo Offline framework is ready to godojo.connect(dojox.off, "onLoad", dojox.off.ui, dojox.off.ui._initialize);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -