r21325: delete children in reverse order since the array is manipulated during the...
[Samba/gbeck.git] / webapps / qooxdoo-0.6.3-sdk / frontend / framework / source / class / qx / ui / embed / GalleryList.js
blobc95b014f6d29ea3ecd0940b439af10a0bf18e128
1 /* ************************************************************************
3    qooxdoo - the new era of web development
5    http://qooxdoo.org
7    Copyright:
8      2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org
10    License:
11      LGPL 2.1: http://www.gnu.org/licenses/lgpl.html
13    Authors:
14      * Sebastian Werner (wpbasti)
15      * Andreas Ecker (ecker)
17 ************************************************************************ */
19 /* ************************************************************************
22 ************************************************************************ */
24 /**
25  * @event loadComplete {qx.event.type.Event}
26  */
27 qx.OO.defineClass("qx.ui.embed.GalleryList", qx.ui.basic.Terminator,
28 function(galleryList)
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);
48 });
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 ---------------------------------------------------------------------------
60   ELEMENT HANDLING
61 ---------------------------------------------------------------------------
64 qx.Proto._applyElementData = function() {
65   this.getElement().appendChild(this.createView());
71 ---------------------------------------------------------------------------
72   UTILITIES
73 ---------------------------------------------------------------------------
76 qx.Proto.getManager = function() {
77   return this._manager;
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 ---------------------------------------------------------------------------
101   EVENT HANDLER
102 ---------------------------------------------------------------------------
105 qx.Proto._onmousedown = function(e)
107   var vItem = this.getListItemTarget(e.getDomTarget());
109   if (vItem) {
110     this._manager.handleMouseDown(vItem, e);
111   }
114 qx.Proto._onmouseup = function(e)
116   var vItem = this.getListItemTarget(e.getDomTarget());
118   if (vItem) {
119     this._manager.handleMouseUp(vItem, e);
120   }
123 qx.Proto._onclick = function(e)
125   var vItem = this.getListItemTarget(e.getDomTarget());
127   if (vItem) {
128     this._manager.handleClick(vItem, e);
129   }
132 qx.Proto._ondblclick = function(e)
134   var vItem = this.getListItemTarget(e.getDomTarget());
136   if (vItem) {
137     this._manager.handleDblClick(vItem, e);
138   }
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") {
148     dt = dt.parentNode;
149   }
151   if (dt.tagName.toLowerCase() == "body") {
152     return null;
153   }
155   return dt;
165 ---------------------------------------------------------------------------
166   SCROLL INTO VIEW
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 ---------------------------------------------------------------------------
217   CREATE VIEW
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";
230   var cframe, cnode;
232   for (var i=0, a=this._list, l=a.length, d; i<l; i++)
233   {
234     d = a[i];
236     cframe = protoCell.cloneNode(true);
238     cframe.id = d.id;
239     cframe.pos = i;
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);
254   }
256   return frame;
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;
267   }
269   inode.width = d.thumbWidth;
270   inode.height = d.thumbHeight;
272   if (this._mshtml) {
273     inode.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + d.src + "',sizingMethod='scale')";
274   } else {
275     inode.src = d.src;
276   }
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);
326   return frame;
336 ---------------------------------------------------------------------------
337   PRELOADING
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);
347   }
350 qx.ui.embed.GalleryList.imageOnLoad = function()
352   this.gallery.imageOnComplete();
353   this.gallery = null;
354   this.onload = null;
355   this.onerror = null;
358 qx.ui.embed.GalleryList.imageOnError = function()
360   this.gallery.imageOnComplete();
361   this.gallery = null;
362   this.onload = null;
363   this.onerror = null;
373 ---------------------------------------------------------------------------
374   DISPOSER
375 ---------------------------------------------------------------------------
378 qx.Proto.dispose = function()
380   if (this.getDisposed()) {
381     return true;
382   }
384   this._list = null;
385   this._frame = null;
387   if (this._manager)
388   {
389     this._manager.dispose();
390     this._manager = null;
391   }
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);