Difference between revisions of "Adding jQuery UI tabs to listing detail page"

From JReviews Documentation
Jump to: navigation, search
 
(26 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The most simple way to add tabs to listing detail page is using jQuery UI tabs.
+
<div class="successbox" style="width: 95%">
  
You will need to modify two files:
+
[https://www.jreviews.com/docs/theme-resources/tabs-in-listing-detail-page There's a new version of this article]
*<span style="color: blue">\com_jreviews\jreviews\views\themes\{theme_name}\listings\detail.thtml</span> - to add the tabs code
+
*<span style="color: blue">\com_jreviews\jreviews\views\helpers\assets.php</span> - to make the jQuery UI tabs plugin work in detail page
+
  
 +
</div>
  
You should never modify original files, instead use [[JReviews Code Overrides]] feature and create copies that will be modified:
+
JReviews includes a tabbed theme for detail pages by default. To use this theme you should add the _tabs theme suffix in the [[Category Layout Manager]] to the categories where you want to use this layout, for example:
*<span style="color: blue">root\templates\jreviews_overrides\views\themes\{theme_name}\listings\detail.thtml</span>
+
*<span style="color: blue">root\templates\jreviews_overrides\views\helpers\assets.php</span>
+
  
 +
[[File:Theme-manager-tabs.png]]
  
== Changes in assets.php file ==
+
This will make sure that listings in that category will use the detail_tabs.thtml theme file instead of the default detail.thtml.
 +
If you open the listing detail page, the tabs area will look something like this:
  
Add <span style="color: blue">'jq.ui.tabs'</span> to the js array in function ComContentComContentView:
+
[[File:Tabs-layout.png]]
  
<source lang="php">
+
If you want to display each field group in its own tab, edit the /views/themes/default/listings/detail_tabs.html theme file and change this line:
function ComContentComContentView()
+
{
+
$assets = array(
+
'js'=>array('jreviews','jquery','jq.ui.core','jq.ui.tabs','jq.jreviews.plugins','jq.fancybox'),
+
'css'=>array('theme','theme.detail','theme.form','paginator','jq.ui.core','jq.fancybox')
+
);
+
  
 +
<source lang="php">
 +
$separate_field_groups = 0;
 
</source>
 
</source>
  
 
+
to this:
And few lines below add <span style="color: blue">jQuery(".jr_tabs").tabs();</span> into jQuery(document).ready(function():
+
  
 
<source lang="php">
 
<source lang="php">
<script type="text/javascript">
+
$separate_field_groups = 1;
jQuery(document).ready(function()
+
{
+
jreviews.lightbox();
+
<?php if($addReviewCheck): // Init tooltips for reviews ?>
+
jreviews.tooltip();
+
<?php endif;?>
+
<?php if($addReviewCheck && $datePickerCheck): // Init datepicker for review fields?>
+
jreviews.datepicker();
+
<?php endif;?> 
+
jQuery(".jr_tabs").tabs();  // Add this line
+
});
+
</script> 
+
 
</source>
 
</source>
  
 +
The result will be:
  
Tabs are now ready to use on the listing detail page!
+
[[File:Tabs-layout-separate-groups.png]]
  
  
== Changes in detail.thtml file ==
+
== Adding custom tabs ==
  
Next step is to test if the tabs are working.
+
If you want to add a new set of tabs to the detail.thtml or some other file, start with this sample code:
  
Add this code into detail.thtml (where you want the tabs to display, usually below SUMMARY/DESCRIPTION text):
 
 
<source lang="php">
 
<source lang="php">
<div class="clr"></div>
+
<div class="jrClear"></div>
<div id="jr_tabs" class="jr_tabs">
+
<div class="jr-tabs jrTabs">
 
<ul>
 
<ul>
 
<li><a href="#tab1">Tab 1</a></li>
 
<li><a href="#tab1">Tab 1</a></li>
Line 73: Line 55:
 
</source>
 
</source>
  
 +
Notice that the tabs have two sections, navigation items inside the ''ul'' tag (tab titles) and tab content below them. What connects them is the value of the href attribute in tab navigation and value in the id attribute of the tab content div. Those references can be any value you want. For example, you could add a forth tab by adding the tab navigation link inside the ''ul'' tag:
  
You should get this:
+
<source lang="php">
 +
<li><a href="#mynewtab">My new tab</a></li>
 +
</source>
  
[[File:UITabs.png]]
+
and add the tab container div with the same id:
  
 
Next, you can start putting parts of detail page into the tabs.
 
 
For example, to add summary/description text inside the first tab, rename "Tab 1" to "Description" and replace "This is tab 1 text" with the summary/description code:
 
 
<source lang="php">
 
<source lang="php">
<div class="clr"></div>
+
<div id="mynewtab">
<div id="jr_tabs" class="jr_tabs">
+
This is the content of my new tab
<ul>
+
</div>
<li><a href="#tab1">Description</a></li>
+
<li><a href="#tab2">Tab 2</a></li>
+
<li><a href="#tab3">Tab 3</a></li>
+
</ul>
+
<div id="tab1">
+
<!-- SUMMARY/DESCRIPTION -->
+
<div class="contentFulltext">
+
<?php echo nl2br($listing['Listing']['text']);?>
+
</div>
+
</div>
+
<div id="tab2">
+
This is tab 2
+
</div>
+
<div id="tab3">
+
This is tab 3
+
</div>
+
</div>  
+
 
</source>
 
</source>
 
[[File:UITabs2.png]] 
 
 
 
Do the same for other parts of detail page, just paste the code into the tab divs.
 
 
 
== Changing  how the tabs look ==
 
 
If you don't like the default look of the tabs, you can style theme using [http://jqueryui.com/themeroller/ jQuery UI ThemeRoller] tool to make your own styles of download other styles from the gallery.
 
 
When you download the jquery ui package (jquery-ui-1.7.1.custom.zip), extract it and copy the files from the '''/css''' directory into this folder:
 
*<span style="color: blue">root\templates\jreviews_overrides\views\themes\{theme_name}\theme_css\jquery_ui_theme\</span>
 
 
 
Copy both jquery-ui-1.7.1.custom.css file and the /images folder.
 
 
After copying, you must '''Clear File Registry''' in JReviews administration
 
 
 
'''NOTE:''' If the downloaded css file has a different version (jquery-ui-1.7.2.custom.css) it will not be recognized by JReviews. The quickest fix is to rename the file to <span style="color: blue">jquery-ui-1.7.1.custom.css</span>
 
 
 
Here is an example of modified tabs theme:
 
 
[[File:UITabs3.png]]
 
 
 
== Tabs only on certain Sections/Categories ==
 
 
If you want tabs only on certain sections or categories, use the [[Theme Manager]] to create theme suffixes.
 
 
For example, you can make modifications on detail_tabs.thtml file, and that file will be used only on sections/categories where you enter "_tabs" as theme suffix in [[Theme Manager]].
 
  
  

Latest revision as of 00:01, 9 July 2020

JReviews includes a tabbed theme for detail pages by default. To use this theme you should add the _tabs theme suffix in the Category Layout Manager to the categories where you want to use this layout, for example:

Theme-manager-tabs.png

This will make sure that listings in that category will use the detail_tabs.thtml theme file instead of the default detail.thtml. If you open the listing detail page, the tabs area will look something like this:

Tabs-layout.png

If you want to display each field group in its own tab, edit the /views/themes/default/listings/detail_tabs.html theme file and change this line:

$separate_field_groups = 0;

to this:

$separate_field_groups = 1;

The result will be:

Tabs-layout-separate-groups.png


Adding custom tabs

If you want to add a new set of tabs to the detail.thtml or some other file, start with this sample code:

<div class="jrClear"></div>
<div class="jr-tabs jrTabs">
	<ul>
		<li><a href="#tab1">Tab 1</a></li>
		<li><a href="#tab2">Tab 2</a></li>
		<li><a href="#tab3">Tab 3</a></li>
	</ul>
	<div id="tab1">
		This is tab 1 text
	</div>
	<div id="tab2">
		This is tab 2 text
	</div>
	<div id="tab3">
		This is tab 3 text
	</div>
</div>

Notice that the tabs have two sections, navigation items inside the ul tag (tab titles) and tab content below them. What connects them is the value of the href attribute in tab navigation and value in the id attribute of the tab content div. Those references can be any value you want. For example, you could add a forth tab by adding the tab navigation link inside the ul tag:

<li><a href="#mynewtab">My new tab</a></li>

and add the tab container div with the same id:

<div id="mynewtab">
	This is the content of my new tab
</div>