421bf22b by Michael Richards

Build 0.5.1.

1 parent b42c7d98
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
2 "name": "rivets", 2 "name": "rivets",
3 "repo": "mikeric/rivets", 3 "repo": "mikeric/rivets",
4 "description": "Declarative data binding facility.", 4 "description": "Declarative data binding facility.",
5 "version": "0.5.0", 5 "version": "0.5.1",
6 "keywords": ["data binding", "templating"], 6 "keywords": ["data binding", "templating"],
7 "scripts": ["dist/rivets.js"], 7 "scripts": ["dist/rivets.js"],
8 "main": "dist/rivets.js", 8 "main": "dist/rivets.js",
......
1 // rivets.js 1 // Rivets.js
2 // version: 0.5.0 2 // version: 0.5.1
3 // author: Michael Richards 3 // author: Michael Richards
4 // license: MIT 4 // license: MIT
5 (function() { 5 (function() {
6 var Rivets, bindEvent, factory, getInputValue, unbindEvent, 6 var Rivets,
7 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 7 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
8 __slice = [].slice, 8 __slice = [].slice,
9 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; 9 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
...@@ -58,14 +58,14 @@ ...@@ -58,14 +58,14 @@
58 } 58 }
59 59
60 Binding.prototype.formattedValue = function(value) { 60 Binding.prototype.formattedValue = function(value) {
61 var args, formatter, id, _i, _len, _ref, _ref1, _ref2, _ref3; 61 var args, formatter, id, _i, _len, _ref;
62 62
63 _ref = this.formatters; 63 _ref = this.formatters;
64 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 64 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
65 formatter = _ref[_i]; 65 formatter = _ref[_i];
66 args = formatter.split(/\s+/); 66 args = formatter.split(/\s+/);
67 id = args.shift(); 67 id = args.shift();
68 formatter = this.model[id] instanceof Function ? this.model[id] : ((_ref1 = this.options) != null ? (_ref2 = _ref1.bindingOptions) != null ? (_ref3 = _ref2.formatters) != null ? _ref3[id] : void 0 : void 0 : void 0) instanceof Function ? this.options.bindingOptions.formatters[id] : this.view.formatters[id]; 68 formatter = this.model[id] instanceof Function ? this.model[id] : this.view.formatters[id];
69 if ((formatter != null ? formatter.read : void 0) instanceof Function) { 69 if ((formatter != null ? formatter.read : void 0) instanceof Function) {
70 value = formatter.read.apply(formatter, [value].concat(__slice.call(args))); 70 value = formatter.read.apply(formatter, [value].concat(__slice.call(args)));
71 } else if (formatter instanceof Function) { 71 } else if (formatter instanceof Function) {
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
89 Binding.prototype.publish = function() { 89 Binding.prototype.publish = function() {
90 var args, formatter, id, value, _i, _len, _ref, _ref1, _ref2; 90 var args, formatter, id, value, _i, _len, _ref, _ref1, _ref2;
91 91
92 value = getInputValue(this.el); 92 value = Rivets.Util.getInputValue(this.el);
93 _ref = this.formatters.slice(0).reverse(); 93 _ref = this.formatters.slice(0).reverse();
94 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 94 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
95 formatter = _ref[_i]; 95 formatter = _ref[_i];
...@@ -424,71 +424,71 @@ ...@@ -424,71 +424,71 @@
424 424
425 })(); 425 })();
426 426
427 bindEvent = function(el, event, handler, context) { 427 Rivets.Util = {
428 var fn; 428 bindEvent: function(el, event, handler, context) {
429 var fn;
429 430
430 fn = function(e) { 431 fn = function(e) {
431 return handler.call(context, e); 432 return handler.call(context, e);
432 }; 433 };
433 if (window.jQuery != null) { 434 if (window.jQuery != null) {
434 el = jQuery(el); 435 el = jQuery(el);
435 if (el.on != null) { 436 if (el.on != null) {
436 el.on(event, fn); 437 el.on(event, fn);
438 } else {
439 el.bind(event, fn);
440 }
441 } else if (window.addEventListener != null) {
442 el.addEventListener(event, fn, false);
437 } else { 443 } else {
438 el.bind(event, fn); 444 event = 'on' + event;
445 el.attachEvent(event, fn);
439 } 446 }
440 } else if (window.addEventListener != null) { 447 return fn;
441 el.addEventListener(event, fn, false); 448 },
442 } else { 449 unbindEvent: function(el, event, fn) {
443 event = 'on' + event; 450 if (window.jQuery != null) {
444 el.attachEvent(event, fn); 451 el = jQuery(el);
445 } 452 if (el.off != null) {
446 return fn; 453 return el.off(event, fn);
447 }; 454 } else {
448 455 return el.unbind(event, fn);
449 unbindEvent = function(el, event, fn) { 456 }
450 if (window.jQuery != null) { 457 } else if (window.removeEventListener) {
451 el = jQuery(el); 458 return el.removeEventListener(event, fn, false);
452 if (el.off != null) {
453 return el.off(event, fn);
454 } else { 459 } else {
455 return el.unbind(event, fn); 460 event = 'on' + event;
461 return el.detachEvent(event, fn);
456 } 462 }
457 } else if (window.removeEventListener) { 463 },
458 return el.removeEventListener(event, fn, false); 464 getInputValue: function(el) {
459 } else { 465 var o, _i, _len, _results;
460 event = 'on' + event; 466
461 return el.detachEvent(event, fn); 467 if (window.jQuery != null) {
462 } 468 el = jQuery(el);
463 }; 469 switch (el[0].type) {
464 470 case 'checkbox':
465 getInputValue = function(el) { 471 return el.is(':checked');
466 var o, _i, _len, _results; 472 default:
467 473 return el.val();
468 if (window.jQuery != null) { 474 }
469 el = jQuery(el); 475 } else {
470 switch (el[0].type) { 476 switch (el.type) {
471 case 'checkbox': 477 case 'checkbox':
472 return el.is(':checked'); 478 return el.checked;
473 default: 479 case 'select-multiple':
474 return el.val(); 480 _results = [];
475 } 481 for (_i = 0, _len = el.length; _i < _len; _i++) {
476 } else { 482 o = el[_i];
477 switch (el.type) { 483 if (o.selected) {
478 case 'checkbox': 484 _results.push(o.value);
479 return el.checked; 485 }
480 case 'select-multiple':
481 _results = [];
482 for (_i = 0, _len = el.length; _i < _len; _i++) {
483 o = el[_i];
484 if (o.selected) {
485 _results.push(o.value);
486 } 486 }
487 } 487 return _results;
488 return _results; 488 break;
489 break; 489 default:
490 default: 490 return el.value;
491 return el.value; 491 }
492 } 492 }
493 } 493 }
494 }; 494 };
...@@ -503,10 +503,10 @@ ...@@ -503,10 +503,10 @@
503 checked: { 503 checked: {
504 publishes: true, 504 publishes: true,
505 bind: function(el) { 505 bind: function(el) {
506 return this.currentListener = bindEvent(el, 'change', this.publish); 506 return this.currentListener = Rivets.Util.bindEvent(el, 'change', this.publish);
507 }, 507 },
508 unbind: function(el) { 508 unbind: function(el) {
509 return unbindEvent(el, 'change', this.currentListener); 509 return Rivets.Util.unbindEvent(el, 'change', this.currentListener);
510 }, 510 },
511 routine: function(el, value) { 511 routine: function(el, value) {
512 var _ref; 512 var _ref;
...@@ -521,10 +521,10 @@ ...@@ -521,10 +521,10 @@
521 unchecked: { 521 unchecked: {
522 publishes: true, 522 publishes: true,
523 bind: function(el) { 523 bind: function(el) {
524 return this.currentListener = bindEvent(el, 'change', this.publish); 524 return this.currentListener = Rivets.Util.bindEvent(el, 'change', this.publish);
525 }, 525 },
526 unbind: function(el) { 526 unbind: function(el) {
527 return unbindEvent(el, 'change', this.currentListener); 527 return Rivets.Util.unbindEvent(el, 'change', this.currentListener);
528 }, 528 },
529 routine: function(el, value) { 529 routine: function(el, value) {
530 var _ref; 530 var _ref;
...@@ -548,10 +548,10 @@ ...@@ -548,10 +548,10 @@
548 value: { 548 value: {
549 publishes: true, 549 publishes: true,
550 bind: function(el) { 550 bind: function(el) {
551 return this.currentListener = bindEvent(el, 'change', this.publish); 551 return this.currentListener = Rivets.Util.bindEvent(el, 'change', this.publish);
552 }, 552 },
553 unbind: function(el) { 553 unbind: function(el) {
554 return unbindEvent(el, 'change', this.currentListener); 554 return Rivets.Util.unbindEvent(el, 'change', this.currentListener);
555 }, 555 },
556 routine: function(el, value) { 556 routine: function(el, value) {
557 var o, _i, _len, _ref, _ref1, _ref2, _results; 557 var o, _i, _len, _ref, _ref1, _ref2, _results;
...@@ -588,9 +588,9 @@ ...@@ -588,9 +588,9 @@
588 "function": true, 588 "function": true,
589 routine: function(el, value) { 589 routine: function(el, value) {
590 if (this.currentListener) { 590 if (this.currentListener) {
591 unbindEvent(el, this.args[0], this.currentListener); 591 Rivets.Util.unbindEvent(el, this.args[0], this.currentListener);
592 } 592 }
593 return this.currentListener = bindEvent(el, this.args[0], value, this.model); 593 return this.currentListener = Rivets.Util.bindEvent(el, this.args[0], value, this.model);
594 } 594 }
595 }, 595 },
596 "each-*": { 596 "each-*": {
...@@ -676,7 +676,7 @@ ...@@ -676,7 +676,7 @@
676 676
677 Rivets.formatters = {}; 677 Rivets.formatters = {};
678 678
679 factory = function(exports) { 679 Rivets.factory = function(exports) {
680 exports.binders = Rivets.binders; 680 exports.binders = Rivets.binders;
681 exports.formatters = Rivets.formatters; 681 exports.formatters = Rivets.formatters;
682 exports.config = Rivets.config; 682 exports.config = Rivets.config;
...@@ -707,14 +707,14 @@ ...@@ -707,14 +707,14 @@
707 }; 707 };
708 708
709 if (typeof exports === 'object') { 709 if (typeof exports === 'object') {
710 factory(exports); 710 Rivets.factory(exports);
711 } else if (typeof define === 'function' && define.amd) { 711 } else if (typeof define === 'function' && define.amd) {
712 define(['exports'], function(exports) { 712 define(['exports'], function(exports) {
713 factory(this.rivets = exports); 713 Rivets.factory(this.rivets = exports);
714 return exports; 714 return exports;
715 }); 715 });
716 } else { 716 } else {
717 factory(this.rivets = {}); 717 Rivets.factory(this.rivets = {});
718 } 718 }
719 719
720 }).call(this); 720 }).call(this);
......
1 { 1 {
2 "name": "rivets", 2 "name": "rivets",
3 "description": "Declarative data binding facility.", 3 "description": "Declarative data binding facility.",
4 "version": "0.5.0", 4 "version": "0.5.1",
5 "author": "Michael Richards", 5 "author": "Michael Richards",
6 "url": "http://rivetsjs.com", 6 "url": "http://rivetsjs.com",
7 "main": "./dist/rivets.js", 7 "main": "./dist/rivets.js",
......
1 # Rivets.js 1 # Rivets.js
2 # ========= 2 # =========
3 3
4 # > version: 0.5.0 4 # > version: 0.5.1
5 # > author: Michael Richards 5 # > author: Michael Richards
6 # > license: MIT 6 # > license: MIT
7 # > 7 # >
......