if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript requires jQuery') } + (function($) { $.widget("psc.blogcomment", { options: { apictrlr: null, omob: '#ffe08030', omof: '#501208', bgc: '#fff', fgc: '#000', lang: 'fr-FR' }, editable: false, editting: false, edctrl: null, _create: function() { var _this = this; this.element.addClass("blogcomment"); var date = new Date(this.element.data("date")); var username = this.element.data("username"); this.editable = this.element.data("allow-edit"); this.element.prepend('
' + username + '
' + date.toLocaleDateString(this.options.lang) + ' ' + date.toLocaleTimeString(this.options.lang) + '
') this.element.on("mouseenter", this.onMouseEnter); this.element.on("mouseleave", this.onMouseLeave); if (this.editable) { this.element.on("click", function(ev) { _this.toggleEdit(_this, ev) }) } }, toggleEdit: function(_this, ev) { if (!_this.edctrl) { // TODO click on button _this.edctrl = $(""); _this.edctrl.on("click", function(ev) { _this.doDeleteComment(_this, ev) }).appendTo(_this.element); } else { _this.edctrl.remove(); _this.edctrl = null; } }, onMouseEnter: function() { $(this).animate({ backgroundColor: $.psc.blogcomment.prototype.options.omob, color: $.psc.blogcomment.prototype.options.omof }, 400); }, onMouseLeave: function() { $(this).animate({ backgroundColor: $.psc.blogcomment.prototype.options.bgc, color: $.psc.blogcomment.prototype.options.fgc }, 400); }, doDeleteComment: function(_this, ev) { var cmtid = $(_this.element).data("id"); var cmtapi = _this.options.apictrlr; $.ajax({ async: true, cache: false, type: 'POST', method: 'DELETE', error: function(xhr, data) { $('span.field-validation-valid[data-valmsg-for="Content"]').html( "Une erreur est survenue : " + xhr.status + "
" ).focus() }, success: function(data) { _this.element.remove() }, url: cmtapi + '/' + cmtid }); } }); $(document).ready(function() { $("[data-type='blogcomment']").blogcomment(); }) })(jQuery);