ferngully-aurelia-tools
Version:
Ferngully Tools for Aurelia
69 lines • 3.31 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { autoinject } from 'aurelia-framework';
import { EventAggregator } from 'aurelia-event-aggregator';
var windowResizeChannel = "window resize";
var BrowserService = (function () {
function BrowserService(eventAggregator) {
this.eventAggregator = eventAggregator;
this.escapeEl = document.createElement('textarea');
this.onWindowResize(this.windowResizeHandler.bind(this));
}
BrowserService.prototype.registerForWindowResize = function (callback) {
return this.eventAggregator.subscribe(windowResizeChannel, callback);
};
BrowserService.prototype.windowResizeHandler = function (event) {
this.eventAggregator.publish(windowResizeChannel, event);
};
BrowserService.prototype.onWindowResize = function (fun) {
if (fun === undefined)
return;
var oldresize = window.onresize;
window.onresize = function (e) {
if (typeof oldresize == 'function')
oldresize(e);
return fun(e);
};
};
BrowserService.prototype.verticalScrollBarIsShowing = function () {
return (window.innerWidth - document.body.clientWidth) > 0;
};
BrowserService.prototype.scrollbarWidth = function () {
if (!this._scrollbarWidth) {
var scrollDiv = document.createElement("div");
scrollDiv.style.width = "100px";
scrollDiv.style.height = "100px";
scrollDiv.style.overflow = "scroll";
scrollDiv.style.position = "absolute";
scrollDiv.style.top = "-9999px;";
document.body.appendChild(scrollDiv);
this._scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
document.body.removeChild(scrollDiv);
}
return this._scrollbarWidth;
};
BrowserService.prototype.escapeHtml = function (unEscapedString) {
this.escapeEl.textContent = unEscapedString ? unEscapedString : "";
return this.escapeEl.innerHTML;
};
;
BrowserService.prototype.unEscapeHtml = function (escapedString) {
this.escapeEl.innerHTML = escapedString ? escapedString : "";
return this.escapeEl.textContent == null ? "" : this.escapeEl.textContent;
};
;
BrowserService = __decorate([
autoinject,
__metadata("design:paramtypes", [EventAggregator])
], BrowserService);
return BrowserService;
}());
export { BrowserService };
//# sourceMappingURL=browser-service.js.map