2010-09-16 09:28:07 -05:00
|
|
|
/* Authors:
|
|
|
|
* Pavel Zuna <pzuna@redhat.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Red Hat
|
|
|
|
* see file 'COPYING' for use and warranty information
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; version 2 only
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
function nav_create(nls, container, tabclass)
|
|
|
|
{
|
|
|
|
if (!container)
|
|
|
|
container = $('#navigation');
|
|
|
|
if (!tabclass)
|
|
|
|
tabclass = 'tabs';
|
|
|
|
|
2010-09-16 14:13:48 -05:00
|
|
|
nav_generate_tabs(nls, container, tabclass, 1);
|
2010-09-16 09:28:07 -05:00
|
|
|
|
|
|
|
var tabs = $('.' + tabclass);
|
|
|
|
tabs.tabs({event: 'change'});
|
|
|
|
tabs.find('ul.ui-tabs-nav a').click(_nav_tab_on_click);
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|
|
|
|
|
2010-09-16 14:13:48 -05:00
|
|
|
function nav_generate_tabs(nls, container, tabclass, depth)
|
2010-09-16 09:28:07 -05:00
|
|
|
{
|
|
|
|
container.addClass(tabclass);
|
2010-09-16 14:13:48 -05:00
|
|
|
container.addClass('tabs'+depth);
|
2010-09-16 09:28:07 -05:00
|
|
|
container.prepend('<ul></ul>');
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
var ul = container.children().first();
|
|
|
|
for (var i = 0; i < nls.length; ++i) {
|
|
|
|
var n = nls[i];
|
2010-08-23 21:32:23 -05:00
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
nav_insert_tab_li(ul, n[0], n[1]);
|
|
|
|
nav_insert_tab_div(container, n[0]);
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
var div = ul.parent().children().last();
|
|
|
|
if (typeof n[2] == 'function') {
|
|
|
|
n[2](div);
|
|
|
|
} else if (n[2].length) {
|
2010-09-16 14:13:48 -05:00
|
|
|
nav_generate_tabs(n[2], div, tabclass, depth +1 );
|
2010-08-23 21:32:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
var _nav_li_tab_template = '<li><a href="#I">N</a></li>';
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
function nav_insert_tab_li(jobj, id, name)
|
|
|
|
{
|
|
|
|
jobj.append(_nav_li_tab_template.replace('I', id).replace('N', name));
|
2010-08-19 19:48:21 -05:00
|
|
|
}
|
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
var _nav_div_tab_template = '<div id="T"></div>';
|
2010-09-07 09:08:19 -05:00
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
function nav_insert_tab_div(jobj, id)
|
|
|
|
{
|
|
|
|
jobj.append(_nav_div_tab_template.replace('T', id));
|
2010-09-07 09:08:19 -05:00
|
|
|
}
|
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
function _nav_tab_on_click(obj)
|
|
|
|
{
|
|
|
|
var jobj = $(this);
|
|
|
|
var state = {};
|
|
|
|
var id = jobj.closest('.tabs').attr('id');
|
|
|
|
var index = jobj.parent().prevAll().length;
|
2010-09-07 09:08:19 -05:00
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
state[id] = index;
|
|
|
|
$.bbq.pushState(state);
|
2010-09-07 09:08:19 -05:00
|
|
|
}
|
|
|
|
|