Skip to content

Commit

Permalink
bug fix and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
qstufie committed Mar 5, 2016
1 parent dcd1b3b commit bcb882c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
1.1.3
15 changes: 9 additions & 6 deletions dist/simple.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function _c(obj) {
var app;
app = function (name, cnf) {
// current version from build
this.version = '1.1.2';
this.version = '1.1.3';
this.aName = name;
// defaults
name = _s(name).hashCode();
Expand Down Expand Up @@ -159,7 +159,6 @@ app = function (name, cnf) {
wrd: {},
drd: {},
rde: {},
ped: {},
siu: {}
};

Expand Down Expand Up @@ -467,11 +466,10 @@ app = function (name, cnf) {
* @returns {{}}
*/
this.parseElementData = function (elName, state, data, type, subNodeCnt) {
// name to default - this is for inputs with names
if (!data.name) data.name = elName;
var attrs = [], parsedData = {};
if (!data) data = {};
// check if callback is registered
var c = this.getCallback('ped', elName);
if (typeof c == 'function') return c(state, data);
if (subNodeCnt > 0) {
attrs.push('data-index="' + (subNodeCnt - 1) + '"');
if (type != 'select') {
Expand All @@ -496,6 +494,10 @@ app = function (name, cnf) {
event = 'on' + data._e_;
}
var act = prefix + '.updateState(this)';
// event is not for options. thus
if (type == 'select' & subNodeCnt > 0) {
event = null;
}
if (event) {
parsedData.act = act;
attrs.push(event + '="' + act + '"');
Expand Down Expand Up @@ -561,9 +563,10 @@ app = function (name, cnf) {
parsedData[secKey] = tmp.join(' ');
}
}
// removed: state for selected item - do it yourself
// removed default attr for selected/checked
console.log('=> Parsed Data:', parsedData);
parsedData.attr = attrs.join(' ');
// finally, return it
return parsedData;
};
/**
Expand Down
36 changes: 17 additions & 19 deletions dist/simple.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ if(0===this.length)return i
for(t=0,a=this.length;a>t;t++)e=this.charCodeAt(t),i=(i<<5)-i+e,i|=0
return Math.abs(i)}
var o
o=function(t,o){this.version="1.1.2",this.aName=t,t=n(t).hashCode()
o=function(t,o){this.version="1.1.3",this.aName=t,t=n(t).hashCode()
var l="_sj_"+t
if(this.name=t,r[l]=this,this.localStorageKey=l+"_data",this.container=null,this.state={},this.pState={},this.cnf={localStorageWrite:!0,localStorageRead:!0,partialRender:!0},"object"==typeof o)for(var p in o)this.cnf[p]=o[p]
this.callbacks={sta:{},fin:{},wrd:{},drd:{},rde:{},ped:{},siu:{}},this.getCallback=function(t,e){return e?"function"==typeof this.callbacks[t][e]?this.callbacks[t][e]:void 0:this.callbacks[t]},this.on=function(t,e,a){"object"==typeof this.callbacks[t]&&"function"==typeof a&&(this.callbacks[t][e]=a)},this._f=function(t){var e=this.getCallback(t)
this.callbacks={sta:{},fin:{},wrd:{},drd:{},rde:{},siu:{}},this.getCallback=function(t,e){return e?"function"==typeof this.callbacks[t][e]?this.callbacks[t][e]:void 0:this.callbacks[t]},this.on=function(t,e,a){"object"==typeof this.callbacks[t]&&"function"==typeof a&&(this.callbacks[t][e]=a)},this._f=function(t){var e=this.getCallback(t)
if("object"==typeof e)for(var a in e){var i=e[a]
"function"==typeof i&&i()}},this.updateState=function(t,e){var a,i,n
if("string"==typeof t)a=t,i=e,this.state[t]=e
Expand All @@ -34,23 +34,21 @@ 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,n){var s=[],r={}
a||(a={})
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")
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){a.name||(a.name=t)
var s=[],r={}
a||(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 h=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_&&(h="on"+a._e_)
var o=l+".updateState(this)"
"select"==i&n>0&&(h=null),h&&(r.act=o,s.push(h+'="'+o+'"'))
for(var p in a){var c=a[p]
"object"!=typeof c&&(p.indexOf("_")<0&&s.push(p+'="'+c+'"'),r[p]=c)}var f=this.template.sub[t]
if("object"==typeof f._sects)for(var d in f._sects){var u=[],v="attr-"+d,m="object"==typeof a[d]?a[d]:{},y=f._sects[d]
if("object"==typeof y){for(var b in y)m[b]=y[b]
if(y._type){var g=this.getEvent(y._type)
g&&u.push(g+'="'+o+'"')}y._action&&u.push('data-action="'+y._action+'"')}m._e_&&u.push("on"+m._e_+'="'+o+'"')
for(var _ in m)_.indexOf("_")<0?u.push(_+'="'+m[_]+'"'):r[_]=m[_]
u.push('data-name="'+t+'"'),u.push('name="'+t+'"'),n>0&&u.push('data-index="'+(n-1)+'"'),r[v]=u.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 Down
13 changes: 8 additions & 5 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ app = function (name, cnf) {
wrd: {},
drd: {},
rde: {},
ped: {},
siu: {}
};

Expand Down Expand Up @@ -466,11 +465,10 @@ app = function (name, cnf) {
* @returns {{}}
*/
this.parseElementData = function (elName, state, data, type, subNodeCnt) {
// name to default - this is for inputs with names
if (!data.name) data.name = elName;
var attrs = [], parsedData = {};
if (!data) data = {};
// check if callback is registered
var c = this.getCallback('ped', elName);
if (typeof c == 'function') return c(state, data);
if (subNodeCnt > 0) {
attrs.push('data-index="' + (subNodeCnt - 1) + '"');
if (type != 'select') {
Expand All @@ -495,6 +493,10 @@ app = function (name, cnf) {
event = 'on' + data._e_;
}
var act = prefix + '.updateState(this)';
// event is not for options. thus
if (type == 'select' & subNodeCnt > 0) {
event = null;
}
if (event) {
parsedData.act = act;
attrs.push(event + '="' + act + '"');
Expand Down Expand Up @@ -560,9 +562,10 @@ app = function (name, cnf) {
parsedData[secKey] = tmp.join(' ');
}
}
// removed: state for selected item - do it yourself
// removed default attr for selected/checked
console.log('=> Parsed Data:', parsedData);
parsedData.attr = attrs.join(' ');
// finally, return it
return parsedData;
};
/**
Expand Down

0 comments on commit bcb882c

Please sign in to comment.