Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Don't overwrite classes specified in expression

  • Loading branch information...
commit 609907920542feab4a4c70c2974dc1587db02be5 1 parent 3d9c846
Felix Gnass authored

Showing 3 changed files with 7 additions and 3 deletions. Show diff stats Hide diff stats

  1. +1 0  mkay.js
  2. +0 2  mkay.min.js
  3. +6 1 test.html
1  mkay.js
@@ -47,6 +47,7 @@ function mk(jsonml) {
47 47 $.each(attrs, function(name, val) {
48 48 m = re.event.exec(name)
49 49 if (m) chain.on(m[1], val)
  50 + else if (name == 'class') chain.addClass(val)
50 51 else chain.attr(name, val)
51 52 })
52 53
2  mkay.min.js
... ... @@ -1,2 +0,0 @@
1   -//github.com/fgnass/mkay
2   -!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
@@ -77,11 +77,16 @@
77 77
78 78 test('attr', function() {
79 79 var el = $.mk('input.text[type=checkbox][name=foo]')[0];
80   - equal(el.className, 'text', 'clas must be text');
  80 + equal(el.className, 'text', 'class must be text');
81 81 equal(el.type, 'checkbox', 'type must be set to checkbox');
82 82 equal(el.name, 'foo', 'name must be set to foo');
83 83 })
84 84
  85 +test('double class', function() {
  86 + var el = $.mk('.foo', {'class': 'bar'})[0];
  87 + equal(el.className, 'foo bar', 'class must match');
  88 +})
  89 +
85 90 test("JsonML", function() {
86 91 var el = $.mk(
87 92 ['a', {href: '#'},

0 comments on commit 6099079

Please sign in to comment.
Something went wrong with that request. Please try again.