1.设置窗口关闭方法委托
System.Gadget.onSettingsClosing = settingsClosing;
function settingsClosing(event)
{
if(event.closeAction == event.Action.commit)
{
saveSettings();
}
else if (event.closeAction == event.Action.cancel)
{
}
event.cancel = false;
}
2.写入系统设置
this.rssFeedPath = System.Gadget.Settings.read("rssFeedPath");
3.读取系统设置
System.Gadget.Settings.write("rssFeedPath", _feedPath);
4.参数初始化
function clearViewElements()
{
positionNumbers.innerText = "";
for(i=0; i < 4; i++)
{
if ( g_viewElements !== null )
{
g_viewElements.FeedItems[i].innerHTML = "";
g_viewElements.FeedItems[i].href = "";
g_viewElements.FeedItems[i].innerText = "";
g_viewElements.FeedItems[i].setAttribute("name", "");
g_viewElements.FeedItems[i].setAttribute("localId", "");
}
eval("FeedItemName"+i).innerHTML = "";
eval("FeedItemName"+i).style.backgroundColor = "";
eval("FeedItemName"+i).innerText = "";
eval("FeedItemName"+i).setAttribute("title","");
eval("FeedItemDate"+i).innerHTML = "";
eval("FeedItemDate"+i).style.backgroundColor = "";
eval("FeedItemDate"+i).innerText = "";
eval("FeedItemDate"+i).setAttribute("title","");
eval("FeedItemLink"+i).style.textOverflow = "";
eval("FeedItemLink"+i).style.overflow = "";
eval("FeedItemLink"+i).style.whiteSpace = "";
eval("FeedItemLink"+i).style.width = "0px";
}
}
5.调试输出
System.Debug.outputString("Start Polling : Pull feeds queued up in bursts"); //DEBUG CODE
6.启动一个定时刷新
function startTimer()
{
if(g_timerFlag)
{
stopTimer();
g_timer = setInterval(setNextViewItems, g_timerMilliSecs);
}
}
setTimeout(loadData, 1000);
7.停止一个定时刷新
function stopTimer()
{
if(g_timerFlag)
{
clearInterval(g_timer);
}
}
8.指定设置页面文件
System.Gadget.settingsUI = "settings.html";
9.打开Flyout 窗口
System.Gadget.Flyout.show = true;
10.键盘按键捕获
<body onkeydown="keyNavigate();" >
function keyNavigate()
{
switch(event.keyCode)
{
case 38:
case 104:
setPreviousViewItems();
break;
case 40:
case 98:
setNextViewItems();
break;
case 32:
case 13:
if(event.srcElement.id == "buttonLeftNarrator")
{
setPreviousViewItems();
}
else if(event.srcElement.id == "buttonRightNarrator")
{
setNextViewItems();
}
break;
case 27:
hideFlyout();
break;
}
}
11.鼠标滑轮
<body onmousewheel="mouseWheeNavigate();" >
function mouseWheeNavigate()
{
if( g_returnFeed == null )
return;
var headlineCount = g_returnFeed.feedItems.length;
if(g_totalViewableItems < headlineCount)
{
headlineCount = g_totalViewableItems;
}
if(event.wheelDelta < -20)
{
setNextViewItems();
}
if(event.wheelDelta > 20)
{
setPreviousViewItems();
}
}
12 获取Flyout 文件对象,并设置内容
var flyoutDiv = System.Gadget.Flyout.document;
flyoutDiv.getElementById("flyoutTitleLink").innerText = tempTitle;
flyoutDiv.getElementById("flyoutTitleLink").href = checkHref(g_feedURL);
flyoutDiv.getElementById("flyoutTitleLink").setAttribute("title", tempTitle);
flyoutDiv.getElementById("flyoutTitleLink").style.textOverflow = "ellipsis";
flyoutDiv.getElementById("flyoutTitleLink").style.overflow = "hidden";
flyoutDiv.getElementById("flyoutTitleLink").style.whiteSpace = "nowrap";
13.窗口 停靠
if(!System.Gadget.docked)
{
var backgroundToLoad = "url(images/item_hover_floating.png)";
}
14. Flyout 窗口 文件设置
System.Gadget.Flyout.file = "flyout.html";
15. 显示设置页面的方法
System.Gadget.onShowSettings = loadSettings;
16. Gadget 是否可见
System.Gadget.visibilityChanged = checkVisibility;
function checkVisibility()
{
isVisible = System.Gadget.visible;
if (!isVisible)
{
stopTimer();
}
if(isVisible)
{
startTimer();
}
}
17. 初始化配置集合
System.Gadget.settingsUI = "settings.htm"; // 设置Setting 页面
System.Gadget.onShowSettings = procSettingsShowEvent; // set settings onshow method
System.Gadget.onSettingsClosed = procSettingsClosedEvent; // set settings onclosed method
// init dock/undock event methods
System.Gadget.onUndock = procUndockEvent; // set gadget onundock method
System.Gadget.onDock = procDockEvent; // set gadget ondock method
// init flyout event methods
System.Gadget.Flyout.file = "flyout.htm"; // set flyout page
System.Gadget.Flyout.onShow = procFlyoutShowEvent; // set gadget flyout show event
System.Gadget.Flyout.onHide = procFlyoutHideEvent; // set gadget flyout hide event
18. 简化开发的最好方法,是下载现有的Gadget,修改其内容实用,下面是地址。
http://vista.gallery.microsoft.com/vista/SideBar.aspx?mkt=zh-cn
http://vista.gallery.microsoft.com/vista/SideBar.aspx?mkt=en
19. 如果Gadget中嵌入Flash
1.要将投影效果去掉
2. 添加透明属性
if(typeof infosoftglobal == "undefined") var infosoftglobal = new Object();
if(typeof infosoftglobal.FusionChartsUtil == "undefined") infosoftglobal.FusionChartsUtil = new Object();
var FusionCharts = infosoftglobal.FusionCharts;
this.addParam('Wmode', 'transparent');
FusionCharts.prototype = {
setAttribute: function(name, value){
this.attributes[name] = value;
},
getAttribute: function(name){
return this.attributes[name];
},
addParam: function(name, value){
this.params[name] = value;
},
getParams: function(){
return this.params;
}
}
var params = this.getParams();
for(var key in params) {
swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
}
3.使用一个透明背景的Png 图片最背景,达到背景透明的效果,并设置四边框为0,如下
<body onload="Initialize();" style=" margin:0; width: 200px; height: 200px; background-repeat:no-repeat; background:url(bgbk5.png);">
function Initialize() {
try {
System.Gadget.settingsUI = "options.html";
} catch (e) { };
}
4.在重复加载一个Flash,数据源的时候,会有缓存的问题,简单的解决办法就是用时间拼装不重复的访问字符串,已达到每次访问都不一样的目的,避免缓存
function updateChart(DOMId) {
var strURL = "http://localhost:9999/Chart/Gallery/Data/Angular5.xml?time=a" + Date.prototype.Format("yyyyMMddhhmmss");
var myChart = new FusionCharts("http://localhost:9999/Chart/Charts/AngularGauge.swf", "myChartId", "200", "200", "0", "0");
myChart.setDataURL(strURL);
myChart.render("chartdiv");
}