r20517: re-add cleaned-up webapps
[kai/samba.git] / webapps / qooxdoo-0.6.3-sdk / frontend / framework / source / class / qx / ui / embed / IconHtmlEmbed.js
1 /* ************************************************************************
2
3    qooxdoo - the new era of web development
4
5    http://qooxdoo.org
6
7    Copyright:
8      2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org
9
10    License:
11      LGPL 2.1: http://www.gnu.org/licenses/lgpl.html
12
13    Authors:
14      * Sebastian Werner (wpbasti)
15      * Andreas Ecker (ecker)
16
17 ************************************************************************ */
18
19 /* ************************************************************************
20
21
22 ************************************************************************ */
23
24 qx.OO.defineClass("qx.ui.embed.IconHtmlEmbed", qx.ui.embed.HtmlEmbed,
25 function(vHtml, vIcon, vIconWidth, vIconHeight)
26 {
27   qx.ui.embed.HtmlEmbed.call(this, vHtml);
28
29   if (typeof vIcon != "undefined")
30   {
31     this.setIcon(vIcon);
32
33     if (typeof vIconWidth != "undefined") {
34       this.setIconWidth(vIconWidth);
35     }
36
37     if (typeof vIconHeight != "undefined") {
38       this.setIconHeight(vIconWidth);
39     }
40   }
41 });
42
43
44
45
46 /*
47 ---------------------------------------------------------------------------
48   PROPERTIES
49 ---------------------------------------------------------------------------
50 */
51
52 /*!
53   Any URI String supported by qx.ui.basic.Image to display a icon
54 */
55 qx.OO.addProperty({ name : "icon", type : "string", impl : "html" });
56
57 /*!
58   The width of the icon.
59   If configured, this makes qx.ui.embed.IconHtmlEmbed a little bit faster as it does not need to wait until the image loading is finished.
60 */
61 qx.OO.addProperty({ name : "iconWidth", type : "number", impl : "html" });
62
63 /*!
64   The height of the icon
65   If configured, this makes qx.ui.embed.IconHtmlEmbed a little bit faster as it does not need to wait until the image loading is finished.
66 */
67 qx.OO.addProperty({ name : "iconHeight", type : "number", impl : "html" });
68
69 /*!
70   Space in pixels between the icon and the HTML.
71 */
72 qx.OO.addProperty({ name : "spacing", type : "number", defaultValue : 4, impl : "html" });
73
74
75
76
77
78 /*
79 ---------------------------------------------------------------------------
80   UTILITIES
81 ---------------------------------------------------------------------------
82 */
83
84 qx.Proto._mshtml = qx.sys.Client.getInstance().isMshtml();
85
86 qx.Proto._syncHtml = function()
87 {
88   var vHtml = [];
89
90   if (qx.util.Validation.isValidString(this.getIcon()))
91   {
92     vHtml.push("<img src=\"");
93     vHtml.push(qx.manager.object.AliasManager.getInstance().resolvePath(this._mshtml ? "static/image/blank.gif" : this.getIcon()));
94     vHtml.push("\" style=\"vertical-align:middle;");
95
96     if (qx.util.Validation.isValidNumber(this.getSpacing()))
97     {
98       vHtml.push("margin-right:");
99       vHtml.push(this.getSpacing());
100       vHtml.push("px;");
101     }
102
103     if (qx.util.Validation.isValidNumber(this.getIconWidth()))
104     {
105       vHtml.push("width:");
106       vHtml.push(this.getIconWidth());
107       vHtml.push("px;");
108     }
109
110     if (qx.util.Validation.isValidNumber(this.getIconHeight()))
111     {
112       vHtml.push("height:");
113       vHtml.push(this.getIconHeight());
114       vHtml.push("px;");
115     }
116
117     if (this._mshtml)
118     {
119       vHtml.push("filter:");
120       vHtml.push("progid:DXImageTransform.Microsoft.AlphaImageLoader(src='");
121       vHtml.push(qx.manager.object.AliasManager.getInstance().resolvePath(this.getIcon()));
122       vHtml.push("',sizingMethod='scale')");
123       vHtml.push(";");
124     }
125
126     vHtml.push("\"/>");
127   }
128
129   if (qx.util.Validation.isValidString(this.getHtml())) {
130     vHtml.push(this.getHtml());
131   }
132
133   this.getElement().innerHTML = vHtml.join("");
134 }