-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup.min.js
More file actions
2 lines (2 loc) · 4.83 KB
/
group.min.js
File metadata and controls
2 lines (2 loc) · 4.83 KB
1
2
/*! groupjs 2017-03-09 */
!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.Grp=b()}):"object"==typeof module&&module.exports?module.exports=b():a.Grp=b()}(this,function(){function a(a,b){for(var c=a.length;c--;)if(a[c]===b)return!0;return!1}"undefined"!=typeof window&&window&&(global=window),Object.create||(Object.create=function(a){function b(){}if(arguments.length>1)throw new Error("Object.create implementation only accepts the first parameter.");return b.prototype=a,new b}),Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),"undefined"==typeof Array.isArray&&(Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)});var b={create:function(a){var b=Object.create(this);if(this.hasOwnProperty("_parentIDs")){b._parentIDs=[];for(var c=this._parentIDs.length,d=0;d<c;d++)b._parentIDs.push(this._parentIDs[d])}return this.hasOwnProperty("_id")&&(b.hasOwnProperty("_parentIDs")||(b._parentIDs=[]),b._parentIDs.push(this._id),a||(a=this._id)),b._id=a,"init"in b&&"function"==typeof b.init&&b.init(),b},extend:function(){for(var a=0;a<arguments.length;a++){var b=arguments[a];for(var c in b)this[c]=b[c],"init"===c&&"function"==typeof this.init&&this.init()}return this},_isReservedAttr:function(c){return!!(c in b||c in d||a(["_parentIDs","obj","group","_memberList","_id"],c)||this.reservedAttr&&Array.isArray(this.reservedAttr)&&a(this.reservedAttr,c))},self:function(){return this}},c="__NOTFOUND__",d=b.create("group");d.extend({create:function(a){var c=b.create.apply(this,arguments);return"_buildMemberList"in c&&"function"==typeof c._buildMemberList&&c._buildMemberList(),c},_buildMemberList:function(){if(this._memberList){if(!this.hasOwnProperty("_memberList")){var a=this._memberList;this._memberList={};for(var b in a){var c=a[b],d=c.create();d.group=this,this._memberList[b]=d}}}else this._memberList={}},join:function(){for(var a=0;a<arguments.length;a++){var b=arguments[a],c=b.create();c.group=this,this._memberList[b._id]=c}return this},call:function(a,b){if("string"!=typeof a)throw"Group "+this._id+" calling "+a+" Error: member id is not string.";if("undefined"==typeof b)throw"Group "+this._id+" calling "+a+" Error: Method name is not provided";if(a in this._memberList){found=!0;var c=this._memberList[a];if(b in c&&"function"==typeof c[b])return c[b].apply(c,Array.prototype.slice.call(arguments,2));throw"Group "+this._id+" calling "+a+" Error: Method name "+b+" is not found"}var d=this._memberList;for(var e in d){var c=d[e];if(c.hasOwnProperty("_parentIDs")&&b in c&&"function"==typeof c[b])for(var f=c._parentIDs,g=f.length,h=0;h<g;h++)if(a===f[h])return c[b].apply(c,Array.prototype.slice.call(arguments,2))}throw"Group "+this._id+" does not contain object member "+a},upCall:function(a,b){var d=this._upCall.apply(this,arguments);if("string"==typeof d&&d===c)throw"The upper groups from group "+this._id+" does not have member "+a+" with method "+b;return d},_upCall:function(a,b){return a in this._memberList?this.call.apply(this,arguments):this.group?this.group._upCall.apply(this.group,arguments):c},downCall:function(a,b){var d=this._downCall.apply(this,arguments);if("string"==typeof d&&d===c)throw"The downward groups from group "+this._id+" does not have member "+a+" with method "+b;return d},_downCall:function(a,b){if(a in this._memberList)return this.call.apply(this,arguments);var d=this._memberList;for(var e in d){var f=d[e];if(f.hasOwnProperty("_memberList"))return f._downCall.apply(f,arguments)}return c},members:function(){function a(b){var c=b._memberList,d=[];for(var e in c){var f={_id:e},g=c[e];g.hasOwnProperty("_memberList")&&(f.members=a(g)),d.push(f)}return d}return a(this)},getMember:function(a,b){function c(a,b){if(Array.isArray(a)&&b&&b.hasOwnProperty("_memberList"))for(var e=a.length,f=0;f<e;f++){if(!a[f].hasOwnProperty("members"))return d(b);var g=c(a[f].members,b.getMember(a[f]._id));if(g)return g}return null}function d(b){var c=b._memberList;if(a in c)return c[a];for(var e in c){var f=c[e];if(f.hasOwnProperty("_memberList")){var g=d(f);if(g)return g}}return null}return b&&Array.isArray(b)?c(b,this):d(this)},override:function(a,b){function c(a,b){if(Array.isArray(a)&&b&&b.hasOwnProperty("_memberList"))for(var e=a.length,f=0;f<e;f++)a[f].hasOwnProperty("members")?c(a[f].members,a[f]):d(b)}function d(b){if(b.hasOwnProperty("_memberList"))for(var c in b._memberList){var e=b._memberList[c];e._id===a._id?b.join(a):e.hasOwnProperty("_memberList")&&d(e)}}return a&&(b&&Array.isArray(b)?c(b,this):d(this)),this}});var e={obj:b,group:d};return e});