krawaller/kranium — Issue #20: Open a window in a new Tab (TabGroupContext)
Author: navidn
Created: 2012-01-20 11:39:51+00:00
State: open

Hi Jacob,

i just tried to open up a window in a new Tab, which didn't work out:
Problem were the following lines in the open-function on line 646 in kranium.js:

```javascript

open: function(parent o){
if(typeof parent === 'string'){
parent = $$(parent)[0] || null;
}

if(el){
switch(el._type){
case 'window':
if(parent == 'tab'){
if(block){ return; } else { block = true; }

el.addEventListener('open', function(){ block = false; });
K.currentWindow = el;

var tab = (
(tmp = ((o&&o.tab)||o)) &&
(typeof tmp === 'string') ? $$(tmp)[0] : tmp
) || (
(tmp = $$('tabgroup')) && tmp[0] && tmp[0].activeTab
);

(tab||Ti.UI.currentTab).open(el, o||{});
} else if(parent && parent._type && ['navigationgroup', 'tabgroup', 'tab'].indexOf(parent._type) !== -1) {

if(parent._type === 'tabgroup'){
parent = parent.activeTab;
}
parent.open(el, o||{});
} else {
el.open();
}
break;

default:
el.open && el.open(parent && K.create(parent, { type: 'window' }), o);
break;
}
}
return this;
},

```

the first lines `if(typeof parent === 'string'){` immediately changes the variable parent to an object so that the comparison `if(parent == 'tab')` never get's executed. Executing `K({…}).open('tab');` in the code opens the new window in the first tab since the selector engines returns all tabs and the code only takes the first it finds.