basant307/AI_Governance_Project
048
1import Selector from '../selector/index.mjs';2 3let elesfn = ({4 allAre: function( selector ){5 let selObj = new Selector( selector );6 7 return this.every(function( ele ){8 return selObj.matches( ele );9 });10 },11 12 is: function( selector ){13 let selObj = new Selector( selector );14 15 return this.some(function( ele ){16 return selObj.matches( ele );17 });18 },19 20 some: function( fn, thisArg ){21 for( let i = 0; i < this.length; i++ ){22 let ret = !thisArg ? fn( this[ i ], i, this ) : fn.apply( thisArg, [ this[ i ], i, this ] );23 24 if( ret ){25 return true;26 }27 }28 29 return false;30 },31 32 every: function( fn, thisArg ){33 for( let i = 0; i < this.length; i++ ){34 let ret = !thisArg ? fn( this[ i ], i, this ) : fn.apply( thisArg, [ this[ i ], i, this ] );35 36 if( !ret ){37 return false;38 }39 }40 41 return true;42 },43 44 same: function( collection ){45 // cheap collection ref check46 if( this === collection ){ return true; }47 48 collection = this.cy().collection( collection );49 50 let thisLength = this.length;51 let collectionLength = collection.length;52 53 // cheap length check54 if( thisLength !== collectionLength ){ return false; }55 56 // cheap element ref check57 if( thisLength === 1 ){ return this[0] === collection[0]; }58 59 return this.every(function( ele ){60 return collection.hasElementWithId( ele.id() );61 });62 },63 64 anySame: function( collection ){65 collection = this.cy().collection( collection );66 67 return this.some(function( ele ){68 return collection.hasElementWithId( ele.id() );69 });70 },71 72 allAreNeighbors: function( collection ){73 collection = this.cy().collection( collection );74 75 let nhood = this.neighborhood();76 77 return collection.every(function( ele ){78 return nhood.hasElementWithId( ele.id() );79 });80 },81 82 contains: function( collection ){83 collection = this.cy().collection( collection );84 85 let self = this;86 87 return collection.every(function( ele ){88 return self.hasElementWithId( ele.id() );89 });90 }91});92 93elesfn.allAreNeighbours = elesfn.allAreNeighbors;94elesfn.has = elesfn.contains;95elesfn.equal = elesfn.equals = elesfn.same;96 97export default elesfn;98 