Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qstufie committed Mar 5, 2016
1 parent 75de3fe commit dcd1b3b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 53 deletions.
21 changes: 6 additions & 15 deletions dist/simple.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,6 @@ app = function (name, cnf) {
// check if callback is registered
var c = this.getCallback('ped', elName);
if (typeof c == 'function') return c(state, data);
// build attr
attrs.push('data-name="' + elName + '"');
attrs.push('data-state="' + state + '"');

if (subNodeCnt > 0) {
attrs.push('data-index="' + (subNodeCnt - 1) + '"');
if (type != 'select') {
Expand All @@ -490,6 +486,10 @@ app = function (name, cnf) {
var event = this.getEvent(type);
if (type == 'input' && !data.value) {
data.value = state;
// build attr for these things
attrs.push('data-name="' + elName + '"');
attrs.push('name="' + elName + '"');
attrs.push('data-state="' + state + '"');
}
// override
if (data._e_) {
Expand Down Expand Up @@ -553,24 +553,15 @@ app = function (name, cnf) {
}
// add index
tmp.push('data-name="' + elName + '"');
tmp.push('name="' + elName + '"');
if (subNodeCnt > 0) {
tmp.push('data-index="' + (subNodeCnt - 1) + '"');
}
// compose
parsedData[secKey] = tmp.join(' ');
}
}


// select attribute for items
if (subNodeCnt > 0 && _s(state).indexOf(_s(data.value)) >= 0) {
if (type == 'select') {
attrs.push('selected="selected"');
}
if (type == 'checkbox' || type == 'radio') {
attrs.push('checked="checked"');
}
}
// removed: state for selected item - do it yourself
console.log('=> Parsed Data:', parsedData);
parsedData.attr = attrs.join(' ');
return parsedData;
Expand Down
46 changes: 23 additions & 23 deletions dist/simple.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ i=i.replace(s,r)}return a!==!0&&(i=i.replace(/{[^<>}]+}/gi,"").replace(/{>([^}]+
if(!t)return
try{this.state=JSON.parse(t)}catch(e){}}},this.template={main:{},sub:{}},this.data={},this.pData={},this.els=function(t,e,a){if(a._style)return a._style
if(e){var i=n(e),s=n(a.value)
return i.indexOf(s)>=0?"selected":"default"}return"default"},this.eId=function(t){return l+"_el_"+t},this.getEvent=function(t){return t&&""!==t?"select"===t?"onchange":"form"===t?"onsubmit":"input"===t?"onkeyup":"onclick":void 0},this.parseElementData=function(t,e,a,i,s){var r=[],h={}
return i.indexOf(s)>=0?"selected":"default"}return"default"},this.eId=function(t){return l+"_el_"+t},this.getEvent=function(t){return t&&""!==t?"select"===t?"onchange":"form"===t?"onsubmit":"input"===t?"onkeyup":"onclick":void 0},this.parseElementData=function(t,e,a,i,n){var s=[],r={}
a||(a={})
var o=this.getCallback("ped",t)
if("function"==typeof o)return o(e,a)
r.push('data-name="'+t+'"'),r.push('data-state="'+e+'"'),s>0?(r.push('data-index="'+(s-1)+'"'),"select"!=i&&(a.id||(a.id=this.eId(t+"_"+s)))):a.id||(a.id=this.eId(t)),h.id=a.id
var p=this.getEvent(i)
"input"!=i||a.value||(a.value=e),a._e_&&(p="on"+a._e_)
var c=l+".updateState(this)"
p&&(h.act=c,r.push(p+'="'+c+'"'))
for(var f in a){var d=a[f]
"object"!=typeof d&&(f.indexOf("_")<0&&r.push(f+'="'+d+'"'),h[f]=d)}var u=this.template.sub[t]
if("object"==typeof u._sects)for(var v in u._sects){var m=[],y="attr-"+v,b="object"==typeof a[v]?a[v]:{},g=u._sects[v]
if("object"==typeof g){for(var _ in g)b[_]=g[_]
if(g._type){var S=this.getEvent(g._type)
S&&m.push(S+'="'+c+'"')}g._action&&m.push('data-action="'+g._action+'"')}b._e_&&m.push("on"+b._e_+'="'+c+'"')
for(var k in b)k.indexOf("_")<0?m.push(k+'="'+b[k]+'"'):h[k]=b[k]
m.push('data-name="'+t+'"'),s>0&&m.push('data-index="'+(s-1)+'"'),h[y]=m.join(" ")}return s>0&&n(e).indexOf(n(a.value))>=0&&("select"==i&&r.push('selected="selected"'),("checkbox"==i||"radio"==i)&&r.push('checked="checked"')),h.attr=r.join(" "),h},this.node=function(t){return i(this.eId(t))},this.style="default",this.render=function(t){if(e(),this._f("wrd"),!this.container)throw new Error("Invalid container specified")
var h=this.getCallback("ped",t)
if("function"==typeof h)return h(e,a)
n>0?(s.push('data-index="'+(n-1)+'"'),"select"!=i&&(a.id||(a.id=this.eId(t+"_"+n)))):a.id||(a.id=this.eId(t)),r.id=a.id
var o=this.getEvent(i)
"input"!=i||a.value||(a.value=e,s.push('data-name="'+t+'"'),s.push('name="'+t+'"'),s.push('data-state="'+e+'"')),a._e_&&(o="on"+a._e_)
var p=l+".updateState(this)"
o&&(r.act=p,s.push(o+'="'+p+'"'))
for(var c in a){var f=a[c]
"object"!=typeof f&&(c.indexOf("_")<0&&s.push(c+'="'+f+'"'),r[c]=f)}var d=this.template.sub[t]
if("object"==typeof d._sects)for(var u in d._sects){var v=[],m="attr-"+u,y="object"==typeof a[u]?a[u]:{},b=d._sects[u]
if("object"==typeof b){for(var g in b)y[g]=b[g]
if(b._type){var _=this.getEvent(b._type)
_&&v.push(_+'="'+p+'"')}b._action&&v.push('data-action="'+b._action+'"')}y._e_&&v.push("on"+y._e_+'="'+p+'"')
for(var S in y)S.indexOf("_")<0?v.push(S+'="'+y[S]+'"'):r[S]=y[S]
v.push('data-name="'+t+'"'),v.push('name="'+t+'"'),n>0&&v.push('data-index="'+(n-1)+'"'),r[m]=v.join(" ")}return r.attr=s.join(" "),r},this.node=function(t){return i(this.eId(t))},this.style="default",this.render=function(t){if(e(),this._f("wrd"),!this.container)throw new Error("Invalid container specified")
var i=this.template.main[this.style],r={}
if(!i)throw new Error("Invalid master template for style: "+this.style)
if(t===!0&&(this.pData={}),!a(this.data)&&n(this.pData)!=n(this.data)){var h=a(this.pData)
Expand All @@ -73,14 +73,14 @@ if(!f.cnf.partialRender||e||b)o+=f.htpl(p,d)
else{var u=v-1,m=f.pData[t].element[u],y=f.data[t].element[u],_=null,S=f.node(t+"_"+v)
if(!g&&S&&(g=S.parentNode),n(m)==n(y))return
_=f.htpl(p,d)
var k
g&&(S?_&&(k=new h(_,g),k.replace(S)):g&&(k=new h(_,g),k.right()))}}),g&&y.length>u.length&&y.map(function(e,a){if(a>=v){var i=f.node(t+"_"+(a+1))
var w
g&&(S?_&&(w=new h(_,g),w.replace(S)):g&&(w=new h(_,g),w.right()))}}),g&&y.length>u.length&&y.map(function(e,a){if(a>=v){var i=f.node(t+"_"+(a+1))
i&&g.removeChild(i)}}),!("string"==typeof o&&o.length>1||0===v))return!1
o=f.htpl(c._wrapper[0],d)+o+c._wrapper[1]}else{var _=this.els(t,r,i),S=this.template.sub[t][_],k=this.parseElementData(t,r,i,c._type)
S||(S=this.template.sub[t]["default"]),o=this.htpl(S,k)}if(this.template.sub[t]._sibling){var w=this.node(this.template.sub[t]._sibling)
if(w){var j=new h(o,w.parentNode)
return j.right(),!1}}if(!e&&this.cnf.partialRender===!0&&o){var E=this.node(t),x=null
if(E)return x=new h(o),x.replace(E),!1}return o},this.init=function(t,e){t&&(this.container=t),this.load(),e!==!1&&(this._f("sta"),this.render(),this._f("fin"))},this.toQuerystring=function(){var t=[]
o=f.htpl(c._wrapper[0],d)+o+c._wrapper[1]}else{var _=this.els(t,r,i),S=this.template.sub[t][_],w=this.parseElementData(t,r,i,c._type)
S||(S=this.template.sub[t]["default"]),o=this.htpl(S,w)}if(this.template.sub[t]._sibling){var j=this.node(this.template.sub[t]._sibling)
if(j){var k=new h(o,j.parentNode)
return k.right(),!1}}if(!e&&this.cnf.partialRender===!0&&o){var E=this.node(t),D=null
if(E)return D=new h(o),D.replace(E),!1}return o},this.init=function(t,e){t&&(this.container=t),this.load(),e!==!1&&(this._f("sta"),this.render(),this._f("fin"))},this.toQuerystring=function(){var t=[]
for(var e in this.state){var a=this.state[e]
a&&t.push(e+"="+a)}return t.join("&")},this.d=function(t,e){return e?"object"==typeof this.data[t].element&&this.data[t].element[e]?this.data[t].element[e]:void 0:this.data[t]}}
var l={},p=function(t,e){return l[t]||(l[t]=new o(t,e)),l[t]}
Expand Down
21 changes: 6 additions & 15 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,6 @@ app = function (name, cnf) {
// check if callback is registered
var c = this.getCallback('ped', elName);
if (typeof c == 'function') return c(state, data);
// build attr
attrs.push('data-name="' + elName + '"');
attrs.push('data-state="' + state + '"');

if (subNodeCnt > 0) {
attrs.push('data-index="' + (subNodeCnt - 1) + '"');
if (type != 'select') {
Expand All @@ -489,6 +485,10 @@ app = function (name, cnf) {
var event = this.getEvent(type);
if (type == 'input' && !data.value) {
data.value = state;
// build attr for these things
attrs.push('data-name="' + elName + '"');
attrs.push('name="' + elName + '"');
attrs.push('data-state="' + state + '"');
}
// override
if (data._e_) {
Expand Down Expand Up @@ -552,24 +552,15 @@ app = function (name, cnf) {
}
// add index
tmp.push('data-name="' + elName + '"');
tmp.push('name="' + elName + '"');
if (subNodeCnt > 0) {
tmp.push('data-index="' + (subNodeCnt - 1) + '"');
}
// compose
parsedData[secKey] = tmp.join(' ');
}
}


// select attribute for items
if (subNodeCnt > 0 && _s(state).indexOf(_s(data.value)) >= 0) {
if (type == 'select') {
attrs.push('selected="selected"');
}
if (type == 'checkbox' || type == 'radio') {
attrs.push('checked="checked"');
}
}
// removed: state for selected item - do it yourself
console.log('=> Parsed Data:', parsedData);
parsedData.attr = attrs.join(' ');
return parsedData;
Expand Down

0 comments on commit dcd1b3b

Please sign in to comment.