0

对不起,伙计们,我认为这是直截了当的,但我只是没有得到结果,并且一直在尝试/搜索年龄!

当图片没有标题/标题时,我希望在幻灯片中设置默认标题(即“没有标题数据”)。我怎样才能做到这一点?脚本如下,感谢您的观看,抱歉是新手。

(这与 PWI(Picasa Web 集成器)、jquery 1.8.3 和 fancybox 2.1.4 结合使用

测试页面也在http://www.talesfromthesaddle.com/photosTEST/photos.shtml

// This function is called by FancyBox to format the title of a picture
function formatPhotoTitleFancyBox() {
    var $title = this.element.title;
        this.title = $title;

    return;
    if (this.element.parentNode.childNodes && (this.element.parentNode.childNodes.length > 1)) {
        var $caption = $(".captiontext", this.element.parentNode);

        if ($caption.length > 0) {
            $title = $caption[0].innerHTML;
        }
        var $links = $(".downloadlink", this.element.parentNode);
        if ($links.length > 0) {
            var downloadLink = '<a style="color: #FFF;" href="' + $links[0].href + '">Download</a>';
            $title = $title + '&nbsp;&nbsp;' + downloadLink;
        }
    }



title = $title;


}
4

3 回答 3

0

对,向所有人道歉....进一步查看我发现并附加了一点的 PWI 脚本,可以在底部附近看到,这似乎有效....并且似乎下部脚本是完全多余的?

function photo(j, hidden, username) {
            var $html, $d = "", $c = "", $youtubeId = "", $caption;
            if (j.summary) {
                var $matched = j.summary.$t.match(/\[youtube\s*:\s*(.*)\s*\](.*)/);
                if ($matched) { // Found youtube video entry
                    $youtubeId = $matched[1];
                    $c = $matched[2].replace(/[\r\n\t\s]+/g, ' ');
                    $caption = $matched[2].replace(/[\n]/g, '<br/>');
                } else {
                    $c = j.summary.$t.replace(/[\r\n\t\s]+/g, ' ');
                    $caption = j.summary.$t.replace(/[\n]/g, '<br/>');
                }
            }
            if (settings.showPhotoFilename) {
                if ($caption.length > 0) {
                    $caption += ", ";
                }
                $caption += settings.labels.fileName + " " + j.media$group.media$title.$t;
            }
            if (settings.showPhotoDate) {
                if ((j.exif$tags) && (j.exif$tags.exif$time)) {
                    $d = formatDateTime(j.exif$tags.exif$time.$t) + " ";
                }
            }
            var $pretitle = $c.replace(new RegExp("'", "g"), "&#39;");
            $title= $pretitle||'There is no caption'; //My appended line
            $d += $title;
于 2013-06-04T15:48:39.773 回答
0

你的意思是:

if ($caption.length > 0) {
    $title = $caption[0].innerHTML;
}

改成

$title = ($caption.length) ? $caption[0].innerHTML : "There is no caption data";
于 2013-06-04T03:10:39.583 回答
0

完全接受 jquery —— 现在你已经完成了一半。这是我如何重写你的函数

// This function is called by FancyBox to format the title of a picture
function formatPhotoTitleFancyBox()
{
    var $elem = $(this.element);
    var title = $elem.attr('title') || 'No Caption'; // use || operator to set a default

    var caption = $elem.parent().find(".captiontext").html();
    title = caption || title; // if no html() found or no element found, default back to title

    var $links = $elem.parent().find(".downloadlink").first();
    if ($links.length > 0)
    {
        var downloadLink = '<a style="color: #FFF;" href="' + $links.attr('href') + '">Download</a>';
        title = title + '&nbsp;&nbsp;' + downloadLink;
    }

    // finally, after ALL the edits to title, set this.title.  setting it above like in the OP question means all future changes are missed out on.

    this.title = title;

}

编辑:鉴于 OP 评论中的更新,我可能提出的建议是:在初始化您的幻想框之前this.title,不要使用函数进行设置,而是确保所有元素都具有更新的title属性。类似于以下内容:

$('.the-same-selector-for-fancybox').each(function()
{
    var $elem = $(this);
    var title = $elem.attr('title') || 'No Caption'; // use || operator to set a default

    var caption = $elem.parent().find(".captiontext").html();
    title = caption || title; // if no html() found or no element found, default back to title

    var $links = $elem.parent().find(".downloadlink").first();
    if ($links.length > 0)
    {
        var downloadLink = '<a style="color: #FFF;" href="' + $links.attr('href') + '">Download</a>';
        title = title + '&nbsp;&nbsp;' + downloadLink;
    }

    // finally, after ALL the edits to title, set this.title.  setting it above like in the OP question means all future changes are missed out on.

    $(this).attr('title', title);
});

// call fancybox init here

通过这样做,您可以确保在 fancybox 初始化时每个元素都有一个标题。

于 2013-06-04T03:11:41.437 回答