Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,60 @@
delete copy['$__page__'];
return copy;
};
viewModel.toJSONByPrototype = function(_theDataModel){
var isNumber = function (obj) {
return (toString.call(obj) == "[object " + Number + "]") || !isNaN(obj);
};
var isString = function (obj) {
return "[object String]" == toString.call(obj);
};
var isObject = function (obj) {
return obj === Object(obj);
};
var isBoolean = function(obj) {
return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
};
var isArray = Array.isArray || function(obj) {
return toString.call(obj) == '[object Array]';
};
var isFunction = function (obj) {
return toString.call(obj) == "[object " + Function + "]";
};
if (typeof (/./) !== 'function') {
isFunction = function(obj) {
return typeof obj === 'function';
};
}
var toInnerJSON = function(obj, dataModel, viewModel){
Object.keys(dataModel).forEach( function(key, index, array){
var value = dataModel[key];
if( isArray( value ) ){
if( isFunction( viewModel[key] ) ){
obj[ key ] = viewModel[key]();
} else if( isArray( viewModel[key] ) ){
obj[ key ] = [];
viewModel[key].forEach( function(element, _index, _array){
if( isFunction( element ) )
obj[ key ].push( element() );
} );
}
}
else if( isString( value ) || isNumber( value ) || isBoolean( value ) ){
if( viewModel[ key ] && isFunction( viewModel[ key ] ) ){
obj[ key ] = viewModel[ key ]();
}
}
else if( isObject( value ) ){
obj[ key ] = {};
toInnerJSON( obj[ key ], dataModel[ key ], viewModel[ key ] );
}
});
return obj;
};

return toInnerJSON( {}, _theDataModel, this );
};

};

var fire = function (scope, name, options) {
Expand Down