The issue is that this line
this.title = alt;
will override your previous title
, which included the facebook button. You should rather do :
this.title += alt;
full code :
$(".fancybox").fancybox({
beforeShow: function () {
if (this.title) {
// New line
this.title += '<br />';
// Add FaceBook like button
this.title += '<iframe src="//www.facebook.com/plugins/like.php?href=' + this.href + '&layout=button_count&show_faces=true&width=500&action=like&font&colorscheme=light&height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:110px; height:23px;" allowTransparency="true"></iframe>';
}
var alt = this.element.find('img').attr('alt');
this.inner.find('img').attr('alt', alt);
this.title += alt;
var toolbar = "<div id='tools'>" + $("#appendContent div").eq(this.index).html() + "</div>";
$(".fancybox-inner").append(toolbar);
},
helpers: {
title: {
type: 'inside'
}
}
});
On the other hand, bear in mind that this line
if (this.title)
validates if the title
attribute exists on the <a>
element .... in your case it does and it simple says image01
, image02
. etc. so it's also shown in the fancybox'a title
.
If you just want to use the title
attribute to show up on mouse hover but not in the fancybox's title
, then remove the condition and built the title
from scratch inside the callback like :
$(".fancybox").fancybox({
beforeShow: function () {
// New line
this.title = '<br />'; // here we start the title
// Add FaceBook like button
this.title += '<iframe src="//www.facebook.com/plugins/like.php?href=' + this.href + '&layout=button_count&show_faces=true&width=500&action=like&font&colorscheme=light&height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:110px; height:23px;" allowTransparency="true"></iframe>';
var alt = this.element.find('img').attr('alt');
this.inner.find('img').attr('alt', alt);
this.title += alt;
var toolbar = "<div id='tools'>" + $("#appendContent div").eq(this.index).html() + "</div>";
$(".fancybox-inner").append(toolbar);
},
helpers: {
title: {
type: 'inside'
}
}
});
JSFIDDLE (Updated)