1 /* ************************************************************************
3 qooxdoo - the new era of web development
8 2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org
11 LGPL 2.1: http://www.gnu.org/licenses/lgpl.html
14 * Sebastian Werner (wpbasti)
15 * Andreas Ecker (ecker)
17 ************************************************************************ */
19 /* ************************************************************************
22 ************************************************************************ */
25 * @event loadComplete {qx.event.type.Event}
27 qx.OO.defineClass("qx.ui.embed.GalleryList", qx.ui.basic.Terminator,
30 qx.ui.basic.Terminator.call(this);
32 this._blank = qx.manager.object.AliasManager.getInstance().resolvePath("static/image/blank.gif");
33 this._list = galleryList;
34 this._listSize = galleryList.length;
35 this._processedImages = 0;
37 this.setOverflow("auto");
39 this.setHtmlProperty("className", "qx_ui_embed_GalleryList");
41 this._manager = new qx.manager.selection.DomSelectionManager(this);
43 this.addEventListener("mousedown", this._onmousedown);
44 this.addEventListener("mouseup", this._onmouseup);
45 this.addEventListener("click", this._onclick);
46 this.addEventListener("dblclick", this._ondblclick);
47 this.addEventListener("keypress", this._onkeypress);
50 qx.OO.addProperty({ name : "thumbMaxWidth", type : "number", defaultValue : 60 });
51 qx.OO.addProperty({ name : "thumbMaxHeight", type : "number", defaultValue : 60 });
52 qx.OO.addProperty({ name : "decorHeight", type : "number", defaultValue : 40 });
59 ---------------------------------------------------------------------------
61 ---------------------------------------------------------------------------
64 qx.Proto._applyElementData = function() {
65 this.getElement().appendChild(this.createView());
71 ---------------------------------------------------------------------------
73 ---------------------------------------------------------------------------
76 qx.Proto.getManager = function() {
81 qx.Proto.update = function(vGalleryList)
83 this._manager.deselectAll();
85 this._list = vGalleryList;
87 var el = this.getElement();
88 el.replaceChild(this.createView(), el.firstChild);
92 qx.Proto.removeAll = function()
94 this._manager.deselectAll();
95 this.getElement().innerHTML = "";
100 ---------------------------------------------------------------------------
102 ---------------------------------------------------------------------------
105 qx.Proto._onmousedown = function(e)
107 var vItem = this.getListItemTarget(e.getDomTarget());
110 this._manager.handleMouseDown(vItem, e);
114 qx.Proto._onmouseup = function(e)
116 var vItem = this.getListItemTarget(e.getDomTarget());
119 this._manager.handleMouseUp(vItem, e);
123 qx.Proto._onclick = function(e)
125 var vItem = this.getListItemTarget(e.getDomTarget());
128 this._manager.handleClick(vItem, e);
132 qx.Proto._ondblclick = function(e)
134 var vItem = this.getListItemTarget(e.getDomTarget());
137 this._manager.handleDblClick(vItem, e);
141 qx.Proto._onkeypress = function(e) {
142 this._manager.handleKeyPress(e);
145 qx.Proto.getListItemTarget = function(dt)
147 while(dt.className.indexOf("galleryCell") == -1 && dt.tagName.toLowerCase() != "body") {
151 if (dt.tagName.toLowerCase() == "body") {
165 ---------------------------------------------------------------------------
167 ---------------------------------------------------------------------------
170 qx.Proto.scrollItemIntoView = function(vItem)
172 this.scrollItemIntoViewX(vItem);
173 this.scrollItemIntoViewY(vItem);
176 qx.Proto.scrollItemIntoViewX = function(vItem) {
177 qx.dom.ScrollIntoView.scrollX(vItem);
180 qx.Proto.scrollItemIntoViewY = function(vItem) {
181 qx.dom.ScrollIntoView.scrollY(vItem);
193 ---------------------------------------------------------------------------
194 SELECTION MANAGER API
195 ---------------------------------------------------------------------------
198 qx.Proto.getItems = function() {
199 return this._frame.childNodes;
202 qx.Proto.getFirstChild = function() {
203 return this._frame.childNodes[0];
206 qx.Proto.getLastChild = function() {
207 return this._frame.childNodes[this._frame.childNodes.length-1];
216 ---------------------------------------------------------------------------
218 ---------------------------------------------------------------------------
221 qx.Proto.createView = function()
223 var s = (new Date).valueOf();
225 var protoCell = this.createProtoCell(this.getThumbMaxHeight());
226 var frame = this._frame = document.createElement("div");
228 this._frame.className = "galleryFrame clearfix";
232 for (var i=0, a=this._list, l=a.length, d; i<l; i++)
236 cframe = protoCell.cloneNode(true);
241 cnode = cframe.childNodes[0];
242 cnode.firstChild.nodeValue = d.number;
244 cnode = cframe.childNodes[1].firstChild;
245 this.createImageCell(cnode, d);
247 cnode = cframe.childNodes[2].firstChild;
248 cnode.firstChild.nodeValue = d.title;
250 cnode = cframe.childNodes[2].lastChild;
251 cnode.firstChild.nodeValue = d.comment;
253 frame.appendChild(cframe);
259 qx.Proto._mshtml = qx.sys.Client.getInstance().isMshtml();
261 qx.Proto.createImageCell = function(inode, d)
263 if (this.hasEventListeners("loadComplete")) {
264 inode.onload = qx.ui.embed.GalleryList.imageOnLoad;
265 inode.onerror = qx.ui.embed.GalleryList.imageOnError;
266 inode.gallery = this;
269 inode.width = d.thumbWidth;
270 inode.height = d.thumbHeight;
273 inode.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + d.src + "',sizingMethod='scale')";
278 inode.style.marginLeft = inode.style.marginRight = Math.floor((this.getThumbMaxWidth()-d.thumbWidth)/2) + "px";
279 inode.style.marginTop = inode.style.marginBottom = Math.floor((this.getThumbMaxHeight()-d.thumbHeight)/2) + "px";
282 qx.Proto.createProtoCell = function(tHeight)
284 var frame = document.createElement("div");
285 frame.className = "galleryCell";
286 frame.unselectable = "on";
287 frame.style.height = (tHeight + 2) + "px";
289 var number = document.createElement("div");
290 number.className = "galleryNumber";
291 number.unselectable = "on";
292 var ntext = document.createTextNode("-");
293 number.appendChild(ntext);
295 var imageContainer = document.createElement("div");
296 imageContainer.className = "galleryImageContainer";
297 imageContainer.unselectable = "on";
299 var image = new Image();
300 image.src = this._blank;
302 imageContainer.appendChild(image);
304 var text = document.createElement("div");
305 text.className = "galleryText";
306 text.unselectable = "on";
307 text.style.width = (this.getWidth()-100-this.getThumbMaxWidth()) + "px";
309 var title = document.createElement("h3");
310 var ttext = document.createTextNode("-");
311 title.appendChild(ttext);
312 title.unselectable = "on";
313 text.appendChild(title);
315 var comment = document.createElement("p");
316 var ctext = document.createTextNode("-");
317 comment.appendChild(ctext);
318 comment.unselectable = "on";
319 text.appendChild(comment);
322 frame.appendChild(number);
323 frame.appendChild(imageContainer);
324 frame.appendChild(text);
336 ---------------------------------------------------------------------------
338 ---------------------------------------------------------------------------
341 qx.Proto.imageOnComplete = function()
343 this._processedImages++;
345 if(this._processedImages == this._listSize) {
346 this.dispatchEvent(new qx.event.type.Event("loadComplete"), true);
350 qx.ui.embed.GalleryList.imageOnLoad = function()
352 this.gallery.imageOnComplete();
358 qx.ui.embed.GalleryList.imageOnError = function()
360 this.gallery.imageOnComplete();
373 ---------------------------------------------------------------------------
375 ---------------------------------------------------------------------------
378 qx.Proto.dispose = function()
380 if (this.getDisposed()) {
389 this._manager.dispose();
390 this._manager = null;
393 this.removeEventListener("mousedown", this._onmousedown);
394 this.removeEventListener("mouseup", this._onmouseup);
395 this.removeEventListener("click", this._onclick);
396 this.removeEventListener("dblclick", this._ondblclick);
397 this.removeEventListener("keydown", this._onkeydown);
399 return qx.ui.basic.Terminator.prototype.dispose.call(this);