javascript - Utilising .data() with FancyBox 2 -


i'm using fancy box 2 , trying use custom data inside .fancybox() call. below html:

<a title="test" data-album-id="5" class="fancybox" href="galleries/paris/originals/paris_001.jpg">'; 

and call:

<script>     $('.fancybox').fancybox({         beforeshow: function () {             alert($(this).data('album-id'));             if (this.title) {                 // new line                 this.title += '<br />';                  // add tweet button                 this.title += '<a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-url="' + this.href + '">tweet</a> ';                  // add facebook button                 this.title += '<iframe src="//www.facebook.com/plugins/like.php?href=http%3a%2f%2f'+'www.tommyreynolds.co.uk%2fgallery.php%3fgallery%3d'+ 5 +'%23image1'+'&amp;width&amp;layout=button_count&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowtransparency="true"></iframe>';             }         },         aftershow: function () {             // render tweet button             twttr.widgets.load();         },         helpers: {             title: {                 type: 'inside'             }, //<-- add comma separate following option             buttons: {} //<-- add buttons         },         closebtn: false, // use buttons         arrows: false     }); </script> 

but alert() on returns undefined. ideas?

instead of

alert($(this).data('album-id')); 

use

alert($(this.element).data('album-id')); 

fiddle

fancybox set content types image, ajax, etc element

fancybox tips & tricks section have samples , fiddled


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -