Kynetx 侧边栏的 jQuery UI 效果

发布于 2024-10-04 10:13:48 字数 1515 浏览 4 评论 0原文

我已经使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿! 2024-10-11 10:13:48

你没有遗漏任何东西。目前,运行时(特别是 watch() 操作)使用 .live() 来注册事件处理程序。 sidetab() 吃掉 .live() 附加的所有事件处理程序。 sidetab() 会吃掉它们,因为 .live() 实际上是通过将点击处理程序附加到 document 对象来工作的,然后监视事件冒泡。当它到达 document 时,它会检查事件是否是从与您的选择器匹配的元素注册的,如果是,它会触发您的处理程序。 sidetab() 通过调用 event.stopPropagation() 来终止此事件,这会停止事件的冒泡,因此它永远不会到达 document,因此你的处理者永远不会开火。

您可以通过使用 jQuery 实用函数 .bind() 注册事件处理程序来解决此问题。 .bind() 只会为已经存在的元素注册处理程序,但只要您注意侧边栏内的元素之前就存在你调用.bind(),你会没事的。

像这样的事情:

$K("#tester").bind("click", function() {
  $K(this).effect("bounce", { "times" : 3 }, 300);
});

让我们把它放在整个应用程序的上下文中,好吗?

为了使这个示例保持简单,我们将简单地发出附加处理程序所需的 JavaScript,并在单击时让 div 弹起。此示例也可以作为要点提供

ruleset a369x111 {
    meta {
        name "Sidetab->Events"
            description <<
                Sidetab jQuery
            >>
            author "AKO"
            logging on

            use javascript resource jquery_ui_js

    }
    global {
        css  <<
            #tester { 
                margin-left: 10px; 
                margin-top: 10px; 
                width: 80px; 
                height: 80px; 
                background: green; 
                position: relative; 
            }
        >>;
    }

    rule tab {
        select when pageview ".*"

            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"
                };
                emit <|
                    $K("#tester").bind("click", function() {
                        $K(this).effect("bounce", { "times" : 3 }, 300);
                    });
               |>;
        }



    }
} 

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 the document object, and then watches for the event to bubble up. When it reaches the document, 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 calling event.stopPropagation(), which stops the bubbling of the event, so it never reaches the document, 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:

$K("#tester").bind("click", function() {
  $K(this).effect("bounce", { "times" : 3 }, 300);
});

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:

ruleset a369x111 {
    meta {
        name "Sidetab->Events"
            description <<
                Sidetab jQuery
            >>
            author "AKO"
            logging on

            use javascript resource jquery_ui_js

    }
    global {
        css  <<
            #tester { 
                margin-left: 10px; 
                margin-top: 10px; 
                width: 80px; 
                height: 80px; 
                background: green; 
                position: relative; 
            }
        >>;
    }

    rule tab {
        select when pageview ".*"

            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"
                };
                emit <|
                    $K("#tester").bind("click", function() {
                        $K(this).effect("bounce", { "times" : 3 }, 300);
                    });
               |>;
        }



    }
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文