/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org License: LGPL 2.1: http://www.gnu.org/licenses/lgpl.html Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) ************************************************************************ */ /* ************************************************************************ ************************************************************************ */ /** * @event loadComplete {qx.event.type.Event} */ qx.OO.defineClass("qx.ui.embed.GalleryList", qx.ui.basic.Terminator, function(galleryList) { qx.ui.basic.Terminator.call(this); this._blank = qx.manager.object.AliasManager.getInstance().resolvePath("static/image/blank.gif"); this._list = galleryList; this._listSize = galleryList.length; this._processedImages = 0; this.setOverflow("auto"); this.setHtmlProperty("className", "qx_ui_embed_GalleryList"); this._manager = new qx.manager.selection.DomSelectionManager(this); this.addEventListener("mousedown", this._onmousedown); this.addEventListener("mouseup", this._onmouseup); this.addEventListener("click", this._onclick); this.addEventListener("dblclick", this._ondblclick); this.addEventListener("keypress", this._onkeypress); }); qx.OO.addProperty({ name : "thumbMaxWidth", type : "number", defaultValue : 60 }); qx.OO.addProperty({ name : "thumbMaxHeight", type : "number", defaultValue : 60 }); qx.OO.addProperty({ name : "decorHeight", type : "number", defaultValue : 40 }); /* --------------------------------------------------------------------------- ELEMENT HANDLING --------------------------------------------------------------------------- */ qx.Proto._applyElementData = function() { this.getElement().appendChild(this.createView()); } /* --------------------------------------------------------------------------- UTILITIES --------------------------------------------------------------------------- */ qx.Proto.getManager = function() { return this._manager; } qx.Proto.update = function(vGalleryList) { this._manager.deselectAll(); this._list = vGalleryList; var el = this.getElement(); el.replaceChild(this.createView(), el.firstChild); } qx.Proto.removeAll = function() { this._manager.deselectAll(); this.getElement().innerHTML = ""; } /* --------------------------------------------------------------------------- EVENT HANDLER --------------------------------------------------------------------------- */ qx.Proto._onmousedown = function(e) { var vItem = this.getListItemTarget(e.getDomTarget()); if (vItem) { this._manager.handleMouseDown(vItem, e); } } qx.Proto._onmouseup = function(e) { var vItem = this.getListItemTarget(e.getDomTarget()); if (vItem) { this._manager.handleMouseUp(vItem, e); } } qx.Proto._onclick = function(e) { var vItem = this.getListItemTarget(e.getDomTarget()); if (vItem) { this._manager.handleClick(vItem, e); } } qx.Proto._ondblclick = function(e) { var vItem = this.getListItemTarget(e.getDomTarget()); if (vItem) { this._manager.handleDblClick(vItem, e); } } qx.Proto._onkeypress = function(e) { this._manager.handleKeyPress(e); } qx.Proto.getListItemTarget = function(dt) { while(dt.className.indexOf("galleryCell") == -1 && dt.tagName.toLowerCase() != "body") { dt = dt.parentNode; } if (dt.tagName.toLowerCase() == "body") { return null; } return dt; } /* --------------------------------------------------------------------------- SCROLL INTO VIEW --------------------------------------------------------------------------- */ qx.Proto.scrollItemIntoView = function(vItem) { this.scrollItemIntoViewX(vItem); this.scrollItemIntoViewY(vItem); } qx.Proto.scrollItemIntoViewX = function(vItem) { qx.dom.ScrollIntoView.scrollX(vItem); } qx.Proto.scrollItemIntoViewY = function(vItem) { qx.dom.ScrollIntoView.scrollY(vItem); } /* --------------------------------------------------------------------------- SELECTION MANAGER API --------------------------------------------------------------------------- */ qx.Proto.getItems = function() { return this._frame.childNodes; } qx.Proto.getFirstChild = function() { return this._frame.childNodes[0]; } qx.Proto.getLastChild = function() { return this._frame.childNodes[this._frame.childNodes.length-1]; } /* --------------------------------------------------------------------------- CREATE VIEW --------------------------------------------------------------------------- */ qx.Proto.createView = function() { var s = (new Date).valueOf(); var protoCell = this.createProtoCell(this.getThumbMaxHeight()); var frame = this._frame = document.createElement("div"); this._frame.className = "galleryFrame clearfix"; var cframe, cnode; for (var i=0, a=this._list, l=a.length, d; i