gd-sprest-js
Version:
SharePoint 2013/Online js components.
89 lines (88 loc) • 3.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require(".");
/**
* Callout Positions
*/
exports.CalloutPositions = {
left: "left",
right: "right",
top: "top",
bottom: "bottom"
};
/**
* Callout Types
*/
var CalloutTypes;
(function (CalloutTypes) {
/** Action */
CalloutTypes[CalloutTypes["Action"] = 0] = "Action";
/** Close */
CalloutTypes[CalloutTypes["Close"] = 1] = "Close";
/** Default */
CalloutTypes[CalloutTypes["Default"] = 2] = "Default";
/** Out of the Box */
CalloutTypes[CalloutTypes["OOBE"] = 3] = "OOBE";
/** Peek */
CalloutTypes[CalloutTypes["Peek"] = 4] = "Peek";
})(CalloutTypes = exports.CalloutTypes || (exports.CalloutTypes = {}));
/**
* Callout
*/
exports.Callout = function (props) {
// Set the template
props.el.innerHTML = _1.Templates.Callout(props);
// Create the callout
var _callout = new _1.fabric.Callout(props.el.querySelector(".ms-Callout"), props.elTarget, props.position || "top");
// Ensure the target element exists
if (props.elTarget) {
// Set the click event
props.elTarget.addEventListener("click", function () {
// See if the host exists
if (_callout._contextualHost) {
// See if the fabric class doesn't exist
if (_callout._contextualHost._contextualHost.classList.contains("fabric") == false) {
// Add the class
_callout._contextualHost._contextualHost.classList.add("fabric");
}
// See if actions are defined
if (props.actions) {
// Parse the action buttons
var buttons = _callout._contextualHost._contextualHost.querySelectorAll(".ms-CommandButton-button");
for (var i = 0; i < buttons.length; i++) {
var action = props.actions[i];
var button = buttons[i];
// Set the button index
button.setAttribute("data-btn-idx", i.toString());
// Ensure the action and click event exist
if (action && action.onClick) {
// Set a click event
button.addEventListener("click", function (ev) {
var btn = ev.currentTarget;
var btnIdx = parseInt(btn.getAttribute("data-btn-idx"));
var action = props.actions[btnIdx];
// See if the click event exists
if (action && action.onClick) {
// Execute the click event
action.onClick(btn);
}
});
}
}
}
}
});
}
// Return the callout
return {
close: function () {
// See if the contextual host exists
if (_callout._contextualHost && _callout._contextualHost) {
// Close the callout
_callout._contextualHost.disposeModal();
}
},
get: function () { return _callout; },
getContent: function () { return _callout._container.querySelector(".ms-Callout-content"); }
};
};