Why Does Settings And then Dock/Undock Break This Win 7 Desktop Gadget?
I've narrowed it down to hitting settings, then cancel or okay (no code handling settings events yet) and then attempting to hit the dock button predictably killing the gadget controls. I've tried all suggestions in comments so far including setting the class which I had a feeling was going to break the thing altog开发者_如何学JAVAether.
What's really bugging me is that it behaves the same way way regardless of arguments fed into the endTransition method or whether the end and beginTrans methods are even there. It's definitely not taking 5 full seconds to transition. That was set at 1 before. Still no difference. Nothing in docs about these transitionTypes that I can find.
HTML file:
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
<title>Time Tracker Gadget</title>
<link type="text/css" rel="stylesheet" media="screen" href="css/main.css" />
</head>
<body id="gadget">
<!-- pure HTML here, no linked scripts, inline JS, or styles -->
<script type="text/jscript" src="js/main.js"></script>
</body>
</html>
JS file:
System.Gadget.settingsUI = "settings.html";
var docked = {width:"161px", height:"110px"},
undocked = {width:"295px", height:"390px"},
gadgetEl = document.getElementById('gadget'),
addStyles = function(el,newStyles){
var elStyle = el.style;
for(var x in newStyles){ elStyle[x] = newStyles[x]; }
},
swapDockStates = function(){
System.Gadget.beginTransition();
if(System.Gadget.docked){
addStyles(gadgetEl,undocked);
}
else {
addStyles(gadgetEl,docked);
}
System.Gadget.endTransition(System.Gadget.TransitionType.morph, 5);
};
System.Gadget.onDock = swapDockStates;
System.Gadget.onUndock = swapDockStates;
XML file:
<?xml version="1.0" encoding="utf-8" ?>
<gadget>
<name>BigTime Gadget</name>
<version>1.0.0.0</version>
<author name="BigTime Software">
<info url="www.bigtime.net" />
</author>
<copyright>© BigTime Software Inc.</copyright>
<description>Time tracking gadget</description>
<hosts>
<host name="sidebar">
<base type="HTML" apiVersion="1.0.0" src="bigtime.html" />
<permissions>Full</permissions>
<platform minPlatformVersion="1.0" />
</host>
</hosts>
</gadget>
Ugh... how embarrassing. Don't link the same JS file with the event handlers and settings location in both your settings file and your gadget file. That would explain some of the apparent behavior of things not mattering whether present or removed. I do wish there was a more in-depth explanation of what's going on in terms of the global scope though.
You have to change the height of the body to avoid this problem:
swapDockStates = function(){
System.Gadget.beginTransition();
if(System.Gadget.docked){
document.body.style.height = '110px';
addStyles(gadgetEl,undocked);
}
else {
document.body.style.height = '390px';
addStyles(gadgetEl,docked);
}
System.Gadget.endTransition(System.Gadget.TransitionType.morph, 5);
};
精彩评论