UNPKG

gd-sprest-js

Version:

SharePoint 2013/Online js components.

67 lines (66 loc) 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _1 = require("."); /** * Dialog */ exports.Dialog = function (props) { // Returns the dialog component var get = function () { return _dialog; }; // Return the actions container var getActions = function () { return _dialog._dialog.querySelector(".ms-Dialog-actions"); }; // Return the actions container var getContent = function () { return _dialog._dialog.querySelector(".ms-Dialog-content"); }; // Return the actions container var getTitle = function () { return _dialog._dialog.querySelector(".ms-Dialog-title"); }; // Create the dialog props.el.innerHTML = _1.Templates.Dialog(props); var _dialog = new _1.fabric.Dialog(props.el.querySelector(".ms-Dialog")); // See if the close button exists if (_dialog._closeButtonElement) { // Add a click event _dialog._closeButtonElement.addEventListener("click", function (ev) { // Prevent postback ev.preventDefault(); }); } // Parse the actions var actions = getActions(); actions = props.actions && actions ? actions.querySelectorAll("button.ms-Button") : []; var _loop_1 = function (i) { var btn = actions[i]; // Set the index btn.setAttribute("data-idx", i.toString()); // Set the index btn.addEventListener("click", function (ev) { // Prevent a postback ev.preventDefault(); // Get the action var action = props.actions[parseInt(ev.currentTarget.getAttribute("data-idx"))]; if (action) { // See if this action has a click event if (action.onClick) { // Call the click event action.onClick(btn); } // Else, see if there is a link else if (action.href) { // Redirect the window window.open(action.href, "_self"); } } }); }; for (var i = 0; i < actions.length && i < props.actions.length; i++) { _loop_1(i); } // Return the dialog return { close: function () { _dialog.close(); }, get: get, getActions: getActions, getContent: getContent, getTitle: getTitle, open: function () { _dialog.open(); } }; };