【问题标题】:How do I get the title attribute as a variable to replace the hashtag in prettyPhoto?如何获取 title 属性作为变量来替换 prettyPhoto 中的主题标签?
【发布时间】:2014-01-26 19:35:26
【问题描述】:

我正在尝试将展开图像的主题标签链接替换为其标题,而不是编号索引。

我已设法从网址中删除不需要的编号,但我不知道如何检索标题。

在编辑 prettyPhoto javascript 时,我将 SetHashtag 函数更改为:

function setHashtag(){
    var title = pp_titles;
    if(typeof theRel == 'undefined') return; // theRel is set on normal calls, it's impossible to deeplink using the API
    location.hash = theRel + '/'+title+'/';
};

在变量中使用“pp_titles”似乎会从整个图库中提取所有标题并将它们添加到 url 的末尾。我只想为当前图像使用标题,但我不确定从哪里检索它。

您可以在此处的任何图片中看到一个示例:http://www.sghalliday.com/urban2.html

当用户退出图库时,我也会尝试并希望从 url 末尾删除主题标签,但目前这没什么大不了的。

【问题讨论】:

    标签: javascript jquery title hashtag prettyphoto


    【解决方案1】:

    快速解决方案,更改prettyphoto.js 中的这些行,您就可以开始了。如果标题为空 URL 会看起来很丑,但仍然可以使用 ;)

    ...
    ...
    
    if(!pp_alreadyInitialized && getHashtag()){
        pp_alreadyInitialized = true;
    
        // Grab the rel index to trigger the click on the correct element
        hashIndex = getHashtag();
        ergec = hashIndex.split("/"); // add this line
        hashRel = hashIndex;
    
        //hashIndex = hashIndex.substring(hashIndex.indexOf('/')+1,hashIndex.length-1); // comment this line
        //hashRel = hashRel.substring(0,hashRel.indexOf('/')); // comment this line
        hashIndex = ergec[ergec.length - 2]; // add this line
        hashRel = ergec[0]; // add this line
    
        // Little timeout to make sure all the prettyPhoto initialize scripts has been run.
    
    ...
    ...
    
    function setHashtag(){
        if(typeof theRel == 'undefined') return; // theRel is set on normal calls, it's impossible to deeplink using the API
        location.hash = theRel + '/' + pp_titles[rel_index] + '/' + rel_index +'/'; // alter this line
    };
    
    ...
    ...
    

    【讨论】:

      猜你喜欢
      • 2014-03-12
      • 2010-09-18
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多