Skip to content

The Motionbox EventHandler in use

by Topper on April 11th, 2008

Sometimes you just have to like convenience. Using our EventHandler I was just able to write the following code:

JavaScript:
  1. MOBX.HighlightTextField = (function() {
  2.    
  3.     var highlightText = function (evt) {
  4.         var el = evt.element();
  5.         el.focus();
  6.         el.select();
  7.     };
  8.    
  9.     MOBX.EventHandler.subscribe(".highlight_on_click", "click", highlightText);
  10. })();

That could have been an anonymous module too. What's great is now whenever I want to have that "embed code" functionality I just add a class to the form element "highlight_on_click" and it will work as expected. No parsing the DOM for form fields and assigning observers, etc.

Nice.

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS