123

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 ng-app="demoApp" class="cont">
  <div ng-controller="FlashDemoCtrl">
    <h3>Click on any button</h3>
    <a class="link" target="_blank" href="https://github.com/sachinchoolur/angular-flash">View on Github</a>
    <br/>
    <button class="btn btn-success" ng-click="success()">Success</button>
    <button class="btn btn-info" ng-click="info()">Info</button>
    <button class="btn btn-warning" ng-click="warning()">Warning</button>
    <button class="btn btn-danger" ng-click="danger()">Danger</button>
    <flash-message duration="5000"></flash-message>
  </div>
</div>
            
          
!
            
              /*! angular-flash - v2.2.5 - 2016-03-17
* https://github.com/sachinchoolur/angular-flash
* Copyright (c) 2016 Sachin; Licensed MIT */

.alert {
  padding: 15px;
  margin-bottom: 20px;
  border: 1px solid transparent;
  border-radius: 4px;
}
.alert h4 {
  margin-top: 0;
  color: inherit;
}
.alert .alert-link {
  font-weight: bold;
}
.alert > p,
.alert > ul {
  margin-bottom: 0;
}
.alert > p + p {
  margin-top: 5px;
}
.alert-dismissable,
.alert-dismissible {
  padding-right: 35px;
}
.alert-dismissable .close,
.alert-dismissible .close {
  position: relative;
  top: -2px;
  right: -21px;
  color: inherit;
}
.alert-success {
  color: #3c763d;
  background-color: #dff0d8;
  border-color: #d6e9c6;
}
.alert-success hr {
  border-top-color: #c9e2b3;
}
.alert-success .alert-link {
  color: #2b542c;
}
.alert-info {
  color: #31708f;
  background-color: #d9edf7;
  border-color: #bce8f1;
}
.alert-info hr {
  border-top-color: #a6e1ec;
}
.alert-info .alert-link {
  color: #245269;
}
.alert-warning {
  color: #8a6d3b;
  background-color: #fcf8e3;
  border-color: #faebcc;
}
.alert-warning hr {
  border-top-color: #f7e1b5;
}
.alert-warning .alert-link {
  color: #66512c;
}
.alert-danger {
  color: #a94442;
  background-color: #f2dede;
  border-color: #ebccd1;
}
.alert-danger hr {
  border-top-color: #e4b9c0;
}
.alert-danger .alert-link {
  color: #843534;
}

.close {
  float: right;
  font-size: 21px;
  font-weight: bold;
  line-height: 1;
  color: #000;
  text-shadow: 0 1px 0 #fff;
  filter: alpha(opacity=20);
  opacity: .2;
}
.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
  filter: alpha(opacity=50);
  opacity: .5;
}

div.close {
  -webkit-appearance: none;
  padding: 0;
  cursor: pointer;
  background: transparent;
  border: 0;
    font-size: 1.7em;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.alert.ng-leave {
    opacity: 1;
    transition: opacity 1.5s ease-out;
}

.alert.ng-leave-active {
    opacity: 0;
}
            
          
!
            
              // Demo controller
var app = angular.module('demoApp', ['ngFlash', 'ngAnimate']);
app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$timeout', function($rootScope, $scope, Flash, $timeout) {
  $scope.success = function() {
    var message = '<strong>Well done!</strong> You successfully read this important alert message.';
    Flash.create('success', message);
  };
  $scope.info = function() {
    var message = '<strong>Heads up!</strong> This alert needs your attention, but it\'s not super important.';
    Flash.create('info', message);
  };
  $scope.warning = function() {
    var message = '<strong>Warning!</strong> Better check yourself, you\'re not looking too good.';
    Flash.create('warning', message);
  };
  $scope.danger = function() {
    var message = '<strong>Oh snap!</strong> Change a few things up and try submitting again.';
    Flash.create('danger', message);
  };
}]);

(function() {
/*! angular-flash - v2.2.5 - 2016-03-17
 * https://github.com/sachinchoolur/angular-flash
 * Copyright (c) 2016 Sachin; Licensed MIT */

'use strict';

var app = angular.module('ngFlash', []);

app.run(['$rootScope', function ($rootScope) {
    return $rootScope.flashes = [];
}]);

app.directive('dynamic', ['$compile', function ($compile) {
    return {
        restrict: 'A',
        replace: true,
        link: function link(scope, ele, attrs) {
            return scope.$watch(attrs.dynamic, function (html) {
                ele.html(html);
                return $compile(ele.contents())(scope);
            });
        }
    };
}]);

app.directive('closeFlash', ['$compile', '$rootScope', 'Flash', function ($compile, $rootScope, Flash) {
    return {
        link: function link(scope, ele, attrs) {
            return ele.on('click', function () {
                var id = parseInt(attrs.closeFlash, 10);
                Flash.dismiss(id);
                $rootScope.$apply();
            });
        }
    };
}]);

app.directive('flashMessage', ['Flash', function (Flash) {
    return {
        restrict: 'E',
        scope: {
            duration: '=',
            showClose: '=',
            onDismiss: '&'
        },
        template: '<div role="alert" ng-repeat="flash in $root.flashes track by $index" id="{{flash.config.id}}" class="alert {{flash.config.class}} alert-{{flash.type}} alert-dismissible alertIn alertOut"><div type="button" class="close" ng-show="flash.showClose" close-flash="{{flash.id}}"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></div> <span dynamic="flash.text"></span> </div>',
        link: function link(scope, ele, attrs) {
            Flash.setDefaultTimeout(scope.duration);
            Flash.setShowClose(scope.showClose);
            function onDismiss(flash) {
                if (typeof scope.onDismiss !== 'function') return;
                scope.onDismiss({ flash: flash });
            }

            Flash.setOnDismiss(onDismiss);
        }
    };
}]);

app.factory('Flash', ['$rootScope', '$timeout', function ($rootScope, $timeout) {
    var dataFactory = {};
    var counter = 0;
    dataFactory.setDefaultTimeout = function (timeout) {
        if (typeof timeout !== 'number') return;
        dataFactory.defaultTimeout = timeout;
    };

    dataFactory.defaultShowClose = true;
    dataFactory.setShowClose = function (value) {
        if (typeof value !== 'boolean') return;
        dataFactory.defaultShowClose = value;
    };
    dataFactory.setOnDismiss = function (callback) {
        if (typeof callback !== 'function') return;
        dataFactory.onDismiss = callback;
    };
    dataFactory.create = function (type, text, timeout, config, showClose) {
        var $this = undefined,
            flash = undefined;
        $this = this;
        flash = {
            type: type,
            text: text,
            config: config,
            id: counter++
        };
        flash.showClose = typeof showClose !== 'undefined' ? showClose : dataFactory.defaultShowClose;
        if (dataFactory.defaultTimeout && typeof timeout === 'undefined') {
            flash.timeout = dataFactory.defaultTimeout;
        } else if (timeout) {
            flash.timeout = timeout;
        }
        $rootScope.flashes.push(flash);
        if (flash.timeout) {
            flash.timeoutObj = $timeout(function () {
                $this.dismiss(flash.id);
            }, flash.timeout);
        }
        return flash.id;
    };
    dataFactory.pause = function (index) {
        if ($rootScope.flashes[index].timeoutObj) {
            $timeout.cancel($rootScope.flashes[index].timeoutObj);
        }
    };
    dataFactory.dismiss = function (id) {
        var index = findIndexById(id);
        if (index !== -1) {
            var flash = $rootScope.flashes[index];
            dataFactory.pause(index);
            $rootScope.flashes.splice(index, 1);
            $rootScope.$digest();
            if (typeof dataFactory.onDismiss === 'function') {
                dataFactory.onDismiss(flash);
            }
        }
    };
    dataFactory.clear = function () {
        while ($rootScope.flashes.length > 0) {
            dataFactory.dismiss($rootScope.flashes[0].id);
        }
    };
    dataFactory.reset = dataFactory.clear;
    function findIndexById(id) {
        return $rootScope.flashes.map(function(flash) {
            return flash.id;
        }).indexOf(id);
    }

    return dataFactory;
}]);
})()
            
          
!
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