當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
ExtJS + Gears
生活随笔
收集整理的這篇文章主要介紹了
ExtJS + Gears
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一直對(duì)Google的Gears很感興趣,現(xiàn)在終于有時(shí)間嘗試一下了,Gears的主要功能如下:
- LocalServer?在本地緩存和提供應(yīng)用程序資源(HTML、JavaScript、圖片等) ;
- Database?將數(shù)據(jù)存儲(chǔ)在本地可以完全搜索的關(guān)系數(shù)據(jù)庫(kù)中 ;
- WorkerPool?通過(guò)異步執(zhí)行資源優(yōu)化操作使網(wǎng)絡(luò)應(yīng)用程序的響應(yīng)速度更快。
如果要將ExtJS和Gears結(jié)合起來(lái)的話,首先想到的是用Gears來(lái)緩存ExtJS的文件,因?yàn)镋xtJS很龐大。因此首先要使用的就是LocalServer,下面就重點(diǎn)介紹如何使用LocalServer對(duì)ExtJS的資源文件進(jìn)行本地緩存。
既然要使用ExtJS和Gears,那么下載和安裝就不再討論了,這些確實(shí)很容易。(Gears安裝參考這里,ExtJS只要下載并建一個(gè)IIS虛擬目錄即可)
下面是測(cè)試用的代碼:
/// <reference path="http://localhost/ext-2.2/vswd-ext_2.2.js" />Ext.BLANK_IMAGE_URL = '/ext-2.2/resources/images/default/s.gif';// 全局緩存名稱和資源文件名稱 var STORE_NAME = 'GearStudy'; var MANIFEST_FILENAME = 'manifest.txt'; // 定義全局對(duì)localserver和ManagedStore的引用 var localServer; var store;Ext.onReady(function() {// 檢查是否已經(jīng)安裝Gearsif (!window.google || !google.gears) {textOut('Note: You must install Gears first.');return;}// 創(chuàng)建localserver和ManagedStorelocalServer = google.gears.factory.create("beta.localserver");store = localServer.createManagedStore(STORE_NAME);// ManagedStore更新出錯(cuò)時(shí)的回調(diào)函數(shù),當(dāng)應(yīng)用程序離線或者manifest文件出錯(cuò)時(shí),// 顯示一個(gè)錯(cuò)誤信息窗口store.onerror = function(error) {Ext.MessageBox.show({title: 'ERROR',msg: error.message,icon: Ext.MessageBox.ERROR,buttons: Ext.MessageBox.OK});}// 定義一個(gè)對(duì)進(jìn)度窗口的引用變量,var ub;// ManagedStore報(bào)告進(jìn)度的回調(diào)函數(shù),下載manifest文件中定義的url時(shí)調(diào)用,// 顯示一個(gè)進(jìn)度窗口,并根據(jù)下載的進(jìn)度更新進(jìn)度條。store.onprogress = function(details) {if (!ub) {ub = Ext.MessageBox.progress('Alert', 'Loading offline manifest files ...', '0.00%');}var val = details.filesComplete / details.filesTotal;ub.updateProgress(val, (val * 100).toFixed(0).toString() + '%');};// ManagedStore完成下載時(shí)的回調(diào)函數(shù),這個(gè)函數(shù)可能在兩種情況下被調(diào)用,// 1. 調(diào)用checkUpdate函數(shù)手工更新;// 2. ManagedStore自動(dòng)檢查更新。store.oncomplete = function(details) {if (ub) {ub.hide();ub = null;}if (!Ext.isEmpty(details.newVersion)) {textOut('Local manifest version is ' + details.newVersion + ' now !');}};// 輸出當(dāng)前的Gears緩存信息var msg;if (Ext.isEmpty(store.currentVersion, false)) {msg = 'No local manifest find' + ' now !';}else {msg = 'Local manifest version is ' + store.currentVersion + ' now !';}textOut(msg);// 手工更新Gears緩存,當(dāng)有了本地緩存之后,即使把IIS停掉,這個(gè)地址依舊可以瀏覽。Ext.fly('offlineBtn').on('click', function() {store.manifestUrl = MANIFEST_FILENAME;store.checkForUpdate();});// 手工刪除Gears緩存,Ext.fly('onlineBtn').on('click', function() {localServer.removeManagedStore(STORE_NAME);textOut("Done. The local store has been removed." +"You will now see online versions of the documents.");});Ext.fly('showWindow').on('click', function() {if (!window.win) {win = new Ext.Window({ width: 320, height: 240, title: 'Hello,world', closeAction: 'hide' });}win.show('showWindow');}); });// Utility function to output some status text.function textOut(s) {Ext.fly('msg').update(s); }最后使用的項(xiàng)目結(jié)構(gòu)如下圖所示,如果有興趣的話可以自己下載體驗(yàn)一下。
張志敏所有文章遵循創(chuàng)作共用版權(quán)協(xié)議,要求署名、非商業(yè) 、保持一致。在滿足創(chuàng)作共用版權(quán)協(xié)議的基礎(chǔ)上可以轉(zhuǎn)載,但請(qǐng)以超鏈接形式注明出處。
本博客已經(jīng)遷移到 GitHub , 圍觀地址:?http://beginor.github.io/
本文轉(zhuǎn)自張志敏博客園博客,原文鏈接:http://www.cnblogs.com/beginor/archive/2009/03/21/1418582.html,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者總結(jié)
以上是生活随笔為你收集整理的ExtJS + Gears的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: PHPUnit 3.4.10 在wind
- 下一篇: Python format() 函数