From 42b886c247010cf7a5f9b543745c1e838c95543e Mon Sep 17 00:00:00 2001 From: pvincent Date: Mon, 29 Jan 2024 02:24:26 +0400 Subject: [PATCH] both toaster --- app/views/layouts/_notification.html.erb | 25 ++++++++++++++++++++---- app/views/layouts/application.html.erb | 2 ++ config/importmap.rb | 1 + vendor/javascript/toastify-js.js | 9 +++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 vendor/javascript/toastify-js.js diff --git a/app/views/layouts/_notification.html.erb b/app/views/layouts/_notification.html.erb index 8abe7ca..80feae8 100644 --- a/app/views/layouts/_notification.html.erb +++ b/app/views/layouts/_notification.html.erb @@ -1,10 +1,27 @@

NOTIFICATION BAR

-<% if flash %> +<% if flash.count.positive? %> <%end%> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e44d233..58c7c1a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,6 +6,8 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> + + <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <%= javascript_importmap_tags %> diff --git a/config/importmap.rb b/config/importmap.rb index b607570..a04618f 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -7,3 +7,4 @@ pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js' pin_all_from 'app/javascript/controllers', under: 'controllers' pin 'notyf' # @3.10.0 +pin 'toastify-js' # @1.12.0 diff --git a/vendor/javascript/toastify-js.js b/vendor/javascript/toastify-js.js new file mode 100644 index 0000000..5cd086b --- /dev/null +++ b/vendor/javascript/toastify-js.js @@ -0,0 +1,9 @@ +var t="undefined"!==typeof globalThis?globalThis:"undefined"!==typeof self?self:global;var o={}; +/*! + * Toastify js 1.12.0 + * https://github.com/apvarun/toastify-js + * @license MIT licensed + * + * Copyright (C) 2018 Varun A P + */(function(t,i){o?o=i():t.Toastify=i()})(o,(function(o){var Toastify=function(t){return new Toastify.lib.init(t)},i="1.12.0";Toastify.defaults={oldestFirst:true,text:"Toastify is awesome!",node:void 0,duration:3e3,selector:void 0,callback:function(){},destination:void 0,newWindow:false,close:false,gravity:"toastify-top",positionLeft:false,position:"",backgroundColor:"",avatar:"",className:"",stopOnFocus:true,onClick:function(){},offset:{x:0,y:0},escapeMarkup:true,ariaLive:"polite",style:{background:""}};Toastify.lib=Toastify.prototype={toastify:i,constructor:Toastify,init:function(o){o||(o={});(this||t).options={};(this||t).toastElement=null;(this||t).options.text=o.text||Toastify.defaults.text;(this||t).options.node=o.node||Toastify.defaults.node;(this||t).options.duration=0===o.duration?0:o.duration||Toastify.defaults.duration;(this||t).options.selector=o.selector||Toastify.defaults.selector;(this||t).options.callback=o.callback||Toastify.defaults.callback;(this||t).options.destination=o.destination||Toastify.defaults.destination;(this||t).options.newWindow=o.newWindow||Toastify.defaults.newWindow;(this||t).options.close=o.close||Toastify.defaults.close;(this||t).options.gravity="bottom"===o.gravity?"toastify-bottom":Toastify.defaults.gravity;(this||t).options.positionLeft=o.positionLeft||Toastify.defaults.positionLeft;(this||t).options.position=o.position||Toastify.defaults.position;(this||t).options.backgroundColor=o.backgroundColor||Toastify.defaults.backgroundColor;(this||t).options.avatar=o.avatar||Toastify.defaults.avatar;(this||t).options.className=o.className||Toastify.defaults.className;(this||t).options.stopOnFocus=void 0===o.stopOnFocus?Toastify.defaults.stopOnFocus:o.stopOnFocus;(this||t).options.onClick=o.onClick||Toastify.defaults.onClick;(this||t).options.offset=o.offset||Toastify.defaults.offset;(this||t).options.escapeMarkup=void 0!==o.escapeMarkup?o.escapeMarkup:Toastify.defaults.escapeMarkup;(this||t).options.ariaLive=o.ariaLive||Toastify.defaults.ariaLive;(this||t).options.style=o.style||Toastify.defaults.style;o.backgroundColor&&((this||t).options.style.background=o.backgroundColor);return this||t},buildToast:function(){if(!(this||t).options)throw"Toastify is not initialized";var o=document.createElement("div");o.className="toastify on "+(this||t).options.className;if(!(this||t).options.position)if(true===(this||t).options.positionLeft){o.className+=" toastify-left";console.warn("Property `positionLeft` will be depreciated in further versions. Please use `position` instead.")}else o.className+=" toastify-right";else o.className+=" toastify-"+(this||t).options.position;o.className+=" "+(this||t).options.gravity;(this||t).options.backgroundColor&&console.warn('DEPRECATION NOTICE: "backgroundColor" is being deprecated. Please use the "style.background" property.');for(var i in(this||t).options.style)o.style[i]=(this||t).options.style[i];(this||t).options.ariaLive&&o.setAttribute("aria-live",(this||t).options.ariaLive);if((this||t).options.node&&(this||t).options.node.nodeType===Node.ELEMENT_NODE)o.appendChild((this||t).options.node);else{(this||t).options.escapeMarkup?o.innerText=(this||t).options.text:o.innerHTML=(this||t).options.text;if(""!==(this||t).options.avatar){var e=document.createElement("img");e.src=(this||t).options.avatar;e.className="toastify-avatar";"left"==(this||t).options.position||true===(this||t).options.positionLeft?o.appendChild(e):o.insertAdjacentElement("afterbegin",e)}}if(true===(this||t).options.close){var s=document.createElement("button");s.type="button";s.setAttribute("aria-label","Close");s.className="toast-close";s.innerHTML="✖";s.addEventListener("click",function(o){o.stopPropagation();this.removeElement((this||t).toastElement);window.clearTimeout((this||t).toastElement.timeOutValue)}.bind(this||t));var n=window.innerWidth>0?window.innerWidth:screen.width;("left"==(this||t).options.position||true===(this||t).options.positionLeft)&&n>360?o.insertAdjacentElement("afterbegin",s):o.appendChild(s)}if((this||t).options.stopOnFocus&&(this||t).options.duration>0){var a=this||t;o.addEventListener("mouseover",(function(t){window.clearTimeout(o.timeOutValue)}));o.addEventListener("mouseleave",(function(){o.timeOutValue=window.setTimeout((function(){a.removeElement(o)}),a.options.duration)}))}"undefined"!==typeof(this||t).options.destination&&o.addEventListener("click",function(o){o.stopPropagation();true===(this||t).options.newWindow?window.open((this||t).options.destination,"_blank"):window.location=(this||t).options.destination}.bind(this||t));"function"===typeof(this||t).options.onClick&&"undefined"===typeof(this||t).options.destination&&o.addEventListener("click",function(o){o.stopPropagation();(this||t).options.onClick()}.bind(this||t));if("object"===typeof(this||t).options.offset){var l=getAxisOffsetAValue("x",(this||t).options);var r=getAxisOffsetAValue("y",(this||t).options);var p="left"==(this||t).options.position?l:"-"+l;var d="toastify-top"==(this||t).options.gravity?r:"-"+r;o.style.transform="translate("+p+","+d+")"}return o},showToast:function(){(this||t).toastElement=this.buildToast();var o;o="string"===typeof(this||t).options.selector?document.getElementById((this||t).options.selector):(this||t).options.selector instanceof HTMLElement||"undefined"!==typeof ShadowRoot&&(this||t).options.selector instanceof ShadowRoot?(this||t).options.selector:document.body;if(!o)throw"Root element is not defined";var i=Toastify.defaults.oldestFirst?o.firstChild:o.lastChild;o.insertBefore((this||t).toastElement,i);Toastify.reposition();(this||t).options.duration>0&&((this||t).toastElement.timeOutValue=window.setTimeout(function(){this.removeElement((this||t).toastElement)}.bind(this||t),(this||t).options.duration));return this||t},hideToast:function(){(this||t).toastElement.timeOutValue&&clearTimeout((this||t).toastElement.timeOutValue);this.removeElement((this||t).toastElement)},removeElement:function(o){o.className=o.className.replace(" on","");window.setTimeout(function(){(this||t).options.node&&(this||t).options.node.parentNode&&(this||t).options.node.parentNode.removeChild((this||t).options.node);o.parentNode&&o.parentNode.removeChild(o);(this||t).options.callback.call(o);Toastify.reposition()}.bind(this||t),400)}};Toastify.reposition=function(){var o={top:15,bottom:15};var i={top:15,bottom:15};var e={top:15,bottom:15};var s=document.getElementsByClassName("toastify");var n;for(var a=0;a0?window.innerWidth:screen.width;if(p<=360){s[a].style[n]=e[n]+"px";e[n]+=l+r}else if(true===containsClass(s[a],"toastify-left")){s[a].style[n]=o[n]+"px";o[n]+=l+r}else{s[a].style[n]=i[n]+"px";i[n]+=l+r}}return this||t};function getAxisOffsetAValue(t,o){return o.offset[t]?isNaN(o.offset[t])?o.offset[t]:o.offset[t]+"px":"0px"}function containsClass(t,o){return!(!t||"string"!==typeof o)&&!!(t.className&&t.className.trim().split(/\s+/gi).indexOf(o)>-1)}Toastify.lib.init.prototype=Toastify.lib;return Toastify}));var i=o;export{i as default}; +