Skip to content

Commit

Permalink
Allowing developers to define views inline for joStack and joStackScr…
Browse files Browse the repository at this point in the history
…oller. Handy, but very messy for large apps. Please code responsibly.
  • Loading branch information
davebalmer committed Oct 10, 2010
1 parent 0d36204 commit 745fc63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
27 changes: 21 additions & 6 deletions js/ui/stack.js
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions js/ui/stackscroller.js
Expand Up @@ -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: [],
Expand Down

0 comments on commit 745fc63

Please sign in to comment.