How can I unbind JQZOOM in my JQuery Script? - php

I have this script at the moment, which changes an image when a thumbnail has been changed. I then want JQZOOM to be added to that new image. However, if I put it inside the Onclick event, it gets slower and slower the more times you click on it... I guess because its running multiple instances.
Is there anyway to unbind the JQZOOM from something then rebind it to something else?
Here is my jquery at the moment:
var options = {
zoomWidth: 400,
zoomHeight: 325,
xOffset: 25,
yOffset: 0,
position: "right",
lens: true,
zoomType: "reverse",
imageOpacity: 0.5,
showEffect: "fadein",
hideEffect: "fadeout",
fadeinSpeed: "medium",
title: false
};
$('.jqzoom').jqzoom(options);
$('.single-zoom-image').click ( function () {
$('#bigProductImage').attr("src", $(this).attr("zoom"));
$('.jqzoom').attr("href", $(this).attr("extrazoom"));
});
Thanks in advance if anyone can help me.
Cheers!

This can be done as follows:
Modify jqzoom1.0.1.js where the other mouse functions are (around line 90)
//Handle clicked thumbnails changing the zoomed image
$(this).bind('changeimage', function(){
smallimage = new Smallimage( $("img", this) );
largeimage = new Largeimage(a[0].href);
smallimage.loadimage();
});
Call the zoomer as follows:
$(document).ready(function(){
var options = {
zoomWidth: 300,
zoomHeight: 200,
xOffset: 30,
yOffset: 0,
position: 'right',
title: false,
showPreload: false
};
//Handle clicking on the thumbnails, swap the mainimage and recycle the zoomer
$('.seemore').bind('click', function(e) {
e.preventDefault();
$('.jssProductFullImage').attr('src', $(this).attr('href'));
$('.zoomer').attr('href', $(this).attr('href') );
//Recall the zoomer to update the page
$('.zoomer').trigger('changeimage');
});
$('.zoomer').jqzoom(options);
});

$('.jqzoom').removeData('jqzoom');
Did the job for me.

Related

Placing Multilple Google Charts on webpage from MYSQL Data

I have been able to show a google chart from mysql data, but when I add the second chart I am only able to see the data from the 2nd array(for 2nd chart) I used json_encode on in my php script. If I change the order of the array encoding so that the 2nd chart's array is now encoded first I no longer see it, but now the first chart is visible. Can anyone see the issue? Maybe I should use column charts instead of material charts??
here is my javascript:
<script type="text/javascript">
google.setOnLoadCallback(drawCharts);
function drawCharts() {
drawChartA();
drawChartB();
}
function drawChartB(){
var data = new google.visualization.DataTable(<?=$jsonTable?>);
var options = {
chart: {
title: 'Calls for <?php echo $cLabel;?>',
subtitle: 'Something to put Here',
},
annotations:{
textStyle:{
fontName: 'Times-Roman',
fontSize: 12,
bold: true,
italic: false
}
},
width: 1200,
height: 600,
};
var chart = new
google.charts.Bar(document.getElementById('chart_div'));
chart.draw(data, google.charts.Bar.convertOptions(options));
}
function drawChartA(){
var data = new google.visualization.DataTable(<?=$jsonTable_ct?>);
var options = {
chart: {
title: 'Calls for <?php echo $cLabel;?>',
subtitle: 'Something to put Here',
},
annotations:{
textStyle:{
fontName: 'Times-Roman',
fontSize: 12,
bold: true,
italic: false
}
},
width: 1200,
height: 600,
isStacked: 'true',
};
var chart = new google.charts.Bar(document.getElementById('chart_div_ct'));
chart.draw(data, google.charts.Bar.convertOptions(options));
}
</script>
my json_encoded files are:
{"cols":[{"label":"Time Interval","type":"string"},{"label":"Calls - All Offices","type":"number"}],"rows":[{"c":[{"v":"05:00"},{"v":1}]},{"c":[{"v":"06:00"},{"v":3}]},{"c":[{"v":"07:00"},{"v":9}]},{"c":[{"v":"07:30"},{"v":22}]},{"c":[{"v":"08:00"},{"v":82}]},{"c":[{"v":"08:30"},{"v":68}]},{"c":[{"v":"09:00"},{"v":97}]},{"c":[{"v":"09:30"},{"v":48}]},{"c":[{"v":"10:00"},{"v":56}]},{"c":[{"v":"10:30"},{"v":70}]},{"c":[{"v":"11:00"},{"v":75}]},{"c":[{"v":"11:30"},{"v":53}]},{"c":[{"v":"12:00"},{"v":56}]},{"c":[{"v":"12:30"},{"v":48}]},{"c":[{"v":"13:00"},{"v":22}]},{"c":[{"v":"13:30"},{"v":42}]},{"c":[{"v":"14:00"},{"v":40}]},{"c":[{"v":"14:30"},{"v":60}]},{"c":[{"v":"15:00"},{"v":69}]},{"c":[{"v":"15:30"},{"v":65}]},{"c":[{"v":"16:00"},{"v":73}]},{"c":[{"v":"16:30"},{"v":37}]},{"c":[{"v":"17:00"},{"v":20}]},{"c":[{"v":"17:30"},{"v":10}]},{"c":[{"v":"18:00"},{"v":10}]},{"c":[{"v":"18:30"},{"v":2}]},{"c":[{"v":"19:00"},{"v":1}]},{"c":[{"v":"19:30"},{"v":2}]},{"c":[{"v":"20:00"},{"v":1}]},{"c":[{"v":"20:30"},{"v":1}]}]}
and the other is here: (they both work so reviewing this may not be necessary)
{"cols":[{"label":"Time Interval","type":"string"},{"label":"NP Calls","type":"number"},{"label":"DR Calls","type":"number"},{"label":"RE Today Calls","type":"number"},{"label":"RE Future","type":"number"},{"label":"ACCT","type":"number"},{"label":"EMER","type":"number"},{"label":"Other Calls","type":"number"}],"rows":[{"c":[{"v":"05:00"},{"v":0},{"v":0},{"v":0},{"v":0},{"v":0},{"v":0},{"v":1}]},{"c":[{"v":"06:00"},{"v":0},{"v":0},{"v":1},{"v":0},{"v":0},{"v":0},{"v":0}]},{"c":[{"v":"07:00"},{"v":0},{"v":0},{"v":0},{"v":0},{"v":0},{"v":0},{"v":2}]},{"c":[{"v":"07:30"},{"v":2},{"v":0},{"v":3},{"v":0},{"v":0},{"v":1},{"v":2}]},{"c":[{"v":"08:00"},{"v":9},{"v":3},{"v":11},{"v":5},{"v":0},{"v":4},{"v":23}]},{"c":[{"v":"08:30"},{"v":1},{"v":2},{"v":13},{"v":7},{"v":2},{"v":4},{"v":14}]},{"c":[{"v":"09:00"},{"v":3},{"v":1},{"v":15},{"v":11},{"v":6},{"v":3},{"v":23}]},{"c":[{"v":"09:30"},{"v":0},{"v":0},{"v":4},{"v":6},{"v":5},{"v":0},{"v":16}]},{"c":[{"v":"10:00"},{"v":1},{"v":3},{"v":2},{"v":10},{"v":2},{"v":0},{"v":17}]},{"c":[{"v":"10:30"},{"v":5},{"v":1},{"v":1},{"v":10},{"v":2},{"v":3},{"v":23}]},{"c":[{"v":"11:00"},{"v":5},{"v":3},{"v":7},{"v":11},{"v":10},{"v":1},{"v":23}]},{"c":[{"v":"11:30"},{"v":4},{"v":1},{"v":2},{"v":6},{"v":2},{"v":0},{"v":18}]},{"c":[{"v":"12:00"},{"v":3},{"v":0},{"v":5},{"v":11},{"v":2},{"v":0},{"v":21}]},{"c":[{"v":"12:30"},{"v":5},{"v":1},{"v":4},{"v":4},{"v":4},{"v":1},{"v":5}]},{"c":[{"v":"13:00"},{"v":2},{"v":1},{"v":3},{"v":2},{"v":2},{"v":0},{"v":6}]},{"c":[{"v":"13:30"},{"v":2},{"v":0},{"v":1},{"v":3},{"v":1},{"v":0},{"v":15}]},{"c":[{"v":"14:00"},{"v":5},{"v":3},{"v":1},{"v":5},{"v":3},{"v":1},{"v":4}]},{"c":[{"v":"14:30"},{"v":3},{"v":1},{"v":5},{"v":6},{"v":6},{"v":0},{"v":19}]},{"c":[{"v":"15:00"},{"v":3},{"v":1},{"v":4},{"v":8},{"v":4},{"v":1},{"v":22}]},{"c":[{"v":"15:30"},{"v":8},{"v":1},{"v":0},{"v":10},{"v":4},{"v":0},{"v":22}]},{"c":[{"v":"16:00"},{"v":6},{"v":5},{"v":1},{"v":12},{"v":3},{"v":2},{"v":20}]},{"c":[{"v":"16:30"},{"v":3},{"v":4},{"v":3},{"v":7},{"v":3},{"v":1},{"v":7}]},{"c":[{"v":"17:00"},{"v":1},{"v":0},{"v":0},{"v":4},{"v":1},{"v":0},{"v":5}]},{"c":[{"v":"17:30"},{"v":0},{"v":1},{"v":0},{"v":1},{"v":1},{"v":0},{"v":1}]},{"c":[{"v":"18:00"},{"v":1},{"v":0},{"v":1},{"v":0},{"v":0},{"v":0},{"v":2}]},{"c":[{"v":"18:30"},{"v":0},{"v":0},{"v":0},{"v":1},{"v":0},{"v":0},{"v":0}]}]}Can
It's most likely the same issue that was reported in google-visualization-issues repository.
There are at least two solution available at the moment:
Option 1. Render charts synchronously
The general idea is to render chart synchronously. Since draw function is asyncronous, we utilize ready event handler for that purpose.
Place ready event handler in every function before draw function invocation:
if (typeof ready != "undefined") google.visualization.events.addOneTimeListener(chart, 'ready', ready);
and change drawChartN() function signature to drawChartN(ready)
Then replace:
function drawCharts() {
drawChartA();
drawChartB();
}
with:
function drawCharts() {
drawChartA(function(){
drawChartB();
});
}
PhpFiddle
Option 2. Using the frozen version loader.
Since
The rollout of the v43 candidate release that would fix this problem
switch to using the frozen version loader.
Steps:
1)Add a reference to loader: <script
src="//www.gstatic.com/charts/loader.js"></script>
2)Then load a 43 version of library: google.charts.load("43",{packages:["corechart","bar"]});
3)Replace:
function drawCharts() {
drawChartA();
drawChartB();
}
with
google.charts.setOnLoadCallback(drawChartA);
google.charts.setOnLoadCallback(drawChartB);

Applying a generic value to an argument using PHP and jQuery

I have the code for a jQuery image slider that pulls from a directory. My client will just be dropping in images into the folder and deleting them without my knowledge. Right now it requires I put in a number (under 'numslides') for how many slides they'll have. With it constantly changing what value do I put it?
(function($){
var directorySlider = function(element, options)
{
var elem = $(element),
obj = this,
elemId = elem[0].id;
// Merge config settings
var config = $.extend({
animation: 'fade',
filebase: 'slide_',
extension: 'jpg',
speed: 1000,
timeout: 4000,
directory: '/path/images/',
numslides: 3,
height: 778,
width: 448
}, options || {});
This is the PHP code on my page:
$(document).ready(function(){
$('.directorySlider').directorySlider();
});
Someone suggested this code below and the top code is what's in my js file. How would I implement this:
$.get('numberoffiles.php', function(data) {
alert(data);
});

Global Variable in Functions.php Then Use in Javascript (WordPress)

I'm sorry if this is the wrong place. Actually this has been asked before by another user (although it was not the same question) and it was said that this is a PHP question. Unfortunately I am not good enough in PHP to implement the answer.
Here is the [previous question]:https://wordpress.stackexchange.com/questions/82503/cant-get-options-with-datavariable
I am facing the same problem. In my options, I have a slider's option (animation - fade or slide) and then I want to use the value stored in the option and pass it into Javascript in my function.php.
In the option file I have these codes:
// Slider animation options
$of_options_slider_animation = array(
"fade" => __("Fade", "themename"),
"slide" => __("Slide", "themename")
);
and
$of_options[] = array( "name" => __("Slider Animation", "themename"),
"desc" => __("Select the type of animation for the slider.", "themename"),
"id" => "slider_animation",
"std" => "fade",
"type" => "radio",
"options" => $of_options_slider_animation
Later I would pass the option into a js block of code in functions.php like so:
jQuery('.flexslider').flexslider({
controlNav: true,
directionNav: true,
prevText: 'Previous',
nextText: 'Next',
**animation: "<?php echo $smof_data['slider_animation']; ?>",**
animationLoop: false
// animation: "slide"
});
(please notice the bold-ed part)
However, as you may predict, it doesn't work.
I've tried defining the $smof_data like in the previous question (see link above) but still no luck. Here is what I do:
// Fetch options data
global $smof_data;
$smof_data = of_get_options("slider_animation");
Please help, thanks in advance :)
EDIT:
SMOF link: https://github.com/sy4mil/Options-Framework
I am using a blank / starter theme by underscores.me
Solved it :D I use the variable directly within the Javascript scope. Here is the code (just in case)
function mytheme_flexslider() {
if (!is_admin()) {
// Enqueue FlexSlider JavaScript
wp_register_script('jquery_flexslider', get_template_directory_uri(). '/js/jquery.flexslider-min.js', array('jquery') );
wp_enqueue_script('jquery_flexslider');
// Enqueue FlexSlider Stylesheet
wp_register_style( 'flexslider-style', get_template_directory_uri() . '/inc/flexslider/flexslider.css', 'all' );
wp_enqueue_style( 'flexslider-style' );
// FlexSlider custom settings
add_action('wp_footer', 'mytheme_flexslider_settings');
function mytheme_flexslider_settings() {
// Fetch options data
**global $smof_data;?>**
<script>
// Can also be used with $(document).ready()
// flexslider have a fixed height
jQuery(window).load(function() {
// jQuery('.subhead_shadow_bottom').hide();
jQuery('.flexslider').flexslider({
controlNav: true,
directionNav: true,
prevText: 'Previous',
nextText: 'Next',
animation: "<?php echo $smof_data['slider_animation']; ?>",
animationLoop: false
// animation: "slide"
});
});
jQuery(document).ready(function() {
fixFlexsliderHeight();
});
jQuery(window).load(function() {
fixFlexsliderHeight();
}); // BUG: this ends up computing the slide height to the image height, not to the resized height, on page reload
jQuery(window).resize(function() {
fixFlexsliderHeight();
});
function fixFlexsliderHeight() {
// Set fixed height based on the tallest slide
jQuery('.flexslider').each(function(){
var sliderHeight = 0;
jQuery(this).find('.slides > li').each(function(){
slideHeight = jQuery(this).height();
if (sliderHeight < slideHeight) {
sliderHeight = slideHeight;
}
});
// jQuery(this).find('ul.slides').css({'height' : sliderHeight});
// console.log("Fixing slider height to " + sliderHeight);
});
}
// jQuery(document).ready(function($){
// $('.flexslider').flexslider();
// });
</script>
<?php
**// return $smof_data;**
}
}
}
add_action('init', 'mytheme_flexslider');
All are working now. Maybe one little question: Do I need to return $smof_data (the second bold-ed part)? It works both ways.. I need to learn more about varible scopes..

on marker click close infobubble

I am using Gmap3 jQuery plugin with infobubble plugin and php to get json reponse for adding markers.
I have added GoogleMap marker using addMarkers option of Gmap3 plugin.
{
action: 'addMarkers',
markers:address_data,
marker:
{
options:
{
draggable: false,
icon: HOST+'img/icons/google_marker.png',
animation: google.maps.Animation.DROP
},
events:
{
click: function(marker, event, data)
{
var map = $(this).gmap3('get');
infoBubble = new InfoBubble({
maxWidth: 310,
shadowStyle: 1,
padding: 5,
borderRadius: 10,
arrowSize: 20,
borderWidth: 5,
borderColor: '#CCC',
disableAutoPan: true,
hideCloseButton: false,
arrowPosition: 50,
arrowStyle: 0
});
if (!infoBubble.isOpen())
{
infoBubble.setContent(data);
infoBubble.open(map, marker);
console.log('open');
}
else
{
infoBubble.close();
}
}
}
}
}
All is working well on first attempt but when i click on marker then infobubble keeps popping up.
Means if i have one marker and some content to display in bubble then when i keep clicking on same marker infobubble added one on other but what i need "I need to close old infobubble if marker clicked again or other marker is clicked " just like normal infowindow dose.
Hope i can make clear point.
Thanks.
Declare infoBubble as a var outside the click handler, and instantiate it there.
Then the checks for infoBubble.isOpen() will be relevant.
From the code you provided, you create a new infoBubble on each click, hence the infoBubble.isOpen() check applies to that newly created object.
How to do it
Declare var infobubble; as global variable.
and inside of click event handler add below line that will do that.
if( infoBubble != null ) { infoBubble.close(); }
so code will look as below,
var infobubble;
//other code for getting markers and all and then `addMarkers` code
{
action: 'addMarkers',
markers:address_data,
marker:
{
options:
{
draggable: false,
icon: HOST+'img/icons/google_marker.png',
animation: google.maps.Animation.DROP
},
events:
{
click: function(marker, event, data)
{
var map = $(this).gmap3('get');
if( infoBubble != null ) { infoBubble.close(); }
infoBubble = new InfoBubble({
maxWidth: 310,
shadowStyle: 1,
padding: 5,
borderRadius: 10,
arrowSize: 20,
borderWidth: 5,
borderColor: '#CCC',
disableAutoPan: true,
hideCloseButton: false,
arrowPosition: 50,
arrowStyle: 0
});
infoBubble.setContent(data);
infoBubble.open(map, marker);
}
}
}
}

Loading images with php and display on a gallery

I have made a javascript code that load dinamically images in a directory (php) and then display them using a jquery galery plugin.
I was unable to run the galleryView after all the pictures were loaded by the client. The single way was to use a delay command.
I donĀ“t have to tell the disadvantages of this method. Does anyone knows how to "correct" the script so that the gallery plugin is called after all the images are loaded?
<script type="text/javascript">
$("document").ready(function() {
$('#aa').load('get_fotos.php').delay(2000).queue(function() {
$('#aa').galleryView({
panel_width: 800,
panel_height: 400,
show_filmstrip_nav: false,
enable_slideshow: false,
panel_animation: 'crossfade',
frame_opacity: 1,
show_infobar: false,
frame_width: 80,
frame_height: 40,
// frame_scale: 'fit',
});
});
});
</script>
Thanks a lot
You can check this out by this:
It worked for me hope it helps.
imageArray = new Array();
imageArray[0] = 'image1.jpg'; // your image path
imageArray[1] = 'image2.jpg'; // your image path
htmldata='';
count = 0;
imgArray = new Array();
$.each(imageArray, function(i,item){
var image=new Image();
$(image).bind("load", {}, function(event) {
count++;
imageArray[i] = $(image).attr("src");
if(count==2){
$("#imageHolder").empty();
$.each(imageArray, function(j,item){
htmldata = '<img id="image'+j+'" src="' + imageArray[j] +'" />'; //create ur image tag u need to call
$("#imageHolder").append(htmldata);
});
$('#aa').galleryView({//call your bind method for plug in
});
}
});
image.src = imageArray[i];

Categories