(Classic) watch()

watch(<selector>,<action>)

sets a watch on the <selector> item in the current page. When the user performs <action> an event will be fired for that action in the web event domain. <selector> is a jQuery selector such as a class (.foo) or id (#bar). The following web domain actions are available:

  • pageview
  • submit
  • change
  • click
watch('#foo', 'click')

The following ruleset shows watch() being used

ruleset a1299x187 {
	meta {
		name "Watch Example"
		author "nathan cerny"
		logging off
	}
	dispatch {
		// domain "exampley.com"
	}
	rule watch_rule {
		select when pageview ".*" setting ()
        pre {
            watch_link = <<
            <div>
                <a id='watched' href="javascript:void(0)">
                    Watched
                </a>
            </div>
            >>;
        }
        {
            append('body', watch_link);
            watch("#watched", "click");
        }
	}
    
    rule clicked_rule {
        select when web click "#watched" 
        notify("You clicked", 'Watch');
    }
}

The following demonstrates the preceding rule:



Copyright Picolabs | Licensed under Creative Commons.