Current section
Files
Jump to
Current section
Files
web/static/vendor/active_admin/lib/popover.js.js
// Generated by CoffeeScript 1.10.0
(function() {
ActiveAdmin.Popover = (function() {
function Popover(options1, element) {
var defaults;
this.options = options1;
this.element = element;
this.$element = $(this.element);
defaults = {
fadeInDuration: 20,
fadeOutDuration: 100,
autoOpen: true,
pageWrapperElement: "#wrapper",
onClickActionItemCallback: null
};
this.options = $.extend(defaults, options);
this.isOpen = false;
if (!(this.$popover = $(this.$element.attr('href'))).length) {
this.$popover = this.$element.next('.popover');
}
this._buildPopover();
this._bind();
}
Popover.prototype.open = function() {
this.isOpen = true;
this.$popover.fadeIn(this.options.fadeInDuration);
this._positionPopover();
this._positionNipple();
return this;
};
Popover.prototype.close = function() {
this.isOpen = false;
this.$popover.fadeOut(this.options.fadeOutDuration);
return this;
};
Popover.prototype.destroy = function() {
this.$element.removeData('popover');
this.$element.unbind();
this.$element = null;
return this;
};
Popover.prototype._buildPopover = function() {
this.$nipple = $('<div class="popover_nipple"></div>');
this.$popover.prepend(this.$nipple);
this.$popover.hide();
return this.$popover.addClass('popover');
};
Popover.prototype._bind = function() {
$(this.options.pageWrapperElement).click((function(_this) {
return function() {
if (_this.isOpen) {
return _this.close();
}
};
})(this));
if (this.options.autoOpen) {
return this.$element.click((function(_this) {
return function(e) {
e.stopPropagation();
if (_this.isOpen) {
return _this.close();
} else {
return _this.open();
}
};
})(this));
}
};
Popover.prototype._positionPopover = function() {
var button_center, popover_center;
button_center = this.$element.offset().left + this.$element.outerWidth() / 2;
popover_center = this.$popover.outerWidth() / 2;
return this.$popover.css('left', button_center - popover_center);
};
Popover.prototype._positionNipple = function() {
this.$popover.css('top', this.$element.offset().top + this.$element.outerHeight() + 10);
return this.$nipple.css('left', this.$popover.outerWidth() / 2 - this.$nipple.outerWidth() / 2);
};
return Popover;
})();
$.widget.bridge('popover', ActiveAdmin.Popover);
}).call(this);