Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

jsarnowski / jsarnowski/elementor-pro   php

Repository URL to install this package:

/ app / modules / site-editor / assets / js / context / models / condition.js

export default class Condition {
	id = elementorCommon.helpers.getUniqueId();
	default = '';
	type = 'include';
	name = '';
	sub = '';
	subId = '';
	options = [];
	subOptions = [];
	subIdAutocomplete = [];
	subIdOptions = [];
	conflictErrors = [];

	constructor( args ) {
		this.set( args );
	}

	set( args ) {
		Object.assign( this, args );
		return this;
	}

	clone() {
		return Object.assign( new Condition(), this );
	}

	remove( keys ) {
		if ( ! Array.isArray( keys ) ) {
			keys = [ keys ];
		}

		keys.forEach( ( key ) => {
			delete this[ key ];
		} );

		return this;
	}

	only( keys ) {
		if ( ! Array.isArray( keys ) ) {
			keys = [ keys ];
		}

		const keysToRemove = Object.keys( this )
			.filter( ( conditionKey ) => ! keys.includes( conditionKey ) );

		this.remove( keysToRemove );

		return this;
	}

	toJson() {
		return JSON.stringify( this );
	}

	toString() {
		return this.forDb().filter( ( item ) => item ).join( '/' );
	}

	forDb() {
		return [ this.type, this.name, this.sub, this.subId ];
	}

	forContext() {
		return {
			type: this.type,
			name: this.name,
			sub: this.sub,
			subId: this.subId,
		};
	}
}