Filtering collapsable panels with Isotope - php

I have a problem using isotope with collapsable panels.
The problem is in the layout when there is a panel opened and you try to filter all data with isotope selecting a category from the filter list.
<div class="col-sm-12 <?php echo esc_attr($categorie_names); ?>">
<div class="h3ader">
<h5 data-parent="#accordion" style="color:white; padding-bottom: 5px;"> <?php the_title(); ?> </h5>
</div>
<div class="c0ntent">
<p><?php echo htmlspecialchars_decode(esc_attr($shortdesc));?></p>
<div class="text-center">
<?php echo esc_attr($theme_option['courses_detail']); ?>
</div>
</div>
And that's the javascript code:
$(window).load(function () {
var $container = $('#portfolio-div');
$container.isotope({
filter: '*',
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
}
});
$('.filter ul li a').click(function () {
$('.filter .active').removeClass('active');
$(this).addClass('active');
var selector = $(this).attr('data-filter');
$container.isotope({
filter: selector,
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
}
});
return false;
});
});
$(".h3ader").click(function () {
$h3ader = $(this);
$c0ntent = $h3ader.next();
$c0ntent.slideToggle(500, function () {
$(".col-sm-12").removeAttr("style")
});
});

Related

get data on mousehover for different id

I have a listing of products each with differnt ID. Now on frontend I want to get prodouct data(say, name,price and a addtocart button) on mousover.
Here is my code:
This is in loop to get all products:
HTML:
<div class="prod">
<a class="product-image pi_470" title="Cushion Tsavorites" href="/tsavorite/cushion-tsavorites-1328.html"><img height="135" width="135" alt="Cushion Tsavorites" src="/small_image.jpg"></a>
<div style="display: none; margin: -65px 0px 0px 5px; position: absolute; z-index: 30;" class="mouse_hover_470">
<input type="hidden" id="prod_id" value="470">
<h2 class="product-name"><a title="Cushion Tsavorites" href="/tsavorite/cushion-tsavorites-1328.html">Cushion Tsavorites</a></h2>
<div class="price-box">
<span id="product-price-470" class="regular-price">
<span class="price">$387.15</span>
</span>
</div>
<div class="actions">
<button onclick="setLocation('http://dev614.trigma.us/chocolate/index.php/checkout/cart/add/uenc/aHR0cDovL2RldjYxNC50cmlnbWEudXMvY2hvY29sYXRlL2luZGV4LnBocC90c2F2b3JpdGUuaHRtbA,,/product/470/form_key/4BR7w0TqeeO9AC0g/')" class="button btn-cart" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button>
</div>
</div>
</div>
jQuery:
jQuery(document).ready(function() {
var bla = jQuery('#prod_id').val();
jQuery(".pi_" + bla).mouseover(function() {
//alert("hello");
jQuery(".mouse_hover_" + bla).css("display", "block");
});
jQuery(".pi_" + bla).mouseout(function() {
jQuery(".mouse_hover_" + bla).css("display", "none");
});
});
But Iam getting only data of first product on mouseover. Its not working for rest of products
Looks like you are executing the above block of code in a loop, once per each product. In that case the problem is jQuery('#prod_id').val(); it will always return the value of first element with id prod_id.
In your case you don't have to do that, you can
jQuery(function ($) {
$('.prod .product-image').hover(function () {
$(this).next().show();
}, function () {
$(this).next().hide();
})
});
There is a much, much easier way to do this:
jQuery(document).ready(function() {
jQuery(".product-image").hover(function() {
$(this).next().show();
}, function() {
$(this).next().hide();
});
});
Demo: JSBin
You can use each() function in jQuery
NOTE: Instead of using id="prod_id", use class, i.e class="prod_id". Since you told that the div is dynamically created it is using the same id attribute
Now loop the product div on ready function
jQuery(document).ready(function() {
jQuery('.prod').each(function(){
var bla = jQuery('.prod_id').val();
jQuery(".pi_" + bla).on('mouseover',function() {
//alert("hello");
jQuery(".mouse_hover_" + bla).css("display", "block");
});
jQuery(".pi_" + bla).on('mouseout',function() {
jQuery(".mouse_hover_" + bla).css("display", "none");
});
});
});
You can checkout this jQuery each()
Ashi,
try using
var bla = jQuery(input[id*='prod_id']).val();
instead of
var bla = jQuery('#prod_id').val();
This will give you all the hidden inputs so loop all of them and bind the mouseover event.
For example:
jQuery(input[id*='prod_id']).each(function(){
var bla = jQuery(this).val();
//carry out your logic..
// you can use jquery().live('mouseover'function(){}) for dynamically created html
});
Hope this will work!!
Cheers!!
function handler(ev) {
var target = $(ev.target);
var elId = target.attr('id');
if( target.is(".el") ) {
alert('The mouse was over'+ elId );
}
}
$(".el").mouseleave(handler);
http://jsfiddle.net/roXon/dJgf4/

Isotope .ajax() not work

I appreciate any help you can give me .
I commented I'm doing an infinite scroll through a foreach php and ajax to load the part of the page that I need, the only detail is that isotope use and when I try to load the new content in the isotope in the sucess function ajax , not load anything, the code above the call if the content loads correctly but not within the isotope.
This is the content of foreach
<ul class="projects_wrapper">
<?php if(isset($feed['gallery']['data'])) { ?>
<?php foreach($feed['gallery']['data'] as $k=>$v){ ?>
<li class="mix <?php echo strtolower($v['parent']['title']); ?>">
<div class="project_item">
<img class="project_item_img" src="<?php echo $v['logo']['src-s'];?>" alt="">
<div class="project_item_description">
<h3 class="project_item_title"><?php echo $v['title']; ?></h3>
<p><?php echo $v['description'];?></p>
<a class="button button_view button_project" href="/<?php echo $v['permalink'];?>">View More</a>
</div>
</div>
</li>
<?php } ?>
<?php } ?>
<div id="loadmoreajaxloader" style="display:none;"><center><img src="http://www.iec.ch/img/loading_sliders_2.gif" /></center></div>
</ul>
This is the content for javascript
var $isotope_container = $('.projects_wrapper');
var current = 2;
var catg = 'all';
$(document).ready(function(){
setTimeout(function(){
$isotope_container.isotope({
itemSelector: '.mix'
});
},1000);
// bind filter button click
$('.filter-link').on( 'click', function() {
catg = $(this).data('filter');
$( ".mix" ).filter(catg).css( "background-color", "red" );
$('.filter-link').removeClass('selected');
$(this).addClass('selected');
var filterValue = $( this ).attr('data-filter');
//use filterFn if matches value
//filterValue = filterFns[ filterValue ] || filterValue;
$isotope_container.isotope({ filter: filterValue });
});
/*$('.add_more').on('click',function(){
var elems = getItemElement().add( getItemElement() ).add( getItemElement() );
//console.log(elems);
// append elements to container
$isotope_container.append(elems).isotope('appended',elems);
});*/
$(window).scroll(function()
{
if($(window).scrollTop() == $(document).height() - $(window).height())
{
$('div#loadmoreajaxloader').show();
$.ajax({
url: "/projects",
data: {pag: current, content_only: 1, category: catg},
success: function(data)
{
if(data)
{
//$(".projects_wrapper").append(data);
$(".projects_wrapper").isotope("appended",data);
$('div#loadmoreajaxloader').hide();
current++;
console.log('Me Ejecuto');
}else
{
$('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
console.log('Termine');
}
}
});
}
});
});
i resolve this for destroy isotope and reconstruct after like this:
function redo_isotope(){
$isotope_container.isotope('destroy');
$isotope_container.isotope({
itemSelector: '.mix'
},1000);
}
var $isotope_container = $('.projects_wrapper');
var current = 2;
var catg = 'all';
$(document).ready(function(){
setTimeout(function(){
$isotope_container.isotope({
itemSelector: '.mix'
});
},1000);
// bind filter button click
$('.filter-link').on( 'click', function() {
catg = $(this).data('filter');
$( ".mix" ).filter(catg).css( "background-color", "red" );
$('.filter-link').removeClass('selected');
$(this).addClass('selected');
var filterValue = $( this ).attr('data-filter');
//use filterFn if matches value
//filterValue = filterFns[ filterValue ] || filterValue;
$isotope_container.isotope({ filter: filterValue });
});
/*$('.add_more').on('click',function(){
var elems = getItemElement().add( getItemElement() ).add( getItemElement() );
//console.log(elems);
// append elements to container
$isotope_container.append(elems).isotope('appended',elems);
});*/
$(window).scroll(function()
{
if($(window).scrollTop() == $(document).height() - $(window).height())
{
$('div#loadmoreajaxloader').show();
$.ajax({
url: "/projects",
method: "get",
data: {pag: current, content_only: 1, category: catg},
success: function(data)
{
if(data)
{
$(".projects_wrapper").append(data);
redo_isotope();
//$(".projects_wrapper").append(data);
$('div#loadmoreajaxloader').hide();
current++;
}else
{
$('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
}
}
});
}
});
});

How to get the id of a div from mouseenter function?

I need to get the id of the productbox div in this jquery code.i tried $this.attr('id) but the result is object object or undefined.how can i get the id of productbox div? thanks in advance
Javascript:
$('body').on('mouseenter', 'div.productbox', function()
{
buttonDiv = $(this).children('div.roll');
myTimeout = setTimeout(function()
{
Divid = ?;
buttonDiv.toggle();
}, 500);
});
$('body').on('mouseleave', 'div.productbox', function()
{
buttonDiv.hide();
clearTimeout(myTimeout);
});
$('body').on('hover', 'div.productbox', function()
{
var buttonDiv = $(this).children('div.roll1');
buttonDiv.toggle();
});
HTML:
<div id="40" class="productbox">
<span class="new">Yeni</span>
<div class="roll" style="display: none;">
<input type="button" value="139"> Like <input type="button" value="34"> Comment
</div>
<div class="productpicture" onclick="rload(40)">
<img style="margin:auto; width:180px;overflow:hidden;display:block" src="pictures/40.jpg">
</div>
<div class="ps">
<div class="productname">Giysi</div>
<div class="companyname" onclick="go('2');">Koton</div>
<div class="price">9.99 TL</div>
</div>
</div>
You can take advantage of closure like this:
<script type="text/javascript">
$('body').on('mouseenter', 'div.productbox', function()
{
var $productBox = $( this );
buttonDiv = $productBox.children('div.roll');
myTimeout = setTimeout(function ()
{
Divid = $productBox.attr('id');
buttonDiv.toggle();
}, 500);
});
$('body').on('mouseleave', 'div.productbox', function ()
{
buttonDiv.hide();
clearTimeout(myTimeout);
});
$('body').on('hover', 'div.productbox', function ()
{
var buttonDiv = $(this).children('div.roll1');
buttonDiv.toggle();
});
</script>
<div id="40" class="productbox">
<span class="new">Yeni</span>
<div class="roll" style="display: none;">
<input type="button" value="139">
Like
<input type="button" value="34">
Comment
</div>
<div class="productpicture" onclick="rload(40)">
<img style="margin:auto; width:180px;overflow:hidden;display:block" src="pictures/40.jpg">
</div>
<div class="ps">
<div class="productname">Giysi</div>
<div class="companyname" onclick="go('2');">Koton</div>
<div class="price">9.99 TL</div>
</div>
</div>
The reason you are getting 'undefined' etc is because you are actually requesting the window for its ID.
What you need to do is declare a local variable for the div and then inside your timeout use that variable to get the ID.
$('body').on('mouseenter', 'div.productbox', function() {
var $this = $(this);
var buttonDiv= $this.children('div.roll');
var myTimeout = setTimeout(function() {
var Divid= $this.attr('id');
buttonDiv.toggle();
}, 500);
});
you need to do this:
$('body').on('mouseenter', 'div.productbox', function() {
myTimeout = setTimeout((function(self) {
return function() {
buttonDiv = $(self).children('div.roll');
Divid= $(self).attr("id");
console.log(Divid);
buttonDiv.toggle();
}
})(this), 500);
});
check the JSFiddle for complete working code: http://jsfiddle.net/kBRyu/2/

jQuery tabs and showing database strings

I am attempting to call data from the db at the head of the page and then use the array information in a foreach to populate the tables in the tab.. currently i am testing with tab 2 but i will want this to originally show in tab 1 unless moved by the user. I am unsure where or how to include the db query and result so that it will populate correctly. Here is what i have so far.
{source 0}
<?php
$user =& JFactory::getUser();
if (!$user->guest)
$name = $user->username;
$db =& JFactory::getDbo();
$query = $db->getQuery(true);
$query = "
SELECT image_url, name_test, image_date
FROM #__image_data
WHERE user_name = '$name'";
$db->setQuery($query);
echo $name."'s Pets" . "<br/>";
$list = $db->loadObjectList();
foreach ($list as $item){
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Tabs - Simple manipulation</title>
<link rel="stylesheet" href="/Joomla3/jquery/themes/base/jquery.ui.all.css">
<script src="/Joomla3/jquery/jquery-1.8.3.js"></script>
<script src="/Joomla3/jquery/ui/jquery.ui.position.js"></script>
<script src="/Joomla3/jquery/ui/jquery.ui.core.js"></script>
<script src="/Joomla3/jquery/ui/jquery.ui.widget.js"></script>
<script src="/Joomla3/jquery/ui/jquery.ui.mouse.js"></script>
<script src="/Joomla3/jquery/ui/jquery.ui.sortable.js"></script>
<script src="/Joomla3/jquery/ui/jquery.ui.button.js"></script>
<script src="/Joomla3/jquery/ui/jquery.ui.tabs.js"></script>
<script src="/Joomla3/jquery/ui/jquery.ui.dialog.js"></script>
<script src="/Joomla3/jquery/ui/jquery.ui.droppable.js"></script>
<link rel="stylesheet" href="/Joomla3/jquery/demos/demos.css">
<style>
#dialog label, #dialog input { display:block; }
#dialog label { margin-top: 0.5em; }
#dialog input, #dialog textarea { width: 95%; }
#tabs { margin-top: 1em; }
#tabs li .ui-icon-close { float: left; margin: 0.4em 0.2em 0 0; cursor: pointer; }
#add_tab { cursor: pointer; }
#sortable1 li, #sortable2 li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 120px; }
</style>
<script>
$(function() {
$( "#sortable1, #sortable2" ).sortable().disableSelection();
var $tabs = $( "#tabs" ).tabs();
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( "select", $tab_items.index( $item ) );
$( this ).appendTo( $list ).show( "slow" );
});
}
});
});
</script>
<script>
$(function() {
var tabTitle = $( "#tab_title" ),
tabContent = $( "#tab_content" ),
tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
tabCounter = 2;
var tabs = $( "#tabs" ).tabs();
// modal dialog init: custom buttons and a "close" callback reseting the form inside
var dialog = $( "#dialog" ).dialog({
autoOpen: false,
modal: true,
buttons: {
Add: function() {
addTab();
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
form[ 0 ].reset();
}
});
// addTab form: calls addTab function on submit and closes the dialog
var form = dialog.find( "form" ).submit(function( event ) {
addTab();
dialog.dialog( "close" );
event.preventDefault();
});
// actual addTab function: adds new tab using the input from the form above
function addTab() {
var label = tabTitle.val() || "Tab " + tabCounter,
id = "tabs-" + tabCounter,
li = $( tabTemplate.replace( /#\{href\}/g, "#" + id ).replace( /#\{label\}/g, label ) ),
tabContentHtml = tabContent.val() || "Tab " + tabCounter;
tabs.find( ".ui-tabs-nav" ).append( li );
tabs.append( "<div id='" + id + "'></div>" );
tabs.tabs( "refresh" );
tabCounter++;
}
// addTab button: just opens the dialog
$( "#add_tab" )
.button()
.click(function() {
dialog.dialog( "open" );
});
// close icon: removing the tab on click
$( "#tabs span.ui-icon-close" ).live( "click", function() {
var panelId = $( this ).closest( "li" ).remove().attr( "aria-controls" );
$( "#" + panelId ).remove();
tabs.tabs( "refresh" );
});
});
</script>
<script>
$(function() {
var tabs = $( "#tabs" ).tabs();
tabs.find( ".ui-tabs-nav" ).sortable({
axis: "x",
stop: function() {
tabs.tabs( "refresh" );
}
});
});
</script>
</head>
<body>
<div id="main_container">
<div id="dialog" title="Tab data">
<form>
<fieldset class="ui-helper-reset">
<label for="tab_title">Title</label>
<input type="text" name="tab_title" id="tab_title" value="" class="ui-widget-content ui-corner-all" />
</fieldset>
</form>
</div>
<button id="add_tab">Add Tab</button>
<div id="tabs">
<ul>
<li>Main</li>
<li>Tab 2</li>
<!--<li>Tab 3</li>  // Additional tabs added to the main-->
</ul>
<div id="tabs-1">
<p>Test information.</p>
</div>
<div id="tabs-2">
<ul id="sortable2" class="connectedSortable ui-helper-reset">
<li class="ui-state-highlight"><img src="http://localhost/Joomla3/myimage.png"></li>
<li class="ui-state-highlight">
<?php"<tr><td>"."<img src='$item->image_url'>" . "<td>" . $item->name_test . "<td>" . $item->image_date ."</td></tr>"?></li>
<li class="ui-state-highlight">Item 2</li>
<li class="ui-state-highlight">Item 3</li> 
<li class="ui-state-highlight">Item 4</li>
<li class="ui-state-highlight">Item 5</li>
</ul>
</div>
</div>
</div>
</body>
</html>
{/source}
Since you already have a foreach loop set up for your db data can create all the html stored in a variable like this:
$tableHtml='<table id="foo">';
foreach ($list as $item){
$tableHtml.="<tr><td><img src='".$item->image_url."'><td>" . $item->name_test . "</td><td>" . $item->image_date ."</td></tr>";
}
$tableHtml='</table';
Then in the part of page you want table :
<?php echo $tableHtml; ?>

Why is this facebook app refreshing endlessly

I kindly request that you help me identify the reason in the code why my app keeps refreshing endlessly. This does not allow me to navigate to other pages, Iam a learner in php and I suspect this could be the issue, help. Could it be a problem with the php arrangement?
Here is the code in index.php
<script type="text/javascript">
$(document).ready(function() {
$('#premium_b').click(function(e) {
e.preventDefault();
$('#tabs').tabs( "select" , 4 );
});
$('#tabs').bind('tabsselect', function(event, ui) {
if (ui.index == 4 )
$('#premium_b').css ('display', 'none');
else
$('#premium_b').css ('display', 'block');
});
});
</script>
<div id="bloc_134" class="li_bloc"><ul class="menu"><li>Home
</li>
<li>Config
</li>
<li>Customize
</li>
<li>Export
</li>
<li>Premium
</li>
<li>Statistics
</li>
<li>Doc
</li>
<li>About
</li>
<li>Other Apps
</li>
<li>FAQ
</li>
</ul>
Upgrade to Premium to get white branding and help us improve your favourite apps! : Click her
<div class="clear"></div>
</div>
</div>
<div id="alerts">
</div>
<div id="zone2" class="li_zone li_x1 li_y2">
<div id="contact_form_about"><div class="zone2">
</div></div>
<div id="contact_form_config"><div class="zone2"><script type="text/javascript">
function refreshApp (url) {
$.get(url, function(data) {
$('*').html(data);
});
}
$(document).ready(function() {
var options = {
success: showResponse,
beforeSubmit: disableButton
};
$('#tab_info_form_0').ajaxForm(options);
});
function addToPage() {
var obj = {
method: 'pagetab',
redirect_uri: 'https://apps.facebook.com/mtkenya-dev/?page_id=#contact_form_config',
};
FB.ui(obj);
}
</script>
<script>top.location.href='https://www.facebook.com/dialog/oauth?client_id=461688580525581&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fmtkenya-dev%2F%3Ftab%3Dcontact_form_config&scope=email,manage_pages'</script></div>
<div class="zone2"><script type="text/javascript">
$(document).ready(function() {
var options = {
success: showResponse,
beforeSubmit: disableButton
};
$('#contact_form').ajaxForm(options);
$('#customize_css').ajaxForm(options);
});
</script>
<div id="bloc_133" class="li_bloc"><p>Page non trouv?e</p>
</div>
</div>
</div>
<div id="contact_form_css"><div class="zone2"><script type="text/javascript">
function refreshApp (url) {
$.get(url, function(data) {
$('*').html(data);
});
}
$(document).ready(function() {
var options = {
success: showResponse,
beforeSubmit: disableButton
};
$('#tab_info_form_0').ajaxForm(options);
});
function addToPage() {
var obj = {
method: 'pagetab',
redirect_uri: 'https://apps.facebook.com/mtkenya-dev/?page_id=#contact_form_css',
};
FB.ui(obj);
}
</script>
<script>top.location.href='https://www.facebook.com/dialog/oauth?client_id=461688580525581&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fmtkenya-dev%2F%3Ftab%3Dcontact_form_css&scope=email,manage_pages'</script></div>
</div>
<div id="contact_form_doc"><div class="zone2"><script type="text/javascript">
$(function() {
$("#bloc_223").tabs({
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. ");
}
},
cache: true
});
});
</script>
</div>
</div>
<div id="contact_form_export"><div class="zone2"><script type="text/javascript">
function refreshApp (url) {
$.get(url, function(data) {
$('*').html(data);
});
}
$(document).ready(function() {
var options = {
success: showResponse,
beforeSubmit: disableButton
};
$('#tab_info_form_0').ajaxForm(options);
});
function addToPage() {
var obj = {
method: 'pagetab',
redirect_uri: 'https://apps.facebook.com/mtkenya-dev/?page_id=#contact_form_export',
};
FB.ui(obj);
}
</script>
<script>top.location.href='https://www.facebook.com/dialog/oauth?client_id=461688580525581&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fmtkenya-dev%2F%3Ftab%3Dcontact_form_export&scope=email,manage_pages'</script></div>
<div id="footer" class="li_zone li_x1 li_y4"> </div>
</div>
</body>
</html>
Well, I see 3 times:
top.location.href=....
without any condition and not in a function call. That would certainly keep your page jumping.

Categories