UNPKG

gd-sprest-js

Version:

SharePoint 2013/Online js components.

40 lines (39 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _1 = require("."); /** * Pivot */ exports.Pivot = function (props) { var _pivot = null; // The tab click event var onTabClick = function (ev) { var elTab = ev.currentTarget; // Get the tab var tabIdx = parseInt(elTab.getAttribute("data-tab-idx")); var tab = props.tabs[tabIdx]; if (tab) { // Execute the click events props.onClick ? props.onClick(elTab, tab) : null; tab.onClick ? tab.onClick(elTab, tab) : null; } }; // Ensure the element exists if (props.el) { // Render a pivot props.el.innerHTML = _1.Templates.Pivot(props); // Initialize the pivot _pivot = new _1.fabric.Pivot(props.el.querySelector(".ms-Pivot")); // Parse the tab links var links = props.el.querySelectorAll(".ms-Pivot-link"); for (var i = 0; i < links.length; i++) { var link = links[i]; // Set the tab index link.setAttribute("data-tab-idx", i.toString()); // Set the click event link.addEventListener("click", onTabClick); } } // Return the pivot return _pivot; };