office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
72 lines (71 loc) • 3.88 kB
JavaScript
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
define(["require", "exports", 'react', '../../utilities/css', './Link.Props', './Link.scss'], function (require, exports, React, css_1, Link_Props_1) {
"use strict";
var Link = (function (_super) {
__extends(Link, _super);
function Link(props) {
_super.call(this, props);
this._onClick = this._onClick.bind(this);
this._popupWindow = this._popupWindow.bind(this);
}
Link.prototype.render = function () {
var _a = this.props, children = _a.children, className = _a.className, href = _a.href;
return (href ? (React.createElement("a", React.__spread({role: 'link'}, this.props, {className: css_1.css('ms-Link', className), onClick: this._onClick}), children)) : (React.createElement("button", React.__spread({role: 'button'}, this.props, {className: css_1.css('ms-Link', className), onClick: this._onClick}), children)));
};
Link.prototype._onClick = function (ev) {
var _a = this.props, popupWindowProps = _a.popupWindowProps, onClick = _a.onClick;
if (popupWindowProps) {
this._popupWindow(popupWindowProps);
}
if (onClick) {
onClick(ev);
}
};
Link.prototype._popupWindow = function (popupWindowProps) {
var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ?
document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ?
document.documentElement.clientHeight : screen.height;
var left = 0;
var top = 0;
switch (popupWindowProps.positionWindowPosition) {
case Link_Props_1.PopupWindowPosition.center:
left = ((width / 2) - (popupWindowProps.width / 2)) + dualScreenLeft;
top = ((height / 2) - (popupWindowProps.height / 2)) + dualScreenTop;
break;
case Link_Props_1.PopupWindowPosition.leftBottom:
left = dualScreenLeft;
top = (height - popupWindowProps.height) + dualScreenTop;
break;
case Link_Props_1.PopupWindowPosition.leftTop:
left = dualScreenLeft;
top = dualScreenTop;
break;
case Link_Props_1.PopupWindowPosition.rightBottom:
left = (width - popupWindowProps.width) + dualScreenLeft;
top = (height - popupWindowProps.height) + dualScreenTop;
break;
case Link_Props_1.PopupWindowPosition.rightTop:
left = (width - popupWindowProps.width) + dualScreenLeft;
top = dualScreenTop;
break;
default:
break;
}
var newWindow = window.open(this.props.href, popupWindowProps.title, 'scrollbars=yes, width='
+ popupWindowProps.width + ', height=' + popupWindowProps.height + ', top=' + top + ', left=' + left);
// Puts focus on the newWindow
if (window.focus && newWindow) {
newWindow.focus();
}
};
return Link;
}(React.Component));
exports.Link = Link;
});