UNPKG

gd-sprest-js

Version:

SharePoint 2013/Online js components.

57 lines (56 loc) 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _1 = require("."); /** * List Item */ exports.ListItem = function (props) { // Ensure the element exists props.el = props.el || document.createElement("div"); // Set the template props.el.innerHTML = _1.Templates.ListItem(props); // Create the list item var listItem = new _1.fabric.ListItem(props.el.querySelector(".ms-ListItem")); // See if actions exist if (props.actions) { var clickEvents = {}; var _loop_1 = function (i) { var action = props.actions[i]; // See if this action has a click event if (action.onClick) { // Add this click event clickEvents[i] = function (ev) { // Execute the click event props.actions[i].onClick(listItem, ev); }; } // Else, see if the url exists else if (action.url) { // Set a click event clickEvents[i] = function (ev) { var el = ev.currentTarget; // Get the target and url info var target = el.getAttribute("data-target") || "_blank"; var url = el.getAttribute("data-url"); if (url) { // Open the url window.open(url, target); } }; } }; // Parse the actions for (var i = 0; i < props.actions.length; i++) { _loop_1(i); } // Get the actions var actions = props.el.querySelectorAll(".ms-ListItem-actions > .ms-ListItem-action"); // Parse the click events for (var idx in clickEvents) { // Set the click event actions[idx] ? actions[idx].addEventListener("click", clickEvents[idx]) : null; } } // Return the list item return listItem; };