Tags: mootools

Sort by: Date / Title /

  1. 1 year ago by dphiffer
    The idea here is that a single 'Page' object would manage the various defined classes that handle interaction on the page. When 'domready' fires, the Controllers object would do a set of searches for each known controller and establish an object for each element that matches the $$ query. For instance all elements with the CSS class 'JS_Calendar' would be controlled by corresponding objects derived from the Page.Calendar class.
    1. /*
    2.  
    3. Class: Controllers
    4.  
    5. This is a namespace for all the classes that control interactive behavior on the
    6. page. It also manages event messaging so that controllers can communicate with
    7. each other.
    8.  
    9. */
    10. var Controllers = new Class({
    11.  
    12.   Implements: Events,
    13.  
    14.   initialize: function(cssPrefix) {
    15.     this.controllers = [];
    16.     window.addEvent('domready', this.initializeControllers.bind(this, cssPrefix));
    17.   },
    18.  
    19.   initializeControllers: function(cssPrefix) {
    20.    
    21.     // After the page loads, search for elements with particular CSS classes
    22.     // that correspond to JavaScript behavior controllers.
    23.    
    24.     for (property in this) {
    25.       if ($type(this[property]) != 'class') {
    26.         continue;
    27.       }
    28.       dbug.log(property);
    29.       $$('.' + cssPrefix + property).each(function(el) {
    30.         try {
    31.           var Controller = this[property];
    32.           this.controllers.push(new Controller(el, this));
    33.         } catch(e) {
    34.           dbug.log(e.message);
    35.         }
    36.       }.bind(this));
    37.     }
    38.     this.fireEvent('onInitialize');
    39.    
    40.   }
    41.  
    42. });
    43.  
    44. dbug.enable();
    45. var Page = new Controllers('JS_');
    46.  
    47. // In another file, calendar.js
    48. Page.Calendar = new Class({
    49.   initialize: function(el, page) {
    50.     // ...
    51.   }
    52. });
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1306"></script>

First / Previous / Next / Last / Page 1 of 1 (1 posteets)