weixin_33701617 2010-12-30 01:06 采纳率: 0%
浏览 52

灯箱图片/链接网址

Basically I have a slightly non-standard implementation of FancyBox. By default you have to include a link to the large version of the image so that the Lightbox can display it. However, in my implementation, the image link URLs point to a script rather than directly to the image file. So for example, instead of:

<a href="mysite/images/myimage.jpg" rel="gallery">

I have:

<a href="mysite/photos/view/abc123" rel="gallery"> 

The above URL points to a function:

public function actionPhotos($view)
{
    $photo=Photo::model()->find('name=:name', array(':name'=>$view));

    if(!empty($photo))
    {           
        $this->renderPartial('_photo', array('photo'=>$photo, true));
    }
}

The "$this->renderPartial()" bit simply calls a layout file which includes a standard HTML tag to output.

Now when the user clicks on a thumbnail, the above function is called and the large image is displayed in the Lightbox.

Now if the user right clicks on the thumbnail and selects "open in new tab/window" then the image is displayed in the browser as per normal, i.e. just the image. I want to change this so that it displays the image within a layout.

In the above code I can include the following and put it in an IF statement:

$this->render('photos', array('photo'=>$photo));

This will call the layout file "photos" which contains the layout to display the image in.

I have a specific limitation for this - the image URL must remain the same, i.e. no additional GET variables in the URL. However if we can pass in a GET variable in the background then that is OK.

I will most likely need to change my function above so that it calls a different file for this functionality.

EDIT: To demonstrate exactly what I am trying to do, check out the following:

http://www.starnow.co.uk/KimberleyMarren

Go to the photos tab and hover over a thumbnail - note the URL. Click the thumbnail and it will open up in the Lightbox. Next right click on that same thumbnail and select "open in new tab/new window". You will notice that the image is now displayed in a layout. So that same URL is used for displaying the image in the Lightbox and on its own page.

The way StarNow have done this is using some crazy long JavaScript functionality, which I'm not too keen on replicating.

  • 写回答

3条回答 默认 最新

  • weixin_33743661 2010-12-30 01:19
    关注

    You should be able to modify the JavaScript function that generates the HTML with the <img /> tag to link the image to such a page. Although, if you are trying to make it so that selecting "Open image in new tab" opens a page like this, then that might be impossible (unless there is some sort of crazy cookie/session implementation to alternate between the image script just passing an image and generating a page, which I think could be possible). To assign a new href for the link to have when you click "Open link in new tab" should be quite possible by just modifying the JavaScript function.

    Could you clarify what exactly you are attempting to do? Open link in new tab or open image in new tab?

    Edit: It appears that the FancyBox script is changing the href of your link to point directly to the image. You would need to find where in the script it is selecting each link tag with rel="gallery" and replacing the href to point to the images; you will want it to not change the href if you want it left as "mysite/photos/view/abc123", for example.

    评论

报告相同问题?