您的位置:首页 > 编程语言 > Go语言

Google Gear 基本使用方法

2012-03-09 00:00 567 查看

转自:http://zybingliu.blogspot.com/2009/04/google-gear.html

Google Gear从例子上看,好像很容易使用(当然,仅仅是最基本的入门):

首先通过例子的gears_init.js生成一个Google Gears对象:google.gears

后面所有的操作通过这个对象进行。这个就直接抄gears_init.js实现,自己不用做任何处理了。

对google.gears对象的判断:

if (!window.google || !google.gears) {

textOut("NOTE: You must install Gears first."); --- 提示没有安装google gear,

} else { ---- 安装了google gear,生成自己的localserver和store

localServer = google.gears.factory.create("beta.localserver");

store = localServer.createManagedStore(STORE_NAME);

textOut("Yeay, Gears is already installed.");

}

其中的:STORE_NAME就是一个自己随意取的名字;

MANIFEST的文件,在create store的时候使用到

if (!window.google || !google.gears) { --- 判断是否安装了gear

alert("You must install Gears first.");

return;

}

store.manifestUrl = MANIFEST_FILENAME; ---
这个就是定义manifest文件名字的,而且mainfest的文件,要和当前的页面放在同一个目录中(如果没有设置目录的话)

store.checkForUpdate(); --- 对store的创建更新

var timerId = window.setInterval(function() { --- 这是一个把更新的状态显示出来的脚本

// When the currentVersion property has a value, all of the resources

// listed in the manifest file for that version are captured. There is

// an open bug to surface this state change as an event.

if (store.currentVersion) {

window.clearInterval(timerId);

textOut("The documents are now available offline./n" +

"With your browser offline, load the document at " +

"its normal online URL to see the locally stored " +

"version. The version stored is: " +

store.currentVersion);

} else if (store.updateStatus == 3) {

textOut("Error: " + store.lastErrorMessage);

}

}, 500);

删除一个store也是相当容易的:

if (!window.google || !google.gears) {

alert("You must install Gears first.");

return;

}

localServer.removeManagedStore(STORE_NAME); --- 删除,这个STORE_NAME就是上面创建时候的STORE NAME

textOut("Done. The local store has been removed." +

"You will now see online versions of the documents.");

$(document).ready(function(){dp.SyntaxHighlighter.HighlightAll('code');});

原文链接:
http://blog.csdn.net/vanessa219/article/details/4441289
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: