Skip to content

Instantly share code, notes, and snippets.

@alexgb
Created November 6, 2015 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexgb/1fac69263b53f42788f6 to your computer and use it in GitHub Desktop.
Save alexgb/1fac69263b53f42788f6 to your computer and use it in GitHub Desktop.
Ember console utils
// 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