UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

79 lines (78 loc) 4.47 kB
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 __()); }; 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; }; define(["require", "exports", 'react', '../../utilities/css', '../../utilities/autobind', './Link.Props', './Link.scss'], function (require, exports, React, css_1, autobind_1, Link_Props_1) { "use strict"; var Link = (function (_super) { __extends(Link, _super); function Link() { _super.apply(this, arguments); } 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(); } }; __decorate([ autobind_1.autobind ], Link.prototype, "_onClick", null); return Link; }(React.Component)); exports.Link = Link; });