Prettyphoto - 如何传递唯一参数到回调函数 [英] Prettyphoto - how to pass unique parameter to the callback function

查看:653
本文介绍了Prettyphoto - 如何传递唯一参数到回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我目前的设置

 
< link rel =stylesheethref =/ css / prettyPhoto.csstype =text / cssmedia =screencharset =utf-8/>
< script src =/ js / jquery.prettyPhoto2.jstype =text / javascriptcharset =utf-8>

< script type =text / javascript charset =utf-8>
$(document).ready(function(){
$(a [rel ^ ='prettyPhoto'])。prettyPhoto({
callback:function()
{
$ .post('/ course / close-video',{topic_id:'13'});
}
});
});
< / script>


< a href =/ course / play-video / topic_id /<?php echo $ topic-> topic_id;? iframe = true&width = 470&height = 340rel =prettyPhototitle =<?php echo $ topic-> topic_name;?>>
< img src =/ images / videos /width = 170height =103alt =topic_name;?>/>
< / a>

注意:我在回调中将主题值硬编码为13,但是这些值应该基于点击哪个链接。



有多个一个href标签在页面中,每一个都有一个唯一的topic_id



那么如何传递这个唯一的topic_id到回调函数



非常感谢

解决方案

我已经检查了源代码和它不被Prettyphoto支持。



在版本1.3.4(未压缩)中,您必须更改回调函数,以便其支持在点击的元素中传递参数。



编辑:
Acullty我不会更改源代码,下次你必须升级Prettyphoto时,你必须再次进行更改。它会boulding对维护。



一种解决方案可以是跟踪任何链接被点击并保存:

  $(document).ready(function(){
var lastClicked = null;
$(a [rel ^ ='prettyPhoto'])。prettyPhoto({
callback:function()
{
if(lastClicked!= null){
var topicid = lastClicked.data(topicid); // lastClicked是您的lastclicked链接。
alert(topic:+ topicid); // topic_id
$ .post('/ course / close-video',{topic_id:'13'}) ;
lastClicked = null; //设置最后一次点击为null
}
}
})click(function(){
lastClicked = $(this) ;
});

});



我为你创建了一个jsfiddle,你可以测试:
http://jsfiddle.net / 26L8w /



这不会处理内置的移动到下一个功能,couse它不会跟踪它。但你可以参加jQuery,如果你想跟踪它。


Is there anyway in prettyphoto for me to pass a parameter to the callback function

This is my current setup

<link rel="stylesheet" href="/css/prettyPhoto.css" type="text/css" media="screen" charset="utf-8" />
<script src="/js/jquery.prettyPhoto2.js" type="text/javascript" charset="utf-8">

<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto({
    callback: function()
    {           
    $.post('/course/close-video', {topic_id: '13'});
    }
    });
  });
</script>


<a href="/course/play-video/topic_id/<?php echo $topic->topic_id;?>?iframe=true&width=470&height=340" rel="prettyPhoto" title="<?php echo $topic->topic_name;?>">
<img src="/images/videos/" width="170" height="103" alt="topic_name;?>"/>
</a>

Note: I've hardcoded the topic value as 13 in the callback - but thats something that should come based on which link is clicked.

There are multiple of those a href tags in the page and each one has a unique topic_id

So how can I pass that unique topic_id to the callback function

Thanks much

解决方案

I have checked the source code and its not supported by Prettyphoto. However you can modify the source of prettyphoto.

In version 1.3.4 (uncompressed) you have to change the callback function so its support to pass in the clicked element as an argument.

Edit: Acullty I woudln't change the source code, next time you have to upgrade Prettyphoto you have to do the changes again. It will be boooring to maintenance.

One solution could be to track whatever a link is clicked and save it:

$(document).ready(function(){
    var lastClicked = null;
    $("a[rel^='prettyPhoto']").prettyPhoto({
    callback: function()
    {           
        if(lastClicked != null) {
                var topicid = lastClicked.data("topicid"); // lastClicked is your lastclicked link. So you can use whatever jQuery method on it..
                alert("topic: " + topicid); // The topic_id
                $.post('/course/close-video', {topic_id: '13'});
                lastClicked = null; // Set the last clicked to null 
        }
    }
    }).click(function (){
        lastClicked = $(this);
});

});​

I created a jsfiddle for you so you can test: http://jsfiddle.net/26L8w/

This will not handle the built in "move to next" feature, couse it will not track it. But you can attath jQuery on if you want to keep track of it.

这篇关于Prettyphoto - 如何传递唯一参数到回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆