<commit_before>/**
 * enyo.Spotlight.Decorator.Container kind definition
 * @author: <NAME>
 */

enyo.kind({
	name: 'enyo.Spotlight.Decorator.Container',
	
	statics: {
		decorates: null,
		
		// Creates oSender._spotlight object
		_initComponent: function(oSender) {
			if (!this._isInitialized(oSender)) {
				this.setLastFocusedChild(oSender, enyo.Spotlight.getFirstChild(oSender));
				enyo.Spotlight.Util.interceptEvents(oSender, this._handleEvent);
			}
		},
		
		_isInitialized: function(oSender) {
			return typeof oSender._spotlight.lastFocusedChild != 'undefined';
		},
		
		// Handle events bubbling from within the container
		_handleEvent: function(oSender, oEvent) {
			switch (oEvent.type) {
				case 'onSpotlightFocus':
					if (oEvent.originator !== oSender) {
						enyo.Spotlight.Decorator.Container.setLastFocusedChild(oSender, oEvent.originator);
					}
				//	return true;	// prevent default ???????? Why whould we need to prevent default here? Why? Why? I think not! Lex.
			}
		},
		
		// Was last spotted control the container's child?
		_hadFocus: function(oSender) {
			var oLastControl = enyo.Spotlight.getLastControl();
			return enyo.Spotlight.Util.isChild(oSender, oLastControl);
		},
		
		_focusLeave: function(oSender, s5WayEventType) {
			// console.log('FOCUS LEAVE', oSender.name);
			var sDirection = s5WayEventType.replace('onSpotlight','').toUpperCase();
			enyo.Spotlight.Util.dispatchEvent('onSpotlightContainerLeave', {direction: sDirection}, oSender);
		},
		
		_focusEnter: function(oSender) {
			// console.log('FOCUS ENTER', oSender.name);
			var oLastFocusedChild = this.getLastFocusedChild(oSender);
			if (oLastFocusedChild) {
				enyo.Spotlight.spot(oLastFocusedChild);
			}
			enyo.Spotlight.Util.dispatchEvent('onSpotlightContainerEnter', {}, oSender);
		},
				
		/******************************/
		
		onSpotlightFocused: function(oSender, oEvent) {
			// console.log('FOCUSED', oSender.name);
			if (enyo.Spotlight.getPointerMode()) { return true; }
			this._initComponent(oSender);
			
			if (this._hadFocus(oSender)) {												// Focus came from within
				var s5WayEventType = enyo.Spotlight.getLast5WayEvent() ? enyo.Spotlight.getLast5WayEvent().type : '';
				if (!(oSender.parent instanceof enyo.Panels)) {
					enyo.Spotlight.Util.dispatchEvent(s5WayEventType, null, oSender);
				} else 
				if (oSender.parent.spotlight !== true && oSender.parent.spotlight != 'true') {
					enyo.Spotlight.Util.dispatchEvent(s5WayEventType, null, oSender);
				}
				this._focusLeave(oSender, s5WayEventType);
			} else {																	// Focus came from without
				this._focusEnter(oSender);
			}
			
			return true;
		},
		
		onSpotlightLeft: function(oSender, oEvent) {
			// console.log('CONTAINER', oSender.name, '| event:', oEvent.type, '|', oEvent.originator.name);
			this._focusLeave(oSender, oEvent.type);
		},
		
		onSpotlightRight: function(oSender, oEvent) {
			// console.log('CONTAINER', oSender.name, '| event:', oEvent.type, '|', oEvent.originator.name);
			this._focusLeave(oSender, oEvent.type);
		},
		
		onSpotlightUp: function(oSender, oEvent) {
			// console.log('CONTAINER', oSender.name, '| event:', oEvent.type, '|', oEvent.originator.name);
			this._focusLeave(oSender, oEvent.type);
		},
		
		onSpotlightDown: function(oSender, oEvent) {
			// console.log('CONTAINER', oSender.name, '| event:', oEvent.type, '|', oEvent.originator.name);
			this._focusLeave(oSender, oEvent.type);
		},
		
		// What child of container was last focused?
		getLastFocusedChild: function(oSender) {
			oSender._spotlight = oSender._spotlight || {};
			if (!oSender._spotlight.lastFocusedChild) {
				oSender._spotlight.lastFocusedChild = enyo.Spotlight.getChildren(oSender)[0];
			}
			return oSender._spotlight.lastFocusedChild;
		},
		
		// Set last focused child
		setLastFocusedChild: function(oSender, oChild) {
			if (!enyo.Spotlight.isSpottable(oChild)) {
				enyo.warn('Spotlight Container' + oSender.name + ' has not spottable lastFocusedChild ' + oChild.name);
			}
			oSender._spotlight = oSender._spotlight || {};
			oSender._spotlight.lastFocusedChild = oChild;
		},
	}
});<commit_msg>Adding check for 'destroyed' on container's lastFocusedChild, as per conversation http://nebula.palm.com/support/index.php?cID=163&ccm_paging_p=1&time=1368824385#msg170<commit_after>/**
 * enyo.Spotlight.Decorator.Container kind definition
 * @author: <NAME>
 */

enyo.kind({
	name: 'enyo.Spotlight.Decorator.Container',
	
	statics: {
		decorates: null,
		
		// Creates oSender._spotlight object
		_initComponent: function(oSender) {
			if (!this._isInitialized(oSender)) {
				this.setLastFocusedChild(oSender, enyo.Spotlight.getFirstChild(oSender));
				enyo.Spotlight.Util.interceptEvents(oSender, this._handleEvent);
			}
		},
		
		_isInitialized: function(oSender) {
			return typeof oSender._spotlight.lastFocusedChild != 'undefined';
		},
		
		// Handle events bubbling from within the container
		_handleEvent: function(oSender, oEvent) {
			switch (oEvent.type) {
				case 'onSpotlightFocus':
					if (oEvent.originator !== oSender) {
						enyo.Spotlight.Decorator.Container.setLastFocusedChild(oSender, oEvent.originator);
					}
				//	return true;	// prevent default ???????? Why whould we need to prevent default here? Why? Why? I think not! Lex.
			}
		},
		
		// Was last spotted control the container's child?
		_hadFocus: function(oSender) {
			var oLastControl = enyo.Spotlight.getLastControl();
			return enyo.Spotlight.Util.isChild(oSender, oLastControl);
		},
		
		_focusLeave: function(oSender, s5WayEventType) {
			// console.log('FOCUS LEAVE', oSender.name);
			var sDirection = s5WayEventType.replace('onSpotlight','').toUpperCase();
			enyo.Spotlight.Util.dispatchEvent('onSpotlightContainerLeave', {direction: sDirection}, oSender);
		},
		
		_focusEnter: function(oSender) {
			// console.log('FOCUS ENTER', oSender.name);
			var oLastFocusedChild = this.getLastFocusedChild(oSender);
			if (oLastFocusedChild) {
				enyo.Spotlight.spot(oLastFocusedChild);
			}
			enyo.Spotlight.Util.dispatchEvent('onSpotlightContainerEnter', {}, oSender);
		},
				
		/******************************/
		
		onSpotlightFocused: function(oSender, oEvent) {
			// console.log('FOCUSED', oSender.name);
			if (enyo.Spotlight.getPointerMode()) { return true; }
			this._initComponent(oSender);
			
			if (this._hadFocus(oSender)) {												// Focus came from within
				var s5WayEventType = enyo.Spotlight.getLast5WayEvent() ? enyo.Spotlight.getLast5WayEvent().type : '';
				if (!(oSender.parent instanceof enyo.Panels)) {
					enyo.Spotlight.Util.dispatchEvent(s5WayEventType, null, oSender);
				} else 
				if (oSender.parent.spotlight !== true && oSender.parent.spotlight != 'true') {
					enyo.Spotlight.Util.dispatchEvent(s5WayEventType, null, oSender);
				}
				this._focusLeave(oSender, s5WayEventType);
			} else {																	// Focus came from without
				this._focusEnter(oSender);
			}
			
			return true;
		},
		
		onSpotlightLeft: function(oSender, oEvent) {
			// console.log('CONTAINER', oSender.name, '| event:', oEvent.type, '|', oEvent.originator.name);
			this._focusLeave(oSender, oEvent.type);
		},
		
		onSpotlightRight: function(oSender, oEvent) {
			// console.log('CONTAINER', oSender.name, '| event:', oEvent.type, '|', oEvent.originator.name);
			this._focusLeave(oSender, oEvent.type);
		},
		
		onSpotlightUp: function(oSender, oEvent) {
			// console.log('CONTAINER', oSender.name, '| event:', oEvent.type, '|', oEvent.originator.name);
			this._focusLeave(oSender, oEvent.type);
		},
		
		onSpotlightDown: function(oSender, oEvent) {
			// console.log('CONTAINER', oSender.name, '| event:', oEvent.type, '|', oEvent.originator.name);
			this._focusLeave(oSender, oEvent.type);
		},
		
		// What child of container was last focused?
		getLastFocusedChild: function(oSender) {
			oSender._spotlight = oSender._spotlight || {};
			if (!oSender._spotlight.lastFocusedChild || oSender._spotlight.lastFocusedChild.destroyed) {
				oSender._spotlight.lastFocusedChild = enyo.Spotlight.getChildren(oSender)[0];
			}
			return oSender._spotlight.lastFocusedChild;
		},
		
		// Set last focused child
		setLastFocusedChild: function(oSender, oChild) {
			if (!enyo.Spotlight.isSpottable(oChild)) {
				enyo.warn('Spotlight Container' + oSender.name + ' has not spottable lastFocusedChild ' + oChild.name);
			}
			oSender._spotlight = oSender._spotlight || {};
			oSender._spotlight.lastFocusedChild = oChild;
		},
	}
});
{'fraction_non_alphanumeric': 0.14647887323943662, 'fraction_numerical': 0.004107981220657277, 'mean_word_length': 3.9976539589442814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4222434', 'n_tokens_mistral': 3399, 'n_tokens_neox': 2813, 'n_words': 473}