1 // ========================================================================== 2 // Project: SproutCore Costello - Property Observing Library 3 // Copyright: ©2006-2011 Strobe Inc. and contributors. 4 // Portions ©2008-2011 Apple Inc. All rights reserved. 5 // License: Licensed under MIT license (see license.js) 6 // ========================================================================== 7 8 /** @private */ 9 SC.Tree = /** @scope SC.Tree.prototype */ { 10 11 /** @private Call the method recursively on all child views. */ 12 invoke: function (methodName, isTopDown, context) { 13 var childView, 14 childViews = this.get('childViews'), 15 method, 16 shouldContinue; 17 18 for (var i = childViews.length - 1; i >= 0; i--) { 19 childView = childViews[i]; 20 21 // We allow missing childViews in the array so ignore them. 22 if (!childView) { continue; } 23 24 // Look up the method on the child. 25 method = childView[methodName]; 26 27 // Call the method on this view *before* its children. 28 if (isTopDown === undefined || isTopDown) { 29 shouldContinue = method.call(childView, context); 30 } 31 32 // Recurse. 33 if (shouldContinue === undefined || shouldContinue) { 34 childView._callOnChildViews(methodName, isTopDown, context); 35 } 36 37 // Call the method on this view *after* its children. 38 if (isTopDown === false) { 39 method.call(childView, context); 40 } 41 } 42 } 43 44 }; 45