Author: max
Date: 2006-11-10 13:14:09 -0800 (Fri, 10 Nov 2006)
New Revision: 2480
Modified:
openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
openlaszlo/branches/legals/demos/lzpix/classes/photocollection.lzx
Log:
Change 20061110-maxcarlson-Z by [EMAIL PROTECTED] on 2006-11-10 09:51:51 PST
in /Users/maxcarlson/openlaszlo/legals
Summary: Finish DHTML sprite implementation of z-ordering - bringToFront(),
sendToBack(), sendBehind() and sendInFrontOf()
New Features:
Bugs Fixed: LPP-3051 - Finish DHTML sprite implementation of z-ordering -
bringToFront(), sendToBack(), sendBehind() and sendInFrontOf()
Technical Reviewer: hminsky
QA Reviewer: promanik
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details: Fixes z-ordering in DHTML. Also cleans up sprite reverences into the
view api.
Tests: Dragging in LzPix now has lat photo selected on top (photos are
ordered),
http://localhost:8080/legals/laszlo-explorer/index.jsp?lzr=dhtml&bookmark=Welcome
shows navigation tab ordering.
Files:
M WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
M demos/lzpix/classes/photocollection.lzx
Changeset:
http://svn.openlaszlo.org/openlaszlo/patches/20061110-maxcarlson-Z.tar
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
2006-11-10 17:59:27 UTC (rev 2479)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
2006-11-10 21:14:09 UTC (rev 2480)
@@ -220,13 +220,11 @@
}
LzSprite.prototype.__topZ = 1;
-LzSprite.prototype.__bottomZ = -1;
+LzSprite.prototype.__parent = null;
+LzSprite.prototype.__children = null;
LzSprite.prototype.addChildSprite = function(sprite) {
- sprite.__parent = this;
- this.__topZ++;
//Debug.info('appendChild', sprite.__LZdiv);
- this.__LZdiv.appendChild( sprite.__LZdiv );
if ($debug) {
if (this.stretches != null && this.__warnstretches != true) {
Debug.warn("Due to limitations in the DHTML runtime, stretches
will only apply to resources in this view, and doesn't affect child views.");
@@ -238,9 +236,19 @@
}
}
+ sprite.__parent = this;
+ if (this.__children) {
+ this.__children.push(sprite);
+ } else {
+ this.__children = [sprite];
+ }
+
+ this.__LZdiv.appendChild( sprite.__LZdiv );
if (LzSprite.prototype.quirks.fix_clickable) {
this.__LZclickdiv.appendChild( sprite.__LZclickdiv );
}
+
+ sprite.__z = ++this.__topZ;
}
LzSprite.prototype.setResource = function ( r ){
@@ -257,7 +265,9 @@
// look up resource name in LzResourceLibrary
var res = LzResourceLibrary[r];
if (! res) {
- Debug.warn('Could not find resource', r);
+ if ($debug) {
+ Debug.warn('Could not find resource', r);
+ }
return;
}
var urls = res.frames;
@@ -793,9 +803,9 @@
if (this.destroyed == true) return;
//alert('destroy' + this + ', recursive ' + recursive);
if (recursive) {
- if (this.owner.subviews) {
- for (var i = 0; i < this.owner.subviews.length; i++) {
- this.owner.subviews[i].sprite.destroy(recursive);
+ if (this.__children) {
+ for (var i = 0; i < this.__children.length; i++) {
+ this.__children[i].destroy(recursive);
}
}
}
@@ -921,45 +931,110 @@
}
LzSprite.prototype.bringToFront = function() {
- if (this.__parent) {
- var z = ++this.__parent.__topZ;
- } else {
- var z = 1;
+ if (! this.__parent) {
+ if ($debug) {
+ Debug.warn('bringToFront with no parent');
+ }
+ return;
}
+ if (this.__parent.__children.length < 2) return;
+ this.__setZ( ++this.__parent.__topZ );
+}
+
+LzSprite.prototype.__setZ = function(z) {
this.__LZdiv.style.zIndex = z;
- //Debug.info('bringToFront', this.__oldZindex, this.__oldZindex2, this);
if (LzSprite.prototype.quirks.fix_clickable) {
this.__LZclickdiv.style.zIndex = z;
}
+ this.__z = z;
}
+// Applies the __z property to all siblings - only called when default z
ordering must be changed
+LzSprite.prototype.__applyZ = function() {
+ if (this.__parent.__appliedZ) return;
+ var c = this.__parent.__children;
+ for (var i = 0; i < c.l; i++) {
+ c[i].__setZ(c[i].__z);
+ }
+ this.__parent.__appliedZ = true;
+}
+
+LzSprite.prototype.__zCompare = function(a, b) {
+ if (a.__z < b.__z)
+ return -1
+ if (a.__z > b.__z)
+ return 1
+ return 0
+}
+
LzSprite.prototype.sendToBack = function() {
- if (this.__parent) {
- var z = --this.__parent.__bottomZ;
- } else {
- var z = 0;
- }
+ if (! this.__parent) {
+ if ($debug) {
+ Debug.warn('sendToBack with no parent');
+ }
+ return;
+ }
- this.__LZdiv.style.zIndex = z;
- //Debug.info('sendToBack', this.__oldZindex);
- if (LzSprite.prototype.quirks.fix_clickable) {
- this.__LZclickdiv.style.zIndex = z;
- }
+ var c = this.__parent.__children;
+ if (c.length < 2) return;
+ c.sort(LzSprite.prototype.__zCompare);
+
+ this.sendBehind(c[0]);
}
-LzSprite.prototype.sendBehind = function ( v ){
- //TODO: implement
- if ($debug) {
- Debug.error('sendBehind not yet implemented for dhtml');
+LzSprite.prototype.sendBehind = function ( behindSprite ){
+ if (! behindSprite) return;
+ if (! this.__parent) {
+ if ($debug) {
+ Debug.warn('sendBehind with no parent');
+ }
+ return;
+ }
+
+ var c = this.__parent.__children;
+ if (c.length < 2) return;
+ c.sort(LzSprite.prototype.__zCompare);
+
+ this.__applyZ();
+ var behindZ = false
+ for (var i = 0; i < c.length; i++) {
+ var s = c[i];
+ if (s == behindSprite) behindZ = behindSprite.__z;
+ if (behindZ != false) {
+ // bump up everyone including behindSprite
+ s.__setZ( ++s.__z );
+ }
}
+ // insert where behindSprite used to be
+ this.__setZ(behindZ);
}
-LzSprite.prototype.sendInFrontOf = function ( v ){
- //TODO: implement
- if ($debug) {
- Debug.error('sendInFrontOf not yet implemented for dhtml');
+LzSprite.prototype.sendInFrontOf = function ( frontSprite ){
+ if (! frontSprite) return;
+ if (! this.__parent) {
+ if ($debug) {
+ Debug.warn('sendInFrontOf with no parent');
+ }
+ return;
+ }
+
+ var c = this.__parent.__children;
+ if (c.length < 2) return;
+ c.sort(LzSprite.prototype.__zCompare);
+
+ this.__applyZ();
+ var frontZ = false
+ for (var i = 0; i < c.length; i++) {
+ var s = c[i];
+ if (frontZ != false) {
+ // bump up everyone after frontSprite
+ s.__setZ( ++s.__z );
+ }
+ if (s == frontSprite) frontZ = frontSprite.__z + 1;
}
+ // insert after frontSprite
+ this.__setZ(frontZ);
}
Modified: openlaszlo/branches/legals/demos/lzpix/classes/photocollection.lzx
===================================================================
--- openlaszlo/branches/legals/demos/lzpix/classes/photocollection.lzx
2006-11-10 17:59:27 UTC (rev 2479)
+++ openlaszlo/branches/legals/demos/lzpix/classes/photocollection.lzx
2006-11-10 21:14:09 UTC (rev 2480)
@@ -12,7 +12,7 @@
var e = sel[ i ];
p.datapath.setFromPointer( e.datapath );
- //p.sendToBack();
+ p.sendToBack();
activephotos.push( p );
}
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins