Last active
August 29, 2015 14:06
-
-
Save hysios/8e11daf61f21d30a384c to your computer and use it in GitHub Desktop.
ember highlight a item in menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* lib/index-array.js */ | |
App.IndexArray = Ember.ArrayController.extend({ | |
_indexName: 'index', | |
_isVirtual: true, | |
/** | |
* initializer function | |
* | |
* @param [Array] array proxy target object | |
* @param [Controller] content array with parent content | |
* @optional [Object] properties additional properties, like itemController, and _indexName also. | |
*/ | |
init: function(array, content, properties){ | |
this._super(); | |
properties = Ember.merge(properties || {}, { | |
itemController: 'isActive', | |
_indexName: 'index' | |
}); | |
this.setProperties(properties); | |
this.set('container', content.get('container')); | |
this.set('model', array'); | |
this.set('parentController', content); | |
}, | |
controllerAt: function(idx, object, controllerClass) { | |
var subController = this._super(idx, object, controllerClass), | |
indexProperty = this.get('_indexName'); | |
subController.set(indexProperty, idx); | |
return subController; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* lib/is-active.js */ | |
App.IsActiveController = Ember.ObjectController.extend({ | |
itemIndexProperty: 'itemIndex', | |
index: null, | |
isActive: function(){ | |
var parent = this.get('parentController'), | |
parentItemIndex = parent.get(this.get('itemIndexproperty')); | |
return parentItemIndex === this.get('index'); | |
}.property() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment