试图触发之前&在jQuery之后的事件show() [英] Attempting to trigger before & after events around jQuery show()

查看:99
本文介绍了试图触发之前&在jQuery之后的事件show()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一些第三方代码使一个模态对话框出现之后,得到一段JavaScript运行。我看到劫持jQuery show功能的一个很整洁的想法,但不幸的是它不工作。我猜这个想法在2009年以前用于旧版本的jQuery,但现在不是最新版本。这是一个jsFiddle的实现和一个例子:

I'm trying to get a piece of our JavaScript run after some 3rd party code makes a modal dialog appear. I saw a pretty neat idea of hijacking the jQuery show function, but unfortunately it is not working. I'm guessing this idea used to work on an older version of jQuery back in 2009, but not now on the latest version. Here is a jsFiddle with the implementation and a sample:

http://jsfiddle.net/mkmurray/drv5w/2/

正如你可以看到,运行示例,它将提醒' beforeShow'事件,但不是'afterShow事件',并且有一些调试我可以看到它不是完全调用'newCallback'功能。

As you can see by running the sample, it will alert the 'beforeShow' event, but not the 'afterShow event' and with some debugging I can see that it is not calling the 'newCallback' function entirely.

提前谢谢任何您可以提供的帮助。

Thank you in advance with any help you can provide.

推荐答案

看起来我能够通过解决方案。它涉及原始的几个因素:

Looks like I was able to work through a solution. It involved a few factors going wrong with the original:


  1. 由于我看到的代码的原始写入,jQuery添加了另一个可选参数名为缓和。这真的搞砸了我如何通过调用 _oldShow.apply(...) show 方法>。

  2. 在我修复后,我发现有时 show 方法调用了一系列其他方法,有时会递归调用code>再次显示我需要一种方法来阻止我的执行拦截这些递归调用;我发现如果有一个选择器属性,我可以依靠。

  1. Since the original writing of the code I saw, jQuery added another optional parameter named easing. This really messed with how I was delegating to the original show method in jQuery by calling _oldShow.apply(...).
  2. After I fixed that, I found that sometimes the show method calls a series of other methods that sometimes recursively call show again. I needed a way to not have my implementation intercept those recursive calls; I found that I could rely on if there was a selector property or not.

这个jsFiddle可以在这里找到一个工作实现:

A working implementation can be found here at this jsFiddle:

http ://jsfiddle.net/mkmurray/drv5w/27/

这个实现非常依赖于jQuery而不改变<$ c $的方法签名c> show 方法。所以你几乎不得不决定是否要修改你的第三方jQuery插件,而不是这样做。无论哪种方式,如果您想要获得最新的第三方插件或最新的jQuery,一些新的更改可能会破坏您的实现。所以这个解决方案不一定比修改你的第三方插件更好或更差。

This implementation is pretty dependent on jQuery not changing the method signature of the show method though. So you pretty much have to decide if you want to modify your 3rd party jQuery plugins instead of doing this. Either way, if you want to get latest of the 3rd party plugin or the latest jQuery, some new change could break your implementation. So this solution is not necessarily better or worse than modifying your third party plugins.

这篇关于试图触发之前&amp;在jQuery之后的事件show()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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