Log in

View Full Version : Javascript variables not displaying



LikeBreathing
07-17-2012, 05:34 PM
Hi

I'm trying to put some social media links inside a lightbox. I have some code that works but it's very lengthy with many repeated links. To make things more managable I'm trying to use variables to shorten things.

In the following code the onClick="window.open(fb_url_comb,fb_name,fb_size) variable works fine. However the href=\'document.write(var fb_url_comb);\' and src=\'document.write(fb_icon);\' do not return their variables, they return the actual code as a string. I've tried many different formats using different combinations of quotes and syntax with no luck.


<script type="text/javascript">
<!--
var fb_var = "http://api.addthis.com/oexchange/0.8/forward/facebook/offer?url=";
var fb_name = "fbwindow";
var fb_size = "width=600,height=350";
var fb_icon = "http://likebreathing.com/exp/facebook-16x16.gif";
var pic_url = "http://likebreathing.com/india/125_india.jpg";
var fb_url_comb = fb_var + pic_url;
//-->
</script>

<a href="http://likebreathing.com/india/125_india.jpg" rel="lightbox"

onmousedown="this.title='&lt;a onClick=&quot;window.open(fb_url_comb,fb_name,fb_size);&quot; href=\'document.write(var fb_url_comb);\' rel=\'nofollow\'&gt;&lt;img src=\'document.write(fb_icon);\' alt=\'Facebook icon\' /&gt;&lt;/a&gt;';"
onmouseout="this.title='';">

<img src="http://likebreathing.com/india/t125_india.jpg" alt="Indian School Kids" /></a>

This code src=\'document.write(fb_icon);\' should show me the icon, but it displays the alt tag instead. If I use this src=\'http://likebreathing.com/exp/facebook-16x16.gif\' the icon displays fine.

If I use the variables outside of the onmousedown code they also work fine, so I guess this is just a syntax thing.

An example can be seen here: http://likebreathing.com/exp/india2.html
The code is attached to: 125_india.jpg (third along, two down).

I have a limited knowledge of javascript, so I'm not sure if I'm even going about this in the right way. Please suggest a different way if there is a better solution. Thanks!

jscheuer1
07-17-2012, 09:15 PM
I think there must be a better way to get what you want, but doing it this way appears to work:


<a href="http://likebreathing.com/india/125_india.jpg" rel="lightbox"
onmousedown="this.title='<a onClick=&quot;window.open(fb_url_comb,fb_name,fb_size);&quot; href=&quot;' + fb_var + pic_url + '&quot; rel=\'nofollow\'><img src=&quot;' + fb_icon + '&quot; alt=\'Facebook icon\' /></a>';"
onmouseout="this.title='';" title="">
<img src="http://likebreathing.com/india/t125_india.jpg" alt="Indian School Kids">
</a>

It's nice to see Lokesh is using jQuery for Lightbox now. I think I still prefer some other scripts that do a lightbox. Some of them make it much easier to get this sort of effect (a Facebook link for example) without so much code having to be in the page. They were all inspired by Lokesh though.

LikeBreathing
07-18-2012, 12:30 PM
Hi John

Thank you very much for helping me out, looks like I was trying to over complicate things. This works perfectly!

What Lightbox version would you recommend for better integration with these social media links? I've stuck with Lightbox2 as it seemed fairly popular with a good amount of support, but if there is something which is easier and requires less code I'd be interested.

Thanks again.

jscheuer1
07-18-2012, 02:04 PM
For now I think we should just look into a better way to carry this out. Of this information:



var fb_var = "http://api.addthis.com/oexchange/0.8/forward/facebook/offer?url=";
var fb_name = "fbwindow";
var fb_size = "width=600,height=350";
var fb_icon = "http://likebreathing.com/exp/facebook-16x16.gif";
var pic_url = "http://likebreathing.com/india/125_india.jpg";
var fb_url_comb = fb_var + pic_url;

Only the highlighted appears to need to be customized for each title/link. And the last can be derived from fb_var (which I'm assuming is constant) and pic_url (which I'm assuming is the url to the image, also the href of the link you're attaching the onmousedown code to.

So to get all lightboxes on a page to do this, we should be able to skip everything in your post except:


<a href="http://likebreathing.com/india/125_india.jpg" rel="lightbox" title="">
<img src="http://likebreathing.com/india/t125_india.jpg" alt="Indian School Kids">
</a>

And add this script to the head of the page after the scripts for jQuery and Lightbox:


<script type="text/javascript">
;(function($){
var fb_var = "http://api.addthis.com/oexchange/0.8/forward/facebook/offer?url=";
var fb_name = "fbwindow";
var fb_size = "width=600,height=350";
var fb_icon = "http://likebreathing.com/exp/facebook-16x16.gif";

$(document).on('mousedown mouseleave', 'a[rel^=lightbox]', function(e){
if(e.type === 'mouseleave') {this.title = ''; return;}
var fb_url_comb = fb_var + encodeURIComponent(this.href);
this.title='<a onclick="window.open(fb_url_comb,fb_name,fb_size);" href="' +
fb_url_comb + '" rel="nofollow"><img src="' +
fb_icon + '" alt="Facebook icon" /></a>';
})
})(jQuery);
</script>

It will get all the lightboxes acting like that.

LikeBreathing
07-18-2012, 04:04 PM
Hi John

Thanks, that has certainly reduced the amount of code I need and puts the icon on each lightbox. It's definitely more managable.

At the moment clicking the FB icon in the lightbox doesn't do anything. I know I had a similar problem when trying to use the href tag in title="", links would display but not work. This is why I ended up using onclick="window.open(...

The updated code is: http://likebreathing.com/exp/india2a.html

Any ideas?

jscheuer1
07-18-2012, 04:58 PM
I'm not sure. It was working here. But I see the variables aren't getting resolved in the onclick function because the text is being passed literally, not as the value assigned. And I know they're out of scope. The link is right though because I used substitution there. Let's try this:


<script type="text/javascript">
;(function($){
var fb_var = "http://api.addthis.com/oexchange/0.8/forward/facebook/offer?url=";
var fb_name = "fbwindow";
var fb_size = "width=600,height=350";
var fb_icon = "http://likebreathing.com/exp/facebook-16x16.gif";

$(document).on('mousedown mouseleave', 'a[rel^=lightbox]', function(e){
if(e.type === 'mouseleave') {this.title = ''; return;}
var fb_url_comb = fb_var + encodeURIComponent(this.href);
this.title='<a onclick="window.open(this.href, \'' + fb_name + '\', \'' + fb_size +'\'); return false;" href="' +
fb_url_comb + '" rel="nofollow"><img src="' +
fb_icon + '" alt="Facebook icon" /></a>';
})
})(jQuery);
</script>

I've changed the onclick to substitution as well, except for the use of this.href which it will get from the newly made link. It works here, but so did the other, which it shouldn't now that I think about it. This has a much better chance.

If it still doesn't work I've at least one other idea. Let me know.

LikeBreathing
07-18-2012, 05:44 PM
Hi John

Looking good, the links now work!
I did a quick test in FF, IE and Chrome, they all show positive results.

Thanks again.



I have another query concerning Lightboxes and social media links. Again this is a piece of AddThis code, but the code is completely different. Should I post it here or start a new thread?

jscheuer1
07-18-2012, 07:27 PM
OK, mmm if it's still for the title attribute on the Lightbox, we can do it here. If it's something completely different, please start a new thread.

I noticed something odd about this arrangement though. In Chrome and IE 9, if you mouse down on the image and hold, and move the mouse a little, you see all that code as a sort of tooltip.

I think this modification will take care of that:


<script type="text/javascript">
;(function($){
var fb_var = "http://api.addthis.com/oexchange/0.8/forward/facebook/offer?url=";
var fb_name = "fbwindow";
var fb_size = "width=600,height=350";
var fb_icon = "http://likebreathing.com/exp/facebook-16x16.gif";

$(document).on('mousedown mouseleave mousemove', 'a[rel^=lightbox]', function(e){
if(e.type !== 'mousedown') {this.title = ''; return;}
var fb_url_comb = fb_var + encodeURIComponent(this.href);
this.title='<a onclick="window.open(this.href, \'' + fb_name + '\', \'' + fb_size +'\'); return false;" href="' +
fb_url_comb + '" rel="nofollow"><img src="' +
fb_icon + '" alt="Facebook icon" /></a>';
})
})(jQuery);
</script>

It may or may not hurt the functionality. I don't think it will, but it should be checked.

I'm thinking that, since the title becomes the caption, we could perhaps edit the Lightbox script or just tell it to use other code there so as to use a different attribute, or even a function to make the caption so you wouldn't need a title at all. That's what I was talking about with other Lightbox type script. jQuery Slimbox2 is set up to take a customizable function for creating the caption. And Pretty Photo has stock FB and Twitter links. Different than what you're after I think. But they might be easily customizable.

Or we could use a more or less normal title, and make it become the link without needing to put all that code in the title.

When I have more time I'll look into those ideas.

LikeBreathing
07-20-2012, 11:10 AM
Hi John

Found some time to give this a proper test...

With the above code in IE9 I don't see any icons in the Lightbox, although I do with both FF and Chrome. Also in IE I so see the occasional tool-tip which I don't in Chrome. I think the tool-tip appears if the mouse is over the image when rendering on screen. Doesn't appear after the mouse if moved.

In the previous code I see the icons on all browsers, but as you mentioned you do see tool-tips, especially in IE.

jscheuer1
07-20-2012, 04:00 PM
Since I posted that, I found the time I needed to test one of my other ideas. And I saw your other thread about addthis. So I decided to combine the two and it appears to work. I also discovered that the addthis code has to think it's on your domain in order to work properly. That's probably due to the hash:

#pubid=ra-4ff5721a4e9875e3

added to the src attribute for the addthis script hosted on their server. I was able to get it to think that by using a base tag, which I've not included in the demo below because if you put it on your server, it will be fine without it.

What I did was to make a slight alteration to lightbox.js that allows its functions to be controlled and/or replaced globally from outside the script. I could have edited it more extensively, but I wanted to allow it to function normally if used alone. At the end of lightbox.js, it has:


$(function() {
var lightbox, options;
options = new LightboxOptions;
return lightbox = new Lightbox(options);
});

}).call(this);

I changed that to:


$(function() {
var lightbox, options;
options = new LightboxOptions;
return this.lightbox = new Lightbox(options); // altered to place the lightbox instance in the document's scope (document.lightbox)
});

this.Lightbox = Lightbox; // added to allow access to Lightbox in the global scope - jds
this.LightboxOptions = LightboxOptions; // added to allow access to LightboxOptions in the global scope - jds

}).call(this);

I also added this comment (highlighted) near the top:


/*
Lightbox v2.51
by Lokesh Dhakar - http://www.lokeshdhakar.com

For more information, visit:
http://lokeshdhakar.com/projects/lightbox2/

Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
- free for use in both personal and commercial projects
- attribution requires leaving author name, author link, and the license info intact

Thanks
- Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.com), and Thomas Fuchs(mir.aculo.us) for ideas, libs, and snippets.
- Artemy Tregubenko (arty.name) for cleanup and help in updating to latest proto-aculous in v2.05.

* Jul 19th 2012 - Unofficial update - place Lightbox functions in the global scope - John Davenport Scheuer (jds)

Table of Contents
=================
LightboxOptions

Lightbox
- cons . . .

That allows this demo to work:


<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="http://likebreathing.com/exp/lb.css" type="text/css" />
<link rel="stylesheet" href="http://likebreathing.com/exp/lightbox.css" type="text/css" media="screen" />
<link rel="shortcut icon" href="http://likebreathing.com/images/favicon.ico" />
<script src="http://likebreathing.com/js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="http://likebreathing.com/exp/lightbox.js" type="text/javascript"></script>
<script type="text/javascript">
Lightbox.prototype.start = function($link) {
var $lightbox, $window, a, i, imageNumber, left, top, _len, _ref;
$(window).on("resize", this.sizeOverlay);
$('select, object, embed').css({
visibility: "hidden"
});
$('#lightboxOverlay').width($(document).width()).height($(document).height()).fadeIn(this.options.fadeDuration);
this.album = [];
imageNumber = 0;
if ($link.attr('rel') === 'lightbox') {
this.album.push({
link: $link.attr('href'),
title: $link.data('caption')
});
} else {
_ref = $($link.prop("tagName") + '[rel="' + $link.attr('rel') + '"]');
for (i = 0, _len = _ref.length; i < _len; i++) {
a = _ref[i];
this.album.push({
link: $(a).attr('href'),
title: $(a).data('caption')
});
if ($(a).attr('href') === $link.attr('href')) imageNumber = i;
}
}
$window = $(window);
top = $window.scrollTop() + $window.height() / 10;
left = $window.scrollLeft();
$lightbox = $('#lightbox');
$lightbox.css({
top: top + 'px',
left: left + 'px'
}).fadeIn(this.options.fadeDuration);
this.changeImage(imageNumber);
};

Lightbox.prototype.updateDetails = function() {
var $lightbox,
_this = this;
$lightbox = $('#lightbox');
if (typeof this.album[this.currentImageIndex].title !== 'undefined' && this.album[this.currentImageIndex].title !== "") {
$lightbox.find('.lb-caption').empty().append(this.album[this.currentImageIndex].title.clone(true)).fadeIn('fast');
}
if (this.album.length > 1) {
$lightbox.find('.lb-number').html(this.options.labelImage + ' ' + (this.currentImageIndex + 1) + ' ' + this.options.labelOf + ' ' + this.album.length).fadeIn('fast');
} else {
$lightbox.find('.lb-number').hide();
}
$lightbox.find('.lb-outerContainer').removeClass('animating');
$lightbox.find('.lb-dataContainer').fadeIn(this.resizeDuration, function() {
return _this.sizeOverlay();
});
};

jQuery(function($){
var $addthisdiv = $('<div style="display: none;"></div>').appendTo('body'),
$triggers = $('a[rel^=lightbox]');
$triggers.each(function(i){
var $cap = $('<div class="addthis_toolbox addthis_default_style" addthis:url="' + this.href + '"><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_pinterest_pinit"></a><a class="addthis_counter addthis_pill_style"></a></div>');
$triggers.eq(i).data('caption', $cap);
$addthisdiv.append($cap);
});
window.addthis_config = {'data_track_addressbar':true};
$('<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4ff5721a4e9875e3"><\/script>').appendTo('body');
});

</script></head>
<body>
<a href="http://likebreathing.com/india/091_india.jpg" rel="lightbox"><img src="http://likebreathing.com/india/t091_india.jpg" alt="India Landscape" /></a><br>
<a href="http://likebreathing.com/india/146_india.jpg" rel="lightbox"><img src="http://likebreathing.com/india/t146_india.jpg" alt="India Temple" /></a>
</body>
</html>

Once we get that working for you, I think you can easily see how to set it up to work with your full page of images.

Remember, it needs the updated copy of lightbox.js which I'm also attaching here (right click and 'Save As'):

4556

This code from the demo:


Lightbox.prototype.start = function($link) {
var $lightbox, $window, a, i, imageNumber, left, top, _len, _ref;
$(window).on("resize", this.sizeOverlay);
$('select, object, embed').css({
visibility: "hidden"
});
$('#lightboxOverlay').width($(document).width()).height($(document).height()).fadeIn(this.options.fadeDuration);
this.album = [];
imageNumber = 0;
if ($link.attr('rel') === 'lightbox') {
this.album.push({
link: $link.attr('href'),
title: $link.data('caption')
});
} else {
_ref = $($link.prop("tagName") + '[rel="' + $link.attr('rel') + '"]');
for (i = 0, _len = _ref.length; i < _len; i++) {
a = _ref[i];
this.album.push({
link: $(a).attr('href'),
title: $(a).data('caption')
});
if ($(a).attr('href') === $link.attr('href')) imageNumber = i;
}
}
$window = $(window);
top = $window.scrollTop() + $window.height() / 10;
left = $window.scrollLeft();
$lightbox = $('#lightbox');
$lightbox.css({
top: top + 'px',
left: left + 'px'
}).fadeIn(this.options.fadeDuration);
this.changeImage(imageNumber);
};

Lightbox.prototype.updateDetails = function() {
var $lightbox,
_this = this;
$lightbox = $('#lightbox');
if (typeof this.album[this.currentImageIndex].title !== 'undefined' && this.album[this.currentImageIndex].title !== "") {
$lightbox.find('.lb-caption').empty().append(this.album[this.currentImageIndex].title.clone(true)).fadeIn('fast');
}
if (this.album.length > 1) {
$lightbox.find('.lb-number').html(this.options.labelImage + ' ' + (this.currentImageIndex + 1) + ' ' + this.options.labelOf + ' ' + this.album.length).fadeIn('fast');
} else {
$lightbox.find('.lb-number').hide();
}
$lightbox.find('.lb-outerContainer').removeClass('animating');
$lightbox.find('.lb-dataContainer').fadeIn(this.resizeDuration, function() {
return _this.sizeOverlay();
});
};

jQuery(function($){
var $addthisdiv = $('<div style="display: none;"></div>').appendTo('body'),
$triggers = $('a[rel^=lightbox]');
$triggers.each(function(i){
var $cap = $('<div class="addthis_toolbox addthis_default_style" addthis:url="' + this.href + '"><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_pinterest_pinit"></a><a class="addthis_counter addthis_pill_style"></a></div>');
$triggers.eq(i).data('caption', $cap);
$addthisdiv.append($cap);
});
window.addthis_config = {'data_track_addressbar':true};
$('<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4ff5721a4e9875e3"><\/script>').appendTo('body');
});

could go in an external file. But for now, let's leave it on the page so we can more easily work out any bugs it might have.

LikeBreathing
07-23-2012, 05:17 PM
Hi John

Looks good, this is a much neater solution.
The only thing that doesn't work is the popup window on the 'AddThis Share' button (addthis_counter addthis_pill_style). I've done some brief testing, this is consistent across browsers. I've tried different AddThis buttons with the same issue.

All the other buttons work fine.

Updated code: http://likebreathing.com/exp/india2c.html

jscheuer1
07-23-2012, 06:30 PM
I see. Hmm, after experimenting a bit, it looks like the fix is easy. Remove the highlighted from this line:


$lightbox.find('.lb-caption').empty().append(this.album[this.currentImageIndex].title.clone(true)).fadeIn('fast');

So you end up with:


$lightbox.find('.lb-caption').empty().append(this.album[this.currentImageIndex].title).fadeIn('fast');

It seems a little counterintuitive to me, as when we append it (which moves it to the lb div) and then empty() it, that's supposed to destroy it. But since we retain a reference to it in in the link's data object, I guess it's OK. At least it is in Chrome, Firefox, Opera and IE 9 in all its modes (IE 9, 8, 7, and compatibility), probably others.

That led me to believe we might not need the display: none; div to hold it at first, but we do . . . Whatever works.

Later I realized that jQuery empty() must use javascript's removeChild(), which doesn't destroy the node. It does remove all events that were assigned to it using that copy of jQuery. But apparently none of the events that make this (the addthis() function) work are assigned via the copy of jQuery that runs Lightbox. Probably they're not assigned by jQuery at all. We do need the display none div initially so that addthis() has something in the document to work with. But after that it's as I was thinking. As long as we maintain a reference to the node in the link's data object, it can be brought back whenever we need it.

The browser cache may need to be cleared and/or the page refreshed to see changes.

LikeBreathing
07-24-2012, 05:29 PM
Making this change now gives the popup on the AddThis Share links. This is exactly what I'm looking for.
Many thanks yet again!

jscheuer1
07-24-2012, 11:28 PM
Great! Now we can make it external (right click and 'Save As'):

4562

Put it in the likebreathing.com/exp/ folder. Then on your page, you can replace:


<script type="text/javascript">
Lightbox.prototype.start = function($link) {
var $lightbox, $window, a, i, imageNumber, left, top, _len, _ref;
$(window).on("resize", this.sizeOverlay);
$('select, object, embed').css({
visibility: "hidden"
});
$('#lightboxOverlay').width($(document).width()).height($(document).height()).fadeIn(this.options.fadeDuration);
this.album = [];
imageNumber = 0;
if ($link.attr('rel') === 'lightbox') {
this.album.push({
link: $link.attr('href'),
title: $link.data('caption')
});
} else {
_ref = $($link.prop("tagName") + '[rel="' + $link.attr('rel') + '"]');
for (i = 0, _len = _ref.length; i < _len; i++) {
a = _ref[i];
this.album.push({
link: $(a).attr('href'),
title: $(a).data('caption')
});
if ($(a).attr('href') === $link.attr('href')) imageNumber = i;
}
}
$window = $(window);
top = $window.scrollTop() + $window.height() / 10;
left = $window.scrollLeft();
$lightbox = $('#lightbox');
$lightbox.css({
top: top + 'px',
left: left + 'px'
}).fadeIn(this.options.fadeDuration);
this.changeImage(imageNumber);
};

Lightbox.prototype.updateDetails = function() {
var $lightbox,
_this = this;
$lightbox = $('#lightbox');
if (typeof this.album[this.currentImageIndex].title !== 'undefined' && this.album[this.currentImageIndex].title !== "") {
$lightbox.find('.lb-caption').empty().append(this.album[this.currentImageIndex].title).fadeIn('fast');
}
if (this.album.length > 1) {
$lightbox.find('.lb-number').html(this.options.labelImage + ' ' + (this.currentImageIndex + 1) + ' ' + this.options.labelOf + ' ' + this.album.length).fadeIn('fast');
} else {
$lightbox.find('.lb-number').hide();
}
$lightbox.find('.lb-outerContainer').removeClass('animating');
$lightbox.find('.lb-dataContainer').fadeIn(this.resizeDuration, function() {
return _this.sizeOverlay();
});
};

jQuery(function($){
var $addthisdiv = $('<div style="display: none;"></div>').appendTo('body'),
$triggers = $('a[rel^=lightbox]');
$triggers.each(function(i){
var $cap = $('<div class="addthis_toolbox addthis_default_style" addthis:url="' + this.href + '"><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>');
$triggers.eq(i).data('caption', $cap);
$addthisdiv.append($cap);
});
window.addthis_config = {'data_track_addressbar':true};
$('<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4ff5721a4e9875e3"><\/script>').appendTo('body');
});
</script>

With:


<script src="http://likebreathing.com/exp/lightboxaddthis.js" type="text/javascript"></script>

LikeBreathing
07-25-2012, 03:56 PM
Works perfect thanks!


I do have another different, but related query.
I'm not sure if there is an answer to this as I have posted the question of the Lightbox2 forums with no luck...

Is there a URL I can share that will view a given image in its Lightbox on my site? Instead of a URL directly to the image itself.

I've tried using this directly in a Lightbox to capture the URL, but it crashes out the Lightbox: <script type="text/javascript">document.write(document.referrer);</script>


These appear to be related queries:
http://stackoverflow.com/questions/4089501/lightbox-that-can-open-automatically-depending-on-url-path
http://stackoverflow.com/questions/1383304/how-to-construct-a-url-to-open-a-page-with-jquery-lightbox-plugin-colorbox

jscheuer1
07-25-2012, 05:03 PM
We can trigger a lightbox with, for example:


jQuery('a[href$="146_india.jpg"]').trigger('click');

That will trigger:


<a href="http://likebreathing.com/india/146_india.jpg" rel="lightbox" title="">
<img src="http://likebreathing.com/india/t146_india.jpg" alt="India Temple" /></a>

But it would also trigger:


<a href="http://likebreathing.com/india/5146_india.jpg" rel="lightbox" title="">
<img src="http://likebreathing.com/india/t5146_india.jpg" alt="India Temple" /></a>

So let's not do it like that. It would be better to give each one a unique id:


<a id="india146" href="http://likebreathing.com/india/146_india.jpg" rel="lightbox" title="">
<img src="http://likebreathing.com/india/t146_india.jpg" alt="India Temple" /></a>

Then it could be triggered via:


jQuery('#india146').trigger('click');

That still doesn't get us anything from the URL that loaded the page, which is what I think you want. This little script can:


<script type="text/javascript">
jQuery(function($){
function getQval(n) {
if(typeof n !== 'string'){
return null;
}
var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
return (m = r.exec(m))? unescape(m[1]) : null;
}
var box = getQval('lightbox');
box && $('#' + box).trigger('click');
});
</script>

Put it after the:


<script src="http://likebreathing.com/exp/lightboxaddthis.js" type="text/javascript"></script>

script. With it on say - india2c.html, you could navigate to that page from anywhere on the web using a link like so:


<a href="http://likebreathing.com/exp/india2c.html?lightbox=india146">Sights of India</a>

And it will launch the lightbox of the link with that id.

That's it.

The browser cache may need to be cleared and/or the page refreshed to see changes.

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.

LikeBreathing
07-26-2012, 03:25 PM
Hi John

Code implemented and works a treat here: http://likebreathing.com/exp/india2e.html

So passing (for example) this url http://likebreathing.com/exp/india2e.html?lightbox=india016 opens the image I've tagged with 'india016' in a lightbox on my site. Perfect!


Could the previous code be adapted to submit this new URL to the social media sites instead of a direct link to an image.

Thanks

jscheuer1
07-26-2012, 04:33 PM
Works pretty well. Unfortunately, if the page hasn't already been cached it takes awhile to load up the image into the lightbox and even longer to load up the addthis bar. I think we can speed up the latter by making the addthis div visibility hidden, position absolute, top -10000px left -10000px instead of display none and/or preloading some or all of the images it uses. But the real drag on load that it represents is initializing all of those bars for all those images as the page loads. If we can figure out a way to only initialize the one that's needed when it's needed and then store that if it's needed again, that might be good. I'll have to play with that.

As mentioned below though, you don't need the images and links on the page. It could be a different sort of page with a link to the gallery page that's only revealed once the lightbox is dismissed.


Could the previous code be adapted to submit this new URL to the social media sites instead of a direct link to an image.

I'm not sure what you mean by that. If you mean that instead of showing the image, it simply presents the addthis icons, that would be easy enough. But I must admit I'm not into social media. I think it's great for folks who are, it's just that I'm not a member of any of the sites, except Google and YouTube and those were required due to some work I did.

So I don't understand what would happen if an image were simultaneously submitted to all those sites you have in the addthis bar. If it happened to me, If I clicked a link that did that, since I'm not a member, I would probably be presented with 5 or so login screens. Even if I were a member I probably would still have to login unless I were also using an add on for each social media site that logs me in automatically whenever I need to be.

Lots of folks are set up that way. But lots of other folks are not.

I was playing around with this concept a bit and discovered that one can make a page with little or no images or links on it that when given the URL to the image in the query string can pop up the lightbox of that image. That could be adapted to show only the addthis bar for that image, or something else, perhaps even attempt to submit the image to all those sites. If the latter, I would need the code that does that, the code that submits to all those sites, if there is any of that around that you know of.

So just what do you mean by that? If you have something else in mind, if I missed the point, please explain, or if you really want the image submitted to all those sites at once, do you have code or know of code that does that?

LikeBreathing
07-26-2012, 05:32 PM
Hi John

After re-reading my post I don't think I explained myself very well.

Currently if you click on (for example) the Twitter icon in my Lightbox this type of link is posted to Twitter (a direct link to the image):
http://likebreathing.com/india/075_india.jpg

Could the lightboxaddthis.js code be changed to post the following type of link to Twitter instead of the one above:
http://likebreathing.com/exp/india2e.html?lightbox=india075

In the lightboxaddthis.js file I guess the addthis:url="' + this.href + '" would need to be altered somehow.


This is so users who click on the link posted in Twitter will be taken to the image in a lightbox on my site instead of just to the image. This is essentially merging the two different bits of code in this thread.

Hope this makes more sense.

jscheuer1
07-26-2012, 06:08 PM
I don't know if Twitter would allow that. Also, this wouldn't affect just Twitter, that link:



addthis:url="' + this.href + '"

is used by addthis for all of its social media links that take a URL. So they all would have to be OK with the new syntax. But we can certainly try it out:

4564

Keep a backup of your other one if this one doesn't work out.

For your information, this is what's added/changed (scroll the code block to see all of the second change):


jQuery(function($){
var $addthisdiv = $('<div style="display: none;"></div>').appendTo('body'),
$triggers = $('a[rel^=lightbox]'), basehref = location.href.replace(/#|\?.*$/g, '');
$triggers.each(function(i){
var $cap = $('<div class="addthis_toolbox addthis_default_style" addthis:url="' + basehref + '?lightbox=' + this.id + '"><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>');
$triggers.eq(i).data('caption', $cap);
$addthisdiv.append($cap);
});
window.addthis_config = {'data_track_addressbar':true};
$('<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4ff5721a4e9875e3"><\/script>').appendTo('body');
});

The browser cache may need to be cleared and/or the page refreshed to see changes.

LikeBreathing
07-27-2012, 11:40 AM
Hi John

This almost works, but the problem is what AddThis does to the URL. When browsing to the site the AddThis code appends some random characters to the end of the URL, I believe they do this to track the links used.
So the URL looks like: http://likebreathing.com/exp/india2e.html#.UBJ6NqMmzoJ

After putting in your new code and submitting to Twitter this URL is submitted:
http://likebreathing.com/exp/india2e.html.UBJ4qKMmzoI?lightbox=india075#.UBJ4rXMEejh.twitter

This part in the middle of the URL is making it invalid: .UBJ4qKMmzoI
If I cut and paste the URL into a browser removing these random characters the link works fine.


On a different note, when submitting an image to facebook it creates a thumbnail from the image. I guess if we submit this type of URL http://likebreathing.com/exp/india2e.html?lightbox=india075 Facebook won't be able to generate the preview thumb nail.


After looking at some more AddThis info it is possible to submit a title and description: http://support.addthis.com/customer/portal/articles/381242-url-title.
I've yet to investigate this further, but it might be a better idea to submit this style link http://likebreathing.com/exp/india2e.html?lightbox=india075 as one of these other attributes instead of the main URL.

jscheuer1
07-27-2012, 02:34 PM
That might be browser dependent. If so, we might be able to find a way that all browsers like. My code looks like it removes that in Opera. But that might not really be the case. What addthis might be doing is adding it back after we remove it. What browser(s) were you testing in?

If we use another field, it won't be the link. But it might work out. Like if we use description, and we can put an a tag in the description, that could work. The link would still be to the page, but the description link could be to the page image loading in the lightbox. However, all of the examples shown on the support page you link to show plain text used for those other fields.

One thing you might try is commenting out this line as shown in red:


//window.addthis_config = {'data_track_addressbar':true};

Tell which browser(s) you're testing in. If I cannot figure that out, let's try it with that line commented out. If that's still no good, we can go for one of the other fields - I'm thinking description.

LikeBreathing
07-27-2012, 03:39 PM
Hi John

Both Firefox (14) and Chrome (20) show the random characters in the URL.
IE 9 does not show the characters.


I tested lightboxaddthis.js with the line commented out, this does remove the random characters from the URL in Firefox and Chrome. So this resolves the Twitter issue.


When posting to Facebook a thumbnail preview is used, but it's not the image being shared, it looks to be a random one taken from the page. Looking through some more AddThis code there maybe be a way to force what image is being used:


<meta property="og:image" content="http://path/to/image.jpg" />

Taken from here: http://support.addthis.com/customer/portal/articles/381222


If this works it could be a better option than using the description field (I've yet to test this).

jscheuer1
07-27-2012, 04:23 PM
I just tested in Chrome with the line uncommented. That browser is removing it from the URL, so the script must be adding it back. So commenting it out is probably the way to go on that. But isn't that a feature? If so, what are you losing by commenting it out? Sounds like some stats will be unavailable, do you know what keeping that line does for you?



Meta tags are placed in the head of the page. We could try to access this one via its property attribute and change its content attribute. But when does this need to be done? Is it as each addthis div is being added, or at the moment when the image is being submitted to facebook? At some other time? Would changing it have any affect at all? Often meta tags are read once, so it doesn't matter how many times you change them, what counts is what they are when they're read.

I can play around with this when I have more time. I would probably have to give you some different things to try out, as I can't see what's happening on facebook.

jscheuer1
07-28-2012, 08:17 AM
OK, this is the only approach to the meta tag I can think of that can work, if it does work, without too much coding and/or research:

4570

Use it in place of lightboxaddthis2.js

It inserts the:


<meta property="og:image" content="http://path/to/image.jpg" />

tag with the content attribute pointing to the first thumbnail on the page, and then sets it's content attribute to whichever thumbnail is being hovered.

If the addthis code reads this tag once, it will read it as the first thumbnail, and that will be it. But if it leaves that to the facebook code, then the facebook code may also read it just once and that also would be it. But the facebook code might read it each time the facebook icon is clicked. If so, then it will be set to the current thumbnail.

There might be a way to deal with either the addtis or facebook code reading it once, but I don't think so. That's because that would probably mean editing their scripts, which we cannot do. We can in theory take control of their scripts, but there are probably too many safeguards against that.

There might be a facebook widget for that - custom thumbnail per click, but if there is, that's probably not meant for use with addthis. But we might be able to adapt it, or it might work with addthis anyway, or we might be able to use it to make the facebook icon and have addthis skip that part.

The browser cache may need to be cleared and/or the page refreshed to see changes.


BTW, I just tested the twitter button in Chrome with the line:


window.addthis_config = {'data_track_addressbar':true};

And the passed url is:


test/lightbox251/demo_addthis_a.html?lightbox=india091#.UBPbvPnX4NQ.twitter

which will work with our code.

Are you sure you updated the page, cleared the cache and refreshed before experimenting with twitter and lightboxaddthis2.js?

And I did a little more research on what 'data_track_addressbar':true is for. It assigns the hash to the URL so that when others click on it - say on Share or Facebook, addthis analytics can tell where the link they clicked on to get back to your page came from.

So, if you're not using addthis analytics, or don't need to know that piece of information when using addthis analytics, you don't need 'data_track_addressbar':true. But if you are using the analytics and do need to know that piece of information, we can try adding the hash back after adding our query string.

This all assumes that the problem you were having with lightboxaddthis2.js before you commented out the 'data_track_addressbar':true line was because you hadn't cleared the browser cache, which I believe it was.

If that part of the analytics is important to you we can do some specific tests to see if this can be made to work. Otherwise, just leave the 'data_track_addressbar':true line commented out.

LikeBreathing
07-29-2012, 01:12 PM
Hi John

If I clear the cache the very first link I share with either Twitter or Facebook is fine, but each share after that has the random charcater in the URL. I've seen the same behaviour with both Firefox and Chrome.


If I share a link with Facebook after initially clearing the cache the preview thumbnail is not the right image. Facebook is always showing the same image as a thumbnail regardless of which image I share. It happens to be this one: http://likebreathing.com/india/t040_india.jpg.


I've been reading and trying to understand this:


http://support.addthis.com/customer/portal/articles/381237

Facebook doesn't work like the other AddThis buttons. Instead of accepting parameters that we pass it, Facebook requests the URL you're sharing and gets the data it displays from the meta and link tags in the header. To control how your page is shared on Facebook you should use OpenGraph tags which are described in Facebook's documentation here: http://developers.facebook.com/docs/opengraph/

Which points here: http://ogp.me/

This page says:


The four required properties for every page are:

og:title - The title of your object as it should appear within the graph, e.g., "The Rock".
og:type - The type of your object, e.g., "video.movie". Depending on the type you specify, other properties may also be required.
og:image - An image URL which should represent your object within the graph.
og:url - The canonical URL of your object that will be used as its permanent ID in the graph, e.g., "http://www.imdb.com/title/tt0117500/".

So I guess the og:image meta tag on its own will not work.

jscheuer1
07-29-2012, 07:15 PM
I'm not sure what to suggest. I think we've taken addthis as far as it can go.

You would need a different widget or widgets. I don't think you want to write your own facebook app, but there might be one out there to do this.

It's very common and standard to use a query string:


somepage.html?something=something

to connote various things for a page, what it should load/display/do. So there must be a way to get those URLs onto the social media sites. Apparently addthis is not that way.

We can back up a little to what was working, with 'data_track_addressbar':true commented out in lightboxaddthis2.js. You say that was working for twitter. Then we drop facebook from addthis, which would mean getting rid of:


<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>

Then look for an alternative widget for facebook.

Or scrap addthis altogether and find another widget or widgets to achieve your objectives.

I'll have to take your word for it, what was happening on twitter with 'data_track_addressbar':true, because if I do it, it works every time. The difference being that here I never actually login to twitter. But as long as I don't, it always shows the correct URL in the address of the popup, regardless of how many times I do it. And like I say, if that's not working, we can just leave 'data_track_addressbar':true commented out.

Back near the beginning of this, I had mentioned Pretty Photo:

http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/#!prettyPhoto

Which has its own built in social media links. It may only do facebook and twitter (but perhaps that can be expanded), and I'm not sure what it gets you on those sites, but you might like to look into it.

LikeBreathing
07-29-2012, 08:37 PM
Hi John

Thanks again for all your help.

I think you're right, any limitations we're hitting now are probably due to AddThis or the actual social media site itself. I think my best option is to stick with your AddThis extended code and share out the image files directly rather than the lighbox links. I've not looked at another lightbox (such as PrettyPhoto) but I doubt it does anything more than your code. In fact your code with AddThis gives me better reach outside of just Twitter and Facebook.

If I'm posting manual links I'll certainly use the lightbox code and links (somepage.html?something=something). Up until now I didn't even think this was possible!

Your code certainly extends the functionality of Lightbox2. I've linked back to this thread from my original post on the Lightbox2 forum as it may be useful for others.

When I get more time I'll look into the OpenGraph bits to see what that gives me. I'll update this thread if I find anything useful.

LikeBreathing
07-31-2012, 10:47 PM
Hi John

Your meta code in lightboxaddthis3.js seems to work fine, the way I was testing it was wrong! The code was based in http://likebreathing.com/exp/ and I was referring to objects in http://likebreathing.com/india/. Using the debug tools (http://developers.facebook.com/tools/debug) I could see things were not happy.

I've created a test file: http://likebreathing.com/india/india3.html using the lightboxaddthis3.js code.
After sharing a link on Facebook the link opens the correct image in a lightbox on my site, so working as designed. To get the thumbnail image correct the other meta tags need to be added.

As an example to see how these work I've added the static meta tags here: http://observingindia.com/index.html (on a different site).


<meta property="og:title" content="Observing India" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://observingindia.com/index.html?lightbox=oicover" />
<meta property="og:image" content="http://observingindia.com/images/front_cover.jpg" />
<meta property="og:site_name" content="Observing India" />
<meta property="fb:admins" content="my-facebook-id" />
<meta property="og:description" content="Observing India is a collection of images documenting my stay in India" />

In lightboxaddthis3.js would it be possible to add these tags in?

- og:type, og:site_name, fb:admins and og:description are all free text.
- Could og:title read read the title HTML tag?
- og:url is the lightbox link and og:image is the image link (although these are fairly obvious!).

For reference the Open Graph tags are listed here: http://ogp.me/


Thanks

jscheuer1
08-02-2012, 08:44 AM
I'm not sure I completely understand. Particularly what you mean by "free text". From the context it would appear that those tags would be the same for all.

And I see you have the tags on india3.html, albeit commented out (shown here with the comment tags removed):



<meta property="og:title" content="Like Breathing / India" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://likebreathing.com/india/india3.html" />
<meta property="og:image" content="http://likebreathing.com/india/075_india.jpg" />
<meta property="og:url" content="http://likebreathing.com/india/india3.html?lightbox=india075" />
<meta property="og:site_name" content="Like Breathing" />
<meta property="fb:admins" content="100003956014200" />
<meta property="og:description" content="Photography, art and design from Like Breathing" />

And that you now have a facebook link for the page itself. So let's drop:


<meta property="og:url" content="http://likebreathing.com/india/india3.html?lightbox=india075" />

and change the image one to point to the thumbnail instead:


<meta property="og:image" content="http://likebreathing.com/india/t075_india.jpg" />

So we end up with:


<meta property="og:title" content="Like Breathing / India" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://likebreathing.com/india/india3.html" />
<meta property="og:image" content="http://likebreathing.com/india/t075_india.jpg" />
<meta property="og:site_name" content="Like Breathing" />
<meta property="fb:admins" content="100003956014200" />
<meta property="og:description" content="Photography, art and design from Like Breathing" />

You can choose a different image from the page, perhaps one a little more representative. Or maybe that one is - that choice is up to you. It's the one that will be used when the on page facebox link is clicked on.

So keep all that and have it use those values or some other values you want and uncomment the block. And then, instead of creating the tags, we can simply change the values of the ones we want to after first storing the defaults so that they can be used when a visitor clicks on the whole page facebook link.

Oh, and I would prefer to use the thumbnail images' alt attributes to get the og:title value.

This is all assuming that this will work as you expect it to. All we can do is set the tags' values and hope for the best. We can work out any script errors and/or try alternative ways of setting the tags' values if our first effort has problems though.

Try this script:

4576

LikeBreathing
08-02-2012, 02:14 PM
Hi John

I included the static meta tags in the head of the page to find out how these worked, this was purely for testing. Looking at your lightboxaddthis4.js code, it looks like the meta tag values are read from the static values in the head element.

In your lightboxaddthis3.js code you had some lines to dynamically capture the image being clicked on from a lightbox:


$triggers = $('a[rel^=lightbox]'), basehref = location.href.replace(/#|\?.*$/g, ''),
$meta = $('<meta property="og:image" content="' + $triggers.eq(0).find('img').attr('src') + '" />');
$('meta').last().after($meta);

Would it be possible to dynamically capture and create a link for both og:image and og:url from the image in a lightbox?

So when image 075_image.jpg is clicked the og:image link is created as http://likebreathing.com/india/075_india.jpg and the og:url link as http://likebreathing.com/india/india3.html?lightbox=india075. These are then the links posted to Facebook.


By 'free text' I meant the other tags can be static for all links (ie not dynamic). For example og:site_name for all links on this site would be Like Breathing.

jscheuer1
08-02-2012, 05:15 PM
That's not really what lightboxaddthis3 does. It creates the tag once. It then assigns it the value of the first thumbnail image on the page. After that, each time a thumbnail is hovered, it assigned that image's value to the tag.

The only changes in lightboxaddthis4 are that instead of creating the meta og tag, it's hard coded on the page, and there are more meta og tags. After that it performs as did lightboxaddthis3. That is it just changes the value(s) of the exiting tag(s).

Try it out. Just add it to that page (india3.html) as instructed in my last post.

Oh, and you don't need the on page facebook link, but you can keep it. You do need the hard coded meta og tags and the one hard coded meta fb tag.

I am thinking that with or without the on page facebook link, you should get rid of:


<!-- <script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script> -->
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4ff5721a4e9875e3"></script>
<!-- AddThis Button END -->

The lightboxaddthis4.js takes care of that for you.

Oh, and now I see you have updated india3.html. It looks like it's working. Is it?

LikeBreathing
08-03-2012, 04:01 PM
Hi John

For testing purposes I have created:
http://likebreathing.com/india/india3.html which uses lightboxaddthis3.js.
http://likebreathing.com/india/india4.html which uses lightboxaddthis4.js.


My observations:

india3.html
When clicking a lightbox and posting to Facebook the link created on Facebook opens the selected image in a lightbox (which is perfect).
Although the preview thumbnail is a random image, not the selected one.

india4.html
The Facebook posted link is a link to the main india4 page, not the selected image in a lightbox.
The preview thumbnail is different to the one selected.

jscheuer1
08-03-2012, 05:12 PM
OK, from what you're saying then it appears that in neither case are the meta og tags having any effect.

On 3, there is no meta og tag for the url except the hard coded one. There is an image one, and we add another, neither of these are random, but that's what you say you get. And from what you're saying it looks like it ignores the url one and is using the addthis:url as generated by the script.

As for why the link doesn't remain correct on 4, I'm not sure, that part of the code is the same as on 3. The meta og tags are set correctly by the script on hover of each image. Facebook is apparently ignoring them. When you say the image is different, is it the same image each time? A random image? What?

LikeBreathing
08-06-2012, 05:18 PM
Hi John

Only had limited time today but wanted to re-test the basic functionality of the Open Graph tags.

I created India2.html: http://likebreathing.com/india/india2.html

In the head are these tags:


<meta property="og:title" content="Like Breathing / India" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://likebreathing.com/india/india2.html?lightbox=india015" />
<meta property="og:image" content="http://likebreathing.com/india/015_india.jpg" />
<meta property="og:site_name" content="Like Breathing" />
<meta property="fb:admins" content="100003956014200" />
<meta property="og:description" content="Photography, art and design from Like Breathing" />


I've commented out lightboxaddthis.js (to test) and included the basic AddThis code:


<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" b:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
<a class="addthis_button_pinterest_pinit"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4ff5721a4e9875e3"></script>


With this setup the meta tags work as designed. The preview thumbnail is 015_india.jpg and the link in Facebook calls the image in a lightbox using this link: http://likebreathing.com/india/india2.html?lightbox=india015.


I had problems at first with caching (I assume). With this in mind I want to retest your code making sure I clear the cache as a fair test.

LikeBreathing
08-08-2012, 05:22 PM
Hi John

After more digging around I've discovered that Facebook also caches pages and images which would explain why my repeated tests kept failing. To overcome this I've changed the name of the files each time so both my local cache and Facebook thinks it's a different file. This seems to work.

india4-4.html (http://likebreathing.com/india/india4-4.html)

Using your lightboxaddthis4.js code.

These tags have been commented out:

<meta property="og:url" content="http://likebreathing.com/india/india4-3.html?lightbox=india091" />
<meta property="og:image" content="http://likebreathing.com/india/091_india.jpg" />

With this combination sharing an image from a lightbox link displays the desired link in Facebook, which loads the image in a lightbox.
The thumbnail preview is different from the one clicked.


india4-5.html (http://likebreathing.com/india/india4-5.html)

Using your lightboxaddthis4.js code.

These tags are in place:

<meta property="og:url" content="http://likebreathing.com/india/india4-3.html?lightbox=india091" />
<meta property="og:image" content="http://likebreathing.com/india/091_india.jpg" />

Using this the lightbox link and thumbnail preview in Facebook always shows the image and link set in the static meta tags, regardless of which image is shared.

jscheuer1
08-08-2012, 06:12 PM
If what you're saying about caching is true, the meta og tags are useless for anything you don't want 'set in stone' for the page.

And it makes sense. If the meta og tag isn't there when the page loads, facebook apparently never sees it.

By commenting out the tags, you not only prevent their use when the page loads, but also prevent their use when the lightboxaddthis4.js script is used. It doesn't create any meta og tags, all it does is update existing ones. If the tag(s) it's meant to update aren't there, that part of the lightboxaddthis4.js code does nothing. It still does set the addthis:url for each image, that must be working, and in the absence of any meta og:url tag, there's no reason it shouldn't work, unless facebook ignores the addthis:url. But we're seeing it doesn't ignore it unless a hard coded meta og:url is in the head of the page.

So, essentially we are back to lightboxaddthis3.js but without any attempt to set the meta og tags.

It looks like the only way to set all the things you want to set for each image would be to have the larger image displayed in an iframe in the lightbox (something lightbox doesn't do, but there are other box scripts that can). Once you're in an iframe, instead of just showing the image, you can show it on a page with all the proper meta og tags hard coded on it and have the social media links, including facebook's on that page. You should be able to run addthis on each of these pages. And would no longer need it for each thumbnail on the main page, essentially eliminating lightboxaddthis4.js and virtually all the work we've done so far. This should also speed loading of the main page.

If you were to use server side code, one page might be able to be used for all of the images in the iframe. But that's getting a little ahead of things because it would require its own query string. But since that url could perhaps only be used internally it could work out.

If that works, and the overall concept works, it would save you a lot of coding/pages. But as I say, it would require server side code. Do you have something like that? PHP is preferable to me as that's what I'm most familiar with but others could be used for this, and it would be relatively simple in any server side language. It would be a simple get on title, url, image.

It might even be able to be done via javascript, but that could get messy.

m1155
09-09-2012, 09:37 AM
Hi
I followed this tread to add addthis to the lightbox script. I use lightbox mod "lightboxHTHcustCap2a.js" wich resize bigger pictures automatically to user screen size and allows to click a link for full size view.

I addes the lightboxaddthis.js and modified the addthis code on the bottom of the script.

When i visit my site nothing happens, i dont see the addthis button appear: www.zkkf.nl/zelfmonteren.php
edit: in IE i only see a little white space where the addthis buttons should be...

What could be the problem ?

jscheuer1
09-09-2012, 09:57 AM
That code on that page uses the prototype/scriptaculous based:


// Lightbox v2.05
// by Lokesh Dhakar - http://www.lokeshdhakar.com
// Last Modification: 3/18/2011
// Last TwoHawks (HTH) Modification: 10/13/2011

The code in this thread works with the jQuery based Lightbox v2.51.

Without extensive modification, the two are incompatible.

m1155
09-09-2012, 11:08 AM
That code on that page uses the prototype/scriptaculous based:


// Lightbox v2.05
// by Lokesh Dhakar - http://www.lokeshdhakar.com
// Last Modification: 3/18/2011
// Last TwoHawks (HTH) Modification: 10/13/2011

The code in this thread works with the jQuery based Lightbox v2.51.

Without extensive modification, the two are incompatible.


Alright, that goes beyond my knowledge... i prefer both options (resize and addthis) but i think the automatic resize and option to see full picture weights more because of the details i have to show in some pictures...

Is it possible to add a simple resize function to LikeBreathing's lightbox ?

m1155
09-09-2012, 02:30 PM
I've add the lightbox 2 with the lightboxaddthis.js and works but when i click "LIKE" i dont see it appear anywere on facebook...i only see the button "jou like this" and the count.

any idea ? (test page www.martinvanderhaven.nl (not my page))

jscheuer1
09-09-2012, 03:09 PM
I don't know how addthis or how facebook work. If you've already liked it though, you can't like it again, can you? I mean, once you've liked something, that's it - right? Wouldn't you have to login to facebook as a different person to add to the like total.

m1155
09-09-2012, 05:15 PM
I figure it out. the LIKE button is not a share button so i add the share button to, see the site for example.

The demo Lightbox (http://lokeshdhakar.com/projects/lightbox2/) show's content from title on bottom of the picture, the modifided lightbox with addthis doens't anymore. Can i turn this back on ?

m1155
09-09-2012, 09:32 PM
I made an example of the problem i can't get solved: http://www.zkkf.nl/lightbox/index.html

Hope there is a solution to resize the second picture.

jscheuer1
09-11-2012, 02:50 AM
The page is valid XHTML transitional and could be made to be valid XHTML strict I think, certainly (with some changes) valid HTML 5. But it should work in any standards invoking DOCTYPE.

I put all the extra script code (what was lightboxaddthis.js + the code you had there to show a lightbox onload) on the page (use the browsers 'view source' to get it), you can make it external. If you do, make it all external:

http://home.comcast.net/~jscheuer1/side/lb251/demo_addthis-title-adv.htm

To launch the first item onload:

http://home.comcast.net/~jscheuer1/side/lb251/demo_addthis-title-adv.htm?lightbox=first

Notes:

I also added a little style:


<style type="text/css">
.lb-caption .addthis_toolbox {
float: left;
overflow: hidden;
}
a[rel] img {
border-width: 0;
}
</style>

to get things to lay out better. Well better to my eye. The layout can be tweaked.


Notice too that I removed the on page scripts for addthis, as the ones added by the new code are sufficient to initialize the on page addthis div.


The reason I used javascript to write the one on page addthis link is because it wouldn't otherwise validate to XHTML.

m1155
09-16-2012, 06:44 PM
Thanks very much jscheuer1, i appreciate your commitment!!

I will try some things when i have time. Only thing i wonder is why i cant "save picture" or choose "see picture" in the right mouse menu. In the version on my site www.zkkf.nl there is a link "see full size picture" so i can save it (it's out of the lightbox then), also no right button option for saving it... mayby there is a solution ?

jscheuer1
09-16-2012, 11:19 PM
I just updated the demo to allow right click on images. The browser cache may need to be cleared and/or the page refreshed to see changes. Once you see it working for you, you can use your browser's 'view source' again to get the updated code.

m1155
09-23-2012, 08:31 PM
I have added the code to my website today and works great. also put it in a separate js file (lightboxaddthis.js again)

Have changed "rev" to "title" so i dont have to change all title tags to rev on every page.

I noticed that when the rev/title text is to long it will put a new line (and 1 empty line) but also puts the face book like box down with it. How can i solve this ?

Mayby u can explain how i change the position of things (like the picture count 1 of 6 for example) Mayby i want the rev/title text first and below that the addthis buttons (for example)

jscheuer1
09-23-2012, 09:33 PM
You probably will be able to move things around and remove blank lines via css. If you don't know how to do that via a DOM inspector to identify the selectors you would want to target, or don't know enough about css to determine what property/value pairs to assign to those selectors, give me a link to your current demo and tell me exactly where you want things and what blank lines, if any you think need to be removed.

BTW, changing from title to rev is pretty easy. Most editors will do a global search and replace on title to rev. Just make sure you only change the ones in the lightbox links. The advantage of using rev over title is that you don't get those unsightly tooltips when hovering over each thumbnail.

m1155
09-27-2012, 08:43 PM
give me a link to your current demo and tell me exactly where you want things and what blank lines, if any you think need to be removed.

Have made a picture how i imagine it (http://www.zkkf.nl/forumpics/Examplelightbox.JPG), mayby it's not possible, then i am happy with current version.


The advantage of using rev over title is that you don't get those unsightly tooltips when hovering over each thumbnail.

Exually i like the yellow tooltips at a link or picture :) (not into a lightbox of course)

jscheuer1
09-27-2012, 10:16 PM
So is "Click to open picture full size." the title? And if it is, doesn't the modification we just made render that unnecessary?

m1155
09-28-2012, 06:01 PM
So is "Click to open picture full size." the title? And if it is, doesn't the modification we just made render that unnecessary?

Yes this is the title (i think this is easy to find and change in a script?). I think not everyone understands to click right en choosse "show picture" to see the full size so i like the clickable link from the mod "lightboxHTHcustCap2a (http://www.rush-creek.com/lightboxHTHcustCap1a/lightboxHTHcustCap1a.html)"

jscheuer1
10-02-2012, 04:15 AM
I have this worked out but my host is experiencing problems so I cannot upload the demo right now. When that's resolved, I will.

m1155
10-02-2012, 05:37 PM
Tnx John, i will wait :)

I observed what happens when i click on the button facebook from addthis.
I get a new window where i can click "share". The link with picture appaers on facebook, when i click the link only the picture opens, not my website or the site where the picture is on. Noticed that http://likebreathing.com/india/india3.html only show a facebook popup and the name and title from the website show on facebook and when clicked on the link the lightbox reopen. Do have to set this with meta tag?

jscheuer1
10-02-2012, 09:34 PM
OK, they're back up:

http://home.comcast.net/~jscheuer1/side/lb251/demo_addthis-title-click-adv.htm

What the share link is depends mostly upon what you put in this section, the first highlighted is probably what you're talking about, the second governs the like button:


makeAddthisCaption: function(link){ // function used to make addthis portion of the caption
return [
'<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url="', link.href, '">',
'<a class="addthis_button_facebook" style="cursor:pointer" title="Plaats/Deel op Facebook"></a>',
'<a class="addthis_button_twitter" style="cursor:pointer" title="Plaats/Deel op Twitter"></a>',
'<a class="addthis_button_linkedin" title="Plaats/Deel op LinkedIn"></a>',
'<a class="addthis_button_google_plusone" g:plusone:count="false" title="Plaats/Deel op Google,"></a>',
'<a class="addthis_button_compact"></a>',
'<a class="addthis_counter addthis_bubble_style" title="Plaats/Deel op andere sites"></a>',
'</div>',
'<div class="addthis_toolbox addthis_default_style addthis_32x32_style" ',
'addthis:url="http://www.facebook.com/pages/Zwetsloot-Kunststof-Kozijnen-Fabriek/207666125965946?ref=hl">',
'<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>',
'</div>' // <-- no trailing comma after last item

You can either hard code that to the page (what I think Like Breathing did), or do it the way it is now - linking to the picture, or put in code that will link back to the page and launch that image in the lightbox. If you want to do the last thing though, I think you have to give up tracking or at least URL tracking because that's incompatible with a link back of that nature. Or at least that's what Like Breathing told me. URL tracking is turned on here:


window.addthis_config = {'data_track_addressbar':true};

URL tracking doesn't work in some browsers anyway. So you could get rid of that and setup id's for each image and pass its id as a query each time. All of that was covered earlier in this thread. Only I'm not 100% certain it works because Like Breathing opted to just link back to the page because they wanted to keep the URL tracking. They did that with a meta tag I believe. But they may have hard coded it, I'm pretty sure either way works if all you want is to link back to the page.

But let's make sure this new demo is acceptable and workable before experimenting with the share link.

m1155
10-04-2012, 05:48 PM
This looks great John, i'll try to add it to my company's website this weekend and show the result. Thanks again!

m1155
10-20-2012, 04:34 PM
Take some longer as thought but i finally added the "John" Lightbox to my website www.zkkf.nl

* I tryed to change "rev" into "title" so the lightbox show the title text but i cant get that work...any idea why? (wit rev it works great, see first picture left on top)

* The link to show full size picture gets the css makeup from the page (it's logic actually) I try to add makeup for the link on lightbox.css, that works but i overrule the css for my whole website..


OK, they're back up:

You can either hard code that to the page (what I think Like Breathing did), or do it the way it is now - linking to the picture, or put in code that will link back to the page and launch that image in the lightbox. If you want to do the last thing though, I think you have to give up tracking or at least URL tracking because that's incompatible with a link back of that nature. Or at least that's what Like Breathing told me. URL tracking is turned on here:


window.addthis_config = {'data_track_addressbar':true};


I like the way you explained in the orange part. Mayby you can give me a hint so i can work it out myself ?

So far i am really happy with the result, i think likebreath can use this version to, i will send him a message.

Edit: i noticed that after adding the new lightboxaddthis.js all ahref / links on the whole page were blokked... so i removed the js temporary

m1155
11-09-2012, 09:24 PM
I still didn't find out why the latest version disables al hyperlinks on whole the webpage, any idea John ?

jscheuer1
11-10-2012, 06:28 AM
Oh, that's easy. I was playing around and left some test code in. It's at the end:


. . . dow = $(window);
top = $window.scrollTop() + $window.height() / 10;
left = $window.scrollLeft();
$lightbox.animate({top: top, left: left});
preloader.src = this.album[imageNumber].link;
this.currentImageIndex = imageNumber;
};
$(document).on('click', 'a', function(e){
e.preventDefault();
});
})(jQuery);
/* ]]> */
</script>

Just get rid of the highlighted.

m1155
11-18-2012, 07:47 PM
Thnx, that simple, i never have found that :)

Works great now!!

now when i click on the facebook button the picture is being shared together with a link. When the link is clicked on facebook the picture appears. Exually i want to show the page where the picture is on so viewers can see the webpage too. is that possible ?

jscheuer1
11-19-2012, 01:39 AM
I'm not sure if that can work with this setup. In fact I'm pretty sure it cannot*. The addThis tool only allows you to specify one url resource, not a link and an image as would be ideal for this. I think you can with facebook, but for that you would have to interface directly with facebook (via their meta tags) and I believe they're limited per page. That is one page can have an image and a url, not each link on that page.

I'm also not sure about - if you use addthis, whether you can also use the facebook meta tags on the page. I think you can, if so that could simplify a little how this could possibly be worked out.

So I think the solution might be just that though. Interface with facebook (either directly or via addthis - either way using the facebook meta tags). Instead of using Lightbox to show the images use a lightbox like script that can handle content in an iframe. Then using either server side code, a CMS, or just by making up the individual pages, have a page for each image that shows that image and has the facebook code on it for that page and that image. On the page there could also be code that forces it into its boxed iframe on the main page if it's not there.

Pretty much a whole different approach.


*I think the one possibility is, you can specify a description with addthis. If that description can include a link, it could be something like:


Images of whatever from <a href="http://yourdomain.com/yourpage.htm?lightbox=idforthisimage">My Site</a>.

which could activate the lightbox for that image when they load the page. I can show you how to put that into the existing code to see if it works. Where we have:


makeAddthisCaption: function(link){ // function used to make addthis portion of the caption
aturl = locarr[0] + '?lightbox=' + link.id; //not currently used
return [
'<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url="', link.href, '">',
'<a class="addthis_button_facebook" style="cursor:pointer" title="Plaats/Deel op Facebook"></a>',
'<a class="addthis_button_twitter" style="cursor:pointer" title="Plaats/Deel op Twitter"></a>',
'<a class="addthis_button_linkedin" title="Plaats/Deel op LinkedIn"></a>',
'<a class="addthis_button_google_plusone" g:plusone:count="false" title="Plaats/Deel op Google,"></a>',
'<a class="addthis_button_compact"></a>',
'<a class="addthis_counter addthis_bubble_style" title="Plaats/Deel op andere sites"></a>',
'</div>',
'<div class="addthis_toolbox addthis_default_style addthis_32x32_style" ',
'addthis:url="http://www.facebook.com/pages/Zwetsloot-Kunststof-Kozijnen-Fabriek/207666125965946?ref=hl">',
'<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>',
'</div>' // <-- no trailing comma after last item

That could be:


makeAddthisCaption: function(link){ // function used to make addthis portion of the caption
aturl = locarr[0] + '?lightbox=' + link.id; //used for description link
return [
'<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url="', link.href,
'" addthis:description="Pictures From <a href=\'' + aturl + '\'>My WebSie</a>.">',
'<a class="addthis_button_facebook" style="cursor:pointer" title="Plaats/Deel op Facebook"></a>',
'<a class="addthis_button_twitter" style="cursor:pointer" title="Plaats/Deel op Twitter"></a>',
'<a class="addthis_button_linkedin" title="Plaats/Deel op LinkedIn"></a>',
'<a class="addthis_button_google_plusone" g:plusone:count="false" title="Plaats/Deel op Google,"></a>',
'<a class="addthis_button_compact"></a>',
'<a class="addthis_counter addthis_bubble_style" title="Plaats/Deel op andere sites"></a>',
'</div>',
'<div class="addthis_toolbox addthis_default_style addthis_32x32_style" ',
'addthis:url="http://www.facebook.com/pages/Zwetsloot-Kunststof-Kozijnen-Fabriek/207666125965946?ref=hl">',
'<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>',
'</div>' // <-- no trailing comma after last item

I just tried it and there was no error, and the description attribute appeared in the generated markup as expected. However, when I clicked the facebook link I didn't see the description getting passed in the query string. I did see the image url though, so I'm assuming the description doesn't get passed along to facebook anyway.

m1155
12-23-2012, 12:04 PM
I will try above facebook solution later ;)

More urgent is the fact my website is loading slowly even when al image's are all loaded it's still slow for 10 or 15 seconds (really annoying)

I installed the firebug for Firefox and dont see any errors but al lot of messages, most of them contain google.plusone and facebook:



https://plusone.google.com/_/scs/apps-static/_/js/k=oz.plusone.en_US.ZVt492FhHy4.O/m=p1b,p1p/am=MA/rt=j/d=1/rs=AItRSTMNI5qONhIfcb7QgryY4zDhc3eQlQ/cb=gapi.loaded_1

http://static.ak.fbcdn.net/rsrc.php/v2/yu/r/LqpqoPlM8sb.js


The facebook like button is loading slow in the picture.


any way to solve this ? (i temporary removed the google+1 button from addthis, speed is much better but not 100%)

m1155
12-24-2012, 09:33 AM
I changed the addthis code a little in lightboxaddthis.js:



'<div class="addthis_toolbox addthis_default_style addthis_default_style" addthis:url="', link.href, '">',
'<a class="addthis_button_facebook_like" title="Onze pagina nuttig Klik op VIND IK LEUK en Volg ons op facebook" fb:like:width="77" addthis:url="http://www.facebook.com/pages/Zwetsloot-Kunststof-Kozijnen-Fabriek/207666125965946"></a>',
'<a class="addthis_button_facebook" style="cursor:pointer" title="Plaats/Deel op Facebook"></a>',
'<a class="addthis_button_twitter" style="cursor:pointer" title="Plaats/Deel op Twitter"></a>',
'<a class="addthis_button_linkedin" title="Plaats/Deel op LinkedIn"></a>',
'<a class="addthis_button_google_plusone_badge" g:plusone:size="small" title="Plaats/Deel op Google,"></a>',
'<a class="addthis_button_compact"></a>',
'<a class="addthis_counter addthis_bubble_style" title="Plaats/Deel op andere sites"></a>',
'</div>' // <-- no trailing comma after last item


The Google+ button is differtent and doesn't give any problems anymore. edit: its the link to google+ page so i removed it, original still gives long loading time

The facebook like box is also different. I added it within the same DIV as the other addthis buttons. Loading faster but still give al those messages (almost the same number as pictures on the site).
I don't know how to solve this. (mayby it's normal?)