vendor/assets/javascripts/emerson/view.js in emerson-0.0.8 vs vendor/assets/javascripts/emerson/view.js in emerson-0.0.9
- old
+ new
@@ -313,10 +313,13 @@
// 'click' : handler // fired outside of the view
// 'selector' : {
// 'click' : handler
// }
// },
+ // window : { // bind window, for events
+ // 'scroll' : handler // fired outside of the view
+ // },
// 'outlet:name' : { // a custom key to specify a
// 'click' : handler // defined outlet as the scope
// }
// }
// });
@@ -324,13 +327,13 @@
// Emerson event handling differs from that of, say, stock jQuery in that
// `this` within the context of the handler will be a view instance. The
// event argument is unadultered, allowing access to the full set of targets
// as defined by the baselib (e.g., jQuery).
//
- // **Special notes regarding document-bound handlers**:
+ // **Special notes regarding document-/window-bound handlers**:
//
- // Binding an event like `click` (without selector scope) to the document
+ // Binding an event like `click` (without selector scope) to document/window
// would likely be a bad idea. A more useful (and less costly) use case
// would be a sort of pub/sub. For example, view "A" could trigger an event
// indicating that it has rendered a new instance, to which "B" (elsewhere)
// would listen in order to update, say, a count of instances of "A".
//
@@ -339,9 +342,14 @@
function bind(instance, key, handler, selector, binder) {
if($.isPlainObject(handler)) {
if(key === 'document') {
_.each(handler, function(subhandler, subkey) {
bind(instance, subkey, subhandler, undefined, $(document));
+ });
+ }
+ else if(key === 'window') {
+ _.each(handler, function(subhandler, subkey) {
+ bind(instance, subkey, subhandler, undefined, $(window));
});
}
else {
_.each(handler, function(subhandler, subkey) {
bind(instance, subkey, subhandler, key, binder);