Skip to content

messages

Mike Byrne edited this page Jan 25, 2022 · 2 revisions

description

Growl like messages

requires

  • CSS to style messages

parameters

  • target - optional - target node for appending message, otherwise appends to body

returns

  • nothing

set up

messages(); // (inset in your application JS on DOM ready)

example usage

  • 1 - "Logged in message"
triggerCustomEvent(document,"message",{
  message: "Logged In"
});
// inserts
// <div class="message s-hide"><span>Logged In</span></div>
  • 1 - Show a message for a longer time
triggerCustomEvent(document,"message",{
  message: "Logged In",
  time: 5000 // time defined in ms
});
// inserts
// <div class="message s-hide"><span>Logged In</span></div>
  • 3 - custom type, "error message"
triggerCustomEvent(document,"message",{
  message: "Could not add to favorites",
  type: "error"
});
// inserts
// <div class="message message--error s-hide"><span>Could not add to favorites</span></div>

Includes a helper class of "message--TYPE"

  • 4 - on load message
<body>
  <div id="a17" data-message-target data-message="On load message">
  • 4 - on load message, with type
<body>
  <div id="a17" data-message-target data-message="On load message" data-message-type="error">

required CSS

Styling and positioning of message, alternative types and hiding of the message with message--hide.

Eg:

.message {
  position: fixed;
  right: 20px;
  top: 20px;
  max-width: 100%;
  pointer-events: none;
  transition: top .25s linear;
}
.message.s-hide {
  top: -50px;
}
.message span {
  display: inline-block;
  padding: 5px 8px;
  background-color: #000;
  font-size: 12px;
  line-height: 20px;
  color: #fff;
}

breakdown of process

On message event trigger, markup is inserted with hide class. Hide class is removed to reveal the message. After 3 seconds, hide class is added to hide message and then 250ms later the message is removed from the DOM.