UNPKG

adlayer-library

Version:

Adlayer javascript core library

74 lines (72 loc) 1.6 kB
/** * @module core */ /** * Abstract class for page * * @class Page * @constructor * @extends Core * @param {Object} attributes */ var Page = function( attributes ){ var Core = require('./core').Core; Core.apply(this, arguments); /** * id unique page id * @property id * @type string */ this.id = ''; /** * page name * @property name * @type string */ this.name = ''; /** * Collection of page spaces * @property spaces * @type array */ this.spaces = []; /** * Collection of page spaces * @property status * @type boolean */ this.status = true; /* * @method __construct * @private * @returns {Object} return this to allow chain pattern */ var __construct = function(self){ self = self.extend(attributes); }(this); }; /** * @method getActiveContent * @public * @return {Page} the instance itself to improve chainability * @require Javascript 1.6 * __Warning:__ Don't use this in browser, because it can not work in old browsers * @todo: should be readonly not modify the object just return filtered value */ Page.prototype.getActiveContent = function(){ if( this.spaces && this.spaces.length >= 1 ){ // Run over and redesign every space (removing ads with status false) this.spaces = this.spaces.map(function(space){ if( space.ads && space.ads.length >= 1 ){ space.ads = space.ads.filter(function(ad){ // If ad has status equal to false will auto removed from array return ad.status; }); } // re-assign modified space to spaces collection return space; }); } return this; }; exports.Page = Page;