67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
(function ($) {
|
|
var ScenarioDetailsGrid = function (element, options) {
|
|
this.init(element, options);
|
|
};
|
|
|
|
ScenarioDetailsGrid.prototype = {
|
|
constructor: ScenarioDetailsGrid,
|
|
init: function (element, options) {
|
|
var plugin = this;
|
|
this.$container = $(element).find('table').parent();
|
|
|
|
this.$settings = $.extend({
|
|
// These are the defaults.
|
|
className: "clpsd" //collapsed CSS class name which will be assigned to the column
|
|
}, options);
|
|
|
|
var anchor = this.$container.find('table thead tr th a.clpsd-btn');
|
|
anchor.parent().css('cursor', 'pointer').on('click', $.proxy(this.toggle, this));
|
|
},
|
|
toggle: function () {
|
|
var className = this.$settings.className;
|
|
if (this.$container.hasClass(className)) {
|
|
this.$container.removeClass(className);
|
|
} else {
|
|
this.$container.addClass(className);
|
|
}
|
|
},
|
|
showSidebar: function (visible) {
|
|
var className = this.$settings.className;
|
|
|
|
if (visible && this.$container.hasClass(className)) {
|
|
this.$container.removeClass(className);
|
|
}
|
|
|
|
if (!visible && !this.$container.hasClass(className)) {
|
|
this.$container.addClass(className);
|
|
}
|
|
},
|
|
destroy: function () {
|
|
var e = $.Event('destroy');
|
|
this.$container.trigger(e);
|
|
|
|
if (e.isDefaultPrevented()) return;
|
|
this.$container.removeData('scenarioDetailsGrid');
|
|
},
|
|
};
|
|
|
|
/* SCENARIO DETAILS GRID PLUGIN DEFINITION
|
|
* ======================= */
|
|
|
|
$.fn.scenarioDetailsGrid = function (option, args) {
|
|
return this.each(function () {
|
|
var $this = $(this),
|
|
data = $this.data('scenarioDetailsGrid'),
|
|
options = $.extend({}, $.fn.scenarioDetailsGrid.defaults, $this.data(), typeof option == 'object' && option);
|
|
|
|
if (!data) $this.data('scenarioDetailsGrid', (data = new ScenarioDetailsGrid(this, options)));
|
|
if (typeof option == 'string')
|
|
data[option].apply(data, [].concat(args));
|
|
});
|
|
};
|
|
$.fn.scenarioDetailsGrid.defaults = {
|
|
className: "clpsd" //collapsed CSS class name which will be assigned to the column
|
|
};
|
|
|
|
$.fn.scenarioDetailsGrid.Constructor = ScenarioDetailsGrid;
|
|
}(jQuery)); |