Merge pull request #141 from pluma/master
Added support for AMD, CommonJS strict (fixes #116, #136)
Showing
1 changed file
with
12 additions
and
10 deletions
... | @@ -375,32 +375,34 @@ Rivets.config = | ... | @@ -375,32 +375,34 @@ Rivets.config = |
375 | Rivets.formatters = {} | 375 | Rivets.formatters = {} |
376 | 376 | ||
377 | # The rivets module. This is the public interface that gets exported. | 377 | # The rivets module. This is the public interface that gets exported. |
378 | rivets = | 378 | factory = (exports) -> |
379 | # Exposes the core binding routines that can be extended or stripped down. | 379 | # Exposes the core binding routines that can be extended or stripped down. |
380 | binders: Rivets.binders | 380 | exports.binders = Rivets.binders |
381 | 381 | ||
382 | # Exposes the formatters object to be extended. | 382 | # Exposes the formatters object to be extended. |
383 | formatters: Rivets.formatters | 383 | exports.formatters = Rivets.formatters |
384 | 384 | ||
385 | # Exposes the rivets configuration options. These can be set manually or from | 385 | # Exposes the rivets configuration options. These can be set manually or from |
386 | # rivets.configure with an object literal. | 386 | # rivets.configure with an object literal. |
387 | config: Rivets.config | 387 | exports.config = Rivets.config |
388 | 388 | ||
389 | # Sets configuration options by merging an object literal. | 389 | # Sets configuration options by merging an object literal. |
390 | configure: (options={}) -> | 390 | exports.configure = (options={}) -> |
391 | for property, value of options | 391 | for property, value of options |
392 | Rivets.config[property] = value | 392 | Rivets.config[property] = value |
393 | return | 393 | return |
394 | 394 | ||
395 | # Binds a set of model objects to a parent DOM element. Returns a Rivets.View | 395 | # Binds a set of model objects to a parent DOM element. Returns a Rivets.View |
396 | # instance. | 396 | # instance. |
397 | bind: (el, models = {}) -> | 397 | exports.bind = (el, models = {}) -> |
398 | view = new Rivets.View(el, models) | 398 | view = new Rivets.View(el, models) |
399 | view.bind() | 399 | view.bind() |
400 | view | 400 | view |
401 | 401 | ||
402 | # Exports rivets for both CommonJS and the browser. | 402 | # Exports rivets for CommonJS, AMD and the browser. |
403 | if module? | 403 | if typeof exports == 'object' |
404 | module.exports = rivets | 404 | factory(exports) |
405 | else if typeof define == 'function' && define.amd | ||
406 | define ['exports'], (exports) -> @rivets = factory(exports) | ||
405 | else | 407 | else |
406 | @rivets = rivets | 408 | factory(@rivets = {}) | ... | ... |
-
Please register or sign in to post a comment