Fancybox 2.0 Facebook Like Buttons to Anchor Links - fancybox

I've got a feeling this is impossible, but I thought I'd ask anyway. There are a couple of similar questions, but none fix my particular problem.
I've got a site with a couple of fancybox galleries (link here). The client wants a like button on each image, which will link back to that specific image. As the site is live I've taken down the like button for now.
I've added anchor links to each image so I can open them from a URL no problem - like so http://www.izzyhodge.com/portfolio/index.html#image01. I can also get the actual like button up no problem, as I'm already using a bit of java to add the "poem" hover over thing (it just includes the contents of a bunch of divs in respect to each image). However, when I add a like button using the Facebook code, not only does it add another like button on the next image in a different position, but the button likes the main portfolio page not the anchor link.
The only solutions I could find for using an anchor link with the Facebook button used meta tags in the header of the liked page, which of course I can't do.
I'd really appreciate some help with this one! BTW, I'm using Fancybox 2.0, and I'm using the HTML5 method of adding a button (not sure if I have to change doctype for this?).
EDIT: I'm now trying to do this using the Social Buttons JSfiddle here, however I'm using the alt tag as the title and I'm not sure how to combine the two pieces of code. My JS now looks like:
$(document).ready(function() {
$(".fancybox").fancybox({
helpers : {
title : { type : 'inside' }
}, // helpers
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);
}
}); // fancybox
}); // ready
If I remove;
this.title = alt;
I get a div which appears about the right size for the like button, but there's nothing in it! This could be due to my custom title formatting in the CSS.
HTML for Fancybox:
<div id="thumb-container">
<a id="image01" class="fancybox thumb" rel="group" href="/images/portfolio/large/big_1.jpg"><img src="/images/portfolio/thumbs/th_1.jpg" alt="<h2>LOLA LURKING IN THE LILYPADS <br/> Book Cover (Book in progress) <br/> Pencil and Digital</h2>"/></a>
<a id="image02" class="fancybox thumb" rel="group" href="/images/portfolio/large/big_2.jpg"><img src="/images/portfolio/thumbs/th_2.jpg" alt="<h2>THE TREMENDOUS TAILS OF TRAVELLERS TRAILS - THE OTTER<br/>Collection published by Zeitgeist Fine Art<br/>Ink and Digital</h2>" /></a>
<a id="image03" class="fancybox thumb" rel="group" href="/images/portfolio/large/big_3.jpg"><img src="/images/portfolio/thumbs/th_3.jpg" alt="<h2>THE TREMENDOUS TAILS OF TRAVELLERS TRAILS - THE POLAR BEAR<br/>Collection published by Zeitgeist Fine Art<br/>Ink and Digital</h2>" /></a>
ETC
</div>
<div id="appendContent" style="display: none;">
<div><div class="fb-like" data-href="http://www.izzyhodge.com/portfolio/index.html#image01" data-layout="button_count" data-action="like" data-show-faces="true" data-share="false"></div></div>
<div><h2><a>READ POEM<img class="hoverpoem" src="/images/poems/otterpoem.png" alt=""/></a></h2></div>
<div><h2><a>READ POEM<img class="hoverpoem" src="/images/poems/polarbearpoem.png" alt=""/></a></h2></div>
ETC
Cheers!

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'
}
}
});
JSFIDDLE
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)

Related

more than one caption with featherlight?

i am using featherlight.js for image galleries and used this code for captions:
$.featherlightGallery.prototype.afterContent = function() {
var caption = this.$currentTarget.find('img').attr('alt');
this.$instance.find('.caption').remove();
$('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content'));
};
now a client wants to add a second caption which contains only copyright-information on the right side of gallery-images. is it possible to have two captions, one named .caption and the second maybe .copyright?
I already tried with "data-caption=" and a simple copy of the above js-initial but it failed.
any ideas?
thank you in advance and merry christmas!
You could use a data attribute.
$.featherlightGallery.prototype.afterContent = function() {
var caption = this.$currentTarget.find('img').attr('alt');
this.$instance.find('.caption').remove();
$('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content'));
var copyright = this.$currentTarget.find('img').data('copyright');
this.$instance.find('.copyright').remove();
$('<div class="copyright">').text(copyright).appendTo(this.$instance.find('.featherlight-content'));
};
Then in your markup add
<img src="..." alt="my caption text" data-copyright="my copyright text">
and in your css
.copyright {
float: right;
}
or something to suit.
If you need it to be conditional you can check for the defined-ness and/or length of the data-copyright attribute.

mithril rendering "background-image url"

I have the following issue with mithril
Image is display properly when it is a proper img tag
`<img src="images/erp/C:%5CProgram%20Files%20(x86)%5CMYTEST%5Cbitmaps%5C10001.jpg" class="scale">`
But same image not rendered at all when it is set as background-image url
`background-image: url("images/erp/C:%5CProgram%20Files%20(x86)%5CMYTEST%5Cbitmaps%5C10001.jpg");`
Based on this issue the cause is a bug in mithril.sj the string C:\Tmp\a\field.png is converted into "C:Tmpa\f ield.png"
This javascript:
view: function (ctrl) {
return [m("button", [m("img[src='C:\\Tmp\\a\\field.png\']"),"btn img"]),
m("div", {'style': { 'background-image' : 'url(\"field.png\")'}},"div a"),
m("div", {'style': { 'background-image' : 'url(\"C:\\Tmp\\a\\field.png\")'}},"div b")];
}
is rendered to this html
<button><img src="C:\Temp\mith\field.png">img inside a btn</button>
<div style="background-image: url("field.png");">no path</div>
<div style="background-image: url("C:Tmp\a\f ield.png");">with path</div>

Add Pinterest Button to Fancybox title

I found this script online that add a pin it button to fancybox v2. Here is the working example:
http://scottgale.com/blogsamples/fancybox-pinterest/index.html
Im working on a site on the Hubspot CMS. For those who are familiar, Fancybox 1.3.4 comes included with Hubspot. And you really don't get editing access to any of the files or scripts associated with it.
The Fancybox works as a gallery module (or widget) so users can just upload images.
I was wondering if there is a way to modify this original script to work with how fancybox 1 is implemented on my site.
Here is my page:
http://www.signdealz.com/gallery-test/
Here is the script:
<script type="text/javascript">
//NOTE: this uses fancybox 2
$(document).ready(function() {
$('.fancybox').fancybox({
//set the next and previous effects so that they make sense
//the elastic method is confusing to the user
nextEffect: 'fade',
prevEffect: 'fade',
//set the position of the title
helpers : {
title: {
// title position options:
// 'float', 'inside', 'outside' or 'over'
type: 'inside'
}
},
beforeShow: function () {
//if you already have titles
//on your fancybox you can append
if(this.title) {
//set description to current title
//this will set what posts
var description = this.title;
//add pinterest button for title
this.title = '<a href="http://pinterest.com/pin/create/button/?url='+
encodeURIComponent(document.location.href)+
'&media='+
//put the path to the image you want to share here
encodeURIComponent('http://scottgale.com/blogsamples/fancybox-pinterest/'+this.href)+
'&description='+description+'" class="pin-it-button" count-layout="horizontal">'+
'<img border="0" src="http://assets.pinterest.com/images/PinExt.png" title="Pin It" align="absmiddle"/></a>'
//add title information
+'<span>'+this.title+'</span>';
//if you don't already have titles
//you can just make the title the pinterest button
} else {
//add pinterest button for title
this.title = '<a href="http://pinterest.com/pin/create/button/?url='+
encodeURIComponent(document.location.href)+
'&media=http%3A%2F%2Fwww.homesburlingtonvermont.com'+
encodeURIComponent(this.href)+
'&description=Pin from ScottGale.com" class="pin-it-button" count-layout="horizontal">'+
'<img border="0" src="http://assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>';
}
}
});
});
</script>
Any help is greatly appreciated!
This is an example of how to add the Pinterest button to your fancybox's (v1.3.4) title using the options titlePosition and titleFormat. If your anchor has a title then it will be displayed along the button, otherwise the button will be displayed alone.
This script is based on the script your found for v2.x but tweaking to options for v1.3.4.
$(".fancybox").fancybox({
"titlePosition": "inside",
"titleFormat": function () {
return this.title ?
'<div class="myPint" style="height: 26px"><a href="http://pinterest.com/pin/create/button/?url='+
encodeURIComponent(document.location.href)+
'&media='+
encodeURIComponent('http://scottgale.com/blogsamples/fancybox-pinterest/'+this.href)+
'&description='+this.title+'" class="pin-it-button" count-layout="horizontal">'+
'<img border="0" src="http://assets.pinterest.com/images/PinExt.png" title="Pin It" align="absmiddle"/></a>'+
'<span>'+this.title+'</span></div>'
:
'<div class="myPint" style="height: 26px"><a href="http://pinterest.com/pin/create/button/?url='+
encodeURIComponent(document.location.href)+
'&media=http%3A%2F%2Fwww.homesburlingtonvermont.com'+
encodeURIComponent(this.href)+
'&description=Pin from ScottGale.com" class="pin-it-button" count-layout="horizontal">'+
'<img border="0" src="http://assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>'+
'<span> </span></div>'
}
});
See JSFIDDLE
NOTE : this is for fancybox v1.3.4
EDIT (Jan 30, 2014) :
New JSFIDDLE using CDN for fancybox files to avoid possible 403 forbidden errors while serving the files from fancybox.net server.

fancyBox gallery Like not posting on facebook

I have a site with a fancyBox gallery. I have added the Facebook like button to the gallery so I have a like for each image in the gallery. Problem is, that when clicking like on one of them, it doens't poste to facebook. However, it saves who likes what, so when others open the same gallery they can see who has liked what, but it's not posted.
I need to have each liked image to be posted on facebook.
I have tried with jsfiddle, but no matter what I do I can't get it to work: http://jsfiddle.net/sZG4L/
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox-button").attr('rel', 'gallery').fancybox({
beforeShow: function () {
if (this.title) {
// New line
this.title += '';
// Add FaceBook like button
this.title += '<iframe src="//www.facebook.com/plugins/like.php?href=' + this.href + '&layout=standard&show_faces=true&width=450&action=like&font&colorscheme=light&height=90" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:90px;" allowTransparency="true"></iframe>';
}
},
helpers : {
title : { type : 'inside' },
buttons : {}
},
afterLoad : function() {
this.title = (this.index + 1) + ' / ' + this.group.length + ' ';
}
});
});
I guess I need some sort of variable, so my "this.href" points to each image, also after it is closed, maybe some dynamically function. I have been searching for this, but not been able to find out.
I have also tried updating the facebook like to html5, but then I'm not able to get it visible.
Hope someone can help.

Accessing the first image when the second image of a two image div is hover or clicked

I have a div containing two images which is wrapped with a hover event. These images are left and right arrows. When I hover on the right arrow, I need to change the opacity on the left arrow. The html code is:
<div class="arrows">
<img src="left-arrow.jpg" id="left" />
<img src="right-arrow.jpg" id="right" />
</div>
jquery code
$('.arrows img').hover(function() {
var imgId = $(this).attr('id');
if (imgId == "right") {
// change opacity on left arrow
$(this).parent().img.eq(0).css({"opacity" : .5}); // does not work
$('arrows img.eq(0)').css({"opacity" : .5}); // does not work
}
});
Any suggestion that I can try.
Try this:
$('.arrows img').hover(function() {
$(this).siblings().css({"opacity" : .5});
});
Edit:
If you are looking to gray out the left or right arrow based on first or last page do this:
On Hover:
$('.arrows img').hover(function() {
$(this).css({"opacity" : .5});
});
On Click:
$('.arrows img').click(function() {
$(this).css({"opacity" : .5});
});