krawaller / kranium

Brains for Titanium
http://www.kraniumjs.com
Other
103 stars 13 forks source link

Open a window in a new Tab (TabGroupContext) #20

Open nvdnkpr opened 12 years ago

nvdnkpr commented 12 years ago

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:


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 alwys opens the new window in the first tab since the selector engines returns all tabs and the code only takes the first it finds.

nvdnkpr commented 12 years ago

My current workaround is changing if(typeof parent === 'string') into if(typeof parent === 'string' && parent !== 'tab')