Widget - How it works
Requires Widget plugin to be added to the toolbar.
XML Format description:
<SHOWWIDGET name="widgetwindow__GadgetRX0" template="template.htm" width="400" height="400">
<PROPERTY key="content"><?[CDATA[ Content goes here ...]]></PROPERTY>
<PROPERTY key="x" value="100"/>
<PROPERTY key="y" value="100"/>
<PROPERTY key="caption" value="No caption"/>
<PROPERTY key="sizeable" value="false"/>
<PROPERTY key="minwidth" value="200"/>
<PROPERTY key="minheight" value="200"/>
</SHOWWIDGET>
Attributes
| Name |
Type |
Description |
| ***name*** |
string |
string to identify the widget window |
| url |
string uri |
URL wich will be opened inside the widget plugin |
| template |
string uri |
URL of the HTML file used as frame for window. Contains close button, movable layer, sizeable scroll and other UI; |
| width |
integer |
|
| height |
integer |
Width of the widget window in pixels |
| caption |
string |
Heightof the widget window in pixels |
| x |
integer |
Position of the widget window in pixels from left side of the screen |
| y |
integer |
Position of the widget window in pixels from top side of the screen |
| position |
string |
Determine position of the window on the screen; |
| use_mainwindow |
0/1 |
Determine navigation frame; when use_mainwindow="1" all links on the widget window will be opened in the main IE window; |
Properties
| Name |
Type |
Description |
| sizeable |
bool |
If sizeable="true" a small corner picture will appear to be used for sizing widget window |
| maxwidth |
integer |
Determine maximal size of widget window in sizeable mode |
| minheight |
integer |
Determine minimal size of widget window in sizeable mode |
Position
- top
- bottom
- left
- right
- right-top
- left-top
- right-bottom
- left-bottom
Javascript Api
Interface
function GetProperty(name, value); // Returns the value of the property by name
function SetProperty(name, value); // Sets the value of the property by name
function SetWindowPos(...); // Changes the position/size of the Widget window on the screen
function ModifyStyle(...); // Changes the styles of the window
function MoveWindow(...); // Changes the position of the Widget windows on the screen
function ResizeWindow(...); // Changes the size of the window
function MakeWindowTransparent(...); // Makes the window semi-transparent
function Capturemouse(); // Moves the window with a mouse cursor
function GetWindowRect(...); // Returns the coordinates of the window
Example :
var oldValue = 300;
var alwaysOnTopState = false;
var isMaximized = true;
var captionSize = 24;
var isBorder = false;
var tool = null;
var ie = true;
function ToolBarInit(_tool)
{
tool = _tool;
ie = false;
onReady();
}
function GetProperty(name, value)
{
if (tool)
{
return tool.getProperty(name, value);
} else
return window.external.GetProperty(name, value);
}
function SetProperty(name, value)
{
if (tool)
{
return tool.setProperty(name, value);
} else
return window.external.SetProperty(name, value);
}
function AlwaysOnTopTriger() {
AlwaysOnTop(alwaysOnTopState);
alwaysOnTopState = !alwaysOnTopState;
}
function AlwaysOnTop(b) {
try{
if (b) window.external.SetWindowPos(-2, 0, 0, 0, 0, 3);
else window.external.SetWindowPos(-1, 0, 0, 0, 0, 3);
} catch (err) {}
}
function MinimizeMaximizeTriger() {
if (isMaximized) {
Minimize();
}
else {
Maximize();
}
isMaximized = !isMaximized;
}
function BorderTriger() {
if (isBorder) {
BorderOff();
}
else {
BorderOn();
}
isBorder = !isBorder;
}
function BorderOn() {
try{
//WS_THICKFRAME, SWP_FRAMECHANGED
window.external.ModifyStyle(0, 262144, 32);
} catch (err) {}
return false;
}
function BorderOff() {
try{
//WS_THICKFRAME, SWP_FRAMECHANGED
window.external.ModifyStyle(262144,0, 32);
} catch (err) {}
return false;
}
function Minimize() {
if (tool)
{
var size = tool.getSize();
oldValue = size[1];
tool.resize(size[0], captionSize);
} else {
try{
window.external.GetWindowRect(function(left, top, right, bottom) {
oldValue = bottom - top;
if (oldValue < 100) oldValue = 100;
window.external.MoveWindow(left, top, right - left, captionSize);
moveSmoothCorner(right - left, captionSize);
document.getElementById("_content").style.display = "none";
});
} catch (err) {}
}
return false;
}
function Maximize() {
if (tool)
{
var size = tool.getSize();
tool.resize(size[0], oldValue);
} else {
try{
window.external.GetWindowRect(function(left, top, right, bottom) {
window.external.MoveWindow(left, top, right - left, oldValue);
moveSmoothCorner(right - left, oldValue);
document.getElementById("_content").style.display = "block";
});
} catch (err) {}
}
return false;
}
function Close() {
if (tool)
{
tool.close();
} else
try{
setTimeout("smoothChangeTransparency(220, 0, -10)", 10);
setTimeout("window.external.Close()", 210);
} catch (err) {}
return false;
}
function Capturemouse() {
try{
window.external.Capturemouse();
} catch (err) {}
}
function whichElement(e) {
if (tool)
{
tool.captureMouse(e);
return;
}
var targ
if (!e) var e = window.event
if (e.target) targ = e.target
else if (e.srcElement) targ = e.srcElement
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode
var tname
tname = targ.tagName
if (tname != "INPUT") Capturemouse()
}
function smoothChangeTransparency(from, to, step)
{
try
{
from += step;
from = (from > 255) ? 255 : ((from < 0)? 0 : from);
window.external.MakeWindowTransparent(0xEEFF00, from);
if ((step>0 && from<=to) || (step<0 && from>=to))
setTimeout("smoothChangeTransparency("+from+","+to+","+step+")", 10);
} catch (err) {}
}
function onReady(){
try
{
//BorderTriger();
var userVarsStr = GetProperty("user_vars","");
placeWindowButtons(true, userVarsStr, !tool, true);
document.getElementById("_header").innerHTML = GetProperty("caption","");
if (!tool)
{
AlwaysOnTopTriger();
window.external.MakeWindowTransparent(0x00FFEE, 0);
placeSmoothCorner();
}
if (userVarsStr && (GetProperty("first_start","true") == "true"))
{
showSettings();
} else {
showContent(false);
}
if (!tool)
{
window.external.Show();
setTimeout("smoothChangeTransparency(0, 220, 10)", 10);
}
} catch (err) {}
}
function prepeareString($0, $1)
{
return GetProperty($1, $1);
}
function prepeareWidget(src)
{
return src.replace(/\[\[(\w*?)\]\]/ig, prepeareString);
}
function showSettings()
{
var userVarsStr = GetProperty("user_vars","");
if (userVarsStr)
{
var userVars = eval("(" + userVarsStr + ");");
var html = "<center><table>";
for(variable in userVars)
{
html += "<tr><td class='name_field'>" + userVars[variable].screenName + "</td>";
if (userVars[variable].type == "enum")
{
html += "<td><SELECT class='input_field' id='"+variable+"'>";
for(val in userVars[variable].values)
{
html += "<OPTION value='"+val+"'";
if (val == GetProperty(variable,""))
html += ' SELECTED';
html += ">"+userVars[variable].values[val]+"</OPTION>";
}
html += "</SELECT></TD>";
} else {
html += "<td><input type='text' class='input_field' id='"+variable+"' value='"+GetProperty(variable,"")+"'></td>";
}
}
html += "</tr>";
html += "<tr><td colspan=2 align=right>";
html += "<input type=button value='Cancel' class='save_button' onClick='javascript:showContent(false);'>";
html += "<input type=button value='Save' class='save_button' onClick='javascript:showContent(true);'></td></tr>";
html += "</table>";
document.getElementById("_content").innerHTML = html;
}
}
function showContent(first_start)
{
if(first_start)
{
var fields = document.getElementsByTagName('input');
for (i=0; i<fields.length; i++) {
SetProperty(fields[i].id, fields[i].value);
}
fields = document.getElementsByTagName('select');
for (i=0; i<fields.length; i++) {
SetProperty(fields[i].id, fields[i].value);
}
SetProperty("first_start", "false");
}
//document.getElementById("_content").innerHTML = "<textarea>" + prepeareWidget(GetProperty("widgetpath","")) + "</textarea>";
document.getElementById("_content").innerHTML = prepeareWidget(GetProperty("widgetpath",""));
}
function onHover(obj, src)
{
obj.src = src;
}
function placeWindowButtons(bMinimize, bSettings, bOnTop, bClose)
{
var buttons = "";
if (bMinimize) buttons += '<span onmousedown="MinimizeMaximizeTriger();"><img src="minimize.gif" onMouseOver="onHover(this, \'onminimize.gif\');" onMouseOut="onHover(this, \'minimize.gif\');"></span>';
if (bSettings) buttons += '<span onmousedown="showSettings();"><img src="settings.gif" onMouseOver="onHover(this, \'onsettings.gif\');" onMouseOut="onHover(this, \'settings.gif\');"></span>';
if (bOnTop) buttons += '<span onmousedown="AlwaysOnTopTriger();"><img src="ontop.gif" onMouseOver="onHover(this, \'onontop.gif\');" onMouseOut="onHover(this, \'ontop.gif\');"></span>';
if (bClose) buttons += '<span onmousedown="Close();"><img src="close.gif" onMouseOver="onHover(this, \'onclose.gif\');" onMouseOut="onHover(this, \'close.gif\');"></span>';
buttons += '<span> </span>';
document.getElementById("_window_buttons").innerHTML = buttons;
}
function placeSmoothCorner()
{
var html = "";
var width = 1*window.external.GetProperty("width", 0)-6;
var height = 1*window.external.GetProperty("height", 0)-6;
html += "<img id=_lt src='lt.gif' border=0 style='position:absolute; top:0px; left:0px;'>";
html += "<img id=_rt src='rt.gif' border=0 style='position:absolute; top:0px; left:"+width+"px;'>";
html += "<img id=_rb src='rb.gif' border=0 style='position:absolute; top:"+height+"px; left:"+width+"px;'>";
html += "<img id=_lb src='lb.gif' border=0 style='position:absolute; top:"+height+"px; left:0px;'>";
document.body.innerHTML += html;
}
function moveSmoothCorner(width, height)
{
try{
document.getElementById("_lb").style.top = 1*height-6 + "px";
document.getElementById("_rb").style.top = 1*height-6 + "px";
document.getElementById("_rb").style.left = 1*width-6 + "px";
document.getElementById("_rt").style.left = 1*width-6 + "px";
} catch(err){}
}
Widget Support Box
For supporting widgets from widgetbox.com the script has been written that adds a button to the page, which adds a widget to the custom_xml of toolbar
function alert(msg)
{
MainWindow.document.parentWindow.alert(msg);
}
function addWidget(widget)
{
try
{
if (widget==null)
return;
if(!MainWindow.document.parentWindow.confirm("Are you sure you want to add this widget on the toolbar?"))
return;
var context = MainWindow.document.parentWindow.document;
var widgetWindow = {width: 300, height: 300, name: "Widget", sourceId: widget.sourceId}
var blidgetWidthField = context.getElementById("appInstance.width");
if (blidgetWidthField)
widgetWindow.width = 40 + 1*blidgetWidthField.value;
var blidgetHeightField = context.getElementById("appInstance.height");
if (blidgetHeightField)
widgetWindow.height = 60 + 1*blidgetHeightField.value;
var blidgetNameField = context.getElementById("wdgt-name");
if (blidgetNameField)
widgetWindow.name = blidgetNameField.innerText;
var sWidgetList = gTool.LoadFile("toolbarWidgetList", "[]");
var widgetList = new Array();
if (sWidgetList != '')
widgetList = JSON.parse(sWidgetList);
widgetList.push(widgetWindow);
gTool.SaveFile("toolbarWidgetList", JSON.stringify(widgetList));
updateCustomXML(widgetList);
} catch(e){alert(e);}
}
function xmlEscape(text)
{
return text.replace(/&/, "&").replace(/</, "<lt;").replace(/>/, ">").replace(/"/, ""e;");
}
function updateCustomXML(widgetList)
{
try
{
var commands = '';
var buttons = '';
for(i=0; i<widgetList.length; i++)
{
var widget = widgetList[i];
commands +=
" <SHOWWIDGET name=\"command_"+widget.sourceId+"\" template=\"template_widget.htm\" width=\""+widget.width+"\" height=\""+widget.height+"\" caption=\""+xmlEscape(widget.name)+"\">"+
" <PROPERTY key=\"sizeable\" value=\"true\"/>"+
" <PROPERTY key=\"minwidth\" value=\""+widget.width+"\"/>"+
" <PROPERTY key=\"minheight\" value=\""+widget.height+"\"/>"+
" <PROPERTY key=\"content\"><![CDATA[if (WIDGETBOX) WIDGETBOX.renderWidget('"+widget.sourceId+"');]]></PROPERTY>"+
" </SHOWWIDGET>";
buttons += "<BUTTON id=\"button_"+widget.sourceId+"\" command=\"command_"+widget.sourceId+"\" caption=\""+xmlEscape(widget.name)+"\" type=\"Split\" visibility=\"1\"/>";
}
var str = "<TOOLBAR><COMMANDS>"+commands+"</COMMANDS>"+buttons+"</TOOLBAR>";
SetXml("WidgetCustomXML", str);
} catch(e)
{
alert("updateCustomXML: " + e);
}
}
function SetXml(section, textXml)
{
try
{
if (gTool.CustomXML(section) != textXml)
{
gTool.CustomXML(section) = textXml;
gTool.Reload(); //-- reload it
}
} catch(e){alert(e)}
}
var gTool;
function DocumentComplete(tool, type)
{
gTool = tool;
if ((tool.url.indexOf("widgetbox.com")>0) && (type=="window"))
{
try
{
addWidgetButton();
} catch(e){alert(e)}
}
}
function addWidgetButton()
{
try
{
var context = MainWindow.document.parentWindow.document;
if (MainWindow.document.parentWindow.WbxGetWidget)
{
var box = context.getElementById("otherInstallTargets");
if (box)
{
var div = context.createElement("IMG");
//div.className = "install-tile";
div.style.width = "41px";
div.style.height = "41px";
div.style.background = "transparent url(http://softomate.net/ext/widget/tb.gif) no-repeat scroll 50% 50%;";
div.src = "http://pub.widgetbox.com/images/tile-overlay.png";
var anc = context.createElement("A");
anc.className = "install-tile";
anc.attachEvent("onmouseover", function(){MainWindow.document.parentWindow.status=''; return true;});
anc.href = "javascript: if(WbxGetWidget) ToolbarAddWidget(WbxGetWidget);";
anc.appendChild(div);
box.insertBefore(anc, box.firstChild);
MainWindow.document.parentWindow.ToolbarAddWidget = addWidget;
}
}
} catch(e){alert("addWidgetButton: "+e);}
}
//////////////////////////////////////////////////////////////////////////
// JSON Parser & Stringifier
// Here goes implmentation of JSON parser