define('jira/ajs/shorten/shortener', [ 'jira/util/formatter', 'jira/ajs/control', 'jira/data/local-storage', 'jquery', 'jira/featureflags/feature-manager' ], function( formatter, Control, localStorage, jQuery, featureManager ) { /** * Shorten long lists with an ellipsis * *
*
*
*
*
* require(["jira/ajs/shorten/shortener"], function(Shortener) {
* // no options
* new Shortener("#mylist");
*
* // with options
* new Shortener({
* element: "#myList",
* numRows: 2
* });
* });
*
*
* @class Shortener
* @extends Control
*
*/
return Control.extend({
_getDefaultOptions: function () {
return {
items: "a, span",
numRows: 1,
shortenText: "hide",
shortenOnInit: true,
persist: true,
expandButtonTooltip: formatter.I18n.getText("viewissue.shorten.view.more"),
collapseButtonTooltip: formatter.I18n.getText("viewissue.shorten.hide")
};
},
/**
* Creates a shorten control
*
* @constructs
* @param {Object} options
* @param {String |jQuery} [options.items=a,span] - selector or jQuery collection specifying items
* @param {Number} [options.numRows=1] - Number of rows to display when shortened
* @param {String} [options.shortenText=hide] - Text to display in link at the end of the list when expanded
* @param {Boolean} [options.shortenOnInit=true] - If true will shorten onload
*/
init: function (options) {
if (typeof options === "string") {
options = {element: options};
}
options = options || {};
this.options = jQuery.extend(this._getDefaultOptions(), options);
this._timerId = 0;
this.expanded = false;
this.$container = jQuery(this.options.element);
if (featureManager.isFeatureEnabled("gdpr-690-fix-spurious-ellipses")) {
this._cleanupOldButtons();
this.$container.css("height", "auto");
}
this._assignEvents("body", document.body);
this._ready();
},
/**
* Validate initialization
* @return {Boolean}
*/
_isValid: function () {
return !this.initialized && this.$container.is(":visible") && this.$container.children().length > 0;
},
/**
* Remove any spurious collapse/expand button elements
* @private
*/
_cleanupOldButtons: function() {
this.$container.find("a.ellipsis.shortener-expand").remove();
this.$container.find("a.shortener-collapse").remove();
this.$container.find("br.shortener-expand-line-break").remove();
},
/**
* Lazy initialization, so that we can init on dom ready if it is visible or when a activating a tab makes it visible
* @private
*/
_ready: function () {
if (this._isValid()) {
this.$items = this.$container.children(this.options.items);
this.$expandButton = this._render("expandButton");
this.$collapseButton = this._render("collapseButton");
this._assignEvents("expand-button", ".shortener-expand");
this._assignEvents("collapse-button", ".shortener-collapse");
if (!jQuery.browser.msie || jQuery.browser.version >= "9") {
// IE8 is excluded from reflowing on "resize" events. Rendering this thing
// is very expensive in IE8 and "resize" events occur too frequently.
this._assignEvents("resize-region", window);
}
if (this._isCollapsedOnInit()) {
this.collapse();
} else {
this.expand();
}
this.initialized = true;
}
},
_renders: {
/**
* Creates the jQuery object representing an ellipsis. The ellipsis appended to the shortened list of items. It
* contains text representing how many items have been hidden. When clicked it reveals the full list.
* The ellipsis has a class of ellipsis and styling should be controlled in css.
*
* @method #_renders.expandButton
* @private
* @param {number} itemsHidden - number of items hidden
* @return {jQuery} jQuery wrapped HTML element
*
*/
"expandButton": function () {
return jQuery("").attr("title", this.options.expandButtonTooltip).add("