jquery-announce
Version:
A micro-plugin for displaying unobtrusive announcements.
2 lines (1 loc) • 2.3 kB
JavaScript
/*jQuery.announce - A micro-plugin for displaying unobtrusive announcements. Developed by Cory LaViska for A Beautiful Site, LLC, 2017. Extended by Philp Mayer <philip.mayer@shadowisth.de>, 2019. Licensed under the MIT license: http://opensource.org/licenses/MIT*/ jQuery&&function(e){"use strict";function n(n,o){let t,s=e.Deferred(),r=e("<div>");if("string"==typeof o&&(o={message:o}),o=e.extend({},e.announce.defaults,o),e("."+o.className).remove(),e(r).addClass(o.className+" "+o.className+"-"+n).hide(),o.hideOnClick&&e(r).on("click.announce",function(){clearTimeout(t),o.hide.call(r).then(s.resolve)}),o.html?e(r).html(o.message):e(r).text(o.message),e("body").append(r),"top"!=o.vPos)switch(o.vPos){case"bottom":e(r).addClass("announce-bottom");break;case"center":e(r).addClass("announce-center")}else e(r).css("top",0);if("center"!=o.hPos)switch(o.hPos){case"left":e(r).css("left",0);break;case"right":e(r).css({left:`calc(100% - ${e(r).width()}px)`})}if(o.customColors){let n=e(r).prop("class");n=n.split(" ")[1].split("-")[1],e(r).css("background-color",o.colors[n]),(o.colors.text===o.colors.dark||o.outline)&&"light"!==n&&"warning"!==n||e(r).css("color",o.colors.text)}return o.outline&&(e(r).css("color",e(r).css("background-color")),e(r).css("background-color",o.outlineColor),e(r).addClass("announce-border")),o.show.call(r),t=setTimeout(function(){o.hide.call(r).then(s.resolve)},o.duration),s}e.announce={defaults:{className:"announce",duration:2e3,hideOnClick:!0,html:!1,customColors:!1,outline:!1,outlineColor:"transparent",vPos:"top",hPos:"center",show:function(){let n=e.Deferred();return e(this).fadeIn(250,function(){n.resolve()}),n},hide:function(){let n=e.Deferred();return e(this).fadeOut(250,function(){e(this).remove(),n.resolve()}),n},colors:{info:"#17a2b8",danger:"#dc3545",warning:"#ffc107",success:"#28a745",primary:"#007bff",secondary:"#6c757d",light:"#f8f9fa",text:"#343a40",dark:"#343a40"}},info:function(e){return n("info",e)},danger:function(e){return n("danger",e)},success:function(e){return n("success",e)},warning:function(e){return n("warning",e)},primary:function(e){return n("primary",e)},secondary:function(e){return n("secondary",e)},light:function(e){return n("light",e)},dark:function(e){return n("dark",e)},say:function(e,o){return n(e,o)}}}(jQuery);