Need help with Joomla? We are available for hire to help with Joomla customization, upgrades, maintenance, and custom development.
Explore our services
OS Property support center

Add cookies and javascript to listing html theme

  • Davor
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 years 9 months ago #54271 by Davor
Hello, I would like to modify the listing layout and add grid/list functionality with cookies. I am not sure, but the code isn't working. I added this to the listing.html.tpl.php.
Code:
<script> $(function(){ var default_view = 'grid'; // choose the view to show by default (grid/list) // check the presence of the cookie, if not create "view" cookie with the default view value if($.cookie('view') !== 'undefined'){ $.cookie('view', default_view, { expires: 31, path: '/' }); } function get_grid(){ $('.list').removeClass('list-active'); $('.grid').addClass('grid-active'); $('.property-view').animate({opacity:0},function(){ $('.property-view').removeClass('property-list'); $('.property-view').addClass('property-grid'); $('.property-view').stop().animate({opacity:1}); }); } // end "get_grid" function function get_list(){ $('.grid').removeClass('grid-active'); $('.list').addClass('list-active'); $('.property-view').animate({opacity:0},function(){ $('.property-view').removeClass('property-grid'); $('.property-view').addClass('property-list'); $('.property-view').stop().animate({opacity:1}); }); } // end "get_list" function if($.cookie('view') == 'list'){ // we dont use the "get_list" function here to avoid the animation $('.grid').removeClass('grid-active'); $('.list').addClass('list-active'); $('.property_view').animate({opacity:0}); $('.property_view').removeClass('property-grid'); $('.property_view').addClass('property-list'); $('.property_view').stop().animate({opacity:1}); } if($.cookie('view') == 'grid'){ $('.list').removeClass('list-active'); $('.grid').addClass('grid-active'); $('.property_view').animate({opacity:0}); $('.property_view').removeClass('prod-box-list'); $('.property_view').addClass('prod-box'); $('.property_view').stop().animate({opacity:1}); } $('#list').click(function(){ $.cookie('view', 'list'); get_list() }); $('#grid').click(function(){ $.cookie('view', 'grid'); get_grid(); }); /* filter */ $('.category-menu ul li').click(function(){ var CategoryID = $(this).attr('category'); $('.category-menu ul li').removeClass('cat-active'); $(this).addClass('cat-active'); $('.property_view').each(function(){ if(($(this).hasClass(CategoryID)) == false){ $(this).css({'display':'none'}); }; }); $('.'+CategoryID).fadeIn(); }); }); </script>
and I added this to the index.php of the main joomla template head
Code:
<link href="<?php echo $templateUrl; ?>/css/grid-list.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="<?php echo $templateUrl; ?>/jquery.cookie.js"></script>

What am I missing?
Thanks

Please Log in or Create an account to join the conversation.

More
11 years 9 months ago #54280 by Mr. Dam
Hi Davor,
I am sorry, i don't know where do you get this source code, but i am afraid it won't work in OS Property. I don't understand that code too.
Thanks
Dam

Please Log in or Create an account to join the conversation.

  • Davor
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 years 9 months ago #54285 by Davor
Hello,

This is some jQuery /javascript code with cookies, that I would like to include and execute in listing.html.tpl.php. The main purpose is to add class and remove class on click.
Code:
$('.property_view').[b]removeClass[/b]('property-grid'); $('.property_view').[b]addClass[/b]('property-list');
This I would like to incorporate so that I can make a grid and list layout.

Why do you say it won't work? Where can I include the JS code?
Thanks

Please Log in or Create an account to join the conversation.

More
11 years 9 months ago #54294 by Mr. Dam
Hi Davor,
I have read the code you attached in this forum, and to be honest, i don't understand what is the purpose of your code. Hope you understand it. And because i don't understand your code and its purpose, i can't let you know how to make it to work.
I hope someone on this forum will be able to help you something.
Thanks
Dam

Please Log in or Create an account to join the conversation.

Moderators: Mr. DamNguyen Phu Quan