2014-01-26 29 views
1

我试图用它的标题而不是编号索引替换扩展图像的哈希标签链接。如何将title属性作为变量来替换prettyPhoto中的hashtag?

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

当编辑JavaScript我已经改变了SetHashtag功能,这个prettyPhoto:

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

我也想尝试,喜欢当用户退出画廊从URL的末尾删除主题标签,但是这不是什么大不了的目前。

回答

0

快速解决方案,在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 
}; 

... 
...