Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't overwrite classes specified in expression

  • Loading branch information...
commit 609907920542feab4a4c70c2974dc1587db02be5 1 parent 3d9c846
Felix Gnass authored
Showing with 7 additions and 3 deletions.
  1. +1 −0  mkay.js
  2. +0 −2  mkay.min.js
  3. +6 −1 test.html
1  mkay.js
View
@@ -47,6 +47,7 @@ function mk(jsonml) {
$.each(attrs, function(name, val) {
m = re.event.exec(name)
if (m) chain.on(m[1], val)
+ else if (name == 'class') chain.addClass(val)
else chain.attr(name, val)
})
2  mkay.min.js
View
@@ -1,2 +0,0 @@
-//github.com/fgnass/mkay
-!function(a,b){function d(a){if(!a||a.constructor!=Object)return!1;var b;for(b in a);return b===undefined||a.hasOwnProperty(b)}function e(f){if(!b.isArray(f))return a.createTextNode(f);var g=f[0],h=f[1],i=(c.tag.exec(g||"")||[0,"div"])[1],j=c.id.exec(g),k=c.cls.exec(g),l=a.createElement(i),m=b(l);j&&(l.id=j[1]),k&&(l.className=k[1].replace(c.dots," "));var n;while(n=c.attr.exec(g))l.setAttribute(n[1],n[2]);d(h)||f.splice(1,0,h={}),b.each(h,function(a,b){n=c.event.exec(a),n?m.on(n[1],b):m.attr(a,b)});for(var o=2;o<f.length;o++){var p=f[o];p.appendTo?p.appendTo(l):m.append(e(p))}return l}var c={tag:/^(\w+)/,id:/#([\w_\-]+)/,cls:/\.([^#\[]+)/,attr:/\[(.+?)=(.+?)\]/g,event:/^on(.+)/,dots:/\./g};b.mk=function(a){var c=Array.prototype.slice.call(arguments);if(!b.isArray(a))a=c;else if(c.length>1)return b(b.map(c,e));return b(e(a))},b.fn.mk=function(a){var c=(this.constructor.mk||b.mk).apply(this,arguments);return c._=this.append(c),c}}(document,this.jQuery||this.Zepto);
7 test.html
View
@@ -77,11 +77,16 @@
test('attr', function() {
var el = $.mk('input.text[type=checkbox][name=foo]')[0];
- equal(el.className, 'text', 'clas must be text');
+ equal(el.className, 'text', 'class must be text');
equal(el.type, 'checkbox', 'type must be set to checkbox');
equal(el.name, 'foo', 'name must be set to foo');
})
+test('double class', function() {
+ var el = $.mk('.foo', {'class': 'bar'})[0];
+ equal(el.className, 'foo bar', 'class must match');
+})
+
test("JsonML", function() {
var el = $.mk(
['a', {href: '#'},
Please sign in to comment.
Something went wrong with that request. Please try again.