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

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/

Related

Php array to ajax var

I have an opensliding side panel in wich I display content. I have a working example, but it works on an ajax var that I've put in. I would like to scan a folder for the files loaded in my ajax code. How can I pass folder content into my ajax?
PHP
<div class="standorte-wrapper">
<div class="panel left"><!-- start pannel left -->
<div class="pan-item tl">
<button class="show-hide" data-ajaxFile="0">OPEN</button>
</div>
<div class="pan-item tr">
<button class="show-hide" data-ajaxFile="1">OPEN</button>
</div>
<div class="pan-item bl">
<button class="show-hide" data-ajaxFile="2">OPEN</button>
</div>
<div class="pan-item br">
<button class="show-hide" data-ajaxFile="3">OPEN</button>
</div>
</div><!-- end pannel left -->
<div id="open" class="panel right"><!-- start sliding pannel right -->
<div class="close-button">
close
</div>
<div id="content">
<div id="php-content"></div>
</div>
</div>
</div>
AJAX
$(document).ready(function() {
var ajaxUrls = [
'/standorteContent/brauerstrasse.php',
'/standorteContent/gutterstrasse.php',
'/standorteContent/kauffmannweg.php',
'/standorteContent/konradstrasse.php'
];
var ajaxFiles = [];
for (var i = 0; i < ajaxUrls.length; i++) {
$.ajax({
method: 'GET',
url: ajaxUrls[i],
success: function(data) {
//console.log(data);
ajaxFiles.push(data);
}
});
}
$('.adres-wrap > button').on('click', function() {
if ($('.panel.left').hasClass('open')) {
//alert('already open');
} else {
$('.panel.left').addClass('open', 1000, "easeInBack");
$('.standorte-wrapper').addClass('expand');
}
$('#php-content').html(ajaxFiles[$(this).attr('data-ajaxFile')]);
setTimeout(function (){
$('.panel.right div').fadeIn(400);
}, 500);
});
$('#close').on('click', function() {
$('.panel.right div').fadeOut(400);
setTimeout(function (){
$('.panel.left').removeClass('open');
$('.standorte-wrapper').removeClass('expand');
}, 500);
});
});
LOOKS LIKE
QUESTION
How can I change so that I don't have to add data-ajaxFile="nr" manual for every button? And I would like ajaxUrls get the path for php files only in a directory on my server. Can anyone help me out on this one?

Filtering collapsable panels with Isotope

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")
});
});

No text change of anchor on toggle

No text change of anchor on toggle please provide me some suggestion
Html:
+Flight Details
<div id="flight_<?php echo $flightlist->id; ?>" class="minDetailBox addmarginB10 borT">
<div class="col1">
<div class="padding">
<div class="airLogo"> <span class="airSprites LS2"> </span>
<p>JET Lite</p>
</div>
</div>
</div>
</div>
Script:
function showHide(id) {
var minDetails = document.getElementById(id);
$(minDetails).toggle('slow');
($(this).text() === "+Flight Details") ? $(this).text("-Flight Details") : $(this).text("+Flight Details");
return false;
}
Pass your element as well like onClick="return showHide('flight1',this)"
function showHide(id,element) {
var minDetails = document.getElementById(id);
$(minDetails).toggle('slow');
($(element).text() === "+Flight Details") ?
$(element).text("-Flight Details") :
$(element).text("+Flight Details");
return false;
}
You can try something like this
+Flight Details
function showHide(id, link) {
$('#' + id).toggle('slow');
($(link).text() === "+Flight Details") ? $(link).text("-Flight Details") : $(link).text("+Flight Details");
return false;
}
+Flight Details
jQuery('a.toggle')
.click(function(e) {
var id = jQuery(this).attr('id');
jQuery('#'+id).toggle('slow');
if(jQuery('#'+id).css('display') == 'none') {
jQuery(this).html("+Flight Details");
} else {
jQuery(this).html("-Flight Details");
}
e.preventDefault();
});
You can do this as below,
jQuery Code
$(function()
{
$('div[id^="flight_"]').hide();
$(document).on('click','.fnt-size12',function(e)
{
e.preventDefault();
var $that = $(this);
$(this).next('#flight1').toggle();
if($that.html() == '+Flight Details') {
$that.html('-Flight Details');
} else {
$that.html('+Flight Details');
}
})
});
Your HTML
+Flight Details
<div id="flight1" class="minDetailBox addmarginB10 borT">
<div class="col1">
<div class="padding">
<div class="airLogo"> <span class="airSprites LS2"> </span>
<p>JET Lite</p>
</div>
</div>
</div>
</div>
See i have modified your HTML code and added new few lines of jQuery code.

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.

trigger link in CListView from dropdownlist

I need to trigger link from CListView when change selected value in dropdownlist.
$(function () {
$(".dd").change(function(){
$('.title').trigger('click');
});
});
<div class="dd">
<?php echo CHtml::dropDownList('title', '', $RawData); ?>
</div>
//view for CListView
<div class="title" id="">
<?php echo CHtml::link(CHtml::encode($data->naslov), Yii::app()->request->baseUrl.'/one/two?id1='.$data->id2.'&id2='.$data->id2 ?>
</div>
OK, I solved the problem
$(function () {
$(".dd").change(function(){
var valString = $(".dd option:selected").val();
var link = $('#titID_'+valString+' a').attr('href');
//alert(link);
$('#titID_'+valString).bind('click', function() {
window.location.href = link;
return false;
});
$('#titID_'+valString).trigger('click')
});
});

Categories