UI jQuery Tabs - Create More than One Link to Tabs within Tabs on Same Page - hyperlink

My code so far:
$(function(){
$( "#tabs" ).tabs().find( ".ui-tabs-nav" ).sortable({ axis: "x" });
$(document).ready(function() {
var $tabs = $("#tabs").tabs();
$('#tabs-1 a').click( function(){
$tabs.tabs('select', 4); });
});
<div id="tabs">
<ul>
<li>Home</li>
<li>Alarms</li>
<li>Access Control</li>
<li>Services</li>
<li>Contact Us</li>
</ul>
<div id="tabs-1">
<p><span class="bodytext">Check our services</span></p> //want to link to tab 4(services)
<p><span class="bodytext">
Contact usfor free 24hours a day...</span></p>
As you can see from the code when you click on "Contact us" text in tab 1 there is a link to tab 5.
What i want to do is to create a link from "Check our services" to tab 4.
In general to create over 10 links withing tabs linking other tabs
I think i know that i have to change $tabs.tabs('select', 4); to $tabs.tabs('select', id); but i dont know how to call the "id" in html when i want to create my link.
Any suggestions?

I think I would handle this differently using the href on the link itself, perhaps with a class to indicate that it is an intra-tab link, to determine which tab to load and setting up the handlers in the tabs create event.
$('#tabs').tabs({
create: function(event,ui) {
$('a.intra-tab',ui.panel).unbind('click').click( function() {
var id = Number( $(this).attr('href').replace(/#tabs-/,'') ) - 1;
$('#tabs').tabs('select',id);
return false;
});
}
});
<div id="tabs">
<ul>
<li>Home</li>
<li>Alarms</li>
<li>Access Control</li>
<li>Services</li>
<li>Contact Us</li>
</ul>
<div id="tabs-1">
<p><span class="bodytext">Check our services</span></p>
</div>
...
You could also do it using live handlers.
$('#tabs').tabs();
$('a.intra-tab').live( 'click', function() {
var id = Number( $(this).attr('href').replace(/#tabs-/,'') ) - 1;
$('#tabs').tabs('select',id);
return false;
});

Related

Combinate JQuery UI sortable and draggable with Bootstrap Tab navigation

I try build page based on Bootstrap with JQuery UI sortable list.
I have one list in global space and two lists in Tabs
and I like to drag items from external list and drop it to tab navigation for adding into list
However when I switch to bootstrap tab navigation the external item on drop disappear but doesn't appear in tab list
this is my example based on JQ UI "Connect list with Tab"
This is my JS FIDDLE
$(function() {
$( "#sortable0, #sortable1, #sortable2" ).sortable().disableSelection();
var $tabs = $( "#tabs" );//.tabs();
$('#myTab a:last').tab('show');
var $tab_items = $( "ul:first li", $tabs ).droppable({
accept: ".connectedSortable li",
hoverClass: "ui-state-hover",
drop: function( event, ui ) {
var $item = $( this );
var $list = $( $item.find( "a" ).attr( "href" ) )
.find( ".connectedSortable" );
ui.draggable.hide( "slow", function() {
$tabs.tabs( "option", "active", $tab_items.index( $item ) );
$( this ).appendTo( $list ).show( "slow" );
});
}
});
});
HTML
<div id="external-tab">
<ul id="sortable0" class="connectedSortable ui-helper-reset">
<li class="ui-state-default">ExItem 1</li>
<li class="ui-state-default">ExItem 2</li>
<li class="ui-state-default">ExItem 3</li>
</ul>
</div>
<div id="tabs" class="tabbable">
<ul id="myTab" class="nav nav-tabs">
<li>Nunc tincidunt</li>
<li>Proin dolor</li>
</ul>
<div class="tab-content">
<div id="tabs-1" class="tab-pane">
<ul id="sortable1" class="connectedSortable ui-helper-reset">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
</ul>
</div>
<div id="tabs-2" class="tab-pane">
<ul id="sortable2" class="connectedSortable ui-helper-reset">
<li class="ui-state-highlight">Item 1</li>
<li class="ui-state-highlight">Item 2</li>
<li class="ui-state-highlight">Item 3</li>
</ul>
</div>
</div>
</div>
It's a shame nobody else got to your question in the past year... I'm guessing this is no longer relevant for you personally, but maybe we can help to resolve this issue for any other user searching on Google for solutions to include jQuery UI's API for Draggable/Droppable items, integrated with Bootstrap's tabbed component.
If I'm reading your question correctly, you'd like to be able to drag items from the external list into either of the two tabs. If your problem is similar to the one I'm personally tackling at the moment, you might also want to drag items from tab one into tab two, and vice-versa. I've updated your fiddle with a solution that accommodates both of these needs. The lists are also sortable, as they were previously, and the classes of items dragged from one space to the other are retained as well.
Items I might consider adding in the future are:
The ability to drag not only onto the tab, but also the space below it
Adding all attributes from the parent element dragged, not just the class list
However, for the moment, all I've done is to rectify the solution you posted.
The updated fiddle is here: http://jsfiddle.net/cr8s/96dsB/30/
Also, since the Internet is a fickle place and things disappear all the time, here's the updated JS (I left your HTML unchanged, and that's already in the question above):
$(function() {
$('.tab-pane > ul').sortable().disableSelection();
var
$tabs = $('#tabs'),
$tabItems = $('#myTab > li', $tabs);
$('#myTab a:last').tab('show');
$tabItems.droppable({
accept: ".connectedSortable li",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
var
$item = $(this),
href = $item.children('a').attr('href'),
$list = $(href).find('.connectedSortable');
console.log($list);
$list.append($('<li />').html(ui.draggable.html()).attr('class', ui.draggable.attr('class')));
$list.closest('.tab-pane').addClass('active').siblings().removeClass('active');
$item.addClass('active').siblings().removeClass('active');
}// drop(event, ui)
});// $tabItems.droppable()
$('#external-tab > ul > li').draggable({
appendTo: 'body',
helper: 'clone'
});
});// end of doc ready
Hope that solves this problem for some folks! It certainly gets me closer to solving my own use case, and I'll likely continue to update the fiddle linked above as I add additional features like the two I mentioned earlier.

submitting the form after clicking the item on the tab menu in Jquery

The example at: http://jqueryui.com/demos/tabs/, I would like the form is submitted when clicking the tab-2 menu.
The following is my code. However, the form doesn't submit after clicking.
Can anyone help me? Many thanks!
<script>
$(function() {
$( "#tabs" ).tabs();
$('#tabs-2').click(function() {
$('#target').submit();
});
});
</script>
<div id="tabs">
<form id="target">
<ul>
<li>Tab-1</li>
<li>Tab-2</li>
<li>Tab-3</li>
</ul>
<div id="tabs-1">
</div>
<div id="tabs-2">
</div>
<div id="tabs-3">
</div>
</form>
$(document).ready(function(){
$('#tabs-2').click(function() {
$('#target').submit();
});
});
You'll probably find that the tab plugin is preventing the default actions of the click anyway and not calling your click event.
You should try hooking into tabselect event instead and use ui.tab to check if the selected tab's href attribute is #tabs-2.
$("#tabs").bind("tabsselect", function(event, ui) {
if(ui.tab.attr('href') == '#tabs-2') {
$('#target').submit();
}
});
Or you could do this when you create the tabs instead:
$("#tabs").tabs({
select: function(event, ui) {
if(ui.tab.attr('href') == '#tabs-2') {
$('#target').submit();
}
}
});
You could also use ui.index to get the zero-basde index of the selected tab, or ui.panel to get the selected content div for that tab. Whichever you prefer!
I think you need to define id for Tab-2 as mentioned here. but here you are referring div id click.
<li>Tab-2</li>
$('#tabs2').click(function() {
$('#target').submit();
});

JQuery disable tab 3 when click tab 2?

I am new to this forum so first let me say a big hello and thanks for providing such a great website!
I am new to JQuery but I love it, I have some JQuery tabs doing the usual List/Edit/Create stuff in a backend.
I have managed to set the edit tab to deisabled when viewing the list tab (as you need to slect a list item to edit) and it is enabled when a list item edit icon is clicked.
The question I have is if I then click the third tab how do I disable the second tab onlick?
This is my standard tab code...
$(function()
{
$("#tabs").tabs({disabled: [2]});
$("#tabs").tabs();
}
);
HTML:
<div class="demo">
<div id="tabs">
<ul>
<li><wont let me post 3 links>Jobs</a></li>
<li>Create Job</li>
<li>Edit Job</li>
</ul>
<div id="tabs-1" style="background-color: #fff">
Include...
</div>
<div id="tabs-2" style="background-color: #fff">
Include...
</div>
<div id="tabs-3" style="background-color: #fff">
Include...
</div>
</div>
Thanks
First you HTML is no correct so the plugin does not initialiaze well. The first tab button link is incorrect:
<li><wont let me post 3 links>Jobs</a></li>
Should be
<li>Jobs</li>
Then you are initializing two times the plugin, only do it once.
In the show event handler, enable/disable the tabs according to the actual tab shown:
$(function()
{
$("#tabs").tabs({
//disabled: [2],
show: function(event, ui) {
if (ui.index === 0) {
$('#tabs').tabs('enable', 1);
$('#tabs').tabs('enable', 2);
} else {
$('#tabs').tabs('disable', ui.index === 1 ? 2 : ui.index === 2 ? 1 : -1);
}
}
});
/*$("#tabs").tabs();
}*/
);
Here is a live working example on jsfiddle

Show feedback to a user when loading content though ajax

I'm using the jquery tab plugin with the same results that are on jquery ui site (link text).
The problem is that I want to change the tab label to something like "Loading" when the Ajax request is waiting for a response. How shall I achieve that?
Edit:
What I have now:
<div id="tabs">
<ul>
<li>User Profile</li>
<li>Edit</li>
<li>Delete AccountT</li>
</ul>
<div id="tabs-1">
<% Html.RenderPartial("UserProfile", Model); %>
</div>
</div>
and on javascript I just have the following code:
<script type="text/javascript">
$(function () {
$("#tabs").tabs({
});
});
</script>
What i want is to show a loading message inside the div of the active tab.
According to the widget doc, ajax should work outside the box if your href is an actual link :
To customize loading message, you can use the spinner option :
Fetch external content via Ajax for
the tabs by setting an href value in
the tab links. While the Ajax request
is waiting for a response, the tab
label changes to say "Loading...",
then returns to the normal label once
loaded.
<script>
$(function() {
$( "#tabs" ).tabs({
spinner: "<em>My Loading Msg</em>",
ajaxOptions: {
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html(
"Couldn't load this tab. We'll try to fix this as soon as possible. " +
"If this wouldn't be a demo." );
}
}
});
});
</script>
Why don't you just set the tab label to "loading" onclick and change it to whatever you want once you get a response back from your AJAX?
$(function () {
$("#tabs").tabs();
$("#tab1").click(function() {
$(this).val("Loading...");
$.ajax({
blablabla...
success: function() {
$("#tab1").val("Tab 1");
}
});
});
This should give you an idea, obviously the function could be written better to act on each tab.
I think what you are after already exists in the jquery ui for Tabs.
The HTML content of this string is
shown in a tab title while remote
content is loading.
http://jqueryui.com/demos/tabs/#option-spinner
Hope this helps!
From your example am I correct in assuming that you want to navigate to another page when the user clicks on either of the second two tabs, but you want a loading message to be displayed while you are waiting for the next tab to load?
If so, you could do it by keeping a loading message in the other tabs like so:
<input type="hidden" id="modelId" value="<%=Model.Id%>" />
<div id="tabs">
<ul>
<li>
User Profile
</li>
<li>
Edit
</li>
<li>
Delete AccountT
</li>
</ul>
<div id="tabs-1">
<% Html.RenderPartial("UserProfile", Model); %>
</div>
<div id="tabs-2">
<p>Loading, please wait...</p>
</div>
<div id="tabs-3">
<p>Loading, please wait...</p>
</div>
</div>
And doing the redirection to your other pages in your javascript, doing it something like this:
$(document).ready(document_ready);
function document_ready()
{
$("tabs").bind("tabsselect", onTabSelected);
}
function onTabSelected(event, ui)
{
var modelId = $("#modelId").val();
switch (ui.panel.id)
{
case "tabs-2":
window.location.href = "/User/EditUser/" + modelId;
break;
case "tabs-3":
window.location.href = "/User/Delete/" + modelId;
break;
}
}

some issue with nested tab while trying to implement jquery ui tab with back/forward/refresh button support

I'm having problems with the browser history (using the "Back" and "Forward" buttons) with jQuery's tab plugin. I combined jQuery UI tab and jQuery BBQ: Back Button & Query Library plugin together for this.
I think the problem may deal with nested tabs.
You can find full code at http://jsfiddle.net/nQgC8/
If you test this, you'll see that tabs at top works fine: you can navigate to any of the tabs and successfully go back and forward at any point. This is not the case for nested tab. Nested tab can be found inside tab 3.
What do I need to do to make this work for nested tabs?
The following are snippets to show my point:
<div id="tabs">
<ul>
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<div id="tabs-1">...</div>
<div id="tabs-2">...</div>
<div id="tabs-3">
<div id="tabs2">
<ul>
<li>Tab 3-1</li>
<li>Tab 3-2</li>
<li>Tab 3-3</li>
</ul>
<div id="tabs-31">...</div>
<div id="tabs-32">...</div>
<div id="tabs-33">...</div>
</div>
</div>
</div>
<script>
$(function() {
$( '#tabs' ).tabs();
// Adding hash to url for tab tracking
$('#tabs').bind('tabsselect', function (event, ui) {
window.location.href = window.location.protocol + '//' + window.location.hostname + window.location.pathname + ui.tab.hash;
});
$( '#tabs2' ).tabs();
// Adding hash to url for tab tracking
$('#tabs2').bind('tabsselect', function (event, ui) {
window.location.href = window.location.protocol + '//' + window.location.hostname + window.location.pathname + ui.tab.hash;
});
// Handle back/forward/refresh buttons
$(window).hashchange(function () {
var hash = location.hash;
switch (hash) {
case '#tabs-1':
case '#tabs-2':
case '#tabs-3':
$('#tabs').tabs('select', hash);
break;
case '#tabs-31':
case '#tabs-32':
case '#tabs-33':
$('#tabs').tabs('select', '#tabs-3');
$('#tabs2').tabs('select', hash);
break;
default:
$('#tabs').tabs('select', '#tabs-1');
location.hash = '#tabs-1';
}
});
$(window).hashchange();
});
</script>
This works for me in chrome. What browser are you trying it with?

Resources