如何将title属性作为变量来替换prettyPhoto中的#标签?

时间:2014-01-26 19:35:27

标签: javascript jquery title hashtag prettyphoto

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

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

在编辑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'似乎从整个图库中提取所有标题并将它们添加到网址的末尾。我只是想使用当前图像的标题,但我不确定从哪里检索它。

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

我还会尝试在用户退出图库时从网址末尾删除主题标签,但现在这不是什么大问题。

1 个答案:

答案 0 :(得分:0)

快速解决方案,改变prettyphoto.js中的这些行,你就可以了。如果title为空,则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
};

...
...