PDA

View Full Version : jQuery Image Magnify v1.11--Disable javascript



More2Do
08-13-2014, 05:41 PM
1) Script Title: jQuery Image Magnify v1.11

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/imagemagnify.htm

3) Describe problem:

Hello,

I'm looking for code that will disable the javascript for "jQuery Image Magnify v1.11" on smartphones devices via media queries or some other method?

Thank you!

Deadweight
08-13-2014, 09:26 PM
Just letting you i am doing research but i know you have to place this code somewhere:


if( !(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))) {
// some code..
}

ddadmin
08-15-2014, 03:24 AM
Deadweight is on the right track. Inside the magnifier.js, find the following line, and add to it the part in red below:


jQuery(document).ready(function($){
if( !(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))) {
return //exit
}
"
"

That should do the trick.

More2Do
08-15-2014, 04:43 PM
Hi Deadweight,

Thanks very much for your help, it's greatly appreciated! Unfortunately, I don't know javascript, so I'm having difficulty placing your code in the correct spot within the original javascript. I believe the code should go under the other "if" statements, but then the curly braces seem out of place. Can you assist further? Here is part of the original javascritpt:

jQuery(document).ready(function($){
var $targets=$('.magnify')
$targets.each(function(i){
var $target=$(this)
var options={}
if ($target.attr('data-magnifyto'))
options.magnifyto=parseFloat($target.attr('data-magnifyto'))
if ($target.attr('data-magnifyby'))
options.magnifyby=parseFloat($target.attr('data-magnifyby'))
if ($target.attr('data-magnifyduration'))
options.duration=parseInt($target.attr('data-magnifyduration'))
$target.imageMagnify(options)
})
var $triggers=$('a[rel^="magnify["]')
$triggers.each(function(i){
var $trigger=$(this)
var targetid=$trigger.attr('rel').match(/\[.+\]/)[0].replace(/[\[\]']/g, '') //parse 'id' from rel='magnify[id]'
$trigger.data('magnifyimageid', targetid)
$trigger.click(function(e){
$('#'+$(this).data('magnifyimageid')).trigger('click.magnify')
e.preventDefault()
})

})
})

Deadweight
08-15-2014, 05:52 PM
ddadmin said it correctly:


jQuery(document).ready(function($){
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))
return //exit
var $targets=$('.magnify')


I had to change it from


if( !(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))) {
return //exit
}

to


if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))
return;

because the first one was saying if its not one of those mobile devices then exit. The second one says if it is one of these then exit

kennyd4110
08-15-2014, 11:13 PM
I use Image Magnify all over my website (Love it BTW!), can someone quickly explain the benefit/downside of adding this code?

My Site-> www.boltonhooks.com

Deadweight
08-16-2014, 06:16 PM
Are you talking about the code that I posted?
All it does it not allow it to magnify if it is on a mobile device.