Created
November 6, 2015 03:51
-
-
Save alexgb/1fac69263b53f42788f6 to your computer and use it in GitHub Desktop.
Ember console utils
This file contains 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
// https://github.com/ebryn/ember-console-utils/blob/master/ember-console-utils.js | |
HTMLElement.prototype.view = function() { | |
var viewEl = this; | |
if (!viewEl.classList.contains('ember-view')) { | |
viewEl = $(viewEl).parents('.ember-view:first')[0]; | |
} | |
return Ember.View.views[viewEl.id]; | |
}; | |
HTMLElement.prototype.controller = function() { | |
var viewObj = this.view(); | |
return viewObj.get('controller'); | |
}; | |
HTMLElement.prototype.template = function() { | |
var viewObj = this.view(), | |
templateName = viewObj.templateName; | |
if (!templateName) { | |
templateName = viewObj.nearestWithProperty('templateName').templateName; | |
} | |
return templateName; | |
}; | |
HTMLElement.prototype.model = function() { | |
var viewObj = this.view(), | |
viewContext = viewObj.get('context'), | |
viewController = this.controller(); | |
return viewContext === viewController ? viewController.get('content') : viewContext; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment