How to pass parameters to the flyout of windows 7 gadget?
This is my code i want to pass parameters to the flyout function but it doesnt work, i remove parameters it work . is this code true?
$(document).ready(function() {
var now = new Date();
$.ajax({
type: "GET",
url: 'http://sarafandnet.com/sites.xml',
dataType: "xml",
success: function(xml) {
$(xml).find('New').each(function() {
var id = $(this).attr('id');
var title = $(this).find('title').text();
var date = $(this).find('date').text();
var url = $(this).find('url').text();
var desc = $(this).find('desc').text();
if (now.getDate() == date) {
document.getElementById("td" + date).innerHTML = '<table width="16" border="0" cellspacing="0" cellpadding="0"><tr><td height="21" ><a href="javascript:void(0);" onclick="showFlyout(\'' + title + '\',\'' + desc + '\')" class="ligh开发者_StackOverflow社区twindow" height="10px" title="' + title + '" caption="' + desc + '" >click</a></td></tr></table>';
}
});
}
});
});
function Init() {
System.Gadget.Flyout.file = "flyout.html";
// Initialize the Flyout state display.
if (!System.Gadget.Flyout.show) {
sFlyoutFeedback.innerText = "Flyout hidden.";
}
}
function showFlyout(titlee, descc) {
System.Gadget.Settings.write("title", titlee);
System.Gadget.Settings.write("desc", descc);
System.Gadget.Flyout.file = "flyout.html";
System.Gadget.Flyout.show = true;
}
function showFlyout() {
System.Gadget.Flyout.show = true;
}
function hideFlyout() {
oGadgetDocument.getElementById("strFlyoutFeedback").innerText = "Flyout hidden.";
System.Gadget.Flyout.show = false;
}
You cannot declare a function with the same name more than once; even if the functions accept different parameters.
Your second declaration of
showFlyout
(accepting no parameters), is overriding the first.If you want this behaviour (optional parameters), you should do something like this:
function showFlyout(titlee, descc) { if (arguments.length == 0) { System.Gadget.Flyout.show = true; } else { System.Gadget.Settings.write("title", titlee); System.Gadget.Settings.write("desc", descc); System.Gadget.Flyout.file = "flyout.html"; System.Gadget.Flyout.show = true; } }
Each time you call
$(this)
, you're recreating exactly the same jQuery object... cache it:$(xml).find('New').each(function() { var self = $(this); // cache this var id = self.attr('id'); // now use self instead of this var title = self.find('title').text(); var date = self.find('date').text(); var url = self.find('url').text(); var desc = self.find('desc').text(); if (now.getDate() == date) { document.getElementById("td" + date).innerHTML = '<table width="16" border="0" cellspacing="0" cellpadding="0"><tr><td height="21" ><a href="javascript:void(0);" onclick="showFlyout(\'' + title + '\',\'' + desc + '\')" class="lightwindow" height="10px" title="' + title + '" caption="' + desc + '" >click</a></td></tr></table>'; } });
The Windows Gallery is retired as of last week, so you will never be able to publish your Gadget to the official Gallery.
精彩评论