|
@@ -0,0 +1,52 @@
|
|
|
+// UMD as of 14 May 2015 from github/umdjs/umd.
|
|
|
+(function (root, factory) {
|
|
|
+ if (typeof define === 'function' && define.amd) {
|
|
|
+ // AMD. Register as an anonymous module.
|
|
|
+ define([], factory);
|
|
|
+ } else if (typeof exports === 'object') {
|
|
|
+ // Node. Does not work with strict CommonJS, but
|
|
|
+ // only CommonJS-like environments that support module.exports,
|
|
|
+ // like Node.
|
|
|
+ module.exports = factory();
|
|
|
+ } else {
|
|
|
+ // Browser globals (root is window)
|
|
|
+ root.returnExports = factory();
|
|
|
+ }
|
|
|
+}(this, function () {
|
|
|
+
|
|
|
+ function mixin(src, dst) {
|
|
|
+ Object.keys(src).forEach(function (k) {
|
|
|
+ if (typeof src[k] === "undefined") delete dst[k];
|
|
|
+ else dst[k] = src[k];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // Model-like entity (one that sends update event).
|
|
|
+ // Uses jQuery-like (jQuery, zepto, ...) event mechanism.
|
|
|
+ // Must set JQUpd.jQuery to the wrapper function
|
|
|
+ // before actual use.
|
|
|
+ function JQUpd() {
|
|
|
+ }
|
|
|
+
|
|
|
+ JQUpd.prototype.update = function (data) {
|
|
|
+ mixin(data, this);
|
|
|
+ JQUpd.jQuery(this).trigger("changed", data);
|
|
|
+ };
|
|
|
+
|
|
|
+ // View-like entity (one that observes changed event).
|
|
|
+ // Uses jQuery-like (jQuery, zepto, ...) event mechanism.
|
|
|
+ function JQChg() {
|
|
|
+ }
|
|
|
+
|
|
|
+ JQChg.prototype.observeModel = function (model) {
|
|
|
+ var self = this;
|
|
|
+ model.on("changed", function (ev, data) {
|
|
|
+ self.modelChanged(data, this);
|
|
|
+ })
|
|
|
+ };
|
|
|
+
|
|
|
+ return {
|
|
|
+ JQUpd: JQUpd,
|
|
|
+ JQChg: JQChg
|
|
|
+ };
|
|
|
+}));
|