var tab_content = ""; var tab_role = ""; var Tab = { /* method : createTab descrition : create a new tab params : { label : Label of the tab * role : Tab type * content : Content of the tab * href : Tab id * callback : a function } comments : { #1 : if the user just set the label, a tab with blank content and a dynamic id is created #2 : if a tab with a set href already exists, don't duplicate, this function only select the tab #3 : if the role is * = Optional */ create : function(label, role, content,href, callback){ if( !$("#tabs-"+href).length){ tab_content = content ? content : ""; tab_role = role ? role : "new"; Tab.count++; $tabs.wijtabs("add", "#tabs-"+(href ? href : Tab.count), (label.length > 21 ? label.substring(0, 18)+"..." : label)); if(typeof(callback) == 'function') callback($("#ptabs_"+(href ? href : Tab.count))); else return $("#tabs-"+(href ? href : Tab.count)); }else{ $tabs.wijtabs( "select", Tab.index("#tabs-"+href) ); } }, /* method : removeTab descrition : remove a tab params : { * href : Tab id * callback : a function } comments : { #1 : if the user doesn't set no parameter, this function just remove the open tab * = Optional */ remove : function(href, callback){ $tabs.wijtabs("remove", ( href ? Tab.index(href) : Tab.lastIndexSelected ) ); if(typeof(callback) == 'function') callback(); }, /* method : Tab.index descrition : return a tab index params : { * href : Tab id } comments : { #1 : if the user doesn't set no parameter, this function just return the index of the open tab * = Optional */ index : function(href){ return href ? $( "li", $tabs ).index( $('[href="'+href+'"]').parent() ) : Tab.lastIndexSelected; }, /* method : idTab descrition : remove a tab id params : { * index : Tab index } comments : { #1 : if the user doesn't set no parameter, this function just return the id of the open tab * = Optional */ id : function(index){ return $( ".ui-tabs-panel", $tabs ).eq((index ? index : Tab.index())).attr("id"); }, getData : function(index){ return { id : parseInt(Tab.id(index).substring(6).split("_r_")[0]), folder : Base64.decode(idTab(index).substring(6).split("_r_")[1]), role : Tab.getRole(index), header : Tab.getHeader(index), content : Tab.getContent(index) }; }, getHeader : function(index){ return $( $tabs ).find('[href="#'+$( ".ui-tabs-panel", $tabs ).eq((index ? index : Tab.index())).attr("id")+'"]').parent(); }, getRole: function(index){ return Tab.getContent(index).attr("role"); }, getContent: function(index){ return $( ".ui-tabs-panel", $tabs ).eq((index ? index : Tab.index())); }, setFolderTotal: function(value){ Tab.getHeader(0).find(".folder-tab-total-msgs-number").html(parseInt(value) ? value : 0); }, setFolderUnread: function(value){ Tab.getHeader(0).find(".folder-tab-new-msgs-number").html(parseInt(value) ? value : 0); if(parseInt(value)) $("title").html($("title").html() +" ("+value+")"); }, setFolderName: function(value){ Tab.getHeader(0).find(".folder-tab-name").html(value); $("title").html(value); }, lastIndexSelected : 0, count: 2, roles : [ "new", "draft", "search", "message", "folder" ] }