Kynetx 侧边栏的 jQuery UI 效果
我已经使用 Kynetx 的 jQuery UI 集成在页面上成功实现了 jQuery UI 效果。
但是,我无法在侧边选项卡中发挥效果。这是我的申请规则。我希望有人能指出我所缺少的内容:
global {
css <<
#tester
{
margin-left: 10px;
margin-top: 10px;
width: 80px;
height: 80px;
background: green;
position: relative;
}
>>;
}
rule tab is active {
select when pageview ".*" setting ()
pre {
results = <<
<div id='tester'></div>
>>;
}
{
sidetab() with pathToTabImage = "http://dl.dropbox.com/u/10762217/search-tab-images/tab2.png"
and tabColor = "transparent"
and topPos = "50px"
and message = results
and divCSS = {
"z-index": 10000,
"backgroundColor": "#ffffff",
"width": "200px",
"padding": "0px",
"imageHeight": "162px",
"imageWidth": "53px",
"-moz-border-radius": "5px"
};
watch("#tester", "click");
}
}
rule jeffect_on_click is active {
select when web click "#tester"
jquery_ui:effect("#tester","bounce","normal");
}
}
我确保包含
use javascript resource jquery_ui_js
在我的元标记中。
I have successfully had a jQuery UI effect take place on a page using Kynetx's jQuery UI integration.
However, I am having trouble getting the effect to work from within a sidetab. Here are the rules for my application. I'm hoping someone can point out what I am missing:
global {
css <<
#tester
{
margin-left: 10px;
margin-top: 10px;
width: 80px;
height: 80px;
background: green;
position: relative;
}
>>;
}
rule tab is active {
select when pageview ".*" setting ()
pre {
results = <<
<div id='tester'></div>
>>;
}
{
sidetab() with pathToTabImage = "http://dl.dropbox.com/u/10762217/search-tab-images/tab2.png"
and tabColor = "transparent"
and topPos = "50px"
and message = results
and divCSS = {
"z-index": 10000,
"backgroundColor": "#ffffff",
"width": "200px",
"padding": "0px",
"imageHeight": "162px",
"imageWidth": "53px",
"-moz-border-radius": "5px"
};
watch("#tester", "click");
}
}
rule jeffect_on_click is active {
select when web click "#tester"
jquery_ui:effect("#tester","bounce","normal");
}
}
I made sure to include
use javascript resource jquery_ui_js
in my meta tag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你没有遗漏任何东西。目前,运行时(特别是
watch()
操作)使用.live()
来注册事件处理程序。sidetab()
吃掉.live()
附加的所有事件处理程序。sidetab()
会吃掉它们,因为.live()
实际上是通过将点击处理程序附加到document
对象来工作的,然后监视事件冒泡。当它到达document
时,它会检查事件是否是从与您的选择器匹配的元素注册的,如果是,它会触发您的处理程序。sidetab()
通过调用event.stopPropagation()
来终止此事件,这会停止事件的冒泡,因此它永远不会到达document
,因此你的处理者永远不会开火。您可以通过使用 jQuery 实用函数
.bind()
注册事件处理程序来解决此问题。.bind()
只会为已经存在的元素注册处理程序,但只要您注意侧边栏内的元素之前就存在你调用.bind()
,你会没事的。像这样的事情:
让我们把它放在整个应用程序的上下文中,好吗?
为了使这个示例保持简单,我们将简单地
发出
附加处理程序所需的 JavaScript,并在单击时让 div 弹起。此示例也可以作为要点提供:You aren't missing anything. Currently, the runtime, specifically the
watch()
action uses,.live()
to register event handlers.sidetab()
eats all event handlers attached with.live()
.sidetab()
eats them because.live()
actually works by attaching your click handler to thedocument
object, and then watches for the event to bubble up. When it reaches thedocument
, it checks to see if the event was registered from the element(s) matching your selector, if so, it fires your handler.sidetab()
kills this by callingevent.stopPropagation()
, which stops the bubbling of the event, so it never reaches thedocument
, so your handler will never fire.You can fix this by registering your event handler with the jQuery utility function,
.bind()
..bind()
will only register the handler for elements that already exist, but as long as you take care that the elements inside of your sidetab exist before you call.bind()
, you will be fine.Something like this:
Let's put that in the context of an entire app, shall we?
To keep this example simple, we'll simply
emit
the javascript necessary to attach our handler and have the div bounce when clicked. This example is also available as a gist: