diff --git a/lib/common/components/StickySidebar/sticky-sidebar.js b/lib/common/components/StickySidebar/sticky-sidebar.js index 345d1d8e..c0f2cd1b 100644 --- a/lib/common/components/StickySidebar/sticky-sidebar.js +++ b/lib/common/components/StickySidebar/sticky-sidebar.js @@ -1,34 +1,26 @@ 'use strict'; -import {Component, View, OnInit, OnDestroy, ElementRef} from 'angular2/core'; +import {Directive, ElementRef} from 'angular2/core'; import {BrowserDomAdapter} from 'angular2/platform/browser'; -@Component({ - selector: 'sticky-sidebar', +@Directive({ + selector: '[sticky-sidebar]', inputs: ['scrollParent', 'scrollYOffset'] }) -@View({ - template: ` -
- `, - lifecycle: [OnInit, OnDestroy] -}) export default class StickySidebar { - constructor(elementRef, adapter) { + constructor(elementRef, dom) { this.element = elementRef.nativeElement; - this.adapter = adapter; + this.dom = dom; // initial styling - this.adapter.setStyle(this.element, 'position', 'absolute'); - this.adapter.setStyle(this.element, 'top', '0'); - this.adapter.setStyle(this.element, 'bottom', '0'); - this.adapter.setStyle(this.element, 'max-height', '100%'); + this.dom.setStyle(this.element, 'position', 'absolute'); + this.dom.setStyle(this.element, 'top', '0'); + this.dom.setStyle(this.element, 'bottom', '0'); + this.dom.setStyle(this.element, 'max-height', '100%'); } bind() { - this.cancelScrollBinding = this.adapter.onAndCancel(this.scrollParent, 'scroll', () => { this.updatePosition(); }); + this.cancelScrollBinding = this.dom.onAndCancel(this.scrollParent, 'scroll', () => { this.updatePosition(); }); this.updatePosition(); } @@ -45,13 +37,13 @@ export default class StickySidebar { } stick() { - this.adapter.setStyle(this.element, 'position', 'fixed'); - this.adapter.setStyle(this.element, 'top', this.scrollYOffset() + 'px'); + this.dom.setStyle(this.element, 'position', 'fixed'); + this.dom.setStyle(this.element, 'top', this.scrollYOffset() + 'px'); } unstick() { - this.adapter.setStyle(this.element, 'position', 'absolute'); - this.adapter.setStyle(this.element, 'top', 0); + this.dom.setStyle(this.element, 'position', 'absolute'); + this.dom.setStyle(this.element, 'top', 0); } get scrollY() { diff --git a/lib/common/components/StickySidebar/sticky-sidebar.spec.js b/lib/common/components/StickySidebar/sticky-sidebar.spec.js index 96bc5b3a..d77ea9eb 100644 --- a/lib/common/components/StickySidebar/sticky-sidebar.spec.js +++ b/lib/common/components/StickySidebar/sticky-sidebar.spec.js @@ -1,6 +1,6 @@ 'use strict'; -import { getChildDebugElement } from 'tests/helpers'; +import { getChildDebugElementByType } from 'tests/helpers'; import {Component, View, provide} from 'angular2/core'; import {BrowserDomAdapter} from 'angular2/platform/browser'; @@ -29,7 +29,7 @@ describe('Common components', () => { beforeEach((done) => { builder.createAsync(TestApp).then(_fixture => { fixture = _fixture; - let debugEl = getChildDebugElement(fixture.debugElement, 'sticky-sidebar'); + let debugEl = getChildDebugElementByType(fixture.debugElement, StickySidebar); component = debugEl.componentInstance; done(); }, err => done.fail(err)); @@ -67,8 +67,8 @@ describe('Common components', () => { `