forEach.js

  1. aeq = ( function ( aeq ) {
  2. aeq.extend({
  3. /**
  4. * Loops through the layers of a comp, array of comps, or all layers in the
  5. * project, and executes a function for each one.
  6. * @method
  7. * @memberof aeq
  8. * @param {CompItem|CompItem[]|forEachArrayCallback} [obj]
  9. * A `CompItem` or array of `compItem`s to get layers from.
  10. * If this is function, the function will loop through all layers in
  11. * the project.
  12. * @param {forEachArrayCallback}
  13. * callback The function to execute for each layer
  14. * @return {aeq}
  15. * The AEQuery library.
  16. */
  17. forEachLayer: function ( obj, callback ) {
  18. if ( aeq.isComp( obj ) ) {
  19. var length = obj.numLayers,
  20. i = 1;
  21. for ( ; i <= length; i++ ) {
  22. if ( callback( obj.layer( i ), i, obj ) === false ) {
  23. break;
  24. }
  25. }
  26. } else if ( aeq.isArray( obj ) ) {
  27. aeq.forEach( obj, function ( obj ) {
  28. aeq.forEachLayer( obj, callback );
  29. });
  30. } else if ( aeq.isFunction( obj ) ) {
  31. callback = obj;
  32. aeq.forEachComp( function ( comp ) {
  33. aeq.forEachLayer( comp, callback );
  34. });
  35. }
  36. return aeq;
  37. },
  38. /**
  39. * Loops through the properties of a Comp, Layer, PropertyGroup, or an array
  40. * of any of them, and executes a function for each one.
  41. * @method
  42. * @memberof aeq
  43. * @param {CompItem|Layer|PropertyGroup|Array|forEachArrayCallback} [obj]
  44. * The object or array of objects to get properties from.
  45. * If this is function, the function will loop through all properties
  46. * in the project.
  47. * @param {forEachArrayCallback} callback
  48. * The function to execute for each property
  49. * @return {aeq}
  50. * The AEQuery library.
  51. */
  52. forEachProperty: function ( obj, callback ) {
  53. if ( aeq.isLayer( obj ) || aeq.isPropertyGroup( obj ) ) {
  54. var properties = aeq.getPropertyChildren( obj, {});
  55. aeq.forEach( properties, callback );
  56. } else if ( aeq.isComp( obj ) ) {
  57. aeq.forEachLayer( obj, function ( layer ) {
  58. var properties = aeq.getPropertyChildren( layer, {});
  59. aeq.forEach( properties, callback );
  60. });
  61. } else if ( aeq.isArray( obj ) ) {
  62. aeq.forEach( obj, function ( obj ) {
  63. aeq.forEachProperty( obj, callback );
  64. });
  65. } else if ( aeq.isFunction( obj ) ) {
  66. callback = obj;
  67. aeq.forEachLayer( function ( layer ) {
  68. aeq.forEachProperty( layer, callback );
  69. });
  70. }
  71. return aeq;
  72. },
  73. /**
  74. * Loops through the effects in a Comp, or on a Layer, and executes a function
  75. * for each one.
  76. * @method
  77. * @memberof aeq
  78. * @param {CompItem|Layer|Array|forEachArrayCallback} [obj]
  79. * The object or array of objects to get effects from.
  80. * If this is function, the function will loop through all properties
  81. * in the project.
  82. * @param {forEachArrayCallback} callback
  83. * The function to execute for each effect
  84. * @return {aeq}
  85. * The AEQuery library.
  86. */
  87. forEachEffect: function ( obj, callback ) {
  88. var i, length, effects;
  89. if ( aeq.isLayer( obj ) ) {
  90. effects = obj.property( 'ADBE Effect Parade' );
  91. length = effects.numProperties;
  92. for ( i = 1; i <= length; i++ ) {
  93. if ( callback( effects.property( i ), i, effects ) === false ) {
  94. break;
  95. }
  96. }
  97. } else if ( aeq.isComp( obj ) ) {
  98. aeq.forEachLayer( obj, function ( layer ) {
  99. aeq.forEachEffect( layer, callback );
  100. });
  101. } else if ( aeq.isArray( obj ) ) {
  102. aeq.forEach( obj, function ( obj ) {
  103. aeq.forEachEffect( obj, callback );
  104. });
  105. } else if ( aeq.isFunction( obj ) ) {
  106. callback = obj;
  107. aeq.forEachLayer( function ( layer ) {
  108. aeq.forEachEffect( layer, callback );
  109. });
  110. }
  111. return aeq;
  112. },
  113. /**
  114. * Loops through the comps in a project and executes a function for each one.
  115. * @method
  116. * @memberof aeq
  117. * @param {forEachArrayCallback} callback
  118. * The function to execute for each comp.
  119. */
  120. forEachComp: function ( callback ) {
  121. aeq.forEach( aeq.getCompositions(), callback );
  122. },
  123. /**
  124. * Loops through the Project items in a project and executes a function
  125. * for each one.
  126. * @method
  127. * @memberof aeq
  128. * @param {forEachArrayCallback} callback
  129. * The function to execute for each item.
  130. * @return {aeq}
  131. * The AEQuery library.
  132. */
  133. forEachItem: function ( callback ) {
  134. var project = app.project;
  135. var items = project.items;
  136. var length = items.length;
  137. for ( var i = 1; i <= length; i++ ) {
  138. if ( callback( items[i], i, project ) === false ) {
  139. break;
  140. }
  141. }
  142. return aeq;
  143. },
  144. /**
  145. * Loops through the items in the renderqueue and executes a function
  146. * for each one.
  147. * @method
  148. * @memberof aeq
  149. * @param {forEachArrayCallback} callback
  150. * The function to execute for each renderQueue Item.
  151. * @return {aeq}
  152. * The AEQuery library.
  153. */
  154. forEachRenderQueueItem: function ( callback ) {
  155. var renderQueue = app.project.renderQueue;
  156. var renderQueueItems = renderQueue.items;
  157. var length = renderQueueItems.length;
  158. for ( var i = 1; i <= length; i++ ) {
  159. if ( callback( renderQueueItems[i], i, renderQueue ) === false ) {
  160. break;
  161. }
  162. }
  163. return aeq;
  164. },
  165. /**
  166. * Loops through the output modules in the renderqueue and executes a function
  167. * for each one.
  168. * @method
  169. * @memberof aeq
  170. * @param {forEachArrayCallback} callback
  171. * The function to execute for each Output Module.
  172. * @return {aeq}
  173. * The AEQuery library.
  174. */
  175. forEachOutputModule: function ( callback ) {
  176. aeq.forEachRenderQueueItem( function ( item ) {
  177. var length = item.outputModules.length;
  178. for ( var i = 1; i <= length; i++ ) {
  179. if ( callback( item.outputModules[i], i, item ) === false ) {
  180. break;
  181. }
  182. }
  183. });
  184. return aeq;
  185. }
  186. });
  187. // ForEach aliases
  188. /**
  189. * @see aeq.forEachProperty
  190. * @function
  191. */
  192. aeq.forEachProp = aeq.forEachProperty;
  193. /**
  194. * @see aeq.forEachComp
  195. * @function
  196. */
  197. aeq.forEachComposition = aeq.forEachComp;
  198. /**
  199. * @see aeq.forEachRenderQueueItem
  200. * @function
  201. */
  202. aeq.forEachRQItem = aeq.forEachRenderQueueItem;
  203. /**
  204. * @see aeq.forEachOutputModule
  205. * @function
  206. */
  207. aeq.forEachOM = aeq.forEachOutputModule;
  208. return aeq;
  209. }( aeq || {}) );