Browse files

Allowing developers to define views inline for joStack and joStackScr…

…oller. Handy, but very messy for large apps. Please code responsibly.
  • Loading branch information...
1 parent 0d36204 commit 745fc63a1da0544b5f3d5fcc03aa1183bafd2129 @davebalmer davebalmer committed Oct 10, 2010
Showing with 24 additions and 9 deletions.
  1. +21 −6 js/ui/stack.js
  2. +3 −3 js/ui/stackscroller.js
View
27 js/ui/stack.js
@@ -49,8 +49,18 @@
*/
joStack = function(data) {
this.visible = false;
-
- joView.apply(this, arguments);
+
+ joContainer.apply(this, arguments);
+
+ // yes, nice to have one control, but we need an array
+ if (this.data && !(this.data instanceof Array))
+ this.data = [ this.data ];
+ else if (this.data.length > 1)
+ this.data = [ this.data[0] ];
+
+ // we need to clear inlined stuff out for this to work
+ if (this.container && this.container.firstChild)
+ this.container.innerHTML = "";
// default to keep first card on the stack; won't pop() off
this.setLocked(true);
@@ -61,14 +71,15 @@ joStack = function(data) {
this.showEvent = new joSubject(this);
this.hideEvent = new joSubject(this);
- this.data = [];
this.index = 0;
this.lastIndex = 0;
this.lastNode = null;
};
-joStack.extend(joView, {
+joStack.extend(joContainer, {
tagName: "jostack",
+ type: "fixed",
eventset: false,
+ data: [],
setEvents: function() {
// do not setup DOM events for the stack
@@ -95,6 +106,9 @@ joStack.extend(joView, {
draw: function() {
if (!this.container)
this.createContainer();
+
+ if (!this.data || !this.data.length)
+ return;
// short term hack for webos
// not happy with it but works for now
@@ -106,7 +120,7 @@ joStack.extend(joView, {
var newchild = this.getChildStyleContainer(newnode);
function getnode(o) {
- return (typeof o.container !== "undefined") ? o.container : o;
+ return (o instanceof joView) ? o.container : o;
}
if (!newchild)
@@ -189,7 +203,8 @@ joStack.extend(joView, {
},
removeChild: function(child) {
- this.container.removeChild(child);
+ if (child && child.parentNode === this.container)
+ this.container.removeChild(child);
},
isVisible: function() {
View
6 js/ui/stackscroller.js
@@ -24,11 +24,11 @@ joStackScroller = function(data) {
this.scroller = this.scrollers[0];
joStack.apply(this, arguments);
-// console.log(this.scroller);
- this.container.appendChild(this.scroller.container);
-// console.log(this.container);
+
+ this.scroller.attach(this.container);
};
joStackScroller.extend(joStack, {
+ type: "scroll",
scrollerindex: 1,
scroller: null,
scrollers: [],

0 comments on commit 745fc63

Please sign in to comment.