8c37555a by Michael Richards

Build 0.3.3.

1 parent 07983619
1 // rivets.js 1 // rivets.js
2 // version: 0.3.2 2 // version: 0.3.3
3 // author: Michael Richards 3 // author: Michael Richards
4 // license: MIT 4 // license: MIT
5 (function() { 5 (function() {
6 var Rivets, attributeBinding, bindEvent, eventBinding, getInputValue, iterationBinding, rivets, unbindEvent, 6 var Rivets, attributeBinding, bindEvent, classBinding, eventBinding, getInputValue, iterationBinding, rivets, unbindEvent,
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; };
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
38 switch (this.options.special) { 38 switch (this.options.special) {
39 case "event": 39 case "event":
40 return eventBinding(this.type); 40 return eventBinding(this.type);
41 case "class":
42 return classBinding(this.type);
41 case "iteration": 43 case "iteration":
42 return iterationBinding(this.type); 44 return iterationBinding(this.type);
43 default: 45 default:
...@@ -161,13 +163,14 @@ ...@@ -161,13 +163,14 @@
161 }; 163 };
162 164
163 View.prototype.build = function() { 165 View.prototype.build = function() {
164 var bindingRegExp, el, eventRegExp, iterationRegExp, iterator, node, parseNode, skipNodes, _i, _len, _ref, _results, 166 var bindingRegExp, classRegExp, el, eventRegExp, iterationRegExp, iterator, node, parseNode, skipNodes, _i, _len, _ref, _results,
165 _this = this; 167 _this = this;
166 this.bindings = []; 168 this.bindings = [];
167 skipNodes = []; 169 skipNodes = [];
168 iterator = null; 170 iterator = null;
169 bindingRegExp = this.bindingRegExp(); 171 bindingRegExp = this.bindingRegExp();
170 eventRegExp = /^on-/; 172 eventRegExp = /^on-/;
173 classRegExp = /^class-/;
171 iterationRegExp = /^each-/; 174 iterationRegExp = /^each-/;
172 parseNode = function(node) { 175 parseNode = function(node) {
173 var a, attribute, binding, context, ctx, dependencies, keypath, model, n, options, path, pipe, pipes, splitPath, type, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _results; 176 var a, attribute, binding, context, ctx, dependencies, keypath, model, n, options, path, pipe, pipes, splitPath, type, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _results;
...@@ -230,6 +233,10 @@ ...@@ -230,6 +233,10 @@
230 type = type.replace(eventRegExp, ''); 233 type = type.replace(eventRegExp, '');
231 options.special = "event"; 234 options.special = "event";
232 } 235 }
236 if (classRegExp.test(type)) {
237 type = type.replace(classRegExp, '');
238 options.special = "class";
239 }
233 if (iterationRegExp.test(type)) { 240 if (iterationRegExp.test(type)) {
234 type = type.replace(iterationRegExp, ''); 241 type = type.replace(iterationRegExp, '');
235 options.special = "iteration"; 242 options.special = "iteration";
...@@ -335,6 +342,17 @@ ...@@ -335,6 +342,17 @@
335 }; 342 };
336 }; 343 };
337 344
345 classBinding = function(name) {
346 return function(el, value) {
347 var elClass, hasClass;
348 elClass = " " + el.className + " ";
349 hasClass = elClass.indexOf(" " + name + " ") !== -1;
350 if (!value === hasClass) {
351 return el.className = value ? "" + el.className + " " + name : elClass.replace(" " + name + " ", " ").trim();
352 }
353 };
354 };
355
338 iterationBinding = function(name) { 356 iterationBinding = function(name) {
339 return function(el, collection, binding) { 357 return function(el, collection, binding) {
340 var data, item, itemEl, iteration, m, n, previous, _i, _j, _len, _len1, _ref, _ref1, _results; 358 var data, item, itemEl, iteration, m, n, previous, _i, _j, _len, _len1, _ref, _ref1, _results;
......
1 { 1 {
2 "name" : "rivets", 2 "name" : "rivets",
3 "description" : "Declarative data binding facility.", 3 "description" : "Declarative data binding facility.",
4 "version" : "0.3.2", 4 "version" : "0.3.3",
5 "author" : "Michael Richards", 5 "author" : "Michael Richards",
6 "url" : "http://rivetsjs.com", 6 "url" : "http://rivetsjs.com",
7 "main" : "./lib/rivets.js", 7 "main" : "./lib/rivets.js",
......
1 # rivets.js 1 # rivets.js
2 # version : 0.3.2 2 # version : 0.3.3
3 # author : Michael Richards 3 # author : Michael Richards
4 # license : MIT 4 # license : MIT
5 5
......