Nested jQuery UI tabs not displaying correctly - jquery-ui

I must apologize for not being able to reproduce this in jsFiddle in the first place (because of code placed in the 2 files).
I got 3 tabs which work fine, in the third I load another file which contains 2 tabs. These tabs are displayed as approximately 400px high gradients wiith content of these tabs shown below them. Which is not what I wanted, as you can imagine :) It´s like the grey header, which contains the tabs was stretched to a whole div...
Here´s the picture:
http://2i.cz/2i/t/954d3e14c7.jpg
As you can see, the tabs itself are big as hell and table is displayed below.
And here´s my code:
1st file:
$(function() {
$( "#tabs" ).tabs();
});
$("#detail").load('./safe/kalkulace_grafy_all.php?k_polozka=<? echo $co; ?>&cu=<? echo $ids; ?>');
<div id="tabs">
<ul>
<li>Info</li>
<li>Info2</li>
<li>Info3</li>
</ul>
<div id="tabs-1" class="detail_ceny_tab" style="height: 446px;"></div>
<div id="tabs-2" class="detail_ceny_tab" style="height: 446px;"></div>
<div id="tabs-3" class="detail_ceny_tab" style="height: 446px;">
<div id="detail"></div>
</div>
</div>
2nd file:
$(function() {
$( "#subTabs" ).tabs();
});
$("#subTab1").load('./safe/kalkulace_kalkVzorec.php?k_polozka=<? echo $k_polozka; ?>&cu='+cu);
<div id="subTabs" style="margin-left:500px">
<ul>
<li>Kalkulační vzorec</li>
<li>Seznam potřeb</li>
</ul>
<div id="subTab1"> </div>
<div id="subTab2"> </div>
</div>

you want to reduce the grey tab panel area?
I think its late but hope it may help some one else if they have something similar in mind.
The following code may be helpful, you can reduce the width of the tab panels.
$( "#subTabs" ).find( ".ui-tabs-nav").css('width', '50%');
$( "#subTabs" ).find( ".ui-tabs-panel").each( function( index, element ){
$( this ).css('width', '50%');
});

Related

Dynamic listview not loading until refresh

I'm using JS render to create dynamic pages in Jquery Mobile for my Phonegap app. The problem however is that the listview isn't loaded until the page is refreshed. Clearly that's not what I want and in another app I used the exact same technique and the listview is loaded immediately. Thing is that there's no difference between the two, so I have no idea why it isn't working in this one.
Here's my script for loading the pages:
<script src="jquery/jsrender.min.js"></script>
<script type="text/javascript">
$(document).on('pageinit', '#kunstwerken_exp1', function (event, ui) {
var $page = $(event.target);
$.ajax({
dataType:"json",
url:"json/exp1_index.js",
success:function(data, textStatus, jqHXR){
for( var x = 0; x < data.length; x++){
//create valid unique IDs for each page.
data[x].id = data[x].link.replace("?","").replace("=","").replace("#","");
}
console.log("success:");
console.log(data);
$("#templateDropPoint").html($("#template").render(data));
$("#templateDropPoint").listview("refresh");
$("body").append($("#pagetemplate").render(data));
},
error:function(jqXHR, textStatus, errorThrown ){
console.log(textStatus+ " "+ errorThrown);
}
});
});
</script>
This is the HTML:
<div data-role="page" id="kunstwerken_exp1" data-url="kunstwerken_exp1">
<div data-role="content">
<ul data-role="listview" id="templateDropPoint"></ul>
</div><!-- /content -->
</div>
<script id="template" type="text/x-jsrender">
<li>
<a href="#{{>id}}">
<img src={{>img}} />
<h5><b>{{>naam}}</b></h5>
<h6>{{>kunstwerk}}</h6>
</a>
</li>
</script>
<script type="text/x-jsrender" id="pagetemplate">
<div data-role="page" id="{{>id}}">
{{if pagina}}
<div data-role="content">
<h1>{{>naam}} ({{:pagina.nationaliteit}})</h1>
<h2>{{:pagina.kunstwerk}}</h2>
<em>{{:pagina.onderschrift}}</em>
<div class="ui-grid-a my-breakpoint">
<div class="ui-block-a">
<div class="koloma">
<div class="callbacks_container">
<ul class="rslides">
<li id="callbacks1_s0">
<img src="{{:pagina.afbeelding1}}" alt=""><p class="caption">{{:pagina.onderschrift1}}</p>
</li>
</ul>
</div>
{{if pagina.videooff}}
<ul class="tabs">
<li><img src="images/video.png"/></li><br>
</ul>
{{/if}}
</div>
</div>
<div class="ui-block-b">
<div class="kolomb">{{:pagina.tekst}}</div>
</div>
</div>
</div>
{{/if}}
</div>
</script>
To understand this situation you need to understand how jQuery Mobile works. It uses AJAX to load other pages.
First page is loaded normally. Its HEAD and BODY is loaded into the DOM, and they are there to await other content. When second page is loaded, only its BODY content is loaded into the DOM. To be more precise, even BODY is not fully loaded. Only first div with an attribute data-role="page" will be loaded, everything else is going to be discarded. Even if you have more pages inside a BODY only first one is going to be loaded. This rule only applies to subsequent pages, if you have more pages in an initial HTML all of them will be loaded.
That's why your listview is show successfully only after a page refresh.
Here's an official documentation: http://jquerymobile.com/demos/1.2.0/docs/pages/page-links.html
Unfortunately you are not going to find this described in their documentation. Ether they think this is a common knowledge or they forgot to describe this like my other topics. (jQuery Mobile documentation is big but lacking many things).
I have another ANSWER that discusses this problem. Solutions and working examples can be found there.

jQuery UI not working for accordion

my html looks like this
<div id="menu">
<h3>Section 1</h3>
<div>
<p>I'm the first section!</p>
</div>
<h3>Section 2</h3>
<div>
<p>I'm the second section!</p>
</div>
<h3>Section 3</h3>
<div>
<p>I'm the third section!</p>
</div>
</div>
And this is my js
$(document).ready(function() {
$('#menu').accordion();
});
Somehow my accordion is not working even though I took this directly off of codeacademy. Previously, I had made my own accordion and it wasn't working so I took it off codeacademy where i first learnt it and still it wasn't working. I am hosting off google. Is something wrong with this?
I tried adding header: 'h3'
but it still has no effect. It just looks like an alternate of h3 and divs.
Your link to jquery should come before jquery UI or else it would not work.

Collapisble Set, jQuery Mobile, inject AJAX content

Given a basic jQuery Mobile Collapisible Set, how can I get AJAX content before the toggle event fires? I am using jQM to create the following:
<div id="test" data-role="collapsible-set" data-inset="false">
<div data-role="collapsible" data-collapsed="true" data-mini="true">
<h2>Title #1</h2>
<ul data-role="listview"></ul>
</div>
<div data-role="collapsible" data-collapsed="true" data-mini="true">
<h2>Title #2</h2>
<ul data-role="listview"></ul>
</div>
</div>
I want to be able to when a user clicks on the "toggle" fire of an AJAX call to get content from the server and place it in the correct ul. I can figure out how to do everything except intercept the "click". I have tried binding on both click and expand on the div's, h2's and even ul's.
I am looking for something like:
$('#test h2').live('click',function() {
// do my AJAX call here to get li's to put in correct ul (assuming none exist)
});
Surely I am missing something super simple.
Ok...Here is a working example (minus the AJAX). The biggest drawback is that this only "fires" on expand. But by then it has already expanded and thus currently shows a blank space. What is really needed is a "before expanding" or "click" event so that you can inject the content you want and then the default can happen (changing icons, showing, etc). Not sure how to go about proposing that...
http://jsfiddle.net/mfumm/
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css"/>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<div data-role="page" id="page">
<div id="set" data-role="collapsible-set" data-inset="false"></div>
</div>
$("#set div:jqmData(role='collapsible')").each(function () {
$(this).bind('expand', function() {
if($(this).find('li').length < 1) {
// do ajax call here to get data
$(this).find('ul').append(items).listview('refresh');
}
});
});
$('#page #set li').live('click',function () {
alert('Go to item');
});

How to show more than one item in single jquery ui accordion opened section

jquery ui accordion contains lot of panels and every panel contains lot of single line menu items.
jqueryui accordion shows only single item in every panel. How to force accordion to show more items ?
$( "#accordion" ).accordion({
fillSpace: true,
autoHeight: false,
navigation: true,
collapsible: true
});
<h3>
mmmmmmm</h3>
<div>
<ul>
<li><a target='DoklstlG' href='xxxxxx'>
jjjjjj</a></li>
<li><a target='DoklstlO' href='yyyyy'>Ostuarve</a></li>
<li><a target='UnpaidG' href='zzzzzzz'>hjkhkjjsumine</a></li>
<li> </li>
...
</ul>
</div>
<h3>
kkkkk</h3>
<ul>
<li><a target='DoklstlVL' href='nnnnnnnn'>Väljastus</a></li>
<li><a target='DoklstlSL' href='mmmmmmmmmm'>Sissetulek</a></li>
...
as the other answer said, The documentation specifically instructs user to NOT do this
"NOTE: If you want multiple sections open at once, don't use an accordion."
yet, there is a way. i use it like this, and i find it very simple and useful:
create multiple one-item accordion panels one after another with collapsible set to true to emulate a multi-panel accordion.
here is the markup:
<div class="accordion">
<h3>First header</h3>
<div>First content</div>
</div>
<div class="accordion">
<h3>Second header</h3>
<div>Second content</div>
</div>
<div class="accordion">
<h3>Third header</h3>
<div>Third content</div>
</div>
here is the script:
$(".accordion").accordion({collapsible: true});
The documentation specifically instructs user to NOT do this:
NOTE: If you want multiple sections open at once, don't use an accordion.
Source: jQuery UI Documentation
UPDATE
Try changing fillSpace: false and autoHeight : true, see what that does.

JQueryUI - A Challenge perhaps?

I'm working on a website which requires a chunk of code, the nature of which is proving to greatly exceed my limited knowledge of JQuery. The structure of the site is as follows (not quite sure if this is optimally structured for what needs to be done with it, JQuery-wise):
<script>
$(function() {
$(".menutype,.contenttype").draggable({revert:true});
$(".content").droppable({accept:".menutype,.contenttype"});
$(".content").droppable({
drop:function(event,ui){
$(this)
$('div.content').attr('id', 'contenthover')
.find( "p" )
.html( "Droppped!" );
}
});
});
</script>
<body>
<div class="header"><p>///HEADER///</p></div>
<div class="container">
<div class="wrapper1">
<div class="wrapper2">
<div class="content">
<p>///CONTENT///</p>
</div><!-- END "content" -->
<div class="menuL">
<div class="menutype-container">
<div class="menutype"></div>
<div class="menutype"></div>
<div class="menutype"></div>
<div class="menutype"></div>
</div><!-- END "menutype-container" -->
</div><!-- END "menuL" -->
<div class="menuR">
<div class="contenttype-container">
<div class="contenttype"></div>
<div class="contenttype"></div>
<div class="contenttype"></div>
<div class="contenttype"></div>
</div><!-- END "contenttype-container" -->
</div><!-- END "menuR" -->
</div><!-- END "wrapper2" -->
</div><!-- END "wrapper1" -->
</div><!-- END "container" -->
<div class="footer"><p>///FOOTER///</p></div>
</body>
The basic premise is that once one of the "menutype" DIVs is dropped within the droppable area, a corresponding menu structure is revealed in the content DIV. Similarly, once dropped, "contenttype" shows the inline content within that menu.
At this point i'm stumped as to how I go about achieving this. My main problem is that I do not know how to differentiate the menu and content types within the .droppable, as I only know how to define which items it accepts, and not what to individually do with draggable items.
I'm not expecting someone to spit out the necessary code, but some pointers or examples would be greatly appreciated.
I see a lot of people try and use draggable/droppable when what they really need is sortable. Menus are usually unordered lists. Try converting your
<div class="menuL">
into
<ul class="menuL">
with all the
<div class="menutype"></div>
changed to
<li class="menutype"></li>
with this js code
$(".menuL").sortable({
items : 'li',
connectWith : '.menuR',
update : function(event, ui){
},
recieve : function(event, ui){
}
});
if you want to drag and drop between menus you could use common class for both ul elements

Resources