(function(window) { 'use strict'; /* -------------------- Infopanel -------------------- */ function Infopanel(options) { this.options = extend({}, this.options); extend(this.options, options); this._init(); } Infopanel.prototype.options = { position: 'top' }; Infopanel.prototype._init = function() { this.position = this.options.position; this.wrapper = $('
').prependTo('body'); this.panels = {}; }; Infopanel.prototype.add = function(options) { var id = this.getUniqueID(); var params = options; params['infopanel'] = this; params['id'] = 'info-' + id; this.panels[id] = new InfoItem(params); }; Infopanel.prototype.getUniqueID = function() { return new Date().valueOf() + '_' + Math.floor((Math.random() + 1) * 2000).toString(); }; window.Infopanel = Infopanel; /* -------------------- InfoItem -------------------- */ function InfoItem(options) { this.options = extend({}, this.options); extend(this.options, options); this._init(); this._initEvents(); } InfoItem.prototype.options = { bgcolor: 'primary', title: '', content: '', contentsize: 'md', hideafter: 0 }; InfoItem.prototype._init = function() { var $this = this; this.infopanel = this.options.infopanel; this.id = this.options.id; this.bgcolor = this.options.bgcolor; this.title = this.options.title; this.content = this.options.content; this.buttons = this.options.buttons; this.contentsize = this.options.contentsize; this.hideafter = this.options.hideafter; this.wrapper = $('
'); this.container = $('
').appendTo(this.wrapper); this.text = $('' + this.content + '').appendTo(this.container); if (this.title != '') $('
' + this.title + '
').prependTo(this.text); this.btns = $('').appendTo(this.container); this.itembuttons = {}; if (typeof this.buttons != 'undefined') for (var i=0; i').prependTo(this.wrapper); this.text.css('max-width', 'calc(100% - ' + Math.round(this.btns.width() + this.closebtn.width()) + 'px)'); this.show(); if (this.hideafter > 0) this.hideTo = setTimeout(function() { $this.hide(); }, this.hideafter); }; InfoItem.prototype._initEvents = function() { var $this = this; this.closebtn.click(function(e){ e.stopPropagation(); $this.hide(); }) }; InfoItem.prototype.show = function() { this.wrapper.addClass('show'); }; InfoItem.prototype.hide = function() { this.wrapper.removeClass('show'); }; window.InfoItem = InfoItem; /* -------------------- InfoItemButton -------------------- */ function InfoItemButton(options) { this.options = extend({}, this.options); extend(this.options, options); this._init(); this._initEvents(); } InfoItemButton.prototype._init = function() { this.item = this.options.item; this.label = (this.options.label != null) ? this.options.label : '[label]'; this.color = (this.options.color != null) ? this.options.color : 'white'; this.size = (this.options.size != null) ? this.options.size : 'md'; this.action = (this.options.action != null) ? this.options.action : function() {console.log('Aucune action n\'a été définie pour ce bouton.');}; this.link = (typeof this.options.action == 'string') ? this.options.action : 'javascript:;'; this.button = $('' + this.label + '') .appendTo(this.item.btns); }; InfoItemButton.prototype._initEvents = function() { var $this = this; this.button.click(function(e){ e.stopPropagation(); if (typeof $this.action == 'function') $this.action(); }) }; window.InfoItemButton = InfoItemButton; })(window);