@kie-tools.dashbuilder-client.dist.org.dashbuilder.DashbuilderRuntime.js.patternfly.dataTables.pfResize.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-dashbuilder-ui
Show all versions of quarkus-dashbuilder-ui
Dashbuilder extension Web Bundle
/**
* @summary pfResize for DataTables
* @description A collection of API methods providing resize functionality in DataTables. This ensures DataTables
* meets the Patternfly design pattern for IE browsers. Inline actions are typically located in the last column of
* DataTables and expected to be styled with table-view-pf-actions. Inline action buttons must also be wrapped with the
* table-view-pf-btn class.
*
* Example:
*
*
* ...
*
*
*
*
* Rendering Engine
* Browser
* Actions
*
*
*
* ...
*
*
* Note: This functionality requires the following Javascript library files to be loaded:
*
* https://cdn.datatables.net/select/1.2.0/js/dataTables.select.min.js
*/
(function (factory) {
"use strict";
if (typeof define === "function" && define.amd ) {
// AMD
define (["jquery", "datatables.net"], function ($) {
return factory ($, window, document);
});
} else if (typeof exports === "object") {
// CommonJS
module.exports = function (root, $) {
if (!root) {
root = window;
}
if (!$ || !$.fn.dataTable) {
$ = require("datatables.net")(root, $).$;
}
return factory($, root, root.document);
};
} else {
// Browser
factory(jQuery, window, document);
}
}(function ($, window, document, undefined) {
"use strict";
var DataTable = $.fn.dataTable;
var BUTTON_ACTIONS_SELECTOR = "td.table-view-pf-actions .table-view-pf-btn";
var KEBAB_ACTIONS_SELECTOR = "td.table-view-pf-actions .dropdown";
DataTable.pfResize = {};
/**
* Initialize
*
* @param {DataTable.Api} dt DataTable
* @private
*/
DataTable.pfResize.init = function (dt) {
var ctx = dt.settings()[0];
ctx._pfResize = {};
if (isIE()) {
// Resize buttons to fill table cells.
$(window).on("resize", function () {
resize(dt);
});
// Initialize
resize(dt);
}
};
// Local functions
/**
* Get inline actions
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function getActions (dt) {
return $(BUTTON_ACTIONS_SELECTOR + ", " + KEBAB_ACTIONS_SELECTOR, dt.table().container());
}
/**
* Detect IE
*
* @return {boolean} True if IE is detected
* @private
*/
function isIE () {
return /(MSIE|Trident\/|Edge\/)/i.test(window.navigator.userAgent);
}
/**
* Reset table cell height prior to resizing inline actions
*
* @param {DataTable.Api} dt DataTable
* @param {Object} actions Inline actions to reset height
* @private
*/
function resetTableCells (dt, actions) {
if (actions === undefined || actions.length === 0) {
return;
}
$(actions).each(function (index, el) {
$(el).css({height: "auto"});
});
}
/**
* Resize inline actions
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function resize (dt) {
var actions = $(BUTTON_ACTIONS_SELECTOR + ", " + KEBAB_ACTIONS_SELECTOR, dt.table().container());
resetTableCells(dt, actions);
resizeInlineActions(dt, actions);
}
/**
* Resize inline actions to fill table cells
*
* @param {DataTable.Api} dt DataTable
* @param {Object} actions Inline actions to resize
* @private
*/
function resizeInlineActions (dt, actions) {
if (actions === undefined || actions.length === 0) {
return;
}
$(actions).each(function (index, el) {
var parent = $(el).parent("td");
if (parent === undefined || parent.length === 0) {
return;
}
$(el).css({height: parent[0].clientHeight});
});
}
// DataTables API
/**
* Resize inline actions
*
* Example: dt.table().pfResize.resize();
*/
DataTable.Api.register("pfResize.resize()", function () {
return this.iterator("table", function (ctx) {
resize(new DataTable.Api(ctx));
});
});
// DataTables creation
$(document).on("init.dt", function (e, ctx, json) {
if (e.namespace !== "dt") {
return;
}
DataTable.pfResize.init(new DataTable.Api(ctx));
});
return DataTable.pfResize;
}));