From 0be3b99ab20038d3ae96add6a139ecf781e243a3 Mon Sep 17 00:00:00 2001 From: Garrett Murphey Date: Mon, 31 Dec 2018 12:41:54 -0500 Subject: [PATCH] Allowing elements to be passed to service. --- addon/services/resize-detector.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/addon/services/resize-detector.js b/addon/services/resize-detector.js index a41fcd3..5684892 100644 --- a/addon/services/resize-detector.js +++ b/addon/services/resize-detector.js @@ -16,7 +16,14 @@ export default Ember.Service.extend({ }, setup(selector, callback) { - let element = document.querySelector(selector) + let element; + + if (selector instanceof HTMLElement) { + element = selector; + } else { + element = document.querySelector(selector); + } + if (!element) { error(`service:resize-detector - could not find an element matching ${selector}`); return; @@ -25,7 +32,14 @@ export default Ember.Service.extend({ }, teardown(selector, callback) { - let element = document.querySelector(selector) + let element; + + if (selector instanceof HTMLElement) { + element = selector; + } else { + element = document.querySelector(selector); + } + if (element) { this.detector.removeListener(element, callback); }