jQuery: PrettyPhoto API isn't working
Asked Answered
P

1

19

i'm trying to use prettyPhoto API, but firebug says that $.prettyPhoto.open() isn't a function and don't work...

CODE: http://jsbin.com/ihuje3/3/edit

$(document).ready(function(){
     $.prettyPhoto.open('http://www.microdual.com/assets/images/newsletters/doublehosting.jpg','Test','Test desc');
});
​
Palliate answered 24/11, 2010 at 11:11 Comment(0)
A
41

You have to setup prettyPhoto first (because of how the plugin is written, unfortunately), like this:

$(document).ready(function(){
  $.fn.prettyPhoto(); //usually $("a[rel^='prettyPhoto']").prettyPhoto();
  $.prettyPhoto.open('http://www.microdual.com/assets/images/newsletters/doublehosting.jpg','Test','Test desc');
});

You can see in the source that functions like $.prettyPhoto.open() are defined by running `$.

The other issue is the plugin seems to have an issue with caller context introduced in jQuery 1.4.4, it works fine with 1.4.3 (you can test it here). This has been reported on the forums, hopefully the author will address it soon. ​

Addition answered 24/11, 2010 at 12:11 Comment(4)
Thanks Nick ;) on my other script i was already initiating the prettyPhoto, but on different scripts. ;)Palliate
@CuSS - welcome :) Definitely odd behavior you found here, I'm not sure why the author chose to do it this way, seems totally off from any other plugin layout (and should at least be covered in the documentation...it isn't, at least not that I could find)Addition
"and should at least be covered in the documentation...it isn't, at least not that I could find" me neither. I think the author didn't initiated the code on jquery load because it needs to set the theme options etc, so users can load all the custom options before call the open or click events. Thanks again Nick ;)Palliate
I wish i could upvote 12 times for you! thanks Nick. I wish you were into Stackoverflow more :-)Empirin

© 2022 - 2024 — McMap. All rights reserved.