2016-05-07 10:54:44 +03:00
|
|
|
'use strict';
|
2016-05-25 18:34:31 +03:00
|
|
|
import { Injectable, EventEmitter, Output } from '@angular/core';
|
2016-05-07 10:54:44 +03:00
|
|
|
import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter';
|
|
|
|
import { global } from '@angular/core/src/facade/lang';
|
|
|
|
|
2016-05-09 22:55:16 +03:00
|
|
|
import { RedocEventsService } from './events.service';
|
2016-05-07 10:54:44 +03:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Hash {
|
2016-05-25 18:34:31 +03:00
|
|
|
@Output() changed = new EventEmitter();
|
|
|
|
private _cancel: any;
|
|
|
|
constructor(private dom:BrowserDomAdapter, private events:RedocEventsService) {
|
2016-05-07 10:54:44 +03:00
|
|
|
this.bind();
|
|
|
|
|
|
|
|
events.bootstrapped.subscribe(() => this.changed.next(this.hash));
|
|
|
|
}
|
|
|
|
|
|
|
|
get hash() {
|
|
|
|
return this.dom.getLocation().hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
bind() {
|
|
|
|
this._cancel = this.dom.onAndCancel(global, 'hashchange', (evt) => {
|
|
|
|
this.changed.next(this.hash);
|
|
|
|
evt.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
unbind() {
|
|
|
|
this._cancel();
|
|
|
|
}
|
|
|
|
}
|