from gitlab

This commit is contained in:
Jörg Henke
2023-12-04 11:52:12 +01:00
parent 05fa4e7209
commit 5fd979c3a4
585 changed files with 400301 additions and 0 deletions

View File

@ -0,0 +1,7 @@
// Util: definition of breakpoint sizes for tablet and desktop modes
(function ($) {
'use strict';
if (patternfly !== undefined) {
$.pfBreakpoints = patternfly.pfBreakpoints;
}
}(jQuery));

View File

@ -0,0 +1,13 @@
// Util: PatternFly C3 Chart Defaults
(function ($) {
'use strict';
if (patternfly !== undefined) {
$.fn.pfSetDonutChartTitle = patternfly.pfSetDonutChartTitle;
$.fn.pfDonutTooltipContents = patternfly.pfDonutTooltipContents;
$.fn.pfGetUtilizationDonutTooltipContentsFn = patternfly.pfGetUtilizationDonutTooltipContentsFn;
$.fn.pfGetBarChartTooltipContentsFn = patternfly.pfGetBarChartTooltipContentsFn;
$.fn.pfSingleLineChartTooltipContentsFn = patternfly.pfSingleLineChartTooltipContentsFn;
$.fn.pfPieTooltipContents = patternfly.pfPieTooltipContents;
$.fn.c3ChartDefaults = patternfly.c3ChartDefaults;
}
}(jQuery));

View File

@ -0,0 +1,8 @@
// Util: PatternFly Palette colors
(function ($) {
'use strict';
if (patternfly !== undefined) {
$.pfPaletteColors = patternfly.pfPaletteColors;
}
}(jQuery));

View File

@ -0,0 +1,59 @@
// Count and Display Remaining Characters
(function ($) {
'use strict';
$.fn.countRemainingChars = function (options) {
var settings = $.extend({
// These are the defaults.
charsMaxLimit: 100,
charsWarnRemaining: 5,
blockInputAtMaxLimit: false
}, options),
$taFld = this,
$countFld = $('#' + settings.countFld).text(settings.charsMaxLimit),
charsRemainingFn = function (charsLength) {
var charsRemaining = settings.charsMaxLimit - charsLength;
$countFld.text(charsRemaining);
$countFld.toggleClass('chars-warn-remaining-pf', charsRemaining <= settings.charsWarnRemaining);
if (charsRemaining < 0) {
$taFld.trigger("overCharsMaxLimitEvent", $taFld.attr('id'));
} else {
$taFld.trigger("underCharsMaxLimitEvent", $taFld.attr('id'));
}
};
this.on('paste', function (event) {
setTimeout(function () {
var charsLength = $taFld.val().length, maxTxt;
if (settings.blockInputAtMaxLimit && charsLength > settings.charsMaxLimit) {
maxTxt = $taFld.val();
maxTxt = maxTxt.substring(0, settings.charsMaxLimit);
$taFld.val(maxTxt);
charsLength = $taFld.val().length;
}
charsRemainingFn(charsLength);
}, 100);
});
this.keyup(function (event) {
charsRemainingFn($taFld.val().length);
});
this.keydown(function (event) {
var charsLength = $taFld.val().length;
if (settings.blockInputAtMaxLimit && charsLength >= settings.charsMaxLimit) {
// Except backspace
if (event.keyCode !== 8) {
event.preventDefault();
}
}
});
return this;
};
}(jQuery));

View File

@ -0,0 +1,149 @@
// Util: DataTables Settings
(function ($) {
'use strict';
if ($.fn.dataTableExt) {
/* Set the defaults for DataTables initialisation */
$.extend(true, $.fn.dataTable.defaults, {
"bDestroy": true,
"bAutoWidth": false,
"iDisplayLength": 20,
"sDom":
"<'dataTables_header' f i r >" +
"<'table-responsive' t >" +
"<'dataTables_footer' p >",
"oLanguage": {
"sInfo": "Showing <b>_START_</b> to <b>_END_</b> of <b>_TOTAL_</b> Items",
"sInfoFiltered" : "(of <b>_MAX_</b>)",
"sInfoEmpty" : "Showing <b>0</b> Results",
"sZeroRecords":
"<p>Suggestions</p>" +
"<ul>" +
"<li>Check the javascript regular expression syntax of the search term.</li>" +
"<li>Check that the correct menu option is chosen (token ID vs. user ID).</li>" +
"<li>Use wildcards (* to match 0 or more characters, + to match 1 or more characters, ? to match 0 or 1 character).</li>" +
"<li>Clear the search field, then click Search to return to the 20 most recent records.</li>" +
"</ul>",
"sSearch": ""
},
"sPaginationType": "bootstrap_input",
"oSearch": {
"sSearch": "",
"bRegex": true,
"bSmart": false
}
});
/* Default class modification */
$.extend($.fn.dataTableExt.oStdClasses, {
"sWrapper": "dataTables_wrapper"
});
/* API method to get paging information */
$.fn.dataTableExt.oApi.fnPagingInfo = function (oSettings) {
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": oSettings._iDisplayLength === -1 ? 0 : Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
"iTotalPages": oSettings._iDisplayLength === -1 ? 0 : Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
};
};
/* Combination of Bootstrap + Input Text style pagination control */
$.extend($.fn.dataTableExt.oPagination, {
"bootstrap_input": {
"fnInit": function (oSettings, nPaging, fnDraw) {
var fnClickHandler = function (e) {
e.preventDefault();
if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
fnDraw(oSettings);
}
},
els,
nInput;
$(nPaging).append(
'<ul class="pagination">' +
' <li class="first disabled"><span class="i fa fa-angle-double-left"></span></li>' +
' <li class="prev disabled"><span class="i fa fa-angle-left"></span></li>' +
'</ul>' +
'<div class="pagination-input">' +
' <input type="text" class="paginate_input">' +
' <span class="paginate_of">of <b>3</b></span>' +
'</div>' +
'<ul class="pagination">' +
' <li class="next disabled"><span class="i fa fa-angle-right"></span></li>' +
' <li class="last disabled"><span class="i fa fa-angle-double-right"></span></li>' +
'</ul>'
);
els = $('li', nPaging);
$(els[0]).bind('click.DT', { action: "first" }, fnClickHandler);
$(els[1]).bind('click.DT', { action: "previous" }, fnClickHandler);
$(els[2]).bind('click.DT', { action: "next" }, fnClickHandler);
$(els[3]).bind('click.DT', { action: "last" }, fnClickHandler);
nInput = $('input', nPaging);
$(nInput).keyup(function (e) {
var iNewStart;
if (e.which === 38 || e.which === 39) {
this.value += 1;
} else if ((e.which === 37 || e.which === 40) && this.value > 1) {
this.value -= 1;
}
if (this.value === "" || !this.value.match(/[0-9]/)) {
/* Nothing entered or non-numeric character */
return;
}
iNewStart = oSettings._iDisplayLength * (this.value - 1);
if (iNewStart >= oSettings.fnRecordsDisplay()) {
/* Display overrun */
oSettings._iDisplayStart = (Math.ceil((oSettings.fnRecordsDisplay() - 1) /
oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength;
fnDraw(oSettings);
return;
}
oSettings._iDisplayStart = iNewStart;
fnDraw(oSettings);
});
},
"fnUpdate": function (oSettings, fnDraw) {
var oPaging = oSettings.oInstance.fnPagingInfo(),
an = oSettings.aanFeatures.p,
ien = an.length,
iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength),
iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1,
i;
for (i = 0; i < ien; i += 1) {
$('.paginate_input', an[i]).val(iCurrentPage)
.siblings('.paginate_of').find('b').html(iPages);
// Add / remove disabled classes from the static elements
if (oPaging.iPage === 0) {
$('li.first', an[i]).addClass('disabled');
$('li.prev', an[i]).addClass('disabled');
} else {
$('li.first', an[i]).removeClass('disabled');
$('li.prev', an[i]).removeClass('disabled');
}
if (oPaging.iPage === oPaging.iTotalPages - 1 || oPaging.iTotalPages === 0) {
$('li.next', an[i]).addClass('disabled');
$('li.last', an[i]).addClass('disabled');
} else {
$('li.next', an[i]).removeClass('disabled');
$('li.last', an[i]).removeClass('disabled');
}
}
}
}
});
}
}(jQuery));

View File

@ -0,0 +1,109 @@
// Util: PatternFly Collapse with fixed heights
// Update the max-height of collapse elements based on the parent container's height.
(function ($) {
'use strict';
$.fn.initCollapseHeights = function (scrollSelector) {
var parentElement = this, setCollapseHeights, targetScrollSelector = scrollSelector;
setCollapseHeights = function () {
var height, openPanel, contentHeight, bodyHeight, overflowY = 'hidden';
height = parentElement.height();
// Close any open panel
openPanel = parentElement.find('.collapse.in');
if (openPanel && openPanel.length > 0) {
openPanel.removeClass('in');
}
// Determine the necessary height for the closed content
contentHeight = 0;
parentElement.children().each($.proxy(function (i, element) {
var $element = $(element);
contentHeight += $element.outerHeight(true);
}, parentElement)).end();
// Determine the height remaining for opened collapse panels
bodyHeight = height - contentHeight;
// Make sure we have enough height to be able to scroll the contents if necessary
if (bodyHeight < 25) {
bodyHeight = 25;
// Allow the parent to scroll so the child elements are accessible
overflowY = 'auto';
}
// Reopen the initially opened panel
if (openPanel && openPanel.length > 0) {
openPanel.addClass("in");
}
setTimeout(function () {
// Set the max-height for the collapse panels
parentElement.find('[data-toggle="collapse"]').each($.proxy(function (i, element) {
var $element, selector, $target, scrollElement, innerHeight = 0;
$element = $(element);
// Determine the selector to find the target
selector = $element.attr('data-target');
if (!selector) {
selector = $element.attr('href');
}
// Determine the scroll element (either the target or the child of the target based on the given selector)
$target = $(selector);
scrollElement = $target;
if (targetScrollSelector) {
scrollElement = $target.find(targetScrollSelector);
if (scrollElement.length === 1) {
innerHeight = 0;
$target.children().each($.proxy(function (j, sibling) {
var $sibling = $(sibling);
if (sibling !== scrollElement[0]) {
innerHeight += $sibling.outerHeight(true);
}
}, $target)).end();
bodyHeight -= innerHeight;
} else {
scrollElement = $target;
}
}
// Set the max-height and vertical scroll of the scroll element
scrollElement.css({'max-height': (bodyHeight - innerHeight) + 'px', 'overflow-y': 'auto'});
}, parentElement)).end();
parentElement.css({'overflow-y': overflowY});
}, 100);
};
setCollapseHeights();
// Update on window resizing
$(window).on('resize', setCollapseHeights);
};
$.fn.initFixedAccordion = function () {
var fixedAccordion = this, initOpen;
fixedAccordion.on('show.bs.collapse','.collapse', function (event) {
$(event.target.parentNode).addClass('panel-open');
});
fixedAccordion.on('hide.bs.collapse','.collapse', function (event) {
$(event.target.parentNode).removeClass('panel-open');
});
fixedAccordion.find('.panel').each(function (index, item) {
$(item).removeClass('panel-open');
});
initOpen = $(fixedAccordion.find('.collapse.in'))[0];
if (initOpen) {
$(initOpen.parentNode).addClass('panel-open');
}
};
}(jQuery));

View File

@ -0,0 +1,79 @@
// PatternFly pf-list
(function ($) {
'use strict';
$.fn.pfList = function () {
function init (list) {
// Ensure the state of the expansion elements is consistent
list.find('[data-list=expansion], .list-pf-item, .list-pf-expansion').each(function (index, element) {
var $expansion = $(element),
$collapse = $expansion.find('.collapse').first(),
expanded = $collapse.hasClass('in');
updateChevron($expansion, expanded);
if ($expansion.hasClass('list-pf-item')) {
updateActive($expansion, expanded);
}
});
list.find('.list-pf-container').each(function (index, element) {
var $element = $(element);
// The toggle element is the element with the data-list=toggle attribute
// or the entire .list-pf-container as a fallback
var $toggles = $element.find('[data-list=toggle]');
$toggles.length || ($toggles = $element);
$toggles.on('keydown', function (event) {
if (event.keyCode === 13 || event.keyCode === 32) {
toggleCollapse(this);
event.stopPropagation();
event.preventDefault();
}
});
$toggles.on('click', function (event) {
toggleCollapse(this);
event.stopPropagation();
event.preventDefault();
});
});
}
function toggleCollapse (toggle) {
var $toggle, $expansion, $collapse, expanded, $listItem;
$toggle = $(toggle);
// Find the parent expansion of the toggle
$expansion = $toggle.parentsUntil('.list-pf', '[data-list=expansion]').first();
$expansion.length || ($expansion = $toggle.closest('.list-pf-item, .list-pf-expansion'));
// toggle the "in" class of its first .collapse child
$collapse = $expansion.find('.collapse').first();
$collapse.toggleClass('in');
// update the state of the expansion element
updateChevron($expansion, $collapse.hasClass('in'));
$listItem = $expansion.closest('.list-pf-item');
updateActive($listItem, $listItem.find('.collapse').first().hasClass('in'));
}
function updateActive ($listItem, expanded) {
// Find the closest .list-pf-item of the expansion, and set its "active" class
if (expanded) {
$listItem.addClass('active');
} else {
$listItem.removeClass('active');
}
}
function updateChevron ($expansion, expanded) {
var $chevron = $expansion.find('.list-pf-chevron .fa').first();
if (expanded) {
$chevron.removeClass('fa-angle-right');
$chevron.addClass('fa-angle-down');
} else {
$chevron.addClass('fa-angle-right');
$chevron.removeClass('fa-angle-down');
}
}
init(this);
return this;
};
}(jQuery));

View File

@ -0,0 +1,113 @@
// Util: PatternFly Collapsible Left Hand Navigation
// Must have navbar-toggle in navbar-pf-alt for expand/collapse
(function ($) {
'use strict';
$.fn.navigation = function () {
var navElement = $('.layout-pf-alt-fixed .nav-pf-vertical-alt'),
bodyContentElement = $('.container-pf-alt-nav-pf-vertical-alt'),
toggleNavBarButton = $('.navbar-toggle'),
explicitCollapse = false,
checkNavState = function () {
var width = $(window).width();
//Always remove the hidden & peek class
navElement.removeClass('hidden show-mobile-nav collapsed');
//Set the body class back to the default
bodyContentElement.removeClass('collapsed-nav hidden-nav');
// Check to see if the nav needs to collapse
if (width < $.pfBreakpoints.desktop || explicitCollapse) {
navElement.addClass('collapsed');
bodyContentElement.addClass('collapsed-nav');
}
// Check to see if we need to move down to the mobile state
if (width < $.pfBreakpoints.tablet) {
//Set the nav to being hidden
navElement.addClass('hidden');
//Make sure this is expanded
navElement.removeClass('collapsed');
//Set the body class to the correct state
bodyContentElement.removeClass('collapsed-nav');
bodyContentElement.addClass('hidden-nav');
}
},
collapseMenu = function () {
//Make sure this is expanded
navElement.addClass('collapsed');
//Set the body class to the correct state
bodyContentElement.addClass('collapsed-nav');
explicitCollapse = true;
},
enableTransitions = function () {
// enable transitions only when toggleNavBarButton is clicked or window is resized
$('html').addClass('transitions');
},
expandMenu = function () {
//Make sure this is expanded
navElement.removeClass('collapsed');
//Set the body class to the correct state
bodyContentElement.removeClass('collapsed-nav');
explicitCollapse = false;
},
bindMenuBehavior = function () {
toggleNavBarButton.on('click', function (e) {
var inMobileState = bodyContentElement.hasClass('hidden-nav');
enableTransitions();
if (inMobileState && navElement.hasClass('show-mobile-nav')) {
//In mobile state just need to hide the nav
navElement.removeClass('show-mobile-nav');
} else if (inMobileState) {
navElement.addClass('show-mobile-nav');
} else if (navElement.hasClass('collapsed')) {
expandMenu();
} else {
collapseMenu();
}
});
},
setTooltips = function () {
$('.nav-pf-vertical-alt [data-toggle="tooltip"]').tooltip({'container': 'body', 'delay': { 'show': '500', 'hide': '200' }});
$(".nav-pf-vertical-alt").on("show.bs.tooltip", function (e) {
return $(this).hasClass("collapsed");
});
},
init = function () {
//Set correct state on load
checkNavState();
// Bind Top level hamburger menu with menu behavior;
bindMenuBehavior();
//Set tooltips
setTooltips();
};
//Listen for the window resize event and collapse/hide as needed
$(window).on('resize', function () {
checkNavState();
enableTransitions();
});
init();
};
$(document).ready(function () {
if ($('.nav-pf-vertical-alt').length > 0) {
$.fn.navigation();
}
});
}(jQuery));

View File

@ -0,0 +1,37 @@
// Util: PatternFly Popovers
// Add data-close="true" to insert close X icon
(function ($) {
'use strict';
$.fn.popovers = function () {
// Initialize
this.popover();
// Add close icons
this.filter('[data-close=true]').each(function (index, element) {
var $this = $(element),
title = $this.attr('data-original-title') + '<button type="button" class="close" aria-hidden="true"><span class="pficon pficon-close"></span></button>';
$this.attr('data-original-title', title);
});
// Bind Close Icon to Toggle Display
this.on('click', function (e) {
var $this = $(this),
$title = $this.next('.popover').find('.popover-title');
// Only if data-close is true add class "x" to title for right padding
$title.find('.close').parent('.popover-title').addClass('closable');
// Bind x icon to close popover
$title.find('.close').on('click', function () {
$this.popover('hide');
});
// Prevent href="#" page scroll to top
e.preventDefault();
});
return this;
};
}(jQuery));

View File

@ -0,0 +1,31 @@
// Util: PatternFly Sidebar
// Set height of sidebar-pf to height of document minus height of navbar-pf if not mobile
(function ($) {
'use strict';
$.fn.sidebar = function () {
var documentHeight = 0,
navbarpfHeight = 0,
colHeight = 0;
if ($('.navbar-pf .navbar-toggle').is(':hidden')) {
documentHeight = $(document).height();
navbarpfHeight = $('.navbar-pf').outerHeight();
colHeight = documentHeight - navbarpfHeight;
}
$('.sidebar-pf').parent('.row').children('[class*="col-"]').css({"min-height" : colHeight});
};
$(document).ready(function () {
// Call sidebar() on ready if .sidebar-pf exists and .datatable does not exist
if ($('.sidebar-pf').length > 0 && $('.datatable').length === 0) {
$.fn.sidebar();
}
});
$(window).on('resize', function () {
// Call sidebar() on resize if .sidebar-pf exists
if ($('.sidebar-pf').length > 0) {
$.fn.sidebar();
}
});
}(jQuery));

View File

@ -0,0 +1,82 @@
// Util: PatternFly TreeGrid Tables
(function ($) {
'use strict';
function getParent (rows, node) {
var parent = node.attr('data-parent');
if (typeof parent === "string") {
if (isNaN(parent)) {
parent = $(parent);
if (parent.length > 1) {
parent = rows.closest(parent);
}
} else {
parent = $(rows[parseInt(parent, 10)]);
}
return parent;
}
return undefined;
}
function renderItem (item, parent) {
if (parent) {
parent.find('.treegrid-node > span.expand-icon')
.toggleClass('fa-angle-right', parent.hasClass('collapsed'))
.toggleClass('fa-angle-down', !parent.hasClass('collapsed'));
item.toggleClass('hidden', parent.hasClass('collapsed'));
if (parent.hasClass('collapsed')) {
item.addClass('collapsed');
}
}
}
function reStripe (tree) {
tree.find('tbody > tr').removeClass('odd');
tree.find('tbody > tr:not(.hidden):odd').addClass('odd');
}
$.fn.treegrid = function (options) {
var i, rows, _this;
rows = this.find('tbody > tr');
_this = this;
$.each(rows, function () {
var node, parent;
node = $(this);
parent = getParent(rows, node);
// Append expand icon dummies
node.children('.treegrid-node').prepend('<span class="icon expand-icon fa"/>');
// Set up an event listener for the node
node.children('.treegrid-node').on('click', function (e) {
var icon = node.find('span.expand-icon');
if (options && typeof options.callback === 'function') {
options.callback(e);
}
if (icon.hasClass('fa-angle-right')) {
node.removeClass('collapsed');
}
if (icon.hasClass('fa-angle-down')) {
node.addClass('collapsed');
}
$.each(rows.slice(rows.index(node) + 1), function () {
renderItem($(this), getParent(rows, $(this)));
});
reStripe(_this);
});
if (parent) {
// Calculate indentation depth
i = parent.find('.treegrid-node > span.indent').length + 1;
for (; i > 0; i -= 1) {
node.children('.treegrid-node').prepend('<span class="indent"/>');
}
// Render expand/collapse icons
renderItem(node, parent);
}
});
reStripe(_this);
};
}(jQuery));

View File

@ -0,0 +1,610 @@
// Util: PatternFly Vertical Navigation
// Must have navbar-toggle in navbar-pf-vertical for expand/collapse
(function ($) {
'use strict';
$.fn.setupVerticalNavigation = function (handleItemSelections, ignoreDrawer, userOptions) {
var options = $.extend({
hoverDelay: 500,
hideDelay: 700,
rememberOpenState: true,
storage: 'localStorage',
}, userOptions || {}),
navElement = $('.nav-pf-vertical'),
bodyContentElement = $('.container-pf-nav-pf-vertical'),
toggleNavBarButton = $('.navbar-toggle'),
handleResize = true,
explicitCollapse = false,
subDesktop = false,
storageLocation = options.storage === 'sessionStorage' ? 'sessionStorage' : 'localStorage',
inMobileState = function () {
return bodyContentElement.hasClass('hidden-nav');
},
forceResize = function (delay) {
setTimeout(function () {
$(window).trigger('resize');
}, delay);
},
showSecondaryMenu = function () {
if (inMobileState() || !subDesktop) {
navElement.addClass('secondary-visible-pf');
bodyContentElement.addClass('secondary-visible-pf');
}
// Dispatch a resize event when showing the secondary menu in non-subdesktop state to
// allow content to adjust to the secondary menu sizing
if (!subDesktop) {
forceResize(100);
}
},
hideSecondaryMenu = function () {
navElement.removeClass('secondary-visible-pf');
bodyContentElement.removeClass('secondary-visible-pf');
if (navElement.find('.secondary-nav-item-pf.is-hover').length <= 1) {
navElement.removeClass('hover-secondary-nav-pf');
}
navElement.find('.mobile-nav-item-pf').each(function (index, item) {
$(item).removeClass('mobile-nav-item-pf');
});
navElement.find('.is-hover').each(function (index, item) {
$(item).removeClass('is-hover');
});
},
hideTertiaryMenu = function () {
navElement.removeClass('tertiary-visible-pf');
bodyContentElement.removeClass('tertiary-visible-pf');
if (navElement.find('.tertiary-nav-item-pf.is-hover').length <= 1) {
navElement.removeClass('hover-tertiary-nav-pf');
}
navElement.find('.mobile-nav-item-pf').each(function (index, item) {
$(item).removeClass('mobile-nav-item-pf');
});
navElement.find('.is-hover').each(function (index, item) {
$(item).removeClass('is-hover');
});
},
setActiveItem = function (item) {
// remove all .active
$('.nav-pf-vertical .list-group-item.active').removeClass('active');
// add .active to item and its parents
item.addClass('active').parents('.list-group-item').addClass('active');
},
updateSecondaryMenuDisplayAfterSelection = function () {
if (inMobileState()) {
navElement.removeClass('show-mobile-nav');
hideSecondaryMenu();
navElement.find('.mobile-nav-item-pf').each(function (index, item) {
$(item).removeClass('mobile-nav-item-pf');
});
} else {
showSecondaryMenu();
}
},
updateSecondaryCollapsedState = function (setCollapsed, collapsedItem) {
if (setCollapsed) {
collapsedItem.addClass('collapsed');
navElement.addClass('collapsed-secondary-nav-pf');
bodyContentElement.addClass('collapsed-secondary-nav-pf');
} else {
if (collapsedItem) {
collapsedItem.removeClass('collapsed');
} else {
// Remove any collapsed secondary menus
navElement.find('[data-toggle="collapse-secondary-nav"]').each(function (index, element) {
var $e = $(element);
$e.removeClass('collapsed');
});
}
navElement.removeClass('collapsed-secondary-nav-pf');
bodyContentElement.removeClass('collapsed-secondary-nav-pf');
}
},
updateTertiaryCollapsedState = function (setCollapsed, collapsedItem) {
if (setCollapsed) {
collapsedItem.addClass('collapsed');
navElement.addClass('collapsed-tertiary-nav-pf');
bodyContentElement.addClass('collapsed-tertiary-nav-pf');
updateSecondaryCollapsedState(false);
} else {
if (collapsedItem) {
collapsedItem.removeClass('collapsed');
} else {
// Remove any collapsed tertiary menus
navElement.find('[data-toggle="collapse-tertiary-nav"]').each(function (index, element) {
var $e = $(element);
$e.removeClass('collapsed');
});
}
navElement.removeClass('collapsed-tertiary-nav-pf');
bodyContentElement.removeClass('collapsed-tertiary-nav-pf');
}
},
updateMobileMenu = function (selected, secondaryItem) {
$(document).find('.list-group-item.mobile-nav-item-pf').each(function (index, item) {
$(item).removeClass('mobile-nav-item-pf');
});
$(document).find('.list-group-item.mobile-secondary-item-pf').each(function (index, item) {
$(item).removeClass('mobile-secondary-item-pf');
});
if (selected) {
selected.addClass('mobile-nav-item-pf');
if (secondaryItem) {
secondaryItem.addClass('mobile-secondary-item-pf');
navElement.removeClass('show-mobile-secondary');
navElement.addClass('show-mobile-tertiary');
} else {
navElement.addClass('show-mobile-secondary');
navElement.removeClass('show-mobile-tertiary');
}
} else {
navElement.removeClass('show-mobile-secondary');
navElement.removeClass('show-mobile-tertiary');
}
},
enterMobileState = function () {
if (!navElement.hasClass('hidden')) {
//Set the nav to being hidden
navElement.addClass('hidden');
navElement.removeClass('collapsed');
//Set the body class to the correct state
bodyContentElement.removeClass('collapsed-nav');
bodyContentElement.addClass('hidden-nav');
// Reset the collapsed states
updateSecondaryCollapsedState(false);
updateTertiaryCollapsedState(false);
explicitCollapse = false;
}
},
exitMobileState = function () {
// Always remove the hidden & peek class
navElement.removeClass('hidden show-mobile-nav');
// Set the body class back to the default
bodyContentElement.removeClass('hidden-nav');
},
checkNavState = function () {
var width = $(window).width(), makeSecondaryVisible;
if (!handleResize) {
return;
}
// Check to see if we need to enter/exit the mobile state
if (width < $.pfBreakpoints.tablet && !explicitCollapse) {
enterMobileState();
} else if (navElement.hasClass('hidden')) {
exitMobileState();
}
// Check to see if we need to enter/exit the sub desktop state
if (width < $.pfBreakpoints.desktop) {
if (!subDesktop) {
// Collapse the navigation bars when entering sub desktop mode
navElement.addClass('collapsed');
bodyContentElement.addClass('collapsed-nav');
}
if (width >= $.pfBreakpoints.tablet) {
hideSecondaryMenu();
}
subDesktop = true;
} else {
makeSecondaryVisible = subDesktop && (navElement.find('.secondary-nav-item-pf.active').length > 0);
subDesktop = false;
if (makeSecondaryVisible) {
showSecondaryMenu();
}
}
if (explicitCollapse) {
navElement.addClass('collapsed');
bodyContentElement.addClass('collapsed-nav');
} else {
navElement.removeClass('collapsed');
bodyContentElement.removeClass('collapsed-nav');
}
},
collapseMenu = function () {
//Make sure this is expanded
navElement.addClass('collapsed');
//Set the body class to the correct state
bodyContentElement.addClass('collapsed-nav');
if (subDesktop) {
hideSecondaryMenu();
}
explicitCollapse = true;
},
enableTransitions = function () {
// enable transitions only when toggleNavBarButton is clicked or window is resized
$('html').addClass('transitions');
},
expandMenu = function () {
//Make sure this is expanded
navElement.removeClass('collapsed');
//Set the body class to the correct state
bodyContentElement.removeClass('collapsed-nav');
explicitCollapse = false;
// Dispatch a resize event when showing the expanding then menu to
// allow content to adjust to the menu sizing
if (!subDesktop) {
forceResize(100);
}
},
bindMenuBehavior = function () {
toggleNavBarButton.on('click', function (e) {
var $drawer;
enableTransitions();
if (inMobileState()) {
// Toggle the mobile nav
if (navElement.hasClass('show-mobile-nav')) {
navElement.removeClass('show-mobile-nav');
} else {
// Always start at the primary menu
updateMobileMenu();
navElement.addClass('show-mobile-nav');
// If the notification drawer is shown, hide it
if (!ignoreDrawer) {
$drawer = $('.drawer-pf');
if ($drawer.length) {
$('.drawer-pf-trigger').removeClass('open');
$drawer.addClass('hide');
}
}
}
} else if (navElement.hasClass('collapsed')) {
if (options.rememberOpenState) {
window[storageLocation].setItem('patternfly-navigation-primary', 'expanded');
}
expandMenu();
} else {
if (options.rememberOpenState) {
window[storageLocation].setItem('patternfly-navigation-primary', 'collapsed');
}
collapseMenu();
}
});
},
forceHideSecondaryMenu = function () {
navElement.addClass('force-hide-secondary-nav-pf');
setTimeout(function () {
navElement.removeClass('force-hide-secondary-nav-pf');
}, 500);
},
bindMenuItemsBehavior = function (handleSelection) {
$(document).find('.nav-pf-vertical .list-group-item').each(function (index, item) {
var onClickFn,
$item = $(item),
$nav = $item.closest('[class*="nav-pf-"]');
if ($nav.hasClass('nav-pf-vertical')) {
// Set main nav active item on click or show secondary nav if it has a secondary nav bar and we are in the mobile state
onClickFn = function (event) {
var $this = $(this), $secondaryItem, $tertiaryItem, $activeItem;
if (!$this.hasClass('secondary-nav-item-pf')) {
hideSecondaryMenu();
if (inMobileState()) {
updateMobileMenu();
navElement.removeClass('show-mobile-nav');
}
if (handleSelection) {
setActiveItem($this);
// Don't process the click on the item
event.stopImmediatePropagation();
}
} else if (inMobileState()) {
updateMobileMenu($this);
} else if (handleSelection) {
$activeItem = $secondaryItem = $item.find('.nav-pf-secondary-nav > .list-group > .list-group-item').eq(0);
if ($secondaryItem.hasClass('tertiary-nav-item-pf')) {
$activeItem = $secondaryItem.find('.nav-pf-tertiary-nav > .list-group > .list-group-item').eq(0);
}
setActiveItem($activeItem);
event.stopImmediatePropagation();
}
};
} else if ($nav.hasClass('nav-pf-secondary-nav')) {
// Set secondary nav active item on click or show tertiary nav if it has a tertiary nav bar and we are in the mobile state
onClickFn = function (event) {
var $this = $(this), $tertiaryItem, $primaryItem;
if (!$this.hasClass('tertiary-nav-item-pf')) {
if (inMobileState()) {
updateMobileMenu();
navElement.removeClass('show-mobile-nav');
}
updateSecondaryMenuDisplayAfterSelection();
if (handleSelection) {
setActiveItem($item);
hideSecondaryMenu();
event.stopImmediatePropagation();
}
} else if (inMobileState()) {
$primaryItem = $item.parents('.list-group-item');
updateMobileMenu($this, $primaryItem);
event.stopImmediatePropagation();
} else if (handleSelection) {
$tertiaryItem = $item.find('.nav-pf-tertiary-nav > .list-group > .list-group-item').eq(0);
setActiveItem($tertiaryItem);
event.stopImmediatePropagation();
}
};
} else if ($nav.hasClass('nav-pf-tertiary-nav')) {
// Set tertiary nav active item on click
onClickFn = function (event) {
if (inMobileState()) {
updateMobileMenu();
navElement.removeClass('show-mobile-nav');
}
updateSecondaryMenuDisplayAfterSelection();
if (handleSelection) {
setActiveItem($item);
hideTertiaryMenu();
hideSecondaryMenu();
event.stopImmediatePropagation();
}
};
}
// register event handler
$item.on('click.pf.secondarynav.data-api', onClickFn);
});
$(document).find('.secondary-nav-item-pf').each(function (index, secondaryItem) {
var $secondaryItem = $(secondaryItem);
// Collapse the secondary nav bar when the toggle is clicked
$secondaryItem.on('click.pf.secondarynav.data-api', '[data-toggle="collapse-secondary-nav"]', function (e) {
var $this = $(this);
if (inMobileState()) {
updateMobileMenu();
e.stopImmediatePropagation();
} else {
if ($this.hasClass('collapsed')) {
if (options.rememberOpenState) {
window[storageLocation].setItem('patternfly-navigation-secondary', 'expanded');
window[storageLocation].setItem('patternfly-navigation-tertiary', 'expanded');
}
updateSecondaryCollapsedState(false, $this);
forceHideSecondaryMenu();
} else {
if (options.rememberOpenState) {
window[storageLocation].setItem('patternfly-navigation-secondary', 'collapsed');
}
updateSecondaryCollapsedState(true, $this);
}
}
navElement.removeClass('hover-secondary-nav-pf');
if (handleSelection) {
// Don't process the click on the parent item
e.stopImmediatePropagation();
}
});
$secondaryItem.find('.tertiary-nav-item-pf').each(function (index, primaryItem) {
var $primaryItem = $(primaryItem);
// Collapse the tertiary nav bar when the toggle is clicked
$primaryItem.on('click.pf.tertiarynav.data-api', '[data-toggle="collapse-tertiary-nav"]', function (e) {
var $this = $(this);
if (inMobileState()) {
updateMobileMenu($secondaryItem);
e.stopImmediatePropagation();
} else {
if ($this.hasClass('collapsed')) {
if (options.rememberOpenState) {
window[storageLocation].setItem('patternfly-navigation-secondary', 'expanded');
window[storageLocation].setItem('patternfly-navigation-tertiary', 'expanded');
}
updateTertiaryCollapsedState(false, $this);
forceHideSecondaryMenu();
} else {
if (options.rememberOpenState) {
window[storageLocation].setItem('patternfly-navigation-tertiary', 'collapsed');
}
updateTertiaryCollapsedState(true, $this);
}
}
navElement.removeClass('hover-secondary-nav-pf');
navElement.removeClass('hover-tertiary-nav-pf');
if (handleSelection) {
// Don't process the click on the parent item
e.stopImmediatePropagation();
}
});
});
});
// Show secondary nav bar on hover of secondary nav items
$(document).on('mouseenter.pf.tertiarynav.data-api', '.secondary-nav-item-pf', function (e) {
var $this = $(this);
if (!inMobileState()) {
if ($this[0].navUnHoverTimeout !== undefined) {
clearTimeout($this[0].navUnHoverTimeout);
$this[0].navUnHoverTimeout = undefined;
} else if ($this[0].navHoverTimeout === undefined) {
$this[0].navHoverTimeout = setTimeout(function () {
navElement.addClass('hover-secondary-nav-pf');
$this.addClass('is-hover');
$this[0].navHoverTimeout = undefined;
}, options.hoverDelay);
}
}
});
$(document).on('mouseleave.pf.tertiarynav.data-api', '.secondary-nav-item-pf', function (e) {
var $this = $(this);
if ($this[0].navHoverTimeout !== undefined) {
clearTimeout($this[0].navHoverTimeout);
$this[0].navHoverTimeout = undefined;
} else if ($this[0].navUnHoverTimeout === undefined &&
navElement.find('.secondary-nav-item-pf.is-hover').length > 0) {
$this[0].navUnHoverTimeout = setTimeout(function () {
if (navElement.find('.secondary-nav-item-pf.is-hover').length <= 1) {
navElement.removeClass('hover-secondary-nav-pf');
}
$this.removeClass('is-hover');
$this[0].navUnHoverTimeout = undefined;
}, options.hideDelay);
}
});
// Show tertiary nav bar on hover of secondary nav items
$(document).on('mouseover.pf.tertiarynav.data-api', '.tertiary-nav-item-pf', function (e) {
var $this = $(this);
if (!inMobileState()) {
if ($this[0].navUnHoverTimeout !== undefined) {
clearTimeout($this[0].navUnHoverTimeout);
$this[0].navUnHoverTimeout = undefined;
} else if ($this[0].navHoverTimeout === undefined) {
$this[0].navHoverTimeout = setTimeout(function () {
navElement.addClass('hover-tertiary-nav-pf');
$this.addClass('is-hover');
$this[0].navHoverTimeout = undefined;
}, options.hoverDelay);
}
}
});
$(document).on('mouseout.pf.tertiarynav.data-api', '.tertiary-nav-item-pf', function (e) {
var $this = $(this);
if ($this[0].navHoverTimeout !== undefined) {
clearTimeout($this[0].navHoverTimeout);
$this[0].navHoverTimeout = undefined;
} else if ($this[0].navUnHoverTimeout === undefined) {
$this[0].navUnHoverTimeout = setTimeout(function () {
if (navElement.find('.tertiary-nav-item-pf.is-hover').length <= 1) {
navElement.removeClass('hover-tertiary-nav-pf');
}
$this.removeClass('is-hover');
$this[0].navUnHoverTimeout = undefined;
}, options.hideDelay);
}
});
},
loadFromLocalStorage = function () {
if (inMobileState()) {
return;
}
if (window[storageLocation].getItem('patternfly-navigation-primary') === 'collapsed') {
collapseMenu();
}
if ($('.nav-pf-vertical.nav-pf-vertical-collapsible-menus').length > 0) {
if (window[storageLocation].getItem('patternfly-navigation-secondary') === 'collapsed') {
updateSecondaryCollapsedState(true, $('.secondary-nav-item-pf.active [data-toggle=collapse-secondary-nav]'));
}
if (window[storageLocation].getItem('patternfly-navigation-tertiary') === 'collapsed') {
updateTertiaryCollapsedState(true, $('.tertiary-nav-item-pf.active [data-toggle=collapse-tertiary-nav]'));
}
}
},
setTooltips = function () {
var tooltipOptions = {
container: 'body',
placement: 'bottom',
delay: { 'show': '500', 'hide': '200' },
template: '<div class="nav-pf-vertical-tooltip tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
};
$('.nav-pf-vertical [data-toggle="tooltip"]').tooltip(tooltipOptions);
$('.nav-pf-vertical').on("show.bs.tooltip", function (e) {
return $(this).hasClass("collapsed");
});
},
init = function (handleItemSelections) {
// Hide the nav menus during initialization
navElement.addClass('hide-nav-pf');
bodyContentElement.addClass('hide-nav-pf');
//Set correct state on load
checkNavState();
// Bind Top level hamburger menu with menu behavior;
bindMenuBehavior();
// Bind menu items
bindMenuItemsBehavior(handleItemSelections);
//Set tooltips
setTooltips();
if (options.rememberOpenState) {
loadFromLocalStorage();
}
// Show the nav menus
navElement.removeClass('hide-nav-pf');
bodyContentElement.removeClass('hide-nav-pf');
forceResize(250);
},
self = {
hideMenu: function () {
handleResize = false;
enterMobileState();
},
showMenu: function () {
handleResize = true;
exitMobileState();
},
isVisible: function () {
return handleResize;
}
};
if (!$.fn.setupVerticalNavigation.self) {
$.fn.setupVerticalNavigation.self = self;
//Listen for the window resize event and collapse/hide as needed
$(window).on('resize', function () {
checkNavState();
enableTransitions();
});
init(handleItemSelections);
}
return $.fn.setupVerticalNavigation.self;
};
}(jQuery));

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,9 @@
interface Patternfly {
pfBreakpoints: {
tablet: number;
desktop: number;
};
}
interface Window {
patternfly: Patternfly;
}

View File

@ -0,0 +1,16 @@
(function (window) {
'use strict';
var patternfly = {
version: "3.59.3"
};
// definition of breakpoint sizes for tablet and desktop modes
patternfly.pfBreakpoints = {
'tablet': 768,
'desktop': 1200
};
window.patternfly = patternfly;
})(typeof window !== 'undefined' ? window : global);

View File

@ -0,0 +1,92 @@
/// <reference types="c3" />
interface Window {
patternfly: Patternfly;
}
interface PFChartDataItem {
id: string;
index: number;
value: string;
name: string;
ratio: number;
}
type PFChartData = PFChartDataItem[];
interface Patternfly {
pfSetDonutChartTitle(
selector: Node,
primary: string,
secondary: string
): void;
pfDonutTooltipContents(
data: PFChartData,
defaultTitleFormat: string,
defaultValueFormat: string,
color: (id: number | string) => string
): string;
pfGetUtilizationDonutTooltipContentsFn(
units: string | number
): (data: PFChartData) => string;
pfGetBarChartTooltipContentsFn(
categories?: string[]
): (data: PFChartData) => string;
pfSingleLineChartTooltipContentsFn(
categories?: string[]
): (data: PFChartData) => string;
pfPieTooltipContents: Patternfly['pfDonutTooltipContents'];
c3ChartDefaults(): {
getDefaultAreaAxis(): c3.Axis
getDefaultAreaConfig(): c3.ChartConfiguration;
getDefaultAreaLegend(): c3.LegendOptions;
getDefaultAreaPoint(): c3.PointOptions;
getDefaultBarConfig(categories: string[]): c3.ChartConfiguration;
getDefaultBarGrid(): c3.Grid;
getDefaultBarLegend(): c3.LegendOptions;
getDefaultBarTooltip(categories: string[]): c3.TooltipOptions;
getDefaultColors(): c3.ChartConfiguration['color'];
getDefaultDonut(title: string): c3.ChartConfiguration['donut'];
getDefaultDonutColors(): c3.ChartConfiguration['color'];
getDefaultDonutConfig(title: string): c3.ChartConfiguration;
getDefaultDonutLegend(): c3.LegendOptions;
getDefaultDonutSize(): c3.ChartConfiguration['size'];
getDefaultDonutTooltip(): c3.TooltipOptions;
getDefaultGroupedBarConfig(): c3.ChartConfiguration;
getDefaultGroupedBarGrid(): c3.Grid;
getDefaultGroupedBarLegend(): c3.LegendOptions;
getDefaultLineAxis(): c3.Axis;
getDefaultLineConfig(): c3.ChartConfiguration;
getDefaultLineGrid(): c3.Grid;
getDefaultLineLegend(): c3.LegendOptions;
getDefaultLinePoint(): c3.PointOptions;
getDefaultPie(): c3.ChartConfiguration['pie'];
getDefaultPieColors(): c3.ChartConfiguration['color'];
getDefaultPieConfig(): c3.ChartConfiguration;
getDefaultPieLegend(): c3.LegendOptions;
getDefaultPieSize(): c3.ChartConfiguration['size'];
getDefaultPieTooltip(): c3.TooltipOptions;
getDefaultRelationshipDonutColors(): c3.ChartConfiguration['color'];
getDefaultRelationshipDonutConfig(): c3.ChartConfiguration;
getDefaultSingleAreaConfig(): c3.ChartConfiguration;
getDefaultSingleAreaTooltip(): c3.TooltipOptions;
getDefaultSingleLineConfig(): c3.ChartConfiguration;
getDefaultSingleLineTooltip(): c3.TooltipOptions;
getDefaultSparklineArea(): c3.ChartConfiguration['area'];
getDefaultSparklineAxis(): c3.Axis;
getDefaultSparklineConfig(): c3.ChartConfiguration;
getDefaultSparklineLegend(): c3.LegendOptions;
getDefaultSparklinePoint(): c3.PointOptions;
getDefaultSparklineSize(): c3.ChartConfiguration['size'];
getDefaultSparklineTooltip(): c3.TooltipOptions;
getDefaultStackedBarConfig(): c3.ChartConfiguration;
getDefaultStackedBarGrid(): c3.Grid;
getDefaultStackedBarLegend(): c3.LegendOptions;
};
}

View File

@ -0,0 +1,449 @@
(function (window) {
'use strict';
// Ensure we are assigning these to the patternfly property of the window argument, and not the implicit global patternfly
var patternfly = window.patternfly;
// Util: PatternFly C3 Chart Defaults
patternfly.pfSetDonutChartTitle = function (selector, primary, secondary) {
var donutChartRightTitle = window.d3.select(selector).select('text.c3-chart-arcs-title');
donutChartRightTitle.text("");
donutChartRightTitle.insert('tspan').text(primary).classed('donut-title-big-pf', true).attr('y', 0).attr('x', 0);
donutChartRightTitle.insert('tspan').text(secondary).classed('donut-title-small-pf', true).attr('y', 20).attr('x', 0);
};
patternfly.pfDonutTooltipContents = function (d, defaultTitleFormat, defaultValueFormat, color) {
return '<table class="c3-tooltip">' +
' <tr>' +
' <td><span style="background-color:' + color(d[0].id) + '"></span>' + '<strong>' + d[0].value + '</strong> ' + d[0].name + '</td>' +
' <td>' + (Math.round(d[0].ratio * 1000) / 10) + '%</td>' +
' </tr>' +
'</table>';
};
patternfly.pfGetUtilizationDonutTooltipContentsFn = function (units) {
return function (d) {
return '<span class="donut-tooltip-pf" style="white-space: nowrap;">' +
(Math.round(d[0].ratio * 1000) / 10) + '%' + ' ' + units + ' ' + d[0].name +
'</span>';
};
};
patternfly.pfGetBarChartTooltipContentsFn = function (categories) {
return function (d) {
var name = categories ? categories[d[0].index] : d[0].index;
return '<table class="c3-tooltip">' +
' <tr>' +
' <td><strong>' + name + ':</td>' +
' <td>' + d[0].value + '</td>' +
' </tr>' +
'</table>';
};
};
patternfly.pfSingleLineChartTooltipContentsFn = function (categories) {
return function (d) {
var name = categories ? categories[d[0].index] : d[0].index;
return '<table class="c3-tooltip">' +
' <tr>' +
' <td><strong>' + name + ':</td>' +
' <td>' + d[0].value + '</td>' +
' </tr>' +
'</table>';
};
};
patternfly.pfPieTooltipContents = function (d, defaultTitleFormat, defaultValueFormat, color) {
return patternfly.pfDonutTooltipContents(d, defaultTitleFormat, defaultValueFormat, color);
};
patternfly.c3ChartDefaults = function () {
var
getDefaultColors = function () {
return {
pattern: [
patternfly.pfPaletteColors.blue,
patternfly.pfPaletteColors.blue300,
patternfly.pfPaletteColors.green,
patternfly.pfPaletteColors.orange,
patternfly.pfPaletteColors.red
]
};
},
getDefaultBarGrid = function () {
return {
y: {
show: true
}
};
},
getDefaultBarTooltip = function (categories) {
return {
contents: patternfly.pfGetBarChartTooltipContentsFn(categories)
};
},
getDefaultBarLegend = function () {
return {
show: false
};
},
getDefaultBarConfig = function (categories) {
return {
color: this.getDefaultColors(),
grid: this.getDefaultBarGrid(),
tooltip: this.getDefaultBarTooltip(categories),
legend: this.getDefaultBarLegend()
};
},
getDefaultGroupedBarGrid = function () {
return {
y: {
show: true
}
};
},
getDefaultGroupedBarLegend = function () {
return {
show: true,
position: 'bottom'
};
},
getDefaultGroupedBarConfig = function () {
return {
color: this.getDefaultColors(),
grid: this.getDefaultGroupedBarGrid(),
legend: this.getDefaultGroupedBarLegend()
};
},
getDefaultStackedBarGrid = function () {
return {
y: {
show: true
}
};
},
getDefaultStackedBarLegend = function () {
return {
show: true,
position: 'bottom'
};
},
getDefaultStackedBarConfig = function () {
return {
color: this.getDefaultColors(),
grid: this.getDefaultStackedBarGrid(),
legend: this.getDefaultStackedBarLegend()
};
},
getDefaultDonut = function (title) {
return {
title: title,
label: {
show: false
},
width: 11
};
},
getDefaultDonutSize = function () {
return {
height: 171 // produces a diameter of 150 and a centered chart when there is no legend
// Don't set a width here, the default is to center horizontally in the parent container
};
},
getDefaultDonutColors = function () {
return {
pattern: [
patternfly.pfPaletteColors.blue,
patternfly.pfPaletteColors.black300
]
};
},
getDefaultRelationshipDonutColors = function () {
return {
pattern: [
patternfly.pfPaletteColors.blue,
patternfly.pfPaletteColors.red100,
patternfly.pfPaletteColors.orange400,
patternfly.pfPaletteColors.green400,
patternfly.pfPaletteColors.cyan500,
patternfly.pfPaletteColors.gold200,
]
};
},
getDefaultDonutTooltip = function () {
return {
show: false
};
},
getDefaultDonutLegend = function () {
return {
show: false
};
},
getDefaultDonutConfig = function (title) {
return {
donut: this.getDefaultDonut(title),
size: this.getDefaultDonutSize(),
legend: this.getDefaultDonutLegend(),
color: this.getDefaultDonutColors(),
tooltip: this.getDefaultDonutTooltip()
};
},
getDefaultRelationshipDonutConfig = function (title) {
return {
donut: this.getDefaultDonut(title),
size: this.getDefaultDonutSize(),
legend: this.getDefaultDonutLegend(),
color: this.getDefaultRelationshipDonutColors(),
tooltip: this.getDefaultDonutTooltip()
};
},
getDefaultPie = function () {
return {
expand: true,
label: {
show: false
}
};
},
getDefaultPieSize = function () {
return {
height: 171 // produces a diameter of 150 and a centered chart when there is no legend
// Don't set a width here, default is to center horizontally in the parent container
};
},
getDefaultPieColors = function () {
return {
pattern: [
patternfly.pfPaletteColors.blue,
patternfly.pfPaletteColors.black300
]
};
},
getDefaultPieTooltip = function () {
return {
contents: patternfly.pfPieTooltipContents
};
},
getDefaultPieLegend = function () {
return {
show: false
};
},
getDefaultPieConfig = function () {
return {
pie: this.getDefaultPie(),
size: this.getDefaultPieSize(),
legend: this.getDefaultPieLegend(),
color: this.getDefaultPieColors(),
tooltip: this.getDefaultPieTooltip()
};
},
getDefaultSparklineArea = function () {
return {
zerobased: true
};
},
getDefaultSparklineSize = function () {
return {
height: 60
};
},
getDefaultSparklineAxis = function () {
return {
x: {
show: false
},
y: {
show: false
}
};
},
getDefaultSparklineLegend = function () {
return {
show: false
};
},
getDefaultSparklinePoint = function () {
return {
r: 1,
focus: {
expand: {
r: 4
}
}
};
},
getDefaultSparklineTooltip = function () {
return {
// because a sparkline should only contain a single data column,
// the tooltip will only work for a single data column
contents: function (d) {
return '<span class="c3-tooltip-sparkline">' + d[0].value + ' ' + d[0].name + '</span>';
}
};
},
getDefaultSparklineConfig = function () {
return {
area: getDefaultSparklineArea(),
size: getDefaultSparklineSize(),
axis: getDefaultSparklineAxis(),
color: getDefaultColors(),
legend: getDefaultSparklineLegend(),
point: getDefaultSparklinePoint(),
tooltip: getDefaultSparklineTooltip()
};
},
getDefaultLineAxis = function () {
return {
x: {
show: true
},
y: {
show: true
}
};
},
getDefaultLineGrid = function () {
return {
x: {
show: false
},
y: {
show: true
}
};
},
getDefaultLineLegend = function () {
return {
show: true
};
},
getDefaultLinePoint = function () {
return {
r: 3,
focus: {
expand: {
r: 5
}
}
};
},
getDefaultLineConfig = function () {
return {
axis: getDefaultLineAxis(),
grid: getDefaultLineGrid(),
color: getDefaultColors(),
legend: getDefaultLineLegend(),
point: getDefaultLinePoint()
};
},
getDefaultSingleLineTooltip = function () {
return {
contents: patternfly.pfGetBarChartTooltipContentsFn()
};
},
getDefaultSingleLineLegend = function () {
return {
show: false
};
},
getDefaultSingleLineConfig = function () {
return {
axis: getDefaultLineAxis(),
grid: getDefaultLineGrid(),
color: getDefaultColors(),
legend: getDefaultSingleLineLegend(),
point: getDefaultLinePoint(),
tooltip: getDefaultSingleLineTooltip()
};
},
getDefaultAreaAxis = function () {
return getDefaultLineAxis();
},
getDefaultAreaGrid = function () {
return getDefaultLineGrid();
},
getDefaultAreaLegend = function () {
return getDefaultLineLegend();
},
getDefaultAreaPoint = function () {
return getDefaultLinePoint();
},
getDefaultAreaConfig = function () {
return {
axis: getDefaultAreaAxis(),
grid: getDefaultAreaGrid(),
color: getDefaultColors(),
legend: getDefaultAreaLegend(),
point: getDefaultAreaPoint()
};
},
getDefaultSingleAreaTooltip = function () {
return {
contents: patternfly.pfGetBarChartTooltipContentsFn()
};
},
getDefaultSingleAreaLegend = function () {
return getDefaultSingleLineLegend();
},
getDefaultSingleAreaConfig = function () {
return {
axis: getDefaultAreaAxis(),
grid: getDefaultAreaGrid(),
color: getDefaultColors(),
legend: getDefaultSingleAreaLegend(),
point: getDefaultAreaPoint(),
tooltip: getDefaultSingleAreaTooltip()
};
};
return {
getDefaultColors: getDefaultColors,
getDefaultBarGrid: getDefaultBarGrid,
getDefaultBarTooltip: getDefaultBarTooltip,
getDefaultBarLegend: getDefaultBarLegend,
getDefaultBarConfig: getDefaultBarConfig,
getDefaultGroupedBarGrid: getDefaultGroupedBarGrid,
getDefaultGroupedBarLegend: getDefaultGroupedBarLegend,
getDefaultGroupedBarConfig: getDefaultGroupedBarConfig,
getDefaultStackedBarGrid: getDefaultStackedBarGrid,
getDefaultStackedBarLegend: getDefaultStackedBarLegend,
getDefaultStackedBarConfig: getDefaultStackedBarConfig,
getDefaultDonut: getDefaultDonut,
getDefaultDonutSize: getDefaultDonutSize,
getDefaultDonutColors: getDefaultDonutColors,
getDefaultDonutTooltip: getDefaultDonutTooltip,
getDefaultDonutLegend: getDefaultDonutLegend,
getDefaultDonutConfig: getDefaultDonutConfig,
getDefaultRelationshipDonutConfig: getDefaultRelationshipDonutConfig,
getDefaultPie: getDefaultPie,
getDefaultPieSize: getDefaultPieSize,
getDefaultPieColors: getDefaultPieColors,
getDefaultRelationshipDonutColors: getDefaultRelationshipDonutColors,
getDefaultPieTooltip: getDefaultPieTooltip,
getDefaultPieLegend: getDefaultPieLegend,
getDefaultPieConfig: getDefaultPieConfig,
getDefaultSparklineArea: getDefaultSparklineArea,
getDefaultSparklineSize: getDefaultSparklineSize,
getDefaultSparklineAxis: getDefaultSparklineAxis,
getDefaultSparklineLegend: getDefaultSparklineLegend,
getDefaultSparklinePoint: getDefaultSparklinePoint,
getDefaultSparklineTooltip: getDefaultSparklineTooltip,
getDefaultSparklineConfig: getDefaultSparklineConfig,
getDefaultLineAxis: getDefaultLineAxis,
getDefaultLineGrid: getDefaultLineGrid,
getDefaultLineLegend: getDefaultLineLegend,
getDefaultLinePoint: getDefaultLinePoint,
getDefaultLineConfig: getDefaultLineConfig,
getDefaultSingleLineTooltip: getDefaultSingleLineTooltip,
getDefaultSingleLineConfig: getDefaultSingleLineConfig,
getDefaultAreaAxis: getDefaultAreaAxis,
getDefaultAreaGrid: getDefaultAreaGrid,
getDefaultAreaLegend: getDefaultAreaLegend,
getDefaultAreaPoint: getDefaultAreaPoint,
getDefaultAreaConfig: getDefaultAreaConfig,
getDefaultSingleAreaTooltip: getDefaultSingleAreaTooltip,
getDefaultSingleAreaConfig: getDefaultSingleAreaConfig
};
};
})(typeof window !== 'undefined' ? window : global);

View File

@ -0,0 +1,88 @@
interface Window {
patternfly: Patternfly;
}
interface Patternfly {
pfPaletteColors: {
black: string;
black100: string;
black200: string;
black300: string;
black400: string;
black500: string;
black600: string;
black700: string;
black800: string;
black900: string;
blue: string;
blue100: string;
blue200: string;
blue300: string;
blue400: string;
blue500: string;
blue600: string;
blue700: string;
gold: string;
gold100: string;
gold200: string;
gold300: string;
gold400: string;
gold500: string;
gold600: string;
gold700: string;
orange: string;
orange100: string;
orange200: string;
orange300: string;
orange400: string;
orange500: string;
orange600: string;
orange700: string;
lightBlue: string;
lightBlue100: string;
lightBlue200: string;
lightBlue300: string;
lightBlue400: string;
lightBlue500: string;
lightBlue600: string;
lightBlue700: string;
green: string;
green100: string;
green200: string;
green300: string;
green400: string;
green500: string;
green600: string;
green700: string;
lightGreen: string;
lightGreen100: string;
lightGreen200: string;
lightGreen300: string;
lightGreen400: string;
lightGreen500: string;
lightGreen600: string;
lightGreen700: string;
cyan: string;
cyan100: string;
cyan200: string;
cyan300: string;
cyan400: string;
cyan500: string;
cyan600: string;
cyan700: string;
purple: string;
purple100: string;
purple200: string;
purple300: string;
purple400: string;
purple500: string;
purple600: string;
purple700: string;
red: string;
red100: string;
red200: string;
red300: string;
red400: string;
red500: string;
};
}

View File

@ -0,0 +1,91 @@
(function (window) {
'use strict';
// Ensure we are assigning these to the patternfly property of the window argument, and not the implicit global patternfly
var patternfly = window.patternfly;
// Util: PatternFly Palette colors
patternfly.pfPaletteColors = {
black: '#030303',
black100: '#fafafa',
black200: '#ededed',
black300: '#d1d1d1',
black400: '#bbbbbb',
black500: '#8b8d8f',
black600: '#72767b',
black700: '#4d5258',
black800: '#393f44',
black900: '#292e34',
blue: '#0088ce',
blue100: '#bee1f4',
blue200: '#7dc3e8',
blue300: '#39a5dc',
blue400: '#0088ce',
blue500: '#00659c',
blue600: '#004368',
blue700: '#002235',
gold: '#f0ab00',
gold100: '#fbeabc',
gold200: '#f9d67a',
gold300: '#f5c12e',
gold400: '#f0ab00',
gold500: '#b58100',
gold600: '#795600',
gold700: '#3d2c00',
orange: '#ec7a08',
orange100: '#fbdebf',
orange200: '#f7bd7f',
orange300: '#f39d3c',
orange400: '#ec7a08',
orange500: '#b35c00',
orange600: '#773d00',
orange700: '#3b1f00',
lightBlue: '#00b9e4',
lightBlue100: '#beedf9',
lightBlue200: '#7cdbf3',
lightBlue300: '#35caed',
lightBlue400: '#00b9e4',
lightBlue500: '#008bad',
lightBlue600: '#005c73',
lightBlue700: '#002d39',
green: '#3f9c35',
green100: '#cfe7cd',
green200: '#9ecf99',
green300: '#6ec664',
green400: '#3f9c35',
green500: '#2d7623',
green600: '#1e4f18',
green700: '#0f280d',
lightGreen: '#92d400',
lightGreen100: '#e4f5bc',
lightGreen200: '#c8eb79',
lightGreen300: '#ace12e',
lightGreen400: '#92d400',
lightGreen500: '#6ca100',
lightGreen600: '#486b00',
lightGreen700: '#253600',
cyan: '#007a87',
cyan100: '#bedee1',
cyan200: '#7dbdc3',
cyan300: '#3a9ca6',
cyan400: '#007a87',
cyan500: '#005c66',
cyan600: '#003d44',
cyan700: '#001f22',
purple: '#703fec',
purple100: '#c7bfff',
purple200: '#a18fff',
purple300: '#8461f7',
purple400: '#703fec',
purple500: '#582fc0',
purple600: '#40199a',
purple700: '#1f0066',
red: '#cc0000',
red100: '#cc0000',
red200: '#a30000',
red300: '#8b0000',
red400: '#470000',
red500: '#2c0000'
};
})(typeof window !== 'undefined' ? window : global);

View File

@ -0,0 +1,3 @@
/// <reference path="patternfly-settings-colors.d.ts" />
/// <reference path="patternfly-settings-base.d.ts" />
/// <reference path="patternfly-settings-charts.d.ts" />

View File

@ -0,0 +1,558 @@
(function (window) {
'use strict';
var patternfly = {
version: "3.59.3"
};
// definition of breakpoint sizes for tablet and desktop modes
patternfly.pfBreakpoints = {
'tablet': 768,
'desktop': 1200
};
window.patternfly = patternfly;
})(typeof window !== 'undefined' ? window : global);
(function (window) {
'use strict';
// Ensure we are assigning these to the patternfly property of the window argument, and not the implicit global patternfly
var patternfly = window.patternfly;
// Util: PatternFly Palette colors
patternfly.pfPaletteColors = {
black: '#030303',
black100: '#fafafa',
black200: '#ededed',
black300: '#d1d1d1',
black400: '#bbbbbb',
black500: '#8b8d8f',
black600: '#72767b',
black700: '#4d5258',
black800: '#393f44',
black900: '#292e34',
blue: '#0088ce',
blue100: '#bee1f4',
blue200: '#7dc3e8',
blue300: '#39a5dc',
blue400: '#0088ce',
blue500: '#00659c',
blue600: '#004368',
blue700: '#002235',
gold: '#f0ab00',
gold100: '#fbeabc',
gold200: '#f9d67a',
gold300: '#f5c12e',
gold400: '#f0ab00',
gold500: '#b58100',
gold600: '#795600',
gold700: '#3d2c00',
orange: '#ec7a08',
orange100: '#fbdebf',
orange200: '#f7bd7f',
orange300: '#f39d3c',
orange400: '#ec7a08',
orange500: '#b35c00',
orange600: '#773d00',
orange700: '#3b1f00',
lightBlue: '#00b9e4',
lightBlue100: '#beedf9',
lightBlue200: '#7cdbf3',
lightBlue300: '#35caed',
lightBlue400: '#00b9e4',
lightBlue500: '#008bad',
lightBlue600: '#005c73',
lightBlue700: '#002d39',
green: '#3f9c35',
green100: '#cfe7cd',
green200: '#9ecf99',
green300: '#6ec664',
green400: '#3f9c35',
green500: '#2d7623',
green600: '#1e4f18',
green700: '#0f280d',
lightGreen: '#92d400',
lightGreen100: '#e4f5bc',
lightGreen200: '#c8eb79',
lightGreen300: '#ace12e',
lightGreen400: '#92d400',
lightGreen500: '#6ca100',
lightGreen600: '#486b00',
lightGreen700: '#253600',
cyan: '#007a87',
cyan100: '#bedee1',
cyan200: '#7dbdc3',
cyan300: '#3a9ca6',
cyan400: '#007a87',
cyan500: '#005c66',
cyan600: '#003d44',
cyan700: '#001f22',
purple: '#703fec',
purple100: '#c7bfff',
purple200: '#a18fff',
purple300: '#8461f7',
purple400: '#703fec',
purple500: '#582fc0',
purple600: '#40199a',
purple700: '#1f0066',
red: '#cc0000',
red100: '#cc0000',
red200: '#a30000',
red300: '#8b0000',
red400: '#470000',
red500: '#2c0000'
};
})(typeof window !== 'undefined' ? window : global);
(function (window) {
'use strict';
// Ensure we are assigning these to the patternfly property of the window argument, and not the implicit global patternfly
var patternfly = window.patternfly;
// Util: PatternFly C3 Chart Defaults
patternfly.pfSetDonutChartTitle = function (selector, primary, secondary) {
var donutChartRightTitle = window.d3.select(selector).select('text.c3-chart-arcs-title');
donutChartRightTitle.text("");
donutChartRightTitle.insert('tspan').text(primary).classed('donut-title-big-pf', true).attr('y', 0).attr('x', 0);
donutChartRightTitle.insert('tspan').text(secondary).classed('donut-title-small-pf', true).attr('y', 20).attr('x', 0);
};
patternfly.pfDonutTooltipContents = function (d, defaultTitleFormat, defaultValueFormat, color) {
return '<table class="c3-tooltip">' +
' <tr>' +
' <td><span style="background-color:' + color(d[0].id) + '"></span>' + '<strong>' + d[0].value + '</strong> ' + d[0].name + '</td>' +
' <td>' + (Math.round(d[0].ratio * 1000) / 10) + '%</td>' +
' </tr>' +
'</table>';
};
patternfly.pfGetUtilizationDonutTooltipContentsFn = function (units) {
return function (d) {
return '<span class="donut-tooltip-pf" style="white-space: nowrap;">' +
(Math.round(d[0].ratio * 1000) / 10) + '%' + ' ' + units + ' ' + d[0].name +
'</span>';
};
};
patternfly.pfGetBarChartTooltipContentsFn = function (categories) {
return function (d) {
var name = categories ? categories[d[0].index] : d[0].index;
return '<table class="c3-tooltip">' +
' <tr>' +
' <td><strong>' + name + ':</td>' +
' <td>' + d[0].value + '</td>' +
' </tr>' +
'</table>';
};
};
patternfly.pfSingleLineChartTooltipContentsFn = function (categories) {
return function (d) {
var name = categories ? categories[d[0].index] : d[0].index;
return '<table class="c3-tooltip">' +
' <tr>' +
' <td><strong>' + name + ':</td>' +
' <td>' + d[0].value + '</td>' +
' </tr>' +
'</table>';
};
};
patternfly.pfPieTooltipContents = function (d, defaultTitleFormat, defaultValueFormat, color) {
return patternfly.pfDonutTooltipContents(d, defaultTitleFormat, defaultValueFormat, color);
};
patternfly.c3ChartDefaults = function () {
var
getDefaultColors = function () {
return {
pattern: [
patternfly.pfPaletteColors.blue,
patternfly.pfPaletteColors.blue300,
patternfly.pfPaletteColors.green,
patternfly.pfPaletteColors.orange,
patternfly.pfPaletteColors.red
]
};
},
getDefaultBarGrid = function () {
return {
y: {
show: true
}
};
},
getDefaultBarTooltip = function (categories) {
return {
contents: patternfly.pfGetBarChartTooltipContentsFn(categories)
};
},
getDefaultBarLegend = function () {
return {
show: false
};
},
getDefaultBarConfig = function (categories) {
return {
color: this.getDefaultColors(),
grid: this.getDefaultBarGrid(),
tooltip: this.getDefaultBarTooltip(categories),
legend: this.getDefaultBarLegend()
};
},
getDefaultGroupedBarGrid = function () {
return {
y: {
show: true
}
};
},
getDefaultGroupedBarLegend = function () {
return {
show: true,
position: 'bottom'
};
},
getDefaultGroupedBarConfig = function () {
return {
color: this.getDefaultColors(),
grid: this.getDefaultGroupedBarGrid(),
legend: this.getDefaultGroupedBarLegend()
};
},
getDefaultStackedBarGrid = function () {
return {
y: {
show: true
}
};
},
getDefaultStackedBarLegend = function () {
return {
show: true,
position: 'bottom'
};
},
getDefaultStackedBarConfig = function () {
return {
color: this.getDefaultColors(),
grid: this.getDefaultStackedBarGrid(),
legend: this.getDefaultStackedBarLegend()
};
},
getDefaultDonut = function (title) {
return {
title: title,
label: {
show: false
},
width: 11
};
},
getDefaultDonutSize = function () {
return {
height: 171 // produces a diameter of 150 and a centered chart when there is no legend
// Don't set a width here, the default is to center horizontally in the parent container
};
},
getDefaultDonutColors = function () {
return {
pattern: [
patternfly.pfPaletteColors.blue,
patternfly.pfPaletteColors.black300
]
};
},
getDefaultRelationshipDonutColors = function () {
return {
pattern: [
patternfly.pfPaletteColors.blue,
patternfly.pfPaletteColors.red100,
patternfly.pfPaletteColors.orange400,
patternfly.pfPaletteColors.green400,
patternfly.pfPaletteColors.cyan500,
patternfly.pfPaletteColors.gold200,
]
};
},
getDefaultDonutTooltip = function () {
return {
show: false
};
},
getDefaultDonutLegend = function () {
return {
show: false
};
},
getDefaultDonutConfig = function (title) {
return {
donut: this.getDefaultDonut(title),
size: this.getDefaultDonutSize(),
legend: this.getDefaultDonutLegend(),
color: this.getDefaultDonutColors(),
tooltip: this.getDefaultDonutTooltip()
};
},
getDefaultRelationshipDonutConfig = function (title) {
return {
donut: this.getDefaultDonut(title),
size: this.getDefaultDonutSize(),
legend: this.getDefaultDonutLegend(),
color: this.getDefaultRelationshipDonutColors(),
tooltip: this.getDefaultDonutTooltip()
};
},
getDefaultPie = function () {
return {
expand: true,
label: {
show: false
}
};
},
getDefaultPieSize = function () {
return {
height: 171 // produces a diameter of 150 and a centered chart when there is no legend
// Don't set a width here, default is to center horizontally in the parent container
};
},
getDefaultPieColors = function () {
return {
pattern: [
patternfly.pfPaletteColors.blue,
patternfly.pfPaletteColors.black300
]
};
},
getDefaultPieTooltip = function () {
return {
contents: patternfly.pfPieTooltipContents
};
},
getDefaultPieLegend = function () {
return {
show: false
};
},
getDefaultPieConfig = function () {
return {
pie: this.getDefaultPie(),
size: this.getDefaultPieSize(),
legend: this.getDefaultPieLegend(),
color: this.getDefaultPieColors(),
tooltip: this.getDefaultPieTooltip()
};
},
getDefaultSparklineArea = function () {
return {
zerobased: true
};
},
getDefaultSparklineSize = function () {
return {
height: 60
};
},
getDefaultSparklineAxis = function () {
return {
x: {
show: false
},
y: {
show: false
}
};
},
getDefaultSparklineLegend = function () {
return {
show: false
};
},
getDefaultSparklinePoint = function () {
return {
r: 1,
focus: {
expand: {
r: 4
}
}
};
},
getDefaultSparklineTooltip = function () {
return {
// because a sparkline should only contain a single data column,
// the tooltip will only work for a single data column
contents: function (d) {
return '<span class="c3-tooltip-sparkline">' + d[0].value + ' ' + d[0].name + '</span>';
}
};
},
getDefaultSparklineConfig = function () {
return {
area: getDefaultSparklineArea(),
size: getDefaultSparklineSize(),
axis: getDefaultSparklineAxis(),
color: getDefaultColors(),
legend: getDefaultSparklineLegend(),
point: getDefaultSparklinePoint(),
tooltip: getDefaultSparklineTooltip()
};
},
getDefaultLineAxis = function () {
return {
x: {
show: true
},
y: {
show: true
}
};
},
getDefaultLineGrid = function () {
return {
x: {
show: false
},
y: {
show: true
}
};
},
getDefaultLineLegend = function () {
return {
show: true
};
},
getDefaultLinePoint = function () {
return {
r: 3,
focus: {
expand: {
r: 5
}
}
};
},
getDefaultLineConfig = function () {
return {
axis: getDefaultLineAxis(),
grid: getDefaultLineGrid(),
color: getDefaultColors(),
legend: getDefaultLineLegend(),
point: getDefaultLinePoint()
};
},
getDefaultSingleLineTooltip = function () {
return {
contents: patternfly.pfGetBarChartTooltipContentsFn()
};
},
getDefaultSingleLineLegend = function () {
return {
show: false
};
},
getDefaultSingleLineConfig = function () {
return {
axis: getDefaultLineAxis(),
grid: getDefaultLineGrid(),
color: getDefaultColors(),
legend: getDefaultSingleLineLegend(),
point: getDefaultLinePoint(),
tooltip: getDefaultSingleLineTooltip()
};
},
getDefaultAreaAxis = function () {
return getDefaultLineAxis();
},
getDefaultAreaGrid = function () {
return getDefaultLineGrid();
},
getDefaultAreaLegend = function () {
return getDefaultLineLegend();
},
getDefaultAreaPoint = function () {
return getDefaultLinePoint();
},
getDefaultAreaConfig = function () {
return {
axis: getDefaultAreaAxis(),
grid: getDefaultAreaGrid(),
color: getDefaultColors(),
legend: getDefaultAreaLegend(),
point: getDefaultAreaPoint()
};
},
getDefaultSingleAreaTooltip = function () {
return {
contents: patternfly.pfGetBarChartTooltipContentsFn()
};
},
getDefaultSingleAreaLegend = function () {
return getDefaultSingleLineLegend();
},
getDefaultSingleAreaConfig = function () {
return {
axis: getDefaultAreaAxis(),
grid: getDefaultAreaGrid(),
color: getDefaultColors(),
legend: getDefaultSingleAreaLegend(),
point: getDefaultAreaPoint(),
tooltip: getDefaultSingleAreaTooltip()
};
};
return {
getDefaultColors: getDefaultColors,
getDefaultBarGrid: getDefaultBarGrid,
getDefaultBarTooltip: getDefaultBarTooltip,
getDefaultBarLegend: getDefaultBarLegend,
getDefaultBarConfig: getDefaultBarConfig,
getDefaultGroupedBarGrid: getDefaultGroupedBarGrid,
getDefaultGroupedBarLegend: getDefaultGroupedBarLegend,
getDefaultGroupedBarConfig: getDefaultGroupedBarConfig,
getDefaultStackedBarGrid: getDefaultStackedBarGrid,
getDefaultStackedBarLegend: getDefaultStackedBarLegend,
getDefaultStackedBarConfig: getDefaultStackedBarConfig,
getDefaultDonut: getDefaultDonut,
getDefaultDonutSize: getDefaultDonutSize,
getDefaultDonutColors: getDefaultDonutColors,
getDefaultDonutTooltip: getDefaultDonutTooltip,
getDefaultDonutLegend: getDefaultDonutLegend,
getDefaultDonutConfig: getDefaultDonutConfig,
getDefaultRelationshipDonutConfig: getDefaultRelationshipDonutConfig,
getDefaultPie: getDefaultPie,
getDefaultPieSize: getDefaultPieSize,
getDefaultPieColors: getDefaultPieColors,
getDefaultRelationshipDonutColors: getDefaultRelationshipDonutColors,
getDefaultPieTooltip: getDefaultPieTooltip,
getDefaultPieLegend: getDefaultPieLegend,
getDefaultPieConfig: getDefaultPieConfig,
getDefaultSparklineArea: getDefaultSparklineArea,
getDefaultSparklineSize: getDefaultSparklineSize,
getDefaultSparklineAxis: getDefaultSparklineAxis,
getDefaultSparklineLegend: getDefaultSparklineLegend,
getDefaultSparklinePoint: getDefaultSparklinePoint,
getDefaultSparklineTooltip: getDefaultSparklineTooltip,
getDefaultSparklineConfig: getDefaultSparklineConfig,
getDefaultLineAxis: getDefaultLineAxis,
getDefaultLineGrid: getDefaultLineGrid,
getDefaultLineLegend: getDefaultLineLegend,
getDefaultLinePoint: getDefaultLinePoint,
getDefaultLineConfig: getDefaultLineConfig,
getDefaultSingleLineTooltip: getDefaultSingleLineTooltip,
getDefaultSingleLineConfig: getDefaultSingleLineConfig,
getDefaultAreaAxis: getDefaultAreaAxis,
getDefaultAreaGrid: getDefaultAreaGrid,
getDefaultAreaLegend: getDefaultAreaLegend,
getDefaultAreaPoint: getDefaultAreaPoint,
getDefaultAreaConfig: getDefaultAreaConfig,
getDefaultSingleAreaTooltip: getDefaultSingleAreaTooltip,
getDefaultSingleAreaConfig: getDefaultSingleAreaConfig
};
};
})(typeof window !== 'undefined' ? window : global);

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,151 @@
/**
* @summary pfColVis for DataTables
* @description An extension providing columns visibility control functionality for DataTables. This ensures
* DataTables meets the Patternfly design pattern with a toolbar.
*
* To enable a colvis, the user just need to specify a region for placing colvis menu. By default, the colvis
* menu includes the items derived from all columns of Datatables. And of course user can also limit the
* generation of the column's visibility checkbox through picking out column index.
*
* The toolbar is expected to contain the classes as shown in the example below.
*
* Example:
*
* <!-- NOTE: Some configuration may be omitted for clarity -->
* <div class="row toolbar-pf table-view-pf-toolbar" id="toolbar1">
* <div class="col-sm-12">
* <form class="toolbar-pf-actions">
* <div class="form-group toolbar-pf-filter">
* </div>
* <div class="form-group toolbar-pf-sort">
* <div class="dropdown btn-group">
* </div>
* <button class="btn btn-link" type="button">
* <span class="fa fa-sort-alpha-asc"></span>
* </button>
* <div class="dropdown btn-group">
* <button class="btn btn-link dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
* <span class="fa fa-columns"></span>
* </button>
* <ul class="dropdown-menu table-view-pf-colvis-menu">
* <li><input type="checkbox" value="1" checked><label>Rendering Engine</label></li>
* <li><input type="checkbox" value="2" checked><label>Browser</label></li>
* <li><input type="checkbox" value="3" checked><label>Platform(s)</label></li>
* <li><input type="checkbox" value="4" checked><label>Engine Version</label></li>
* <li><input type="checkbox" value="5" checked><label>CSS Grade</label></li>
* </ul>
* </div>
* </div>
* ...
* </form>
* </div>
* </div>
* <table class="table table-striped table-bordered table-hover" id="table1">
* <thead>
* <tr>
* <th><input type="checkbox" name="selectAll"></th>
* <th>Rendering Engine</th>
* <th>Browser</th>
* </tr>
* </thead>
* </table>
* ...
* <script>
* // NOTE: Some properties may be omitted for clarity
* $(document).ready(function() {
* var dt = $("#table1").DataTable({
* columns: [
* { data: null, ... },
* { data: "engine" },
* { data: "browser" }
* ],
* data: [
* { engine: "Gecko", browser: "Firefox" }
* { engine: "Trident", browser: "Mozilla" }
* ],
* dom: "t",
* pfConfig: {
* ...
* colvisMenuSelector: '.table-view-pf-colvis-menu'
* }
* });
*
* });
* </script>
*/
(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;
DataTable.pfColVis = {};
/**
* Initialize
*
* @param {DataTable.Api} dt DataTable
* @private
*/
DataTable.pfColVis.init = function (dt) {
var i;
var ctx = dt.settings()[0];
var opts = (ctx.oInit.pfConfig) ? ctx.oInit.pfConfig : {};
if (opts.colvisMenuSelector === undefined) {
return;
}
ctx._pfColVis = {};
ctx._pfColVis.colvisMenu = $(opts.colvisMenuSelector, opts.toolbarSelector);
// Attach event handler for checkbox of ColVis menu
ctx._pfColVis.colvisMenu.on('click', 'li', { 'dt': dt }, colvisMenuHandler);
};
// Local functions
/**
* Handle actions when ColVis menu items are toggled
*
* @param {object} jquery eventObject - click event of ColVis menu items
* @private
*/
function colvisMenuHandler (event) {
var $check = $(this).children(':checkbox');
if (event.target.nodeName !== 'INPUT') {
event.stopPropagation();
$check.prop('checked', !$check.prop('checked'));
}
event.data.dt.column($check.val()).visible($check.prop('checked'));
}
// DataTables creation
$(document).on("init.dt", function (e, ctx, json) {
if (e.namespace !== "dt") {
return;
}
DataTable.pfColVis.init(new DataTable.Api(ctx));
});
return DataTable.pfColVis;
}));

View File

@ -0,0 +1,253 @@
/**
* @summary pfEmpty for DataTables
* @description A collection of API methods providing functionality to hide and show elements when DataTables is empty.
* This ensures DataTables meets the Patternfly design pattern with a toolbar and empty state.
*
* When DataTable is redrawn and data length is zero, controls under the toolbar-pf-actions and toolbar-pf-results
* classes are disabled; including the filter drop down, filter input, action buttons, kebab, find, etc. (You may
* re-enable specific controls via the DataTables "draw.dt" event.) In addition, the DataTables empty table header and
* row are hidden while the empty state (i.e., blank slate) layout is shown.
*
* The toolbar and empty state layouts are expected to contain the classes as shown in the example below.
*
* Example:
*
* <!-- NOTE: Some configuration may be omitted for clarity -->
* <div class="row toolbar-pf table-view-pf-toolbar" id="toolbar1">
* <div class="col-sm-12">
* <form class="toolbar-pf-actions">
* ...
* </form>
* <div class="row toolbar-pf-results">
* ...
* </div>
* </div>
* </div>
* <table class="table table-striped table-bordered table-hover" id="table1">
* <thead>
* <tr>
* <th><input type="checkbox" name="selectAll"></th>
* <th>Rendering Engine</th>
* <th>Browser</th>
* </tr>
* </thead>
* </table>
* <div class="blank-slate-pf table-view-pf-empty hidden" id="emptyState1">
* <div class="blank-slate-pf-icon">
* <span class="pficon pficon pficon-add-circle-o"></span>
* </div>
* <h1>Empty State Title</h1>
* ...
* </div>
* <script>
* // NOTE: Some properties may be omitted for clarity
* $(document).ready(function() {
* var dt = $("#table1").DataTable({
* columns: [
* { data: null, ... },
* { data: "engine" },
* { data: "browser" }
* ],
* data: null,
* dom: "t",
* pfConfig: {
* emptyStateSelector: "#emptyState1",
* ...
* toolbarSelector: "#toolbar1"
* }
* });
* dt.table().pfEmpty.updateState(); // Optional API to force update
* });
* </script>
*
* 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 ACTIONS_SELECTOR = ".toolbar-pf-actions"; // Toolbar actions
var RESULTS_SELECTOR = ".toolbar-pf-results"; // Toolbar results row
DataTable.pfEmpty = {};
/**
* Initialize
*
* @param {DataTable.Api} dt DataTable
* @private
*/
DataTable.pfEmpty.init = function (dt) {
var ctx = dt.settings()[0];
var opts = (ctx.oInit.pfConfig) ? ctx.oInit.pfConfig : {};
ctx._pfEmpty = {};
ctx._pfEmpty.emptyState = $(opts.emptyStateSelector); // Empty state (Blank slate)
ctx._pfEmpty.isEmptyState = false; // Flag indicating DatTable entered an empty state
ctx._pfEmpty.pagination = $(opts.paginationSelector); // Pagination
ctx._pfEmpty.tbody = $("tbody", dt.table().container()); // Table body
ctx._pfEmpty.thead = $("thead", dt.table().container()); // Table head
ctx._pfEmpty.toolbarActions = $(ACTIONS_SELECTOR, opts.toolbarSelector); // Toolbar actions
ctx._pfEmpty.toolbarResults = $(RESULTS_SELECTOR, opts.toolbarSelector); // Toolbar results row
// Update table on DataTables draw event
dt.on("draw.dt", function () {
updateState(dt);
});
// Initialize
updateState(dt);
};
// Local functions
/**
* Disable and hide elements when DataTables has no data
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateEmptyState (dt) {
var ctx = dt.settings()[0];
// Show blank slate
if (ctx._pfEmpty.emptyState !== undefined && ctx._pfEmpty.emptyState.length !== 0) {
ctx._pfEmpty.emptyState.removeClass("hidden");
}
// Hide zero records message
if (ctx._pfEmpty.tbody !== undefined && ctx._pfEmpty.tbody.length !== 0) {
ctx._pfEmpty.tbody.addClass("hidden");
}
// Hide column headers
if (ctx._pfEmpty.thead !== undefined && ctx._pfEmpty.thead.length !== 0) {
ctx._pfEmpty.thead.addClass("hidden");
}
// Disable all buttons
if (ctx._pfEmpty.toolbarActions !== undefined && ctx._pfEmpty.toolbarActions.length !== 0) {
$("button", ctx._pfEmpty.toolbarActions).prop("disabled", true);
}
// Disable all inputs
if (ctx._pfEmpty.toolbarActions !== undefined && ctx._pfEmpty.toolbarActions.length !== 0) {
$("input", ctx._pfEmpty.toolbarActions).prop("disabled", true);
}
// Hide results container
if (ctx._pfEmpty.toolbarResults !== undefined && ctx._pfEmpty.toolbarResults.length !== 0) {
ctx._pfEmpty.toolbarResults.children().addClass("hidden");
}
// Hide pagination
if (ctx._pfEmpty.pagination !== undefined && ctx._pfEmpty.pagination.length !== 0) {
ctx._pfEmpty.pagination.addClass("hidden");
}
// Enable on empty
if (ctx._pfEmpty.enableOnEmpty !== undefined) {
$(ctx._pfEmpty.enableOnEmpty).prop("disabled", false);
}
// Enable on empty
if (ctx._pfEmpty.enableOnEmpty !== undefined) {
$(ctx._pfEmpty.enableOnEmpty).prop("disabled", false);
}
}
/**
* Enable and show elements when DataTables has data
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateNonEmptyState (dt) {
var ctx = dt.settings()[0];
// Hide blank slate
if (ctx._pfEmpty.emptyState !== undefined && ctx._pfEmpty.emptyState.length !== 0) {
ctx._pfEmpty.emptyState.addClass("hidden");
}
// Show table body
if (ctx._pfEmpty.tbody !== undefined && ctx._pfEmpty.tbody.length !== 0) {
ctx._pfEmpty.tbody.removeClass("hidden");
}
// Show column headers
if (ctx._pfEmpty.thead !== undefined && ctx._pfEmpty.thead.length !== 0) {
ctx._pfEmpty.thead.removeClass("hidden");
}
// Enable all buttons
if (ctx._pfEmpty.toolbarActions !== undefined && ctx._pfEmpty.toolbarActions.length !== 0) {
$("button", ctx._pfEmpty.toolbarActions).prop("disabled", false);
}
// Enable all inputs
if (ctx._pfEmpty.toolbarActions !== undefined && ctx._pfEmpty.toolbarActions.length !== 0) {
$("input", ctx._pfEmpty.toolbarActions).prop("disabled", false);
}
// Show results container
if (ctx._pfEmpty.toolbarResults !== undefined && ctx._pfEmpty.toolbarResults.length !== 0) {
ctx._pfEmpty.toolbarResults.children().removeClass("hidden");
}
// Show pagination
if (ctx._pfEmpty.pagination !== undefined && ctx._pfEmpty.pagination.length !== 0) {
ctx._pfEmpty.pagination.removeClass("hidden");
}
}
/**
* Update elements upon empty DataTable state
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateState (dt) {
var ctx = dt.settings()[0];
// Don't enable or show elements unless DataTable was empty
if (dt.data().length === 0) {
ctx._pfEmpty.isEmptyState = true;
updateEmptyState(dt);
} else if (ctx._pfEmpty.isEmptyState === true) {
ctx._pfEmpty.isEmptyState = false;
updateNonEmptyState(dt);
}
}
// DataTables API
/**
* Update state upon empty or non-empty DataTable
*
* Example: dt.table().pfEmpty.updateState();
*/
DataTable.Api.register("pfEmpty.updateState()", function () {
return this.iterator("table", function (ctx) {
updateState(new DataTable.Api(ctx));
});
});
// DataTables creation
$(document).on("init.dt", function (e, ctx, json) {
if (e.namespace !== "dt") {
return;
}
DataTable.pfEmpty.init(new DataTable.Api(ctx));
});
return DataTable.pfEmpty;
}));

View File

@ -0,0 +1 @@
!function(factory){"use strict";"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function($){return factory($,window,document)}):"object"==typeof exports?module.exports=function(root,$){return root||(root=window),$&&$.fn.dataTable||($=require("datatables.net")(root,$).$),factory($,root,root.document)}:factory(jQuery,window,document)}(function($,window,document,undefined){"use strict";function updateEmptyState(dt){var ctx=dt.settings()[0];ctx._pfEmpty.emptyState!==undefined&&0!==ctx._pfEmpty.emptyState.length&&ctx._pfEmpty.emptyState.removeClass("hidden"),ctx._pfEmpty.tbody!==undefined&&0!==ctx._pfEmpty.tbody.length&&ctx._pfEmpty.tbody.addClass("hidden"),ctx._pfEmpty.thead!==undefined&&0!==ctx._pfEmpty.thead.length&&ctx._pfEmpty.thead.addClass("hidden"),ctx._pfEmpty.toolbarActions!==undefined&&0!==ctx._pfEmpty.toolbarActions.length&&$("button",ctx._pfEmpty.toolbarActions).prop("disabled",!0),ctx._pfEmpty.toolbarActions!==undefined&&0!==ctx._pfEmpty.toolbarActions.length&&$("input",ctx._pfEmpty.toolbarActions).prop("disabled",!0),ctx._pfEmpty.toolbarResults!==undefined&&0!==ctx._pfEmpty.toolbarResults.length&&ctx._pfEmpty.toolbarResults.children().addClass("hidden"),ctx._pfEmpty.pagination!==undefined&&0!==ctx._pfEmpty.pagination.length&&ctx._pfEmpty.pagination.addClass("hidden"),ctx._pfEmpty.enableOnEmpty!==undefined&&$(ctx._pfEmpty.enableOnEmpty).prop("disabled",!1),ctx._pfEmpty.enableOnEmpty!==undefined&&$(ctx._pfEmpty.enableOnEmpty).prop("disabled",!1)}function updateNonEmptyState(dt){var ctx=dt.settings()[0];ctx._pfEmpty.emptyState!==undefined&&0!==ctx._pfEmpty.emptyState.length&&ctx._pfEmpty.emptyState.addClass("hidden"),ctx._pfEmpty.tbody!==undefined&&0!==ctx._pfEmpty.tbody.length&&ctx._pfEmpty.tbody.removeClass("hidden"),ctx._pfEmpty.thead!==undefined&&0!==ctx._pfEmpty.thead.length&&ctx._pfEmpty.thead.removeClass("hidden"),ctx._pfEmpty.toolbarActions!==undefined&&0!==ctx._pfEmpty.toolbarActions.length&&$("button",ctx._pfEmpty.toolbarActions).prop("disabled",!1),ctx._pfEmpty.toolbarActions!==undefined&&0!==ctx._pfEmpty.toolbarActions.length&&$("input",ctx._pfEmpty.toolbarActions).prop("disabled",!1),ctx._pfEmpty.toolbarResults!==undefined&&0!==ctx._pfEmpty.toolbarResults.length&&ctx._pfEmpty.toolbarResults.children().removeClass("hidden"),ctx._pfEmpty.pagination!==undefined&&0!==ctx._pfEmpty.pagination.length&&ctx._pfEmpty.pagination.removeClass("hidden")}function updateState(dt){var ctx=dt.settings()[0];0===dt.data().length?(ctx._pfEmpty.isEmptyState=!0,updateEmptyState(dt)):!0===ctx._pfEmpty.isEmptyState&&(ctx._pfEmpty.isEmptyState=!1,updateNonEmptyState(dt))}var DataTable=$.fn.dataTable;return DataTable.pfEmpty={},DataTable.pfEmpty.init=function(dt){var ctx=dt.settings()[0],opts=ctx.oInit.pfConfig?ctx.oInit.pfConfig:{};ctx._pfEmpty={},ctx._pfEmpty.emptyState=$(opts.emptyStateSelector),ctx._pfEmpty.isEmptyState=!1,ctx._pfEmpty.pagination=$(opts.paginationSelector),ctx._pfEmpty.tbody=$("tbody",dt.table().container()),ctx._pfEmpty.thead=$("thead",dt.table().container()),ctx._pfEmpty.toolbarActions=$(".toolbar-pf-actions",opts.toolbarSelector),ctx._pfEmpty.toolbarResults=$(".toolbar-pf-results",opts.toolbarSelector),dt.on("draw.dt",function(){updateState(dt)}),updateState(dt)},DataTable.Api.register("pfEmpty.updateState()",function(){return this.iterator("table",function(ctx){updateState(new DataTable.Api(ctx))})}),$(document).on("init.dt",function(e,ctx,json){"dt"===e.namespace&&DataTable.pfEmpty.init(new DataTable.Api(ctx))}),DataTable.pfEmpty});

View File

@ -0,0 +1,429 @@
/**
* @summary pfFilter for DataTables
* @description A collection of API methods providing simple filter functionality for DataTables. This ensures
* DataTables meets the Patternfly design pattern with a toolbar.
*
* To apply a filter, the user must press enter in the given filter input. The user may apply a filter to a different
* column via the given filter drop down. After a filter has been applied, the filter results text, active filter
* controls, and a clear all control are shown.
*
* The toolbar and empty state layouts are expected to contain the classes as shown in the example below.
*
* Example:
*
* <!-- NOTE: Some configuration may be omitted for clarity -->
* <div class="row toolbar-pf table-view-pf-toolbar" id="toolbar1">
* <div class="col-sm-12">
* <form class="toolbar-pf-actions">
* <div class="form-group toolbar-pf-filter">
* <label class="sr-only" for="filter">Rendering Engine</label>
* <div class="input-group">
* <div class="input-group-btn">
* <button type="button" class="btn btn-default dropdown-toggle" id="filter" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Rendering Engine <span class="caret"></span></button>
* <ul class="dropdown-menu">
* <li><a href="#" id="filter1">Rendering Engine</a></li>
* <li><a href="#" id="filter2">Browser</a></li>
* </ul>
* </div>
* <input type="text" class="form-control" placeholder="Filter By Rendering Engine..." autocomplete="off" id="filterInput">
* </div>
* </div>
* ...
* </form>
* <div class="row toolbar-pf-results">
* <div class="col-sm-9">
* <div class="hidden">
* <h5>0 Results</h5>
* <p>Active filters:</p>
* <ul class="list-inline"></ul>
* <p><a href="#">Clear All Filters</a></p>
* </div>
* </div>
* <div class="col-sm-3 table-view-pf-select-results">
* <strong>0</strong> of <strong>0</strong> selected
* </div>
* </div>
* </div>
* </div>
* <table class="table table-striped table-bordered table-hover" id="table1">
* <thead>
* <tr>
* <th><input type="checkbox" name="selectAll"></th>
* <th>Rendering Engine</th>
* <th>Browser</th>
* </tr>
* </thead>
* </table>
* ...
* <script>
* // NOTE: Some properties may be omitted for clarity
* $(document).ready(function() {
* var dt = $("#table1").DataTable({
* columns: [
* { data: null, ... },
* { data: "engine" },
* { data: "browser" }
* ],
* data: [
* { engine: "Gecko", browser: "Firefox" }
* { engine: "Trident", browser: "Mozilla" }
* ],
* dom: "t",
* pfConfig: {
* ...
* filterCaseInsensitive: true,
* filterCols: [
* null,
* {
* default: true,
* optionSelector: "#filter1",
* placeholder: "Filter By Rendering Engine..."
* }, {
* optionSelector: "#filter2",
* placeholder: "Filter By Browser..."
* }
* ],
* toolbarSelector: "#toolbar1"
* }
* });
* // Optional API to clear filters
* dt.table().pfFilter.clearFilters();
*
* // Optional API to add filter
* dt.table().pfFilter.addFilter({
* column: 2,
* name: "Browser",
* value: "Firefox"
* });
* });
* </script>
*
* 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 ACTIVE_FILTER_CONTROLS_SELECTOR = ".list-inline"; // Active filter controls
var CLEAR_FILTERS_SELECTOR = ".toolbar-pf-results a"; // Clear filters control
var FILTER_SELECTOR = ".toolbar-pf-filter"; // Filter input
var FILTER_BUTTON_SELECTOR = FILTER_SELECTOR + " button"; // Filter button
var FILTER_INPUT_SELECTOR = FILTER_SELECTOR + " input"; // Filter input
var FILTER_LABEL_SELECTOR = FILTER_SELECTOR + " label"; // Filter label
var RESULTS_SELECTOR = ".toolbar-pf-results"; // Toolbar results row
var FILTER_RESULTS_SELECTOR = RESULTS_SELECTOR + " h5"; // Toolbar filter results
DataTable.pfFilter = {};
/**
* Initialize
*
* @param {DataTable.Api} dt DataTable
* @private
*/
DataTable.pfFilter.init = function (dt) {
var i;
var ctx = dt.settings()[0];
var opts = (ctx.oInit.pfConfig) ? ctx.oInit.pfConfig : {};
ctx._pfFilter = {};
ctx._pfFilter.filterButton = $(FILTER_BUTTON_SELECTOR, opts.toolbarSelector); // Filter button
ctx._pfFilter.filterCols = opts.filterCols; // Filter colums config
ctx._pfFilter.filterLabel = $(FILTER_LABEL_SELECTOR, opts.toolbarSelector); // Filter label
ctx._pfFilter.filterInput = $(FILTER_INPUT_SELECTOR, opts.toolbarSelector); // Filter input
ctx._pfFilter.filters = []; // Applied filters array
ctx._pfFilter.activeFilterControls = $(ACTIVE_FILTER_CONTROLS_SELECTOR, opts.toolbarSelector); // Active filter controls
ctx._pfFilter.activeFilters = ctx._pfFilter.activeFilterControls.closest("div"); // Active filters container
ctx._pfFilter.clearFilters = $(CLEAR_FILTERS_SELECTOR, opts.toolbarSelector); // Clear filters control
ctx._pfFilter.results = $(RESULTS_SELECTOR, opts.toolbarSelector); // Toolbar results row
ctx._pfFilter.filterCaseInsensitive = opts.filterCaseInsensitive; // Filter filter case insensitive
ctx._pfFilter.filterResults = $(FILTER_RESULTS_SELECTOR, opts.toolbarSelector); // Toolbar filter results
if (ctx._pfFilter.filterCols === undefined) {
return;
}
// Set default filter properties
for (i = 0; i < ctx._pfFilter.filterCols.length; i++) {
if (ctx._pfFilter.filterCols[i] === null) {
continue;
}
ctx._pfFilter.filterColumn = i; // Current filter column
ctx._pfFilter.filterName = $(ctx._pfFilter.filterCols[i].optionSelector).text(); // Name of current filter
if (ctx._pfFilter.filterCols[i].default === true) {
break;
}
}
// Handle click on filter menu to set current filter column and name
for (i = 0; i < ctx._pfFilter.filterCols.length; i++) {
handleFilterOption(dt, i); // Need to pass value of i as a function
}
// Handle actions when enter is pressed within filter input
handleFilterInput(dt);
// Handle actions when clear filters control is selected
handleClearFilters(dt);
// Simple filter
$.fn.dataTable.ext.search.push(function (ctx, data, dataIndex) {
var showThisRow = true;
// Must match all filters
if (ctx._pfFilter) {
$.each(ctx._pfFilter.filters, function (index, filter) {
if (ctx._pfFilter.filterCaseInsensitive !== undefined && ctx._pfFilter.filterCaseInsensitive === true) {
if (data[filter.column].toLowerCase().indexOf(filter.value.toLowerCase()) === -1) {
showThisRow = false;
}
} else {
if (data[filter.column].indexOf(filter.value) === -1) {
showThisRow = false;
}
}
});
}
return showThisRow;
});
};
// Local functions
/**
* Add active filter control
*
* @param {DataTable.Api} dt DataTable
* @param {object} filter Properties associated with a new filter
* @param {string} filter.column - Column associated with DataTable
* @param {string} filter.name - Name of the filter
* @param {string} filter.value - Value of the filter
* @private
*/
function addActiveFilterControl (dt, filter) {
var ctx = dt.settings()[0];
var i;
// Append active filter control
ctx._pfFilter.activeFilterControls.append('<li><span class="label label-info">' + filter.name + ': ' +
filter.value + '<a href="#"><span class="pficon pficon-close"/></a></span></li>');
// Handle click to clear active filter
$("a", ctx._pfFilter.activeFilterControls).last().on("click", function (e) {
// Find existing filter and remove
for (i = 0; i < ctx._pfFilter.filters.length; i++) {
if (ctx._pfFilter.filters[i].column === filter.column && ctx._pfFilter.filters[i].value === filter.value) {
ctx._pfFilter.filters.splice(i, 1);
$(this).parents("li").remove();
break;
}
}
if (ctx._pfFilter.filters.length === 0) {
ctx._pfFilter.activeFilters.addClass("hidden"); // Hide
}
dt.draw();
updateFilterResults(dt);
});
// Show active filters
ctx._pfFilter.activeFilters.removeClass("hidden");
}
/**
* Add filter
*
* @param {DataTable.Api} dt DataTable
* @param {object} filter Properties associated with a new filter
* @param {string} filter.column - Column associated with DataTable
* @param {string} filter.name - Name of the filter
* @param {string} filter.value - Value of the filter
* @private
*/
function addFilter (dt, filter) {
var ctx = dt.settings()[0];
var found = false;
// Find existing entry
$.grep(ctx._pfFilter.filters, function (f) {
if (f.column === filter.column && f.value === filter.value) {
found = true;
}
});
// Add new filter
if (!found) {
ctx._pfFilter.filters.push(filter);
dt.draw();
addActiveFilterControl(dt, filter);
updateFilterResults(dt);
}
ctx._pfFilter.filterInput.val(""); // Clear input
}
/**
* Clear filters
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function clearFilters (dt) {
var ctx = dt.settings()[0];
ctx._pfFilter.filters.length = 0; // Reset filters
ctx._pfFilter.activeFilterControls.html(""); // Remove active filter controls
ctx._pfFilter.activeFilters.addClass("hidden"); // Hide active filters area
dt.draw();
}
/**
* Handle actions when clear filters control is selected
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function handleClearFilters (dt) {
var ctx = dt.settings()[0];
if (ctx._pfFilter.clearFilters === undefined || ctx._pfFilter.clearFilters.length === 0) {
return;
}
ctx._pfFilter.clearFilters.on("click", function (e) {
clearFilters(dt);
});
}
/**
* Handle actions when enter is pressed within filter input
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function handleFilterInput (dt) {
var ctx = dt.settings()[0];
if (ctx._pfFilter.filterInput === undefined || ctx._pfFilter.filterInput.length === 0) {
return;
}
ctx._pfFilter.filterInput.on("keypress", function (e) {
var keycode = (e.keyCode ? e.keyCode : e.which);
if (keycode === 13) {
e.preventDefault();
if (this.value.trim().length > 0) {
addFilter(dt, {
column: ctx._pfFilter.filterColumn,
name: ctx._pfFilter.filterName,
value: this.value
});
}
return false;
}
return true;
});
}
/**
* Handle actions when filter options are selected
*
* @param {DataTable.Api} dt DataTable
* @param {number} i The column associated with this handler
* @private
*/
function handleFilterOption (dt, i) {
var ctx = dt.settings()[0];
if (ctx._pfFilter.filterCols[i] === null || ctx._pfFilter.filterCols[i].optionSelector === undefined) {
return;
}
$(ctx._pfFilter.filterCols[i].optionSelector).on("click", function (e) {
// Set input placeholder
if (ctx._pfFilter.filterInput !== undefined && ctx._pfFilter.filterInput.length !== 0) {
ctx._pfFilter.filterInput.get(0).placeholder = ctx._pfFilter.filterCols[i].placeholder;
}
// Set filter label
if (ctx._pfFilter.filterLabel !== undefined && ctx._pfFilter.filterLabel.length !== 0) {
ctx._pfFilter.filterLabel.html($(this).text());
}
// Set filter button
if (ctx._pfFilter.filterButton !== undefined && ctx._pfFilter.filterButton.length !== 0) {
ctx._pfFilter.filterButton.html($(this).text() + ' <span class="caret"></span>');
}
ctx._pfFilter.filterColumn = i; // Save filter column when applying filter
ctx._pfFilter.filterName = $(this).text(); // Save filter name for active filter control
});
}
/**
* Update active filter results
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateFilterResults (dt) {
var ctx = dt.settings()[0];
var filteredRows = dt.rows({"page": "current", "search": "applied"}).flatten().length;
if (ctx._pfFilter.filterResults === undefined || ctx._pfFilter.filterResults.length === 0) {
return;
}
ctx._pfFilter.filterResults.html(filteredRows + " Results");
}
// DataTables API
/**
* Add filter
*
* Example: dt.table().pfFilter.addFilter({
* column: 2,
* name: "Browser",
* value: "Firefox"
* });
*
* @param {object} filter Properties associated with a new filter
* @param {string} filter.column - Column associated with DataTable
* @param {string} filter.name - Name of the filter
* @param {string} filter.value - Value of the filter
*/
DataTable.Api.register("pfFilter.addFilter()", function (filter) {
return this.iterator("table", function (ctx) {
addFilter(new DataTable.Api(ctx), filter);
});
});
/**
* Clear filters
*
* Example: dt.table().pfFilter.clearFilters();
*
*/
DataTable.Api.register("pfFilter.clearFilters()", function () {
return this.iterator("table", function (ctx) {
clearFilters(new DataTable.Api(ctx));
});
});
// DataTables creation
$(document).on("init.dt", function (e, ctx, json) {
if (e.namespace !== "dt") {
return;
}
DataTable.pfFilter.init(new DataTable.Api(ctx));
});
return DataTable.pfFilter;
}));

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,401 @@
/**
* @summary pfPagination for DataTables
* @description A collection of API methods providing functionality to paginate DataTables data. This ensures
* DataTables meets the Patternfly design pattern while maintaining accessibility.
*
* The pagination layout is expected to contain the classes as shown in the example below.
*
* Example:
*
* <!-- NOTE: Some configuration may be omitted for clarity -->
* <table class="table table-striped table-bordered table-hover" id="table1">
* <thead>
* <tr>
* <th><input type="checkbox" name="selectAll"></th>
* <th>Rendering Engine</th>
* <th>Browser</th>
* </tr>
* </thead>
* </table>
* <form class="content-view-pf-pagination table-view-pf-pagination clearfix" id="pagination1">
* <div class="form-group">
* <select class="selectpicker pagination-pf-pagesize">
* <option value="6">6</option>
* <option value="10">10</option>
* <option value="15" selected="selected">15</option>
* <option value="25">25</option>
* <option value="50">50</option>
* </select>
* <span>per page</span>
* </div>
* <div class="form-group">
* <span><span class="pagination-pf-items-current">1-15</span> of <span class="pagination-pf-items-total">75</span></span>
* <ul class="pagination pagination-pf-back">
* <li><a href="#" onclick="return false;" title="First Page"><span class="i fa fa-angle-double-left"></span></a></li>
* <li><a href="#" onclick="return false;" title="Previous Page"><span class="i fa fa-angle-left"></span></a></li>
* </ul>
* <label for="pagination1-page" class="sr-only">Current Page</label>
* <input class="pagination-pf-page" type="text" value="1" id="pagination1-page"/>
* <span>of <span class="pagination-pf-pages">5</span></span>
* <ul class="pagination pagination-pf-forward">
* <li><a href="#" onclick="return false;" title="Next Page"><span class="i fa fa-angle-right"></span></a></li>
* <li><a href="#" onclick="return false;" title="Last Page"><span class="i fa fa-angle-double-right"></span></a></li>
* </ul>
* </div>
* </form>
* <script>
* // NOTE: Some properties may be omitted for clarity
* $(document).ready(function() {
* var dt = $("#table1").DataTable({
* columns: [
* { data: null, ... },
* { data: "engine" },
* { data: "browser" }
* ],
* data: null,
* dom: "t",
* pfConfig: {
* ...
* pageSize: 15,
* paginationSelector: "#pagination1",
* }
* });
* dt.table().pfPagination.next(); // Optional API to navigate to the next page
* dt.table().pfPagination.previous(); // Optional API to navigate to the previous page
* });
* </script>
*/
(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 BACK_ACTIONS_SELECTOR = ".pagination-pf-back"; // Back navigation actions
var CURRENT_ITEMS_SELECTOR = ".pagination-pf-items-current"; // Current items text (e.g., 1-15)
var CURRENT_PAGE_SELECTOR = ".pagination-pf-page"; // Current page input
var FIRST_PAGE_SELECTOR = ".pagination-pf-back .fa-angle-double-left"; // First page button
var FORWARD_ACTIONS_SELECTOR = ".pagination-pf-forward"; // Forward navigation actions
var LAST_PAGE_SELECTOR = ".pagination-pf-forward .fa-angle-double-right"; // Last page button
var PAGE_SIZE_SELECTOR = "select.pagination-pf-pagesize"; // Page size selection
var TOTAL_ITEMS_SELECTOR = ".pagination-pf-items-total"; // Total items
var TOTAL_PAGES_SELECTOR = ".pagination-pf-pages"; // Total pages text
var PREVIOUS_PAGE_SELECTOR = ".pagination-pf-back .fa-angle-left"; // Previous page button
var NEXT_PAGE_SELECTOR = ".pagination-pf-forward .fa-angle-right"; // Next page button
DataTable.pfPagination = {};
/**
* Initialize
*
* @param {DataTable.Api} dt DataTable
* @private
*/
DataTable.pfPagination.init = function (dt) {
var ctx = dt.settings()[0];
var opts = (ctx.oInit.pfConfig) ? ctx.oInit.pfConfig : {};
ctx._pfPagination = {};
ctx._pfPagination.backActions = $(BACK_ACTIONS_SELECTOR, opts.paginationSelector); // Back navigation actions
ctx._pfPagination.currentItems = $(CURRENT_ITEMS_SELECTOR, opts.paginationSelector); // Current items
ctx._pfPagination.currentPage = $(CURRENT_PAGE_SELECTOR, opts.paginationSelector); // Current page
ctx._pfPagination.firstPage = $(FIRST_PAGE_SELECTOR, opts.paginationSelector); // First page button
ctx._pfPagination.forwardActions = $(FORWARD_ACTIONS_SELECTOR, opts.paginationSelector); // Forward navigation actions
ctx._pfPagination.lastPage = $(LAST_PAGE_SELECTOR, opts.paginationSelector); // Last page button
ctx._pfPagination.nextPage = $(NEXT_PAGE_SELECTOR, opts.paginationSelector); // Next page button
ctx._pfPagination.pageSize = $(PAGE_SIZE_SELECTOR, opts.paginationSelector); // Page size selection
ctx._pfPagination.previousPage = $(PREVIOUS_PAGE_SELECTOR, opts.paginationSelector); // Next page button
ctx._pfPagination.totalItems = $(TOTAL_ITEMS_SELECTOR, opts.paginationSelector); // Total items
ctx._pfPagination.totalPages = $(TOTAL_PAGES_SELECTOR, opts.paginationSelector); // Total pages
// Set initial page size
ctx._pfPagination.currentPageSize = (opts.pageSize !== undefined) ? opts.pageSize : 15;
// Handle page navigation
handleCurrentPage(dt);
handleFirstPage(dt);
handleLastPage(dt);
handlePageSize(dt);
handleNextPage(dt);
handlePreviousPage(dt);
// Update table on DataTables draw event
dt.on("draw.page", function () {
updateCurrentPage(dt);
updateCurrentItems(dt);
updateTotalItems(dt);
updateTotalPages(dt);
updateBackActions(dt);
updateForwardActions(dt);
});
// Initialize page info
dt.table().page.len(ctx._pfPagination.currentPageSize);
dt.table().draw('page');
};
// Local functions
/**
* Handle page navigation when enter is pressed
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function handleCurrentPage (dt) {
var ctx = dt.settings()[0];
if (ctx._pfPagination.currentPage === undefined || ctx._pfPagination.currentPage.length === 0) {
return;
}
ctx._pfPagination.currentPage.on("keypress", function (e) {
var page, pageInfo = dt.table().page.info();
var keycode = (e.keyCode ? e.keyCode : e.which);
if (keycode === 13) {
e.preventDefault();
page = parseInt(this.value) - 1;
if (page >= 0 && page < pageInfo.pages) {
dt.table().page(page).draw('page');
} else {
updateCurrentPage(dt); // Always update to replace bad values
}
return false;
}
return true;
});
}
/**
* Handle page navigation when first button is selected
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function handleFirstPage (dt) {
var ctx = dt.settings()[0];
if (ctx._pfPagination.firstPage === undefined || ctx._pfPagination.firstPage.length === 0) {
return;
}
$(ctx._pfPagination.firstPage).closest('li').on("click", function (e) {
dt.table().page('first').draw('page');
});
}
/**
* Handle page navigation when last button is selected
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function handleLastPage (dt) {
var ctx = dt.settings()[0];
if (ctx._pfPagination.lastPage === undefined || ctx._pfPagination.lastPage.length === 0) {
return;
}
$(ctx._pfPagination.lastPage).closest('li').on("click", function (e) {
dt.table().page('last').draw('page');
});
}
/**
* Handle page navigation when next button is selected
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function handleNextPage (dt) {
var ctx = dt.settings()[0];
if (ctx._pfPagination.nextPage === undefined || ctx._pfPagination.nextPage.length === 0) {
return;
}
$(ctx._pfPagination.nextPage).closest('a').on("click", function (e) {
dt.table().page('next').draw('page');
});
}
/**
* Handle page size when selected
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function handlePageSize (dt) {
var ctx = dt.settings()[0];
if (ctx._pfPagination.pageSize === undefined || ctx._pfPagination.pageSize.length === 0) {
return;
}
ctx._pfPagination.pageSize.on("change", function (e) {
ctx._pfPagination.currentPageSize = parseInt(this.value);
dt.table().page.len(ctx._pfPagination.currentPageSize).draw('page');
});
}
/**
* Handle page navigation when previous button is selected
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function handlePreviousPage (dt) {
var ctx = dt.settings()[0];
if (ctx._pfPagination.previousPage === undefined || ctx._pfPagination.previousPage.length === 0) {
return;
}
$(ctx._pfPagination.previousPage).closest('a').on("click", function (e) {
dt.table().page('previous').draw('page');
});
}
/**
* Update current page
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateCurrentPage (dt) {
var ctx = dt.settings()[0];
var pageInfo = dt.table().page.info();
var page = (pageInfo.recordsDisplay === 0) ? 0 : pageInfo.page + 1;
if (ctx._pfPagination.currentPage === undefined || ctx._pfPagination.currentPage.length === 0) {
return;
}
// Disable if pagination is not available due to filtering
if (pageInfo.recordsDisplay > pageInfo.length) {
$(ctx._pfPagination.currentPage).prop("disabled", false);
} else {
$(ctx._pfPagination.currentPage).prop("disabled", true);
}
// Set current page value
$(ctx._pfPagination.currentPage).val(page);
}
/**
* Update back navigation actions
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateBackActions (dt) {
var ctx = dt.settings()[0];
var pageInfo = dt.table().page.info();
if (pageInfo.page === 0) {
$("li", ctx._pfPagination.backActions).each(function () {
$(this).addClass("disabled");
});
} else {
$("li", ctx._pfPagination.backActions).each(function () {
$(this).removeClass("disabled");
});
}
}
/**
* Update current items
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateCurrentItems (dt) {
var ctx = dt.settings()[0];
var pageInfo = dt.table().page.info();
var start = (pageInfo.recordsDisplay === 0) ? 0 : pageInfo.start + 1;
ctx._pfPagination.currentItems.html(start + "-" + pageInfo.end);
}
/**
* Update forward navigation actions
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateForwardActions (dt) {
var ctx = dt.settings()[0];
var pageInfo = dt.table().page.info();
if (pageInfo.recordsDisplay === 0 || pageInfo.page === pageInfo.pages - 1) {
$("li", ctx._pfPagination.forwardActions).each(function () {
$(this).addClass("disabled");
});
} else {
$("li", ctx._pfPagination.forwardActions).each(function () {
$(this).removeClass("disabled");
});
}
}
/**
* Update total items
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateTotalItems (dt) {
var ctx = dt.settings()[0];
var pageInfo = dt.table().page.info();
ctx._pfPagination.totalItems.html(pageInfo.recordsDisplay);
}
/**
* Update total pages
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateTotalPages (dt) {
var ctx = dt.settings()[0];
var pageInfo = dt.table().page.info();
ctx._pfPagination.totalPages.html(pageInfo.pages);
}
// DataTables API
/**
* Navigate to next page
*
* Example: dt.table().pfPagination.next();
*/
DataTable.Api.register("pfPagination.next()", function () {
return this.iterator("table", function (ctx) {
handleNextPage(new DataTable.Api(ctx));
});
});
/**
* Navigate to previous page
*
* Example: dt.table().pfPagination.previous();
*/
DataTable.Api.register("pfPagination.previous()", function () {
return this.iterator("table", function (ctx) {
handlePreviousPage(new DataTable.Api(ctx));
});
});
// DataTables creation
$(document).on("init.dt", function (e, ctx, json) {
if (e.namespace !== "dt") {
return;
}
DataTable.pfPagination.init(new DataTable.Api(ctx));
});
return DataTable.pfPagination;
}));

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,214 @@
/**
* @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:
*
* <!-- NOTE: Some configuration may be omitted for clarity -->
* ...
* <table class="table table-striped table-bordered table-hover" id="table1">
* <thead>
* <tr>
* <th><input type="checkbox" name="selectAll"></th>
* <th>Rendering Engine</th>
* <th>Browser</th>
* <th colspan="2">Actions</th>
* </tr>
* </thead>
* </table>
* ...
* <script>
* // NOTE: Some properties may be omitted for clarity
* $(document).ready(function() {
* var dt = $("#table1").DataTable({
* columns: [
* { data: null, ... },
* { data: "engine" },
* { data: "browser" }
* { data: null,
* className: "table-view-pf-actions",
* render: function (data, type, full, meta) {
* // Inline action button renderer
* return '<div class="table-view-pf-btn"><button class="btn btn-default" type="button">Actions</button></div>';
* }
* }, {
* data: null,
* className: "table-view-pf-actions",
* render: function (data, type, full, meta) {
* // Inline action kebab renderer
* return '<div class="dropdown dropdown-kebab-pf">' +
* '<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">' +
* '<span class="fa fa-ellipsis-v"></span></button>' +
* '<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownKebabRight">' +
* '<li><a href="#">Action</a></li>' +
* '<li><a href="#">Another action</a></li>' +
* '<li><a href="#">Something else here</a></li>' +
* '<li role="separator" class="divider"></li>' +
* '<li><a href="#">Separated link</a></li></ul></div>';
* }
* }
* ],
* data: [
* { engine: "Gecko", browser: "Firefox" }
* { engine: "Trident", browser: "Mozilla" }
* ],
* dom: "t",
* pfConfig: {
* ...
* }
* });
* dt.table().pfResize.resize(); // Optional API to force resize
* });
* </script>
*
* 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;
}));

View File

@ -0,0 +1 @@
!function(factory){"use strict";"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function($){return factory($,window,document)}):"object"==typeof exports?module.exports=function(root,$){return root||(root=window),$&&$.fn.dataTable||($=require("datatables.net")(root,$).$),factory($,root,root.document)}:factory(jQuery,window,document)}(function($,window,document,undefined){"use strict";function isIE(){return/(MSIE|Trident\/|Edge\/)/i.test(window.navigator.userAgent)}function resetTableCells(dt,actions){actions!==undefined&&0!==actions.length&&$(actions).each(function(index,el){$(el).css({height:"auto"})})}function resize(dt){var actions=$(BUTTON_ACTIONS_SELECTOR+", "+KEBAB_ACTIONS_SELECTOR,dt.table().container());resetTableCells(dt,actions),resizeInlineActions(dt,actions)}function resizeInlineActions(dt,actions){actions!==undefined&&0!==actions.length&&$(actions).each(function(index,el){var parent=$(el).parent("td");parent!==undefined&&0!==parent.length&&$(el).css({height:parent[0].clientHeight})})}var DataTable=$.fn.dataTable,BUTTON_ACTIONS_SELECTOR="td.table-view-pf-actions .table-view-pf-btn",KEBAB_ACTIONS_SELECTOR="td.table-view-pf-actions .dropdown";return DataTable.pfResize={},DataTable.pfResize.init=function(dt){dt.settings()[0]._pfResize={},isIE()&&($(window).on("resize",function(){resize(dt)}),resize(dt))},DataTable.Api.register("pfResize.resize()",function(){return this.iterator("table",function(ctx){resize(new DataTable.Api(ctx))})}),$(document).on("init.dt",function(e,ctx,json){"dt"===e.namespace&&DataTable.pfResize.init(new DataTable.Api(ctx))}),DataTable.pfResize});

View File

@ -0,0 +1,281 @@
/**
* @summary pfSelect for DataTables
* @description A collection of API methods providing individual row selection and select all functionality in
* DataTables using traditional HTML checkboxes. This ensures DataTables meets the Patternfly design pattern while
* maintaining accessibility.
*
* The following selection styles are supported for user interaction with DataTables:
*
* api - Selection can only be performed via the API
* multi - Multiple items can be selected
* multi+shift - a hybrid between the os style and multi
* os - Operating system style selection with complex behaviors such as ctrl/cmd, shift and an unmodified click
* single - Only a single item can be selected
*
* For details see: https://datatables.net/reference/option/select.style
*
* Note that when a selection is made, the selection results text is also updated in the toolbar. The toolbar layouts is
* expected to contain the classes as shown in the example below. Selection checkboxes are also expected to be located
* in the first column.
*
* Example:
*
* <!-- NOTE: Some configuration may be omitted for clarity -->
* <div class="row toolbar-pf table-view-pf-toolbar" id="toolbar1">
* <div class="col-sm-12">
* ...
* <div class="row toolbar-pf-results">
* <div class="col-sm-9">
* ...
* </div>
* <div class="col-sm-3 table-view-pf-select-results">
* <strong>0</strong> of <strong>0</strong> selected
* </div>
* </div>
* </div>
* </div>
* <table class="table table-striped table-bordered table-hover" id="table1">
* <thead>
* <tr>
* <th><input type="checkbox" name="selectAll"></th>
* <th>Rendering Engine</th>
* <th>Browser</th>
* </tr>
* </thead>
* </table>
* ...
* <script>
* // NOTE: Some properties may be omitted for clarity
* $(document).ready(function() {
* var dt = $("#table1").DataTable({
* columns: [
* { data: null,
* className: "table-view-pf-select",
* render: function (data, type, full, meta) {
* return '<input type="checkbox" name="select">';
* },
* sortable: false
* },
* { data: "engine" },
* { data: "browser" }
* ],
* data: [
* { engine: "Gecko", browser: "Firefox" }
* { engine: "Trident", browser: "Mozilla" }
* ],
* dom: "t",
* order: [[ 1, "asc" ]],
* pfConfig: {
* ...
* toolbarSelector: "#toolbar1",
* selectAllSelector: 'th:first-child input[type="checkbox"]'
* }
* select: {
* selector: 'td:first-child input[type="checkbox"]',
* style: "multi"
* }
* });
* dt.table().pfSelect.selectAllRows(true); // Optional API to select all rows
* });
* </script>
*
* 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 RESULTS_SELECTOR = ".table-view-pf-select-results"; // Toolbar selection results
var SELECT_ALL_SELECTOR = 'th:first-child input[type="checkbox"]'; // Default checkbox for selecting all rows
var SELECT_SELECTOR = 'td:first-child input[type="checkbox"]'; // Default checkboxes for row selection
DataTable.pfSelect = {};
/**
* Initialize
*
* @param {DataTable.Api} dt DataTable
* @private
*/
DataTable.pfSelect.init = function (dt) {
var ctx = dt.settings()[0];
var opts = (ctx.oInit.pfConfig) ? ctx.oInit.pfConfig : {};
var select = (ctx.oInit.select) ? ctx.oInit.select : {};
var style = dt.select.style();
ctx._pfSelect = {};
ctx._pfSelect.selectAllSelector = (opts.selectAllSelector !== undefined)
? opts.selectAllSelector : SELECT_ALL_SELECTOR; // Select all checkbox
ctx._pfSelect.selector = (select.selector !== undefined)
? select.selector : SELECT_SELECTOR; // Select checkbox
ctx._pfSelect.results = $(RESULTS_SELECTOR, opts.toolbarSelector); // Toolbar selection results
if (style === "api") {
// Select all checkbox
$(dt.table().container()).on("click", ctx._pfSelect.selectAllSelector, function (evt) {
evt.preventDefault();
});
// Select checkboxes
$(dt.table().container()).on("click", ctx._pfSelect.selector, function (evt) {
evt.preventDefault();
});
dt.table().on("select.dt", function () {
syncSelectCheckboxes(dt);
});
} else {
// Select all checkbox
$(dt.table().container()).on("click", ctx._pfSelect.selectAllSelector, function (evt) {
selectAllRows(dt, evt.target.checked);
});
// Select checkboxes
$(dt.table().container()).on("click", ctx._pfSelect.selector, function (evt) {
if (style !== "multi" || style !== "multi+shift") {
syncSelectCheckboxes(dt); // No need to sync checkbox selections when "multi" is used
} else {
syncSelectAllCheckbox(dt); // Still need to sync select all checkbox
}
});
}
// Sync checkbox selections when paging and filtering is applied
dt.table().on("draw.dt", function () {
syncSelectCheckboxes(dt);
});
// Initialize selected rows text
updateSelectedRowsText(dt);
};
// Local functions
/**
* Select all rows on current page
*
* @param {DataTable.Api} dt DataTable
* @param {boolean} select True to select all rows on current page, defaults to false
* @private
*/
function selectAllRows (dt, select) {
var ctx = dt.settings()[0];
// Retrieve all rows taking into account currently applied filter
var filteredRows = dt.rows({"page": "current", "search": "applied"});
// Check if style is single
if (dt.select.style() === "single") {
throw new Error("Cannot select all rows with selection style 'single'");
}
// Select rows
if (select) {
filteredRows.select();
} else {
filteredRows.deselect();
}
$(ctx._pfSelect.selector, dt.table().container()).prop("checked", select); // De/select checkboxes in view
syncSelectAllCheckbox(dt);
}
/**
* Sync select all checkbox with row selections on current page
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function syncSelectAllCheckbox (dt) {
var ctx = dt.settings()[0];
// Retrieve all rows taking into account currently applied filter
var filteredRows = dt.rows({"page": "current", "search": "applied"}).flatten().length;
var selectedFilteredRows = dt.rows({"page": "current", "search": "applied", "selected": true}).flatten().length;
// De/select the select all checkbox
var selectAll = $(ctx._pfSelect.selectAllSelector, dt.table().container())[0];
if (selectAll) {
selectAll.checked = (filteredRows !== 0 && filteredRows === selectedFilteredRows);
}
updateSelectedRowsText(dt);
}
/**
* Sync select checkboxes with row selections on current page
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function syncSelectCheckboxes (dt) {
var ctx = dt.settings()[0];
$(ctx._pfSelect.selector, dt.table().container()).prop("checked", false); // Deselect all checkboxes
dt.rows({"page": "current", "search": "applied", "selected": true}).every(function (index) {
$(ctx._pfSelect.selector, dt.table().row(index).node()).prop("checked", true); // Select checkbox for selected row
});
syncSelectAllCheckbox(dt);
}
/**
* Update selection results text
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateSelectedRowsText (dt) {
var ctx = dt.settings()[0];
var selectedRows = dt.rows({"selected": true}).flatten().length;
var totalRows = dt.rows().flatten().length;
if (ctx._pfSelect.results !== undefined && ctx._pfSelect.results.length !== 0) {
$(ctx._pfSelect.results).html("<strong>" + selectedRows + "</strong> of <strong>" +
totalRows + "</strong> selected");
}
}
// DataTables API
/**
* Select all rows on current page
*
* Example: dt.table().pfSelect.selectAllRows(true);
*
* @param {boolean} select True to select all rows on current page, defaults to false
*/
DataTable.Api.register("pfSelect.selectAllRows()", function (select) {
return this.iterator("table", function (ctx) {
selectAllRows(new DataTable.Api(ctx), select);
});
});
// DataTables creation
$(document).on("preInit.dt.dtSelect", function (e, ctx) {
if (e.namespace !== "dt") {
return;
}
DataTable.pfSelect.init(new DataTable.Api(ctx));
});
return DataTable.pfSelect;
}));

View File

@ -0,0 +1 @@
!function(factory){"use strict";"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function($){return factory($,window,document)}):"object"==typeof exports?module.exports=function(root,$){return root||(root=window),$&&$.fn.dataTable||($=require("datatables.net")(root,$).$),factory($,root,root.document)}:factory(jQuery,window,document)}(function($,window,document,undefined){"use strict";function selectAllRows(dt,select){var ctx=dt.settings()[0],filteredRows=dt.rows({page:"current",search:"applied"});if("single"===dt.select.style())throw new Error("Cannot select all rows with selection style 'single'");select?filteredRows.select():filteredRows.deselect(),$(ctx._pfSelect.selector,dt.table().container()).prop("checked",select),syncSelectAllCheckbox(dt)}function syncSelectAllCheckbox(dt){var ctx=dt.settings()[0],filteredRows=dt.rows({page:"current",search:"applied"}).flatten().length,selectedFilteredRows=dt.rows({page:"current",search:"applied",selected:!0}).flatten().length,selectAll=$(ctx._pfSelect.selectAllSelector,dt.table().container())[0];selectAll&&(selectAll.checked=0!==filteredRows&&filteredRows===selectedFilteredRows),updateSelectedRowsText(dt)}function syncSelectCheckboxes(dt){var ctx=dt.settings()[0];$(ctx._pfSelect.selector,dt.table().container()).prop("checked",!1),dt.rows({page:"current",search:"applied",selected:!0}).every(function(index){$(ctx._pfSelect.selector,dt.table().row(index).node()).prop("checked",!0)}),syncSelectAllCheckbox(dt)}function updateSelectedRowsText(dt){var ctx=dt.settings()[0],selectedRows=dt.rows({selected:!0}).flatten().length,totalRows=dt.rows().flatten().length;ctx._pfSelect.results!==undefined&&0!==ctx._pfSelect.results.length&&$(ctx._pfSelect.results).html("<strong>"+selectedRows+"</strong> of <strong>"+totalRows+"</strong> selected")}var DataTable=$.fn.dataTable;return DataTable.pfSelect={},DataTable.pfSelect.init=function(dt){var ctx=dt.settings()[0],opts=ctx.oInit.pfConfig?ctx.oInit.pfConfig:{},select=ctx.oInit.select?ctx.oInit.select:{},style=dt.select.style();ctx._pfSelect={},ctx._pfSelect.selectAllSelector=opts.selectAllSelector!==undefined?opts.selectAllSelector:'th:first-child input[type="checkbox"]',ctx._pfSelect.selector=select.selector!==undefined?select.selector:'td:first-child input[type="checkbox"]',ctx._pfSelect.results=$(".table-view-pf-select-results",opts.toolbarSelector),"api"===style?($(dt.table().container()).on("click",ctx._pfSelect.selectAllSelector,function(evt){evt.preventDefault()}),$(dt.table().container()).on("click",ctx._pfSelect.selector,function(evt){evt.preventDefault()}),dt.table().on("select.dt",function(){syncSelectCheckboxes(dt)})):($(dt.table().container()).on("click",ctx._pfSelect.selectAllSelector,function(evt){selectAllRows(dt,evt.target.checked)}),$(dt.table().container()).on("click",ctx._pfSelect.selector,function(evt){"multi"!==style||"multi+shift"!==style?syncSelectCheckboxes(dt):syncSelectAllCheckbox(dt)})),dt.table().on("draw.dt",function(){syncSelectCheckboxes(dt)}),updateSelectedRowsText(dt)},DataTable.Api.register("pfSelect.selectAllRows()",function(select){return this.iterator("table",function(ctx){selectAllRows(new DataTable.Api(ctx),select)})}),$(document).on("preInit.dt.dtSelect",function(e,ctx){"dt"===e.namespace&&DataTable.pfSelect.init(new DataTable.Api(ctx))}),DataTable.pfSelect});

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long