ferngully-aurelia-tools
Version:
Ferngully Tools for Aurelia
84 lines • 4.62 kB
JavaScript
System.register(["aurelia-framework", "aurelia-event-aggregator"], function (exports_1, context_1) {
"use strict";
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);
};
var __moduleName = context_1 && context_1.id;
var aurelia_framework_1, aurelia_event_aggregator_1, windowResizeChannel, BrowserService;
return {
setters: [
function (aurelia_framework_1_1) {
aurelia_framework_1 = aurelia_framework_1_1;
},
function (aurelia_event_aggregator_1_1) {
aurelia_event_aggregator_1 = aurelia_event_aggregator_1_1;
}
],
execute: function () {
windowResizeChannel = "window resize";
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([
aurelia_framework_1.autoinject,
__metadata("design:paramtypes", [aurelia_event_aggregator_1.EventAggregator])
], BrowserService);
return BrowserService;
}());
exports_1("BrowserService", BrowserService);
}
};
});
//# sourceMappingURL=browser-service.js.map