Opening images by fancybox from custom link - php

I'm doing a photo gallery for my site and I wanted to have all my added photos in database. I did everything good. Database responses with the "custom link" .. I mean for example that my photo has src like something.php?id=25 .. what I want is to open this image in fancybox (I already have fancybox installed on webpage, it shows normal-src-images well), but I'm not so good in js, etc. So I don't really know what should I do...
Basicly, the problem is that everytime I want to open the image, browser shows me image in his actual src, not in fancybox.
I did this, but It doesn't work:
<script type="text/javascript">
$(document).ready(function() {
$(".selector").fancybox({
'type' : 'image'
});
});
</script>
I found this script content -- $(".selector").fancybox({'type' : 'image'}); -- on the official web page of fancybox (they said it would help when I'm trying to open images from custom links), but It just doesn't work or I inserted it bad. I don't really know what I'm doing in js or jquery or what it is... can you guys help me with it ?
Here is a part of the source code from my gallery.php where I want fancybox to work (all scripts for fancybox are set good):
<div class="images">
<?php
include_once('actions/db_connection.php');
$query = "SELECT * FROM gallery";
$response = mysql_query($query, $connection)
if(!$response)
{
mysql_error();
}
else
{
while($qs = mysql_fetch_array($response))
{
echo '<a class="fancybox" rel="group" href="actions/download_large.php?image_ID='.$qs['image_ID'].'">
<img class="gallery" alt="image" src="actions/download_small.php?image_ID='.$qs['image_ID'].'"></a>';
}
}
?>
</div>
As I told my php "script" is showing my images good, so I think I just need some script to tell the fancybox how to open a link, but If you see something bad in code I'm opened for suggestions. Thank you so much. (Sorry for my english, hope you understand).. I'm running fancybox 2.

Can you try this,
$(".fancybox").fancybox({'type' : 'image'});
instead of
$(".selector").fancybox({'type' : 'image'});

Related

Google Chrome: URL could not be located

I have a large website with many hard coded pages. If there is a broken URL Firefox doesnt seem to care. But Google Chrome and IE seem to display a horrible placeholder box (as if there should be an image in its place).
What is the best solution to scan the page of broken images? and assigning display:none to the image to stop the placeholder showing up?
function imgError(image){
image.onerror = "";
image.src = "/images/noimage.gif";
return true;
}
<img src="someimage.png" onerror="imgError(this);"/>
I found the above client side solution. But is there a way with PHP do it before the page is loaded? I am using concrete5
For cases like this use the 'alt' HTML tag. This tag is used to display a description of the img in case it is not found.
<img src="myPath.png" alt="Here was my broken image">
If images are on same server then try file_exists function to check if there's image. If not show something else.
Here's the code to help you:
if(file_exists("../img/logo.png")) {
echo '<img src="../img/logo.png" />';
} else {
//something else
}

Gallery and Fancybox

I am using the Gallery Snippet on MODx Revolution 2.1.5.
I am calling out the basic Gallery Snippet along with the specified Album.
I am trying to link Fancybox (jQuery Lightbox) up to the Thumbnails and images.
This is what MODx Outputs on the Resource:
<div class="gal-item">
<a href="path/to/page/test.html?galItem=1&galAlbum=1&galTag=">
<img class="" src="/assets/components/gallery/connector.php?action=web/phpthumb&w=100&h=100&zc=1&far=C&q=90&src=%2Fassets%2Fcomponents%2Fgallery%2Ffiles%2F1%2F4.jpg" alt="lorem-ipsum-2.jpg" />
</a>
</div>
I have selected the content correctly, When I click on the image wrapped in the link tag I get this message:
The requested content cannot be loaded.
Please try again later.
How can it not be loaded? It's loading the Thumbnail and it needs the original image to create the Thumbnail. How can it not find the image?
Note: I am using the default setup for this Add-on.
Thank you!
As AlexC has mentioned I reckon it's to do with your big image path. Have you tried going to that URL direct and seeing if the image loads. You could trying removing the fancybox code and then click on the thumb and see if the link works as normal. The image should load on it's own in the browser window.
I can be am lots of causes why id does like that.
I think what it can be, you try to load content before you have this guy, I mean use some Ajax and it loads after you apply the "fancybox"
you can try this :
remove the "fancybox" classname
and use this code :
$(".gal-item").live("click", function(){
var $href = $(this).find("a").attr("href");
var $href = $(this).attr("href");
$.fancybox({
href:$href
});
});

Convert href link to image link use with thumbshots

I have seen some good scripts come by but not one i really could use.
My website is php sql driven and i like to change the links on the site with a image
from thumbshots.
The code i have so far is:
<?php echo openld_htmlspecialchars($link['title']); ?>
And as far as the script i have go like:
$('.post-body a').each(
function(){
$('<img />').attr('src','http://open.thumbshots.org/image.aspx?url='+encodeURIComponent(this.href)).replaceAll($(this));
});
I used the .replaceAll function but it shows only the pictures and are not click links.
I used .insertAfter but then the text link keeps showing.
It's probably not a huge change in the script code but i don't seem to find the answer on my question.
Thanks
I hope that what you are looking for ...
$('.post-body a').each(function(){
$(this).html("<img src='http://open.thumbshots.org/image.aspx?url="+encodeURIComponent(this.href)">");
});

href inside javascript

I'm trying to construct a table on the right of the page where I pull out all the videos from the server. I want the users to click a row in the table and it starts to play a video in flowplayer on the left of the page. The video url is something I pull out of the DB.
<?php
for($i=0;$i<$num_videos;$i++)
{
?>
<tr onclick="DoNav('<?php echo $result_videos[$i]["video_url"]; ?>');">
<td>
...
Here's the javascript:
function DoNav(theUrl)
{
flowplayer("player", "flowplayer/flowplayer-3.2.7.swf", document.location.href = theUrl);
}
For whatever reason I can't seem to get flowplayer to work with this div:
<div id="player"><img src="recordings/landscape.jpg" width="320" height="240" /></div>
It will only prompt you to open or save the video instead of playing in the current window. If anyone knows this issue here that would be appreciated. At any rate, I know I can get flowplayer working with a href like so:
<a
href="url"
style="display:block;width:320px;height:240px;"
id="player"><img src="recordings/landscape.jpg" width="320" height="240" />
</a>
But I don't want to put the href in the table as I want that splash image included as well. Any ideas?
Edited to improve clarity.
When the function flowplayer("player", "flowplayer/flowplayer-3.2.7.swf", document.location.href = theUrl); Was called the document.location.href was being evluated and caused the browser to go to the theUrl which prompted for file to be downloaded.
Furthermore we found there is some sort of issue updating a with the as a child DOM object. This was solved by moving the image to the background of the using the inline CSS.
JS Code:
function DoNav(theUrl)
{
flowplayer("player", "flowplayer/flowplayer-3.2.7.swf", theUrl);
}
HTML table:
<div id="player" style="display:block;width:320px;height:240px;background-image:url(recordings/landscape.jpg)"></div>
PHP stayed the same.

Make active div for youtube URL a different shade

I have a page where in the top middle there is a large youtube player. Below it there are a bunch of youtube thumbnails which are clickable. Clicking them changes the player video to the thumbnail that was clicked. The youtube ID is passed thru the URL.
I wanted to change the shade of the thumbnail background so that the active ("clicked") thumbnail was shaded.
The following code generates the linked thumbnails:
while ($row = mysql_fetch_array($result)) {
$tubeID = $row['videoinfo'];
echo
'<div class="vid"><img src="http://img.youtube.com/vi/' . $tubeID . '/0.jpg" width="225" height="175"/></div>';
}
And the following code uses the clicked thumbnail to display the video:
<iframe id="player" width="640" height="385" src="http://www.youtube.com/embed/<?php echo $_GET['id'] ?>" frameborder="0"></iframe>
I know I need to compare the thumbnail URL to the current URL and if they match and set an ID to that thumbnail which can be assigned properties in CSS... though I'm not sure how to do so. Can someone help?
edit : this sorta explain what BZ suggested.
I kicked out some php to make the answer more concise. Don't forget to add it back.
<div class="vid">
<a href="videos.php?id=$tubeID" id="m+$tubeID" onclick="changeVid(this);return false;">
<img src="http://img.youtube.com/vi/01/0.jpg" width="225" height="175"/>
</a>
</div>
<script type="text/javascript>
function changeVid(obj) {
document.getElementById('player').src = "videos.php?id="+ substr(obj.id,1)
document.getElementById(obj.id).style.visibility='visible'; //or other style
document.getElementById(obj.id).setAttribute("class", newClass); //For Most Browsers
document.getElementById(obj.id).setAttribute("className", newClass); //For IE; harmless to other browsers.
}
</script>
of course, I'd be a lot easier with a JS framework... (ie jquery)
Basically, when you click a link, the function is called, when it's done, return false; disable the page loading (ignoring the href).
The function will change the iframe source and then will add some custom styling to the link you clicked to load the new video.
I've thrown a "m" in the link ID, because id can't start with numbers...
edit : my function changeVid lack some reset function to remove the old thumbnail active state (easy way to solve it : remove the active state from all thumbnail then put the active state on the clicked thumbnail.)
In each link you could put an onclick attribute to do some javascript that would do the highlighting.

Categories