UNPKG

gd-sprest-js

Version:

SharePoint 2013/Online js components.

77 lines (76 loc) 3.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var common_1 = require("./common"); var _1 = require("."); /** * Command Bar */ exports.CommandBar = function (props) { // Method to get the command bar var get = function () { return _menu; }; // Set the command bar html props.el.innerHTML = _1.Templates.CommandBar(props); // Create the command bar var _menu = new _1.fabric.CommandBar(props.el.querySelector(".ms-CommandBar")); // Parse the menu buttons var buttonProps = (props.sideCommands || []).concat(props.mainCommands || []); var buttons = _menu._container.querySelectorAll(".ms-CommandButton-button"); var _html = []; var _loop_1 = function (i) { // Set the html _html[i] = null; // Add the index attribute buttons[i].setAttribute("data-btn-idx", i.toString()); // See if a click event exists if (buttonProps[i].onClick && buttons[i]) { // Add a click event buttons[i].addEventListener("click", function (ev) { var btn = ev.currentTarget; // Disable postback ev.preventDefault(); // Get the button index var idx = parseInt(btn.getAttribute("data-btn-idx")); if (idx >= 0 && buttonProps[idx]) { // Execute the postback buttonProps[idx].onClick(btn); } }); } // See if this is a menu if (buttonProps[i].menu && buttons[i]) { // Get the elements var elMenu = buttons[i].parentElement.querySelector(".ms-ContextualMenu"); if (elMenu) { // Create the contextual menu var menu_1 = new _1.fabric.ContextualMenu(elMenu, buttons[i]); // Set a click event buttons[i].addEventListener("click", function (ev) { // See if the host exists and fabric class doesn't exist if (menu_1._isOpen && menu_1._host._contextualHost.classList.contains("fabric") == false) { // Set the class menu_1._host._contextualHost.classList.add("fabric"); // Get the button index var btn = ev.currentTarget; var idx = parseInt(btn.getAttribute("data-btn-idx")); if (idx >= 0 && buttonProps[idx] && buttonProps[idx].menu) { // Set the inner html manually, to remove any events associated with this menu // The core framework doesn't work well w/ sub-menus. _html[idx] = _html[idx] || menu_1._host._contextualHost.innerHTML || ""; menu_1._host._contextualHost.innerHTML = _html[idx]; // Set the click events common_1.setClickEvents(menu_1._host._contextualHost.querySelector(".ms-ContextualMenu"), buttonProps[idx].menu.items, function (ev, item) { // Close the menu menu_1._host.disposeModal(); }); } } }); } } }; for (var i = 0; i < buttons.length; i++) { _loop_1(i); } // Return the command bar return { get: get }; };