Search code examples
jqueryjquery-uikrl

jQuery UI effects in Kynetx sidetab


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.


Solution

  • 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);
                        });
                   |>;
            }
    
    
    
        }
    }