Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

riverjs

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

riverjs - npm Package Compare versions

Comparing version 1.0.74 to 1.0.81

lib/main/ready.js

2

bower.json
{
"name": "riverjs",
"version": "1.0.74",
"version": "1.0.81",
"main": "dist/river.js",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/zhang-ning/RiverJS",

@@ -77,3 +77,4 @@ /*

if (doc.attributes && doc.attributes.length) {
tool.loop(doc.attributes, function(attr) {
for(var i = 0;i<doc.attributes.length;i++){
var attr= doc.attributes[i];
var key = attr.nodeName;

@@ -83,5 +84,2 @@ var value = attr.nodeValue.replace(reg, '');

if ('repeat' === key) {
state.hasRepeat = true;
}
if ('scope' === key) {

@@ -108,3 +106,7 @@ //here we cover the current context by newContext;

}
});
if ('repeat' === key) {
state.hasRepeat = true;
break;
}
}
}

@@ -133,2 +135,3 @@ return state;

value = typeof value == 'object' ? JSON.stringify(value) : value;
if(typeof value == 'undefined') value = '';
doc.nodeValue = doc.nodeValue.replace(/\r|\n/g,'').replace(/{{.*}}/, value);

@@ -166,15 +169,59 @@ }

/*!
* contentloaded.js
*
* Author: Diego Perini (diego.perini at gmail.com)
* Summary: cross-browser wrapper for DOMContentLoaded
* Updated: 20101020
* License: MIT
* Version: 1.2
*
* URL:
* http://javascript.nwbox.com/ContentLoaded/
* http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
*
*/
// @win window reference
// @fn function reference
function contentLoaded(win, fn) {
var done = false, top = true,
doc = win.document, root = doc.documentElement,
add = doc.addEventListener ? 'addEventListener' : 'attachEvent',
rem = doc.addEventListener ? 'removeEventListener' : 'detachEvent',
pre = doc.addEventListener ? '' : 'on',
init = function(e) {
if (e.type == 'readystatechange' && doc.readyState != 'complete') return;
(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
if (!done && (done = true)) fn.call(win, e.type || e);
},
poll = function() {
try { root.doScroll('left'); } catch(e) { setTimeout(poll, 50); return; }
init('poll');
};
if (doc.readyState == 'complete') fn.call(win, 'lazy');
else {
if (doc.createEventObject && root.doScroll) {
try { top = !win.frameElement; } catch(e) { }
if (top) poll();
}
doc[add](pre + 'DOMContentLoaded', init, false);
doc[add](pre + 'readystatechange', init, false);
win[add](pre + 'load', init, false);
}
}
return {
scan:scan
scan:scan,
ready:contentLoaded
};
});
main(function(){
var me = this;
document.addEventListener('DOMContentLoaded', function() {
var scan = me.need('river.engine').scan;
scan(document);
});
});
define('river.scenario',function(){

@@ -265,3 +312,3 @@

var _eoms = {}, lasts = {} , me = this;
var me = this;

@@ -275,4 +322,7 @@ var isArray = tools.isArray;

function update(value, key, eom ,oldvalue) {
function update(value, key, eom ,last) {
var scope = this;
var oldvalue = last[key];
var isEqual = value == oldvalue;
if(isEqual) return;
if (isString(value) || isNumber(value)) {

@@ -287,29 +337,17 @@ if(eom && eom[key]){

});
var fns = scope.__listeners__ && scope.__listeners__[key] ;
if(fns){
for (var i = 0, len = fns.length; i < len; i++) {
fns[i](value,last[key]);
}
}
}
last[key] = value;
} else if (isArray(value)) {
oldvalue = oldvalue ? oldvalue : [];
var children = eom[key].repeatContainer.children;
var length = value.length - children.length
, len = Math.abs(length)
, addItems = length > 0
, removeItems = length < 0;
if(addItems){
var vv = value.slice(value.length-len,value.length);
for(var i = 0;i<len;i++){
buildNewEom(eom[key],vv);
}
}else if(removeItems){
Array.prototype.splice.call(eom[key],0,len);
for(var k= 0;k<len;k++){
children[k].parentNode.removeChild(children[k]);
}
}
loop(value, function(item, index) {
updateGrammar(eom[key][index],item);
update.call(scope,item, index, eom[key][index],oldvalue[index]);
});
last[key] = oldvalue ? oldvalue : [];
diff(value,last[key],eom[key],scope,key,last);
} else if (isObject(value)) {
oldvalue = oldvalue ? oldvalue : {};
each(value, function(item, index) {
update.call(scope,item, index, eom , oldvalue[index]);
update.call(scope,item, index, eom[key], oldvalue);
});

@@ -319,4 +357,50 @@ }

function diff(value,oldvalue,eom,scope,key,last){
var len = value.length >= oldvalue.length ? value.length : oldvalue.length;
var expect = tools.expect;
var container = eom.repeatContainer;
var cnt = 0;
for (var i = 0 ; i < len; i++) {
var newvalue = value[i];
var exists = typeof newvalue !== 'undefined';
if(exists && !expect(newvalue).toEqual(oldvalue[i])){
var neweom = getNewEom(eom,newvalue,scope,key,i,last);
var refnode = container.children[i];
//oldvalue.splice(i,1,newvalue); // sync oldvalue
if(typeof newvalue == 'object'){
oldvalue[i] = oldvalue[i] || {};
cover(oldvalue[i],newvalue);
}else{
oldvalue[i] = newvalue;
}
eom.splice(i,1,neweom); //sync eom
container.insertBefore(neweom.repeat,refnode); //sync dom
if(refnode)container.removeChild(refnode);
}else if(!exists){
oldvalue.splice(i-cnt,1);
eom.splice(i-cnt,1);
container.removeChild(container.children[i-cnt]);
cnt++;
}
}
}
function buildNewEom(eom,data) {
function cover(oldvalue,newvalue){
for(var x in newvalue){
oldvalue[x] = newvalue[x];
}
}
function getIndex(v,srcarray){
var result = -1;
for (var i = 0, len = srcarray.length; i < len; i++) {
if(tools.expect(v).toEqual(srcarray[i])){
result = i;
break;
}
}
return result;
}
function getNewEom(eom,d,parentscope,ns,index,last){
var trans = eom.trans;

@@ -326,57 +410,60 @@ var node = eom.repeatNode;

var key = eom.key;
var parentNode = eom.repeatContainer;
var frg = document.createDocumentFragment();
if (data && data.length) {
data.forEach(function(d,i) {
var _n = node.cloneNode(true);
var m = {};
var grammars = [];
trans(_r, _n, d, key, m,grammars,true);
m.grammars = grammars;
m.repeat = _n;
eom.push(m);
frg.appendChild(_n);
});
parentNode.appendChild(frg);
}
var _n = node.cloneNode(true);
var m = {};
var F = function(f){
this.__eom__ = {};
this.__last__ = {};
this.__listeners__ = {};
this[key] = f;
this.__eom__[key] = m;
this.__last__[key] = last[ns] && last[ns][index] || tools.clone(d);
};
F.prototype = parentscope;
var mod = new F(d);
trans(_r, _n, mod, key, m);
m.repeat = _n;
return m;
}
function loadGrammar(key) {
return require('river.grammer.' + key);
}
function updateGrammar(eom,data){
var grammars = eom.grammars;
if(!grammars) return;
grammars.forEach(function(d,i){
var context = {};
context.node = d.node;
context.scope = data;//scope; waiting for refactory
context.reg = d.reg;
context.eom = d.eom;
loadGrammar(d.grammar).call(context,d.str,d.rootScope,d.node,data);
});
function Model(ref) {
if(typeof ref === 'object'){
for(var x in ref){
this[x] = ref[x];
}
}else{
this._$value = ref;
}
this.__listeners__ = {};
}
function Model(ns, eom) {
_eoms[ns] = eom;
lasts[ns] = {};
this.$$ns = ns;
}
Model.prototype.apply = function() {
var father = Object.getPrototypeOf(this);
var me = this;
apply.call(me);
apply.call(father);
};
Model.prototype.apply = function() {
var _eom = _eoms[this.$$ns]
, last = lasts[this.$$ns]
function apply (){
var _eom = this.__eom__
, last = this.__last__
, scope = this;
if(!_eom) return;
each(this, function(val, index) {
if(/__/.test(index)) return;
if (_eom[index] && !tools.expect(last[index]).toEqual(val)) {
update.call(scope,val, index, _eom,last[index]);
last[index] = tools.clone(val);
update.call(scope,val, index, _eom,last);
//last[index] = tools.clone(val);
}
});
};
}
Model.prototype.watch = function(eom, repeat) {};
Model.prototype.onchange = function(id,fn) {
var lis = this.__listeners__[id] = this.__listeners__[id] || [];
lis.push(fn);
};
Model.prototype.inject = function(source) {

@@ -389,3 +476,2 @@ var me = this;

return Model;

@@ -502,2 +588,3 @@ });

var isObject = type('Object',source[x]) || type('Array',source[x]);
if(!this._diffFlag){ return false}
if(isObject && target){

@@ -508,6 +595,7 @@ diff.call(this,target[x],source[x]);

this._diffFlag = false;
return;
break;
}
if(target[x] != source[x]){
this._diffFlag = false;
break;
}

@@ -536,2 +624,3 @@ }

var exports = {

@@ -554,7 +643,10 @@ inherit : inherit,

});
define('river.grammer.jbind',function(){
define('river.grammer.jbind',function(exports,require,module){
function jbind (str,scope,element,repeatscope){
scope = repeatscope || scope;
var oldValue = element.value = scope[str] || '';
function jbind (str,scope,element){
var value = getValue(str,scope);
var oldValue = element.value = value || '';
// todo:still have bugs
var ns = str.split('.');
this.eom[str] = this.eom[str] || [];

@@ -565,2 +657,3 @@ this.eom[str].push({

});

@@ -582,3 +675,3 @@ var interval;

if(newValue !== oldValue){
scope[str] = newValue;
setValue(str,scope,newValue);
oldValue = newValue;

@@ -590,4 +683,27 @@ scope.apply();

return jbind;
function getValue(ns,scope){
var result = '';
if(!scope) throw new TypeError('value not exists');
var key = ns.replace(/\..*/,'')
var value = scope[key];
if(typeof value === 'object'){
result = getValue(ns.replace(key+'.',''),value);
}else if(typeof value !== 'undefined'){
result = value;
}
return result;
}
function setValue(str,scope,value){
if(!scope) throw new TypeError('value not exists');
var key = str.replace(/\..*/,'')
var childscope = scope[key];
if(typeof childscope === 'object'){
setValue(str.replace(key+'.',''),childscope,value);
}else{
scope[key] = value;
}
}
exports = module.exports = jbind;
});

@@ -606,6 +722,6 @@ define('river.grammer.jChange', function() {

});
define('river.grammer.jclick', function() {
function click (str,scope,element,repeatscope) {
var key = str.replace(/\(.*\)/,'');
var fn = scope[key];
define('river.grammer.jclick', function(exports,require,module) {
function click (str,scope,element) {
var f = str.replace(/\(.*\)/,'');
var fn = scope[f];

@@ -622,12 +738,6 @@ var param = /\((.*)\)/;

var argsdata = [];
for (var i = 0, len = args; i < len; i++) {
var item = scope[args[i]] ? scope[args[i]] : args[i];
argsdata.push(item);
for (var i = 0, len = args.length; i < len; i++) {
argsdata[i] = scope[args[i]]
}
//to-do hot-fix
if(repeatscope){
argsdata = [repeatscope];
}
var eom = this.eom;

@@ -639,3 +749,4 @@ element.onclick = function(e){

}
return click;
exports = module.exports = click;
});

@@ -656,3 +767,3 @@ define('river.grammer.jcompile',function(){

define('river.grammer.jon', function() {
function on (str,scope,element,repeatscope) {
function on (str,scope,element) {
var expression = str.replace(/\(.*\)/,'');

@@ -670,8 +781,4 @@

args = target[1].split(',');
//Array.prototype.indexOf.call(this.node.parentNode,this.node);
}
var eom = this.eom;
var event = 'on' + type;

@@ -685,7 +792,2 @@

}
//to-do hot-fix
if(repeatscope){
argsdata = [repeatscope];
}
fn.apply(element,[e].concat(argsdata));

@@ -697,5 +799,6 @@ scope.apply();

});
define("river.grammer.repeat", function() {
var $tool = this.need('river.core.tools')
, $scan = this.need('river.engine').scan
define("river.grammer.repeat", function(exports,require,module) {
var $tool = require('river.core.tools')
, $scan = require('river.engine').scan
, model = require('river.core.model')
, me = this;

@@ -717,15 +820,14 @@

var repeatNode,repeatContainer,rootScope;
var repeatNode,repeatContainer;
var afterIn = /.*in\s/;
var beforeIn = /\sin.*/;
function repeat(str) {
function repeat(str,scope,element) {
//to-do
var afterIn = /.*in\s/;
var beforeIn = /\sin.*/;
var ns = /.*\./;
var pro = str.replace(afterIn, '').replace(ns, '');
var data = this.scope[pro];
var data = scope[pro];
var key = str.replace(beforeIn, '');
var parentNode = this.node.parentNode;
var node = parentNode.removeChild(this.node);
var parentNode = element.parentNode;
var node = parentNode.removeChild(element);
var frg = document.createDocumentFragment();

@@ -735,6 +837,2 @@ var _r = this.reg;

rootScope = this.scope;
node.removeAttribute('repeat');

@@ -749,2 +847,3 @@ repeatNode = node;

eom.reg = _r;
scope.__children__ = scope.__children__ || [];

@@ -755,5 +854,16 @@ if (data && data.length) {

var m = {};
var grammars=[];
trans(_r, _n, d, key, m,grammars);
m.grammars = grammars;
var F = function(f){
//this._$value = f;
this[key] = f;
}
F.prototype = scope;
var mod = new F(d);//new model(d);
mod.__eom__ = {};
mod.__eom__[key] = m;
mod.__last__ = {};
mod.__last__[key] = scope.__last__ && scope.__last__[pro][i] || $tool.clone(d);
mod.__listeners__ = {};
scope.__children__.push(mod);
trans(_r, _n, mod, key, m);
m.repeat = _n;

@@ -770,3 +880,3 @@ eom.push(m);

function trans(reg, doc, scope, key, eom,grammars,stop) {
function trans(reg, doc, scope, key, eom) {
var hasRepeat = false;

@@ -785,3 +895,4 @@ if (doc.attributes && doc.attributes.length) {

});
attr.nodeValue = attr.nodeValue.replace(/{{.*}}/, scope[k]);
var value = typeof scope[key] == 'object' ? scope[key][k] : scope[key];
attr.nodeValue = attr.nodeValue.replace(/{{.*}}/, value);
}

@@ -795,18 +906,11 @@

hasRepeat = true;
repeat.call(context, attr.nodeValue.replace(reg, ''));
var ch = attr.nodeValue.replace(afterIn,'').replace(/\..*/,'');
context.scope = scope[ch];
repeat.call(context, attr.nodeValue.replace(reg, ''),scope[ch],doc);
}else{
var grammer = loadGrammar(attr.nodeName);
if($tool.isFunction(grammer)){
//context.scope = rootScope;
var str = attr.nodeValue.replace(reg, '');
grammars.push({
grammar : attr.nodeName,
eom:eom,
reg:reg,
node:doc,
str : str,
rootScope:rootScope
});
//todo : scope should inherit from rootScope
if(!stop)grammer.call(context,str,rootScope,context.node,context.scope);
context.eom = {};
grammer.call(context,str,scope,context.node);
}

@@ -828,3 +932,3 @@ }

// 2. scope = "string" or number
var value = $tool.isObject(scope) ? scope[k] : scope;
var value = typeof scope[key] == 'object' ? scope[key][k] : scope[key];
doc.nodeValue = doc.nodeValue.replace(/{{.*}}/, value);

@@ -834,3 +938,3 @@ }

Array.prototype.forEach.call(doc.childNodes, function(child) {
trans(reg, child, scope, key, eom,grammars,stop);
trans(reg, child, scope, key, eom);
});

@@ -852,17 +956,23 @@ }

if (tools.isObject(source)) {
var mod = new model(str, this.eom);
//source.watch(this.eom);
var mod = new model();
//make source inherit from mod
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto
//as the __proto__ is deprecated,I have to do this
for(var x in mod){
source[x] = mod[x]
}
source.__last__ = tools.clone(source);
source.__eom__ = this.eom;
this.scope = source;
} else if (tools.isFunction(source)) {
var m = new model(str, this.eom);
var m = new model();
this.scope = m;
source.call(m);
m.__last__ = tools.clone(m);
m.__eom__ = this.eom;
} else {
var guid = tools.guid();
this.scope = new model(guid, this.eom);
var mo = new model();
mo.__last__ = tools.clone(mo);
mo.__eom__ = this.eom;
this.scope = mo;
}

@@ -873,1 +983,7 @@ }

});
main(function(exports,require,module){
var engine = require('river.engine');
engine.ready(window,function(){
engine.scan(document);
});
});

@@ -1,2 +0,2 @@

var _$river={sandbox:function(){var e={};return{create:function(t,n){t=t.toLowerCase(),e[t]=n},run:function(t){var n={need:function(t){t=t.toLowerCase();var r=Object.create(n);r.exports={};var o=e[t]&&e[t].call(r,r.exports,r.need,r)||void 0;return o="function"==typeof r.exports?r.exports:Object.keys(r.exports).length?r.exports:o},exports:{}};t.call(n,n.exports,n.need,n)}}}};_$river.module=_$river.sandbox(),Object.create=Object.create||function(e){var t=function(){};return t.prototype=e,new t};var define=_$river.module.create,main=_$river.module.run;define("river.engine",function(){function e(e){return i.need("river.grammer."+e)}function t(t,r){var o={hasRepeat:!1,context:r},i={scope:{},node:t,eom:{},reg:c};return t.attributes&&t.attributes.length&&a.loop(t.attributes,function(s){var l=s.nodeName,u=s.nodeValue.replace(c,""),p=e(l);"repeat"===l&&(o.hasRepeat=!0),"scope"===l?(o.context=i,p.call(o.context,u,o.context.scope,o.context.node),r&&a.inherit(o.context.scope,r.scope)):a.isFunction(p)&&(o.context?(o.context.node=t,p.call(o.context,u,o.context.scope,o.context.node),n(s,o.context)):(o.context=i,e("scope").call(o.context,u),p.call(o.context,u,o.context.scope,o.context.node)))}),o}function n(e,t){if(c.test(e.nodeValue)){var n=e.nodeValue.replace(/\r|\n/g,"").replace(c,"");t.eom[n]||(t.eom[n]=[]),t.eom[n].push({element:e,expression:e.nodeValue});for(var r=n.split("."),o={},i=0;i<r.length;i++)"object"==typeof o&&(o=o[r[i]]||t.scope[r[i]]);o="object"==typeof o?JSON.stringify(o):o,e.nodeValue=e.nodeValue.replace(/\r|\n/g,"").replace(/{{.*}}/,o)}}function r(e,t){if(e.childNodes&&e.childNodes.length)for(var n=0;n<e.childNodes.length;n++){var r=e.childNodes[n],i=t?t.context:void 0,a=o(r,i);if(a.hasRepeat)break}}function o(e,o){var i=t(e,o);return i.context&&n(e,i.context),"CODE"===e.nodeName||"PRE"===e.nodeName||i.hasRepeat||(i.context?r(e,i):r(e)),i}var i=this,a=i.need("river.core.tools"),c=/.*{{\s*|\s*}}.*/g;return{scan:o}}),main(function(){var e=this;document.addEventListener("DOMContentLoaded",function(){var t=e.need("river.engine").scan;t(document)})}),define("river.scenario",function(){function e(e,t){var n=document.createEvent("MouseEvents");n.initEvent(e,!0,!0),t.dispatchEvent(n)}function t(e,t,n,r){var o=document.createEvent("Events");o.initEvent(e,!0,!0),o.view=null,o.altKey=!1,o.ctrlKey=!1,o.shiftKey=!1,o.metaKey=!1,o.keyCode=t,o.charCode=n,r.dispatchEvent(o)}this.need("river.core.tools");return{trigger:e,key:t}}),define("river.core.Date",function(){function e(e){var t={"M+":this.getMonth()+1,"d+":this.getDate(),"h+":this.getHours(),"m+":this.getMinutes(),"s+":this.getSeconds(),"q+":Math.floor((this.getMonth()+3)/3),S:this.getMilliseconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length)));for(var n in t)new RegExp("("+n+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?t[n]:("00"+t[n]).substr((""+t[n]).length)));return e}var t=function(t){var n=new Date,r=new Date(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate(),n.getUTCHours()+parseInt(t),n.getUTCMinutes(),n.getUTCSeconds());return{date:r,toString:function(t){return r.toString=e,r.toString(t)}}};return{getDateByCity:t}}),define("river.core.model",function(e,t){function n(e,t,o,a){var c=this;if(f(e)||d(e))o&&o[t]&&v(o[t],function(t){t.element.nodeValue=t.expression.replace(/{{.*}}/,e),"INPUT"==t.element.nodeName&&(t.element.value=t.expression.replace(/{{.*}}/,e))});else if(u(e)){a=a?a:[];var s=o[t].repeatContainer.children,l=e.length-s.length,m=Math.abs(l),g=l>0,y=0>l;if(g)for(var x=e.slice(e.length-m,e.length),b=0;m>b;b++)r(o[t],x);else if(y){Array.prototype.splice.call(o[t],0,m);for(var N=0;m>N;N++)s[N].parentNode.removeChild(s[N])}v(e,function(e,r){i(o[t][r],e),n.call(c,e,r,o[t][r],a[r])})}else p(e)&&(a=a?a:{},h(e,function(e,t){n.call(c,e,t,o,a[t])}))}function r(e,t){var n=e.trans,r=e.repeatNode,o=e.reg,i=e.key,a=e.repeatContainer,c=document.createDocumentFragment();t&&t.length&&(t.forEach(function(t){var a=r.cloneNode(!0),s={},l=[];n(o,a,t,i,s,l,!0),s.grammars=l,s.repeat=a,e.push(s),c.appendChild(a)}),a.appendChild(c))}function o(e){return t("river.grammer."+e)}function i(e,t){var n=e.grammars;n&&n.forEach(function(e){var n={};n.node=e.node,n.scope=t,n.reg=e.reg,n.eom=e.eom,o(e.grammar).call(n,e.str,e.rootScope,e.node,t)})}function a(e,t){s[e]=t,l[e]={},this.$$ns=e}var c=this.need("river.core.tools"),s={},l={},u=c.isArray,p=c.isObject,f=c.isString,d=c.isNumber,h=c.each,v=c.loop;return a.prototype.apply=function(){var e=s[this.$$ns],t=l[this.$$ns],r=this;h(this,function(o,i){e[i]&&!c.expect(t[i]).toEqual(o)&&(n.call(r,o,i,e,t[i]),t[i]=c.clone(o))})},a.prototype.watch=function(){},a.prototype.inject=function(e){var t=this;h(e,function(n,r){t[r]=e[r]})},a}),define("river.core.tools",function(){function e(e,t){var n=function(){for(var t in e)e.hasOwnProperty&&e.hasOwnProperty(t)?this[t]=e[t]:n.prototype[t]=e[t]};for(var r in t)n.prototype[r]=t[r];var o=new n;for(var i in o)e[i]=o[i];return e}function t(e){var t=document.createElement("div");return t.innerHTML=e,t.childNodes[0]}function n(){for(var e="$$",t=1;8>=t;t++){var n=Math.floor(16*Math.random()).toString(16);e+=n,(3==t||5==t)&&(e+="-")}return e}function r(e,t){for(var n={},r=0;r<e.length;r++)t.call(n,e[r],r)}function o(e,t){var n={};for(var r in e)e.hasOwnProperty&&e.hasOwnProperty(r)&&t.call(n,e[r],r)}function i(e,t){return window.Object.prototype.toString.call(t)==="[object "+e+"]"}function a(e,t){if("object"!=typeof e)return e;t=t?t:i("Object",e)?{}:[];for(var n in e){var r=i("Object",e[n]),o=i("Array",e[n]),c=r||o;c?(t[n]=r?{}:[],a(e[n],t[n])):t[n]=e[n]}return t}function c(e,t){this._diffFlag=!0;for(var n in t){var r=i("Object",t[n])||i("Array",t[n]);if(r&&e)c.call(this,e[n],t[n]);else{if(!e)return void(this._diffFlag=!1);e[n]!=t[n]&&(this._diffFlag=!1)}}return this._diffFlag}function s(e){function t(t){return n?e==t:r?c.call({},t,e)&&c.call({},e,t):void 0}var n="string"==typeof e||"number"==typeof e||"boolean"==typeof e||"undefined"==typeof e,r="function"!=typeof e;return{toEqual:t}}var l=(Object.prototype.toString,{inherit:e,compile:t,guid:n,loop:r,each:o,clone:a,expect:s,isArray:function(e){return i("Array",e)},isObject:function(e){return i("Object",e)},isFunction:function(e){return i("Function",e)},isString:function(e){return i("String",e)},isNumber:function(e){return i("Number",e)}});return l}),define("river.grammer.jbind",function(){function e(e,t,n,r){function o(n){n!==i&&(t[e]=n,i=n,t.apply())}t=r||t;var i=n.value=t[e]||"";this.eom[e]=this.eom[e]||[],this.eom[e].push({element:n,expression:"{{"+e+"}}"});var a;n.onfocus=function(){var e=this;a=setInterval(function(){o(e.value)},30)},n.onblur=function(){clearInterval(a)}}return e}),define("river.grammer.jChange",function(){function e(e){var t=this.scope[e],n=this.scope;this.node.onchange=function(){t.call({},this.value),n.apply()}}return e}),define("river.grammer.jclick",function(){function e(e,t,n,r){var o=e.replace(/\(.*\)/,""),i=t[o],a=/\((.*)\)/,c=e.match(a),s=[];c&&c.length&&(s=c[1].split(","));for(var l=[],u=0,p=s;p>u;u++){var f=t[s[u]]?t[s[u]]:s[u];l.push(f)}r&&(l=[r]);this.eom;n.onclick=function(){i.apply(n,l),t.apply()}}return e}),define("river.grammer.jcompile",function(){return function(){{var e=this.node,t=(this.scope,this.reg);e.textContent.replace(t,"")}}}),define("river.grammer.jon",function(){function e(e,t,n,r){var o=e.replace(/\(.*\)/,""),i=o.replace(/\s*[\||:].*/,""),a=o.replace(/.*[\||:]\s*/,""),c=t[a],s=/\((.*)\)/,l=e.match(s),u=[];l&&l.length&&(u=l[1].split(","));var p=(this.eom,"on"+i);n[p]=function(e){for(var o=[],i=0,a=u.length;a>i;i++){var s=t[u[i]]?t[u[i]]:"";o.push(s)}r&&(o=[r]),c.apply(n,[e].concat(o)),t.apply()}}return e}),define("river.grammer.repeat",function(){function e(e){return c.need("river.grammer."+e)}function t(e){var t=/.*in\s/,a=/\sin.*/,c=/.*\./,s=e.replace(t,"").replace(c,""),l=this.scope[s],u=e.replace(a,""),p=this.node.parentNode,f=p.removeChild(this.node),d=document.createDocumentFragment(),h=this.reg,v=this.eom[s]=[];i=this.scope,f.removeAttribute("repeat"),r=f,o=p,v.repeatNode=f,v.repeatContainer=p,v.trans=n,v.key=u,v.reg=h,l&&l.length&&(l.forEach(function(e){var t=f.cloneNode(!0),r={},o=[];n(h,t,e,u,r,o),r.grammars=o,r.repeat=t,v.push(r),d.appendChild(t)}),p.appendChild(d))}function n(r,o,c,l,u,p,f){var d=!1;if(o.attributes&&o.attributes.length&&Array.prototype.forEach.call(o.attributes,function(n){if(r.test(n.nodeValue)){var h=n.nodeValue.replace(r,"").replace(l+".","");u[h]||(u[h]=[]),u[h].push({element:n,expression:n.nodeValue}),n.nodeValue=n.nodeValue.replace(/{{.*}}/,c[h])}if(s.node=o,s.scope=c,s.reg=r,s.eom=u,"repeat"===n.nodeName)d=!0,t.call(s,n.nodeValue.replace(r,""));else{var v=e(n.nodeName);if(a.isFunction(v)){var m=n.nodeValue.replace(r,"");p.push({grammar:n.nodeName,eom:u,reg:r,node:o,str:m,rootScope:i}),f||v.call(s,m,i,s.node,s.scope)}}}),r.test(o.nodeValue)){var h=o.nodeValue.replace(r,"").replace(l+".","");u[h]||(u[h]=[]),u[h].push({element:o,expression:o.nodeValue});var v=a.isObject(c)?c[h]:c;o.nodeValue=o.nodeValue.replace(/{{.*}}/,v)}o.childNodes&&o.childNodes.length&&!d&&Array.prototype.forEach.call(o.childNodes,function(e){n(r,e,c,l,u,p,f)})}var r,o,i,a=this.need("river.core.tools"),c=(this.need("river.engine").scan,this),s={};return t}),define("river.grammer.scope",function(){function e(e){this.node.removeAttribute("scope");var o=t.need(e);if(r.isObject(o)){var i=new n(e,this.eom);for(var a in i)o[a]=i[a];this.scope=o}else if(r.isFunction(o)){var c=new n(e,this.eom);this.scope=c,o.call(c)}else{var s=r.guid();this.scope=new n(s,this.eom)}}var t=this,n=t.need("river.core.model"),r=t.need("river.core.tools");return e});
var _$river={sandbox:function(){var e={};return{create:function(t,n){t=t.toLowerCase(),e[t]=n},run:function(t){var n={need:function(t){t=t.toLowerCase();var r=Object.create(n);r.exports={};var o=e[t]&&e[t].call(r,r.exports,r.need,r)||void 0;return o="function"==typeof r.exports?r.exports:Object.keys(r.exports).length?r.exports:o},exports:{}};t.call(n,n.exports,n.need,n)}}}};_$river.module=_$river.sandbox(),Object.create=Object.create||function(e){var t=function(){};return t.prototype=e,new t};var define=_$river.module.create,main=_$river.module.run;define("river.engine",function(){function e(e){return a.need("river.grammer."+e)}function t(t,r){var o={hasRepeat:!1,context:r},i={scope:{},node:t,eom:{},reg:l};if(t.attributes&&t.attributes.length)for(var a=0;a<t.attributes.length;a++){var s=t.attributes[a],u=s.nodeName,f=s.nodeValue.replace(l,""),p=e(u);if("scope"===u?(o.context=i,p.call(o.context,f,o.context.scope,o.context.node),r&&c.inherit(o.context.scope,r.scope)):c.isFunction(p)&&(o.context?(o.context.node=t,p.call(o.context,f,o.context.scope,o.context.node),n(s,o.context)):(o.context=i,e("scope").call(o.context,f),p.call(o.context,f,o.context.scope,o.context.node))),"repeat"===u){o.hasRepeat=!0;break}}return o}function n(e,t){if(l.test(e.nodeValue)){var n=e.nodeValue.replace(/\r|\n/g,"").replace(l,"");t.eom[n]||(t.eom[n]=[]),t.eom[n].push({element:e,expression:e.nodeValue});for(var r=n.split("."),o={},i=0;i<r.length;i++)"object"==typeof o&&(o=o[r[i]]||t.scope[r[i]]);o="object"==typeof o?JSON.stringify(o):o,"undefined"==typeof o&&(o=""),e.nodeValue=e.nodeValue.replace(/\r|\n/g,"").replace(/{{.*}}/,o)}}function r(e,t){if(e.childNodes&&e.childNodes.length)for(var n=0;n<e.childNodes.length;n++){var r=e.childNodes[n],i=t?t.context:void 0,a=o(r,i);if(a.hasRepeat)break}}function o(e,o){var i=t(e,o);return i.context&&n(e,i.context),"CODE"===e.nodeName||"PRE"===e.nodeName||i.hasRepeat||(i.context?r(e,i):r(e)),i}function i(e,t){var n=!1,r=!0,o=e.document,i=o.documentElement,a=o.addEventListener?"addEventListener":"attachEvent",c=o.addEventListener?"removeEventListener":"detachEvent",l=o.addEventListener?"":"on",s=function(r){("readystatechange"!=r.type||"complete"==o.readyState)&&(("load"==r.type?e:o)[c](l+r.type,s,!1),!n&&(n=!0)&&t.call(e,r.type||r))},u=function(){try{i.doScroll("left")}catch(e){return void setTimeout(u,50)}s("poll")};if("complete"==o.readyState)t.call(e,"lazy");else{if(o.createEventObject&&i.doScroll){try{r=!e.frameElement}catch(f){}r&&u()}o[a](l+"DOMContentLoaded",s,!1),o[a](l+"readystatechange",s,!1),e[a](l+"load",s,!1)}}var a=this,c=a.need("river.core.tools"),l=/.*{{\s*|\s*}}.*/g;return{scan:o,ready:i}}),define("river.scenario",function(){function e(e,t){var n=document.createEvent("MouseEvents");n.initEvent(e,!0,!0),t.dispatchEvent(n)}function t(e,t,n,r){var o=document.createEvent("Events");o.initEvent(e,!0,!0),o.view=null,o.altKey=!1,o.ctrlKey=!1,o.shiftKey=!1,o.metaKey=!1,o.keyCode=t,o.charCode=n,r.dispatchEvent(o)}this.need("river.core.tools");return{trigger:e,key:t}}),define("river.core.Date",function(){function e(e){var t={"M+":this.getMonth()+1,"d+":this.getDate(),"h+":this.getHours(),"m+":this.getMinutes(),"s+":this.getSeconds(),"q+":Math.floor((this.getMonth()+3)/3),S:this.getMilliseconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length)));for(var n in t)new RegExp("("+n+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?t[n]:("00"+t[n]).substr((""+t[n]).length)));return e}var t=function(t){var n=new Date,r=new Date(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate(),n.getUTCHours()+parseInt(t),n.getUTCMinutes(),n.getUTCSeconds());return{date:r,toString:function(t){return r.toString=e,r.toString(t)}}};return{getDateByCity:t}}),define("river.core.model",function(){function e(n,r,o,i){var a=this,d=i[r],v=n==d;if(!v)if(s(n)||u(n)){if(o&&o[r]){p(o[r],function(e){e.element.nodeValue=e.expression.replace(/{{.*}}/,n),"INPUT"==e.element.nodeName&&(e.element.value=e.expression.replace(/{{.*}}/,n))});var h=a.__listeners__&&a.__listeners__[r];if(h)for(var _=0,m=h.length;m>_;_++)h[_](n,i[r])}i[r]=n}else c(n)?(i[r]=d?d:[],t(n,i[r],o[r],a,r,i)):l(n)&&(d=d?d:{},f(n,function(t,n){e.call(a,t,n,o[r],d)}))}function t(e,t,o,i,c,l){for(var s=e.length>=t.length?e.length:t.length,u=a.expect,f=o.repeatContainer,p=0,d=0;s>d;d++){var v=e[d],h="undefined"!=typeof v;if(h&&!u(v).toEqual(t[d])){var _=r(o,v,i,c,d,l),m=f.children[d];"object"==typeof v?(t[d]=t[d]||{},n(t[d],v)):t[d]=v,o.splice(d,1,_),f.insertBefore(_.repeat,m),m&&f.removeChild(m)}else h||(t.splice(d-p,1),o.splice(d-p,1),f.removeChild(f.children[d-p]),p++)}}function n(e,t){for(var n in t)e[n]=t[n]}function r(e,t,n,r,o,i){var c=e.trans,l=e.repeatNode,s=e.reg,u=e.key,f=l.cloneNode(!0),p={},d=function(e){this.__eom__={},this.__last__={},this.__listeners__={},this[u]=e,this.__eom__[u]=p,this.__last__[u]=i[r]&&i[r][o]||a.clone(t)};d.prototype=n;var v=new d(t);return c(s,f,v,u,p),p.repeat=f,p}function o(e){if("object"==typeof e)for(var t in e)this[t]=e[t];else this._$value=e;this.__listeners__={}}function i(){var t=this.__eom__,n=this.__last__,r=this;t&&f(this,function(o,i){/__/.test(i)||t[i]&&!a.expect(n[i]).toEqual(o)&&e.call(r,o,i,t,n)})}var a=this.need("river.core.tools"),c=a.isArray,l=a.isObject,s=a.isString,u=a.isNumber,f=a.each,p=a.loop;return o.prototype.apply=function(){var e=Object.getPrototypeOf(this),t=this;i.call(t),i.call(e)},o.prototype.watch=function(){},o.prototype.onchange=function(e,t){var n=this.__listeners__[e]=this.__listeners__[e]||[];n.push(t)},o.prototype.inject=function(e){var t=this;f(e,function(n,r){t[r]=e[r]})},o}),define("river.core.tools",function(){function e(e,t){var n=function(){for(var t in e)e.hasOwnProperty&&e.hasOwnProperty(t)?this[t]=e[t]:n.prototype[t]=e[t]};for(var r in t)n.prototype[r]=t[r];var o=new n;for(var i in o)e[i]=o[i];return e}function t(e){var t=document.createElement("div");return t.innerHTML=e,t.childNodes[0]}function n(){for(var e="$$",t=1;8>=t;t++){var n=Math.floor(16*Math.random()).toString(16);e+=n,(3==t||5==t)&&(e+="-")}return e}function r(e,t){for(var n={},r=0;r<e.length;r++)t.call(n,e[r],r)}function o(e,t){var n={};for(var r in e)e.hasOwnProperty&&e.hasOwnProperty(r)&&t.call(n,e[r],r)}function i(e,t){return window.Object.prototype.toString.call(t)==="[object "+e+"]"}function a(e,t){if("object"!=typeof e)return e;t=t?t:i("Object",e)?{}:[];for(var n in e){var r=i("Object",e[n]),o=i("Array",e[n]),c=r||o;c?(t[n]=r?{}:[],a(e[n],t[n])):t[n]=e[n]}return t}function c(e,t){this._diffFlag=!0;for(var n in t){var r=i("Object",t[n])||i("Array",t[n]);if(!this._diffFlag)return!1;if(r&&e)c.call(this,e[n],t[n]);else{if(!e){this._diffFlag=!1;break}if(e[n]!=t[n]){this._diffFlag=!1;break}}}return this._diffFlag}function l(e){function t(t){return n?e==t:r?c.call({},t,e)&&c.call({},e,t):void 0}var n="string"==typeof e||"number"==typeof e||"boolean"==typeof e||"undefined"==typeof e,r="function"!=typeof e;return{toEqual:t}}var s=(Object.prototype.toString,{inherit:e,compile:t,guid:n,loop:r,each:o,clone:a,expect:l,isArray:function(e){return i("Array",e)},isObject:function(e){return i("Object",e)},isFunction:function(e){return i("Function",e)},isString:function(e){return i("String",e)},isNumber:function(e){return i("Number",e)}});return s}),define("river.grammer.jbind",function(e,t,n){function r(e,t,n){function r(n){n!==c&&(i(e,t,n),c=n,t.apply())}{var a=o(e,t),c=n.value=a||"";e.split(".")}this.eom[e]=this.eom[e]||[],this.eom[e].push({element:n,expression:"{{"+e+"}}"});var l;n.onfocus=function(){var e=this;l=setInterval(function(){r(e.value)},30)},n.onblur=function(){clearInterval(l)}}function o(e,t){var n="";if(!t)throw new TypeError("value not exists");var r=e.replace(/\..*/,""),i=t[r];return"object"==typeof i?n=o(e.replace(r+".",""),i):"undefined"!=typeof i&&(n=i),n}function i(e,t,n){if(!t)throw new TypeError("value not exists");var r=e.replace(/\..*/,""),o=t[r];"object"==typeof o?i(e.replace(r+".",""),o,n):t[r]=n}e=n.exports=r}),define("river.grammer.jChange",function(){function e(e){var t=this.scope[e],n=this.scope;this.node.onchange=function(){t.call({},this.value),n.apply()}}return e}),define("river.grammer.jclick",function(e,t,n){function r(e,t,n){var r=e.replace(/\(.*\)/,""),o=t[r],i=/\((.*)\)/,a=e.match(i),c=[];a&&a.length&&(c=a[1].split(","));for(var l=[],s=0,u=c.length;u>s;s++)l[s]=t[c[s]];this.eom;n.onclick=function(){o.apply(n,l),t.apply()}}e=n.exports=r}),define("river.grammer.jcompile",function(){return function(){{var e=this.node,t=(this.scope,this.reg);e.textContent.replace(t,"")}}}),define("river.grammer.jon",function(){function e(e,t,n){var r=e.replace(/\(.*\)/,""),o=r.replace(/\s*[\||:].*/,""),i=r.replace(/.*[\||:]\s*/,""),a=t[i],c=/\((.*)\)/,l=e.match(c),s=[];l&&l.length&&(s=l[1].split(","));var u="on"+o;n[u]=function(e){for(var r=[],o=0,i=s.length;i>o;o++){var c=t[s[o]]?t[s[o]]:"";r.push(c)}a.apply(n,[e].concat(r)),t.apply()}}return e}),define("river.grammer.repeat",function(e,t){function n(e){return l.need("river.grammer."+e)}function r(e,t,n){var r=/.*\./,l=e.replace(s,"").replace(r,""),f=t[l],p=e.replace(u,""),d=n.parentNode,v=d.removeChild(n),h=document.createDocumentFragment(),_=this.reg,m=this.eom[l]=[];v.removeAttribute("repeat"),i=v,a=d,m.repeatNode=v,m.repeatContainer=d,m.trans=o,m.key=p,m.reg=_,t.__children__=t.__children__||[],f&&f.length&&(f.forEach(function(e,n){var r=v.cloneNode(!0),i={},a=function(e){this[p]=e};a.prototype=t;var s=new a(e);s.__eom__={},s.__eom__[p]=i,s.__last__={},s.__last__[p]=t.__last__&&t.__last__[l][n]||c.clone(e),s.__listeners__={},t.__children__.push(s),o(_,r,s,p,i),i.repeat=r,m.push(i),h.appendChild(r)}),d.appendChild(h))}function o(e,t,i,a,l){var u=!1;if(t.attributes&&t.attributes.length&&Array.prototype.forEach.call(t.attributes,function(o){if(e.test(o.nodeValue)){var p=o.nodeValue.replace(e,"").replace(a+".","");l[p]||(l[p]=[]),l[p].push({element:o,expression:o.nodeValue});var d="object"==typeof i[a]?i[a][p]:i[a];o.nodeValue=o.nodeValue.replace(/{{.*}}/,d)}if(f.node=t,f.scope=i,f.reg=e,f.eom=l,"repeat"===o.nodeName){u=!0;var v=o.nodeValue.replace(s,"").replace(/\..*/,"");f.scope=i[v],r.call(f,o.nodeValue.replace(e,""),i[v],t)}else{var h=n(o.nodeName);if(c.isFunction(h)){var _=o.nodeValue.replace(e,"");f.eom={},h.call(f,_,i,f.node)}}}),e.test(t.nodeValue)){var p=t.nodeValue.replace(e,"").replace(a+".","");l[p]||(l[p]=[]),l[p].push({element:t,expression:t.nodeValue});var d="object"==typeof i[a]?i[a][p]:i[a];t.nodeValue=t.nodeValue.replace(/{{.*}}/,d)}t.childNodes&&t.childNodes.length&&!u&&Array.prototype.forEach.call(t.childNodes,function(t){o(e,t,i,a,l)})}var i,a,c=t("river.core.tools"),l=(t("river.engine").scan,t("river.core.model"),this),s=/.*in\s/,u=/\sin.*/,f={};return r}),define("river.grammer.scope",function(){function e(e){this.node.removeAttribute("scope");var o=t.need(e);if(r.isObject(o)){var i=new n;for(var a in i)o[a]=i[a];o.__last__=r.clone(o),o.__eom__=this.eom,this.scope=o}else if(r.isFunction(o)){var c=new n;this.scope=c,o.call(c),c.__last__=r.clone(c),c.__eom__=this.eom}else{var l=(r.guid(),new n);l.__last__=r.clone(l),l.__eom__=this.eom,this.scope=l}}var t=this,n=t.need("river.core.model"),r=t.need("river.core.tools");return e}),main(function(e,t){var n=t("river.engine");n.ready(window,function(){n.scan(document)})});
//# sourceMappingURL=river.map

@@ -5,3 +5,3 @@ define('river.core.model', function(exports,require,module) { //@sourceURL=../lib/core/model.js

var _eoms = {}, lasts = {} , me = this;
var me = this;

@@ -15,4 +15,7 @@ var isArray = tools.isArray;

function update(value, key, eom ,oldvalue) {
function update(value, key, eom ,last) {
var scope = this;
var oldvalue = last[key];
var isEqual = value == oldvalue;
if(isEqual) return;
if (isString(value) || isNumber(value)) {

@@ -27,29 +30,17 @@ if(eom && eom[key]){

});
var fns = scope.__listeners__ && scope.__listeners__[key] ;
if(fns){
for (var i = 0, len = fns.length; i < len; i++) {
fns[i](value,last[key]);
}
}
}
last[key] = value;
} else if (isArray(value)) {
oldvalue = oldvalue ? oldvalue : [];
var children = eom[key].repeatContainer.children;
var length = value.length - children.length
, len = Math.abs(length)
, addItems = length > 0
, removeItems = length < 0;
if(addItems){
var vv = value.slice(value.length-len,value.length);
for(var i = 0;i<len;i++){
buildNewEom(eom[key],vv);
}
}else if(removeItems){
Array.prototype.splice.call(eom[key],0,len);
for(var k= 0;k<len;k++){
children[k].parentNode.removeChild(children[k]);
}
}
loop(value, function(item, index) {
updateGrammar(eom[key][index],item);
update.call(scope,item, index, eom[key][index],oldvalue[index]);
});
last[key] = oldvalue ? oldvalue : [];
diff(value,last[key],eom[key],scope,key,last);
} else if (isObject(value)) {
oldvalue = oldvalue ? oldvalue : {};
each(value, function(item, index) {
update.call(scope,item, index, eom , oldvalue[index]);
update.call(scope,item, index, eom[key], oldvalue);
});

@@ -59,4 +50,50 @@ }

function diff(value,oldvalue,eom,scope,key,last){
var len = value.length >= oldvalue.length ? value.length : oldvalue.length;
var expect = tools.expect;
var container = eom.repeatContainer;
var cnt = 0;
for (var i = 0 ; i < len; i++) {
var newvalue = value[i];
var exists = typeof newvalue !== 'undefined';
if(exists && !expect(newvalue).toEqual(oldvalue[i])){
var neweom = getNewEom(eom,newvalue,scope,key,i,last);
var refnode = container.children[i];
//oldvalue.splice(i,1,newvalue); // sync oldvalue
if(typeof newvalue == 'object'){
oldvalue[i] = oldvalue[i] || {};
cover(oldvalue[i],newvalue);
}else{
oldvalue[i] = newvalue;
}
eom.splice(i,1,neweom); //sync eom
container.insertBefore(neweom.repeat,refnode); //sync dom
if(refnode)container.removeChild(refnode);
}else if(!exists){
oldvalue.splice(i-cnt,1);
eom.splice(i-cnt,1);
container.removeChild(container.children[i-cnt]);
cnt++;
}
}
}
function buildNewEom(eom,data) {
function cover(oldvalue,newvalue){
for(var x in newvalue){
oldvalue[x] = newvalue[x];
}
}
function getIndex(v,srcarray){
var result = -1;
for (var i = 0, len = srcarray.length; i < len; i++) {
if(tools.expect(v).toEqual(srcarray[i])){
result = i;
break;
}
}
return result;
}
function getNewEom(eom,d,parentscope,ns,index,last){
var trans = eom.trans;

@@ -66,57 +103,60 @@ var node = eom.repeatNode;

var key = eom.key;
var parentNode = eom.repeatContainer;
var frg = document.createDocumentFragment();
if (data && data.length) {
data.forEach(function(d,i) {
var _n = node.cloneNode(true);
var m = {};
var grammars = [];
trans(_r, _n, d, key, m,grammars,true);
m.grammars = grammars;
m.repeat = _n;
eom.push(m);
frg.appendChild(_n);
});
parentNode.appendChild(frg);
}
var _n = node.cloneNode(true);
var m = {};
var F = function(f){
this.__eom__ = {};
this.__last__ = {};
this.__listeners__ = {};
this[key] = f;
this.__eom__[key] = m;
this.__last__[key] = last[ns] && last[ns][index] || tools.clone(d);
};
F.prototype = parentscope;
var mod = new F(d);
trans(_r, _n, mod, key, m);
m.repeat = _n;
return m;
}
function loadGrammar(key) {
return require('river.grammer.' + key);
}
function updateGrammar(eom,data){
var grammars = eom.grammars;
if(!grammars) return;
grammars.forEach(function(d,i){
var context = {};
context.node = d.node;
context.scope = data;//scope; waiting for refactory
context.reg = d.reg;
context.eom = d.eom;
loadGrammar(d.grammar).call(context,d.str,d.rootScope,d.node,data);
});
function Model(ref) {
if(typeof ref === 'object'){
for(var x in ref){
this[x] = ref[x];
}
}else{
this._$value = ref;
}
this.__listeners__ = {};
}
function Model(ns, eom) {
_eoms[ns] = eom;
lasts[ns] = {};
this.$$ns = ns;
}
Model.prototype.apply = function() {
var father = Object.getPrototypeOf(this);
var me = this;
apply.call(me);
apply.call(father);
};
Model.prototype.apply = function() {
var _eom = _eoms[this.$$ns]
, last = lasts[this.$$ns]
function apply (){
var _eom = this.__eom__
, last = this.__last__
, scope = this;
if(!_eom) return;
each(this, function(val, index) {
if(/__/.test(index)) return;
if (_eom[index] && !tools.expect(last[index]).toEqual(val)) {
update.call(scope,val, index, _eom,last[index]);
last[index] = tools.clone(val);
update.call(scope,val, index, _eom,last);
//last[index] = tools.clone(val);
}
});
};
}
Model.prototype.watch = function(eom, repeat) {};
Model.prototype.onchange = function(id,fn) {
var lis = this.__listeners__[id] = this.__listeners__[id] || [];
lis.push(fn);
};
Model.prototype.inject = function(source) {

@@ -129,4 +169,3 @@ var me = this;

return Model;
});

@@ -110,2 +110,3 @@ define('river.core.tools', function() {

var isObject = type('Object',source[x]) || type('Array',source[x]);
if(!this._diffFlag){ return false}
if(isObject && target){

@@ -116,6 +117,7 @@ diff.call(this,target[x],source[x]);

this._diffFlag = false;
return;
break;
}
if(target[x] != source[x]){
this._diffFlag = false;
break;
}

@@ -144,2 +146,3 @@ }

var exports = {

@@ -146,0 +149,0 @@ inherit : inherit,

@@ -27,3 +27,4 @@ define('river.engine',function() {

if (doc.attributes && doc.attributes.length) {
tool.loop(doc.attributes, function(attr) {
for(var i = 0;i<doc.attributes.length;i++){
var attr= doc.attributes[i];
var key = attr.nodeName;

@@ -33,5 +34,2 @@ var value = attr.nodeValue.replace(reg, '');

if ('repeat' === key) {
state.hasRepeat = true;
}
if ('scope' === key) {

@@ -58,3 +56,7 @@ //here we cover the current context by newContext;

}
});
if ('repeat' === key) {
state.hasRepeat = true;
break;
}
}
}

@@ -83,2 +85,3 @@ return state;

value = typeof value == 'object' ? JSON.stringify(value) : value;
if(typeof value == 'undefined') value = '';
doc.nodeValue = doc.nodeValue.replace(/\r|\n/g,'').replace(/{{.*}}/, value);

@@ -116,14 +119,58 @@ }

/*!
* contentloaded.js
*
* Author: Diego Perini (diego.perini at gmail.com)
* Summary: cross-browser wrapper for DOMContentLoaded
* Updated: 20101020
* License: MIT
* Version: 1.2
*
* URL:
* http://javascript.nwbox.com/ContentLoaded/
* http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
*
*/
// @win window reference
// @fn function reference
function contentLoaded(win, fn) {
var done = false, top = true,
doc = win.document, root = doc.documentElement,
add = doc.addEventListener ? 'addEventListener' : 'attachEvent',
rem = doc.addEventListener ? 'removeEventListener' : 'detachEvent',
pre = doc.addEventListener ? '' : 'on',
init = function(e) {
if (e.type == 'readystatechange' && doc.readyState != 'complete') return;
(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
if (!done && (done = true)) fn.call(win, e.type || e);
},
poll = function() {
try { root.doScroll('left'); } catch(e) { setTimeout(poll, 50); return; }
init('poll');
};
if (doc.readyState == 'complete') fn.call(win, 'lazy');
else {
if (doc.createEventObject && root.doScroll) {
try { top = !win.frameElement; } catch(e) { }
if (top) poll();
}
doc[add](pre + 'DOMContentLoaded', init, false);
doc[add](pre + 'readystatechange', init, false);
win[add](pre + 'load', init, false);
}
}
return {
scan:scan
scan:scan,
ready:contentLoaded
};
});
main(function(){
var me = this;
document.addEventListener('DOMContentLoaded', function() {
var scan = me.need('river.engine').scan;
scan(document);
});
});

@@ -1,6 +0,9 @@

define('river.grammer.jbind',function(){
define('river.grammer.jbind',function(exports,require,module){
function jbind (str,scope,element,repeatscope){
scope = repeatscope || scope;
var oldValue = element.value = scope[str] || '';
function jbind (str,scope,element){
var value = getValue(str,scope);
var oldValue = element.value = value || '';
// todo:still have bugs
var ns = str.split('.');
this.eom[str] = this.eom[str] || [];

@@ -11,2 +14,3 @@ this.eom[str].push({

});

@@ -28,3 +32,3 @@ var interval;

if(newValue !== oldValue){
scope[str] = newValue;
setValue(str,scope,newValue);
oldValue = newValue;

@@ -36,4 +40,27 @@ scope.apply();

return jbind;
function getValue(ns,scope){
var result = '';
if(!scope) throw new TypeError('value not exists');
var key = ns.replace(/\..*/,'')
var value = scope[key];
if(typeof value === 'object'){
result = getValue(ns.replace(key+'.',''),value);
}else if(typeof value !== 'undefined'){
result = value;
}
return result;
}
function setValue(str,scope,value){
if(!scope) throw new TypeError('value not exists');
var key = str.replace(/\..*/,'')
var childscope = scope[key];
if(typeof childscope === 'object'){
setValue(str.replace(key+'.',''),childscope,value);
}else{
scope[key] = value;
}
}
exports = module.exports = jbind;
});

@@ -1,5 +0,5 @@

define('river.grammer.jclick', function() {
function click (str,scope,element,repeatscope) {
var key = str.replace(/\(.*\)/,'');
var fn = scope[key];
define('river.grammer.jclick', function(exports,require,module) {
function click (str,scope,element) {
var f = str.replace(/\(.*\)/,'');
var fn = scope[f];

@@ -16,12 +16,6 @@ var param = /\((.*)\)/;

var argsdata = [];
for (var i = 0, len = args; i < len; i++) {
var item = scope[args[i]] ? scope[args[i]] : args[i];
argsdata.push(item);
for (var i = 0, len = args.length; i < len; i++) {
argsdata[i] = scope[args[i]]
}
//to-do hot-fix
if(repeatscope){
argsdata = [repeatscope];
}
var eom = this.eom;

@@ -33,3 +27,4 @@ element.onclick = function(e){

}
return click;
exports = module.exports = click;
});
define('river.grammer.jon', function() {
function on (str,scope,element,repeatscope) {
function on (str,scope,element) {
var expression = str.replace(/\(.*\)/,'');

@@ -15,8 +15,4 @@

args = target[1].split(',');
//Array.prototype.indexOf.call(this.node.parentNode,this.node);
}
var eom = this.eom;
var event = 'on' + type;

@@ -30,7 +26,2 @@

}
//to-do hot-fix
if(repeatscope){
argsdata = [repeatscope];
}
fn.apply(element,[e].concat(argsdata));

@@ -37,0 +28,0 @@ scope.apply();

@@ -1,4 +0,5 @@

define("river.grammer.repeat", function() {
var $tool = this.need('river.core.tools')
, $scan = this.need('river.engine').scan
define("river.grammer.repeat", function(exports,require,module) {
var $tool = require('river.core.tools')
, $scan = require('river.engine').scan
, model = require('river.core.model')
, me = this;

@@ -20,15 +21,14 @@

var repeatNode,repeatContainer,rootScope;
var repeatNode,repeatContainer;
var afterIn = /.*in\s/;
var beforeIn = /\sin.*/;
function repeat(str) {
function repeat(str,scope,element) {
//to-do
var afterIn = /.*in\s/;
var beforeIn = /\sin.*/;
var ns = /.*\./;
var pro = str.replace(afterIn, '').replace(ns, '');
var data = this.scope[pro];
var data = scope[pro];
var key = str.replace(beforeIn, '');
var parentNode = this.node.parentNode;
var node = parentNode.removeChild(this.node);
var parentNode = element.parentNode;
var node = parentNode.removeChild(element);
var frg = document.createDocumentFragment();

@@ -38,6 +38,2 @@ var _r = this.reg;

rootScope = this.scope;
node.removeAttribute('repeat');

@@ -52,2 +48,3 @@ repeatNode = node;

eom.reg = _r;
scope.__children__ = scope.__children__ || [];

@@ -58,5 +55,16 @@ if (data && data.length) {

var m = {};
var grammars=[];
trans(_r, _n, d, key, m,grammars);
m.grammars = grammars;
var F = function(f){
//this._$value = f;
this[key] = f;
}
F.prototype = scope;
var mod = new F(d);//new model(d);
mod.__eom__ = {};
mod.__eom__[key] = m;
mod.__last__ = {};
mod.__last__[key] = scope.__last__ && scope.__last__[pro][i] || $tool.clone(d);
mod.__listeners__ = {};
scope.__children__.push(mod);
trans(_r, _n, mod, key, m);
m.repeat = _n;

@@ -73,3 +81,3 @@ eom.push(m);

function trans(reg, doc, scope, key, eom,grammars,stop) {
function trans(reg, doc, scope, key, eom) {
var hasRepeat = false;

@@ -88,3 +96,4 @@ if (doc.attributes && doc.attributes.length) {

});
attr.nodeValue = attr.nodeValue.replace(/{{.*}}/, scope[k]);
var value = typeof scope[key] == 'object' ? scope[key][k] : scope[key];
attr.nodeValue = attr.nodeValue.replace(/{{.*}}/, value);
}

@@ -98,18 +107,11 @@

hasRepeat = true;
repeat.call(context, attr.nodeValue.replace(reg, ''));
var ch = attr.nodeValue.replace(afterIn,'').replace(/\..*/,'');
context.scope = scope[ch];
repeat.call(context, attr.nodeValue.replace(reg, ''),scope[ch],doc);
}else{
var grammer = loadGrammar(attr.nodeName);
if($tool.isFunction(grammer)){
//context.scope = rootScope;
var str = attr.nodeValue.replace(reg, '');
grammars.push({
grammar : attr.nodeName,
eom:eom,
reg:reg,
node:doc,
str : str,
rootScope:rootScope
});
//todo : scope should inherit from rootScope
if(!stop)grammer.call(context,str,rootScope,context.node,context.scope);
context.eom = {};
grammer.call(context,str,scope,context.node);
}

@@ -131,3 +133,3 @@ }

// 2. scope = "string" or number
var value = $tool.isObject(scope) ? scope[k] : scope;
var value = typeof scope[key] == 'object' ? scope[key][k] : scope[key];
doc.nodeValue = doc.nodeValue.replace(/{{.*}}/, value);

@@ -137,3 +139,3 @@ }

Array.prototype.forEach.call(doc.childNodes, function(child) {
trans(reg, child, scope, key, eom,grammars,stop);
trans(reg, child, scope, key, eom);
});

@@ -140,0 +142,0 @@ }

@@ -11,17 +11,23 @@ define('river.grammer.scope', function() {

if (tools.isObject(source)) {
var mod = new model(str, this.eom);
//source.watch(this.eom);
var mod = new model();
//make source inherit from mod
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto
//as the __proto__ is deprecated,I have to do this
for(var x in mod){
source[x] = mod[x]
}
source.__last__ = tools.clone(source);
source.__eom__ = this.eom;
this.scope = source;
} else if (tools.isFunction(source)) {
var m = new model(str, this.eom);
var m = new model();
this.scope = m;
source.call(m);
m.__last__ = tools.clone(m);
m.__eom__ = this.eom;
} else {
var guid = tools.guid();
this.scope = new model(guid, this.eom);
var mo = new model();
mo.__last__ = tools.clone(mo);
mo.__eom__ = this.eom;
this.scope = mo;
}

@@ -28,0 +34,0 @@ }

{
"name": "riverjs",
"version": "1.0.74",
"version": "1.0.81",
"description": "a simple font-end framework with extendable two-way binding",

@@ -5,0 +5,0 @@ "main": "Gruntfile.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc