Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container">

  <h1>Alert! Alert!</h1>

  <!-- Begin badges -->
  <a href="http://badge.fury.io/js/alert-alert"><img src="https://camo.githubusercontent.com/3ef8ee1e585c74788f7635e709df9f22bd542ac7/68747470733a2f2f62616467652e667572792e696f2f6a732f616c6572742d616c6572742e737667" alt="npm version" data-canonical-src="https://badge.fury.io/js/alert-alert.svg" style="max-width:100%;" target="_blank"></a>
  
  <a href="https://travis-ci.org/whusterj/alert-alert"><img src="https://camo.githubusercontent.com/09b6db625c0577729524417dad368ca3538a645f/68747470733a2f2f7472617669732d63692e6f72672f776875737465726a2f616c6572742d616c6572742e7376673f6272616e63683d6d6173746572" alt="Build Status" data-canonical-src="https://travis-ci.org/whusterj/alert-alert.svg?branch=master" style="max-width:100%;" target="_blank"></a>
  <!-- End badges -->
  
  <p>A simple JavaScript library for generating growl-style notifications.
     No framework necessary.</p>

  <div>
    <button id="genAlertBtn">Generic Alert</button>
    <button id="infoAlertBtn">Info Alert</button>
    <button id="successAlertBtn">Success Alert</button>
    <button id="warnAlertBtn">Warning Alert</button>
    <button id="errorAlertBtn">Error Alert</button>
  </div>

  <h2>Sample Usage</h2>
  
  <p>Trigger new alerts with this simple API</p>
  
  <pre><code class="javascript">var type = 'info',
    message = '&lt;p&gt;Something you outta know!&lt;/p&gt;',
    config = { timeout: 7000 };
  
Alert.alert(type,message, config);</code></pre>
  
  <p>Alert options include: 'info', 'success', 'warning', and 'error', which are
     color-coded to match their respective status.</p>
  
</div>

<a href="https://github.com/whusterj/alert-alert" target="_blank">
  <img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
</a>
            
          
!
            
              /**
 * Demo page styles
 */
@import url(https://fonts.googleapis.com/css?family=Abril+Fatface);
@import url(https://fonts.googleapis.com/css?family=Signika);

body {
  font-family: Signika, Arial, Helvetica, sans-serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.40;
  background: rgb(234, 234, 242);
}

h1 {
  font-size: 50px;
}

h2 {
  font-size: 37px;
}

button {
  pointer: cursor;
  padding: 8px;
  border-radius: 6px;
}

.container {
  max-width: 600px;
  margin: 0 auto;
}

/**
 * Alert! Alert! styles
 */
/* variables */
@aa-blue       :  rgb(100, 100, 200);
@aa-green      :  rgb(100, 180, 100);
@aa-yellow     :  rgb(230, 215, 100);
@aa-red        :  rgb(230, 100, 100);
@aa-gray       :  rgb(100, 100, 100);
@aa-darkGray   :  rgb( 60,  60,  60);

@aa-dropShadow :  rgba(0, 0, 0, 0.6);

@aa-zIndex : 1001;

/* styles */

#aa-notificationContainer {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: @aa-zIndex;
}

.aa-notification {
  width: 300px;
  min-height: 40px;
  padding: 12px;
  margin-bottom: 12px;
  background-color: white;
  border-left: 4px solid @aa-gray;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 1px 1px 3px @aa-dropShadow;
  transition: 0.3s linear all;
  
  &:hover {
    transform: scale(1.06);
    box-shadow: 3px 3px 4px @aa-dropShadow;
  }
  
  &.info {
    border-left-color: @aa-blue;
  }
  
  &.success {
    border-left-color: @aa-green;
  }
  
  &.warning {
    border-left-color: @aa-yellow;
  }
  
  &.error {
    border-left-color: @aa-red;
  }
}
            
          
!
            
              /// Library (usage example at bottom) ///

/**
 * Alert! Alert! is a minimalist JavaScript growl-style notification library
 * designed to run in modern browsers without external dependencies.
 *
 * @author  William Huster  <whusterj@gmail.com>
 * @version 1.0.2
 *
 * Usage:
 *
 *     var type    = 'info',
 *         message = '<p>Something you outta know!</p>',
 *         config  = { timeout: 7000 };
 *
 *     Alert.alert(type, message [, config]);
 *
 * @param type: type of alert - 'info', 'success', 'warning', or 'error'
 * @param message: string/html to display in notification
 * @param config: currently only supports 'timeout' - how long to wait before
 *                dismissing the notification.
 */

var Alert = (function () {
  
  var container,
      CONTAINER_ID  = 'aa-notificationContainer',
      ALERT_CLASS   = 'aa-notification',
      INFO_CLASS    = 'info',
      SUCCESS_CLASS = 'success',
      WARNING_CLASS = 'warning',
      ERROR_CLASS   = 'error';
  
  exports = {
    alert: alert
  };
  
  return exports;
  
  /// functions ///
  
  function alert (type, message, config) {
    if (typeof(config) === 'undefined') { config = {}; }
    if (!container) { container = genNotificationContainer(); }
    container.appendChild(
      genAlertDiv(type, message, config.timeout)
    );
  }
  
  function genNotificationContainer () {
    if (container) { return; }
    var containerDiv = document.createElement('div');
    containerDiv.id = CONTAINER_ID;
    document.body.appendChild(containerDiv);
    return containerDiv;
  }
  
  function genAlertDiv (type, message, timeout) {
    var alertDiv = document.createElement('div');
    alertDiv.className = ALERT_CLASS + ' ' + type;
    alertDiv.innerHTML = message;
    
    //
    alertDiv.addEventListener('click', alertClickHandler);

    //
    if (timeout) {
      alertDiv.timeout = setTimeout(
        function () {
          removeAlert(alertDiv);
        }, timeout); 
    }
    
    return alertDiv;
  }
  
  function removeAlert (alert) {
    window.clearTimeout(alert.timeout);
    container.removeChild(alert);
  }
  
  function alertClickHandler (event) {
    removeAlert(event.currentTarget);
  }
  
})();


/// Usage Example ///

var genAlertBtn     = document.getElementById('genAlertBtn'),
    infoAlertBtn    = document.getElementById('infoAlertBtn'),
    successAlertBtn = document.getElementById('successAlertBtn'),
    warnAlertBtn    = document.getElementById('warnAlertBtn'),
    errorAlertBtn   = document.getElementById('errorAlertBtn');

genAlertBtn.addEventListener('click', newAlert);
infoAlertBtn.addEventListener('click', infoAlert);
successAlertBtn.addEventListener('click', successAlert);
warnAlertBtn.addEventListener('click', warnAlert);
errorAlertBtn.addEventListener('click', errorAlert);

function newAlert (type, message, timeout) {
  var type = type || 'info',
      message = message || 'No message given',
      config = {
        timeout: timeout || 7000
      };
  
  // AND HERE'S THE MAGIC:
  Alert.alert(type, message, config);
}

function infoAlert () {
  newAlert('info', '<p>Here\'s some vital info!</p>');
}

function successAlert () {
  newAlert('success', '<p>Waaah! Great success!</p>');
}

function warnAlert () {
  newAlert('warning', '<p>Ah, ah, ah. I wouldn\'t do that!</p>');
}

function errorAlert () {
  newAlert('error', '<p>Woah! Oh noes! Something broke!</p>');
}

// Syntax highlighting for demo
hljs.initHighlightingOnLoad();

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console