Giter VIP home page Giter VIP logo

ng-notify's Introduction

ng-notify (live demo) Build Status Code Climate

A simple, lightweight module for displaying notifications in your AngularJS app.

ngNotify Demo

Both JS and CSS files combine for ~5.5 kBs.

IE9+ (AngularJS v1.3.x no longer supports IE8) and the latest versions of Chrome, FireFox and Safari have been tested and are supported. If you do run across any issues, please submit a new issue and I'll take a look - or better yet - submit a PR with the bug fix and I'll merge it in.

You can check out the vitals and demo here: http://matowens.github.io/ng-notify

Newest Additions

With v0.8.0 comes a couple new features. The first, being able to target a specific container for your notification to display in - for a more modular style display. To do so, simply specify a target option with the value set to a CSS selector string when you set a message or setup the initial configuration. More on that below. In addition, you are now able to provide a callback that will fire after fadeout and the notification has been removed from view. This callback can be added as an optional third parameter when calling the set() method. More on that here. With these changes comes a refactor that uses notification instances which will assist with future development as we look to introduce new features like stacked notifications and upgrade for use with Angular 2.

Implementation

Requirements

AngularJS is the only dependency. Animation is achieved with pure JS, jQuery not necessary.

Installation

You can install ng-notify with Bower.

bower install ng-notify --save

You can also install ng-notify with npm.

npm install ng-notify --save

As of v0.6.0, ng-notify is now available via the jsDelivr CDN if you'd prefer to go down that route.

//cdn.jsdelivr.net/angular.ng-notify/{version.number.here}/ng-notify.min.js
//cdn.jsdelivr.net/angular.ng-notify/{version.number.here}/ng-notify.min.css

For example:

//cdn.jsdelivr.net/angular.ng-notify/0.6.0/ng-notify.min.js
//cdn.jsdelivr.net/angular.ng-notify/0.6.0/ng-notify.min.css

And as always, you can download the source files straight from this repo - they're located in the dist dir. Be sure to include the minified version of both js and css files.

Usage

After including ng-notify.min.js and ng-notify.min.css, inject the ng-notify provider into your project.

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

Now you can trigger notifications from anywhere in your app. To display a notification, just use the set method.

ngNotify.set('Your notification message goes here!');

To specify the type of notification to display, provide the optional type param. (For available types, check the definitions below.)

ngNotify.set('Your error message goes here!', 'error');

Advanced Usage

Default Configuration

You can override the default options for all notifications by using the config method. None of these options are required. (For available options, check the definitions below.)

ngNotify.config({
    theme: 'pure',
    position: 'bottom',
    duration: 3000,
    type: 'info',
    sticky: false,
    button: true,
    html: false
});

Default configuration options can be set during the run() block. If your app utilizes a global controller, the config options could be set there just as well. For a discussion and working example on this topic, checkout this comment.

Individual Configurations

You can also pass an object of options to individual notifications. You can pass through any combination of our available options here as well. (For available options, check the definitions below.) For example:

ngNotify.set('Your first message.', {
    position: 'top',
    sticky: true
});

ngNotify.set('Your second message.', {
    type: 'error',
    duration: 2000
});

ngNotify.set('Your third message.', 'error'); // Original use case still works, too.

ngNotify.set('Your <i>fourth</i> message.', {
    theme: 'pitchy',
    html: true
});

Sticky Notifications

Sticky notifications allow you to set a persistent notification that doesn't fade away. To do this, simply set the sticky attribute to true:

ngNotify.set('This is sticky.', {
    sticky: true
});

This will give the user the option of closing the notification themselves. If you need to dismiss a notification manually, you can do so with the dismiss method like this:

ngNotify.dismiss();

If you'd prefer to dismiss the notification programmatically and prevent the user from doing so, you can add an option to remove the button:

ngNotify.set('This is sticky without a button.', {
    sticky: true,
    button: false
});

Any time a notification is set to sticky, the duration attribute will be ignored since the notification will not be automatically fading out.

HTML Notifications

HTML notifications will allow you to display messages with HTML content in them. To do this, you'll need to set the html attribute to true:

ngNotify.set('This has <b>HTML</b> content!', {
    html: true
});

You can also set HTML notifications to be enabled for all of your notifications by adding it the ngNotify config like so:

ngNotify.config({
    html: true
});

In order for HTML notifications to display, you are required to include the ngSanitize script in your app (eg, via Google CDN, Bower, or code.angular.org). There's no need to add it as a dependency to ngNotify. If ngNotify has found the ngSanitize script, it will add it as a dependency to the ngNotify module dynamically. Once included, you just need to toggle the html attribute to true and the module will handle the rest.

If you don't have ngSanitize included and you do set html to true, ngNotify will gracefully degrade back to the default message display and print a debug message to remind you in your browser's console.

Modular Notifications

By specifying a target option, you are able to control where your notifications are displayed. By default, the target is set to the body tag but you may provide any other CSS selector in order to control where the notification is appended. For example:

ngNotify.set('This message has a specific container!', {
    target: '#new-container'
});

You may also specific a default target for all notifications by adding it to the ngNotify config, for example:

ngNotify.config({
    target: '#new-container'
});

** Notifications that have a custom target specified are set to display with absolute positioning, overriding the default fixed positioning. It's impossible to tailor ngNotify's style to fit every situation for every app, so you may have to tweak the styles to fit your specific needs when not appending notifications to the body tag - using anything other than the default target.

Notification Callbacks

You have an option to call a function when a notification has completed. This callback can only be called through the set() method and is passed as an optional third parameter. For example:

var callback = function() {};

ngNotify.set('This message has a callback.', {}, callback);

The callback will fire every time it is specified, even if the notification is dismissed early through the dismiss method. The callback fires once the notification has faded out.

Roll Your Own

There are two additional methods that allow you to create your own types and themes.

Custom Notification Types

Creating a custom type will allow you to add additional types of notifications to use throughout your application. To create a new type, use the addType method. The first param is the name you'll use to reference your new type. The second param is the class you'll use to style your new notification type.

ngNotify.addType('notice', 'my-notice-type');

Then you can set any of your notifications up to use that type as you would any other, triggering it by using the name you gave it.

ngNotify.set('This notification is using our new type!', 'notice');

To style your new type, pick a color you'd like to use and set it to the background color of your new style.

.my-notice-type
    background-color: #ABC123
Custom Themes

Creating a custom theme will allow you to build an entirely new spectrum of notification messages utilizing the existing notification types. To create a new theme, use the addTheme method. The first param is the name you'll use to reference your new theme. The second param is the class you'll use to style your new theme's notification types.

ngNotify.addTheme('newTheme', 'my-new-theme');

Now you can activate your new theme via the config method, using the name you previously assigned to it.

ngNotify.config({
    theme: 'newTheme'
});

To style your new theme, pick a collection of colors you'd like to use for each notification type and set them to each type's background color.

.my-new-theme.ngn-info
    background-color: #0033CC

.my-new-theme.ngn-error
    background-color: #FF0000

.my-new-theme.ngn-success
    background-color: #00CC00

.my-new-theme.ngn-warn
    background-color: #FF9900

.my-new-theme.ngn-grimace
    background-color: #660099
Custom Styles

The position, size, color, alignment and more are all styled based on the notification's classes and are all specified in the CSS file. See the style definitions below to see which classes can be used to override any of the styles within your own application.

Definitions

Methods

set(message, type|config, callback)

displays a notification message and sets the formatting/behavioral options for this one notification.

  • message: string - required - the message to display in your notification.
  • type: string|object - optional - the type of notification to display (string) OR an object of options.
    • types:
      • info (default)
      • error
      • success
      • warn
      • grimace
    • options: (see config below)
  • callback: string - optional - target to append notification to, value set to CSS selector.

config(options)

sets default settings for all notifications to take into account when displaying.

  • options - object - an object of options that overrides the default settings.
    • theme: string - optional - sets the theme to use, altering the styles for each notification type.
      • pure (default)
      • prime
      • pastel
      • pitchy
    • type: string - optional - sets the default notification type when a type isn't explicitly set.
      • info (default)
      • error
      • success
      • warn
      • grimace
    • position: string - optional - sets where the notifications will be displayed at in the app.
      • bottom (default)
      • top
    • duration: integer - optional - the duration the notification stays visible to the user, in milliseconds.
    • sticky: bool - optional - determines whether or not the message will fade at the end of the duration or if the message will persist until the user dismisses it themselves. when true, duration will not be set, even if it has a value. (false by default).
    • button: bool - optional - determines whether or not the dismiss button will show on sticky notifications. when true, the button will display. when false, the button wil not display. sticky must be set to true in order to control the visibility of the dismiss button. (true by default).
    • target: string - optional - CSS selector where the notification(s) should be appended to. (body by default).

dismiss()

manually dismisses any sticky notifications that may still be set.

addType(name, class)

allows a dev to create a new type of notification to use in their app.

  • name: string - required - the name used to trigger this notification type in the set method.
  • class: string - required - the class used to target this type in the stylesheet.

addTheme(name, class)

allows a dev to create a whole new set of styles for each notification type.

  • name: string - required - the name used when setting the theme in the config object.
  • class: string - required - the class used to target this theme in the stylesheet.

Styles

  • primary: the class that's present on every notification and controls all of the primary styles.

    • .ngn
  • position: purely responsible for where notifications are displayed. default is set to bottom, one is present on every notification.

    • .ngn-top
    • .ngn-bottom
  • types: default classes for setting each notification type's background color. default is set to info, one is present on every notification.

    • .ngn-info
    • .ngn-error
    • .ngn-success
    • .ngn-warn
    • .ngn-grimace
  • themes: theme specific classes that are chained together with type classes to override default background colors. not always present, default excludes all of these.

    • .ngn-prime
    • .ngn-pastel
    • .ngn-pitchy
  • sticky: styles responsible for displaying the dismissal button for sticky notifications.

    • .ngn-sticky - displays the dismissal button when sticky is enabled.
    • .ngn-dismiss - styles the dismissal button.

Development

If you've forked or cloned the project and would like to make any sort of adjustments, there are few items to make note of. First, your system will need to have the following bits in place:

  • Node & NPM
  • Grunt
  • Ruby
  • Sass

Second, there are a few grunt tasks that you'll be able to leverage to help validate and prepare your changes for use.

You can fire off a grunt or grunt build command manually at any time to lint, minify, and setup your demo (built in the _gh-pages dir) for testing.

grunt (or grunt build)

Also, you can run grunt dev to lint, minify, and prep your demo for testing. Once the build is complete, it'll also fire off a watch so that any changes that are made to the the sass, js, and demo files will automatically trigger the build script to update your project.

grunt dev

To run through the configured unit tests, you can run grunt test. This will fire off a series of tests that check that all default options are set correctly, all configurable options are able to be set correctly, and that all methods carry out the functionality that they're supposed to. These tests should let you know if any of the updates that you've made have negatively effected any preexisting functionality. Also, when the tests complete, there will be a test coverage report generated and stored in the coverage directory.

grunt test

Next, you'll want to do all of your development within three locations. If you add changes anywhere else, they're likely to be overwritten during the build process. These locations are:

src/scripts/ng-notify.js - for any script modifications.

src/styles/ng-notify.sass - for any style modifications.

demo/* - for any modifications to the demo.

Lastly, once you've made your changes and run through the appropriate grunt tasks, your changes should be baked and ready for you to consume - located in the dist directory as minified js and css files.

ng-notify's People

Contributors

danjarvis avatar fduch2k avatar genu avatar idpaterson avatar jessamynsmith avatar matowens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng-notify's Issues

Conflict? with angular-underscore after build

Hi,

First of all, I'm not sure if that's the issue with ngNotify, underscore, angular-underscore, grunt or whatever but I'm adding the issue here because ngNotify caused the problem.

I have an app with grunt file mostly generated by angular generator for yo.
When I use grunt serve for local testing everything works great, with grunt build and concat angular doesn't see ngNotify module anymore.

Below is my grunt file for reference and part of the minified, concatenated vendor.js (formatted for readability).

With underscore:

      })
    })
  })
}(angular, _),function () {
  "use strict";
  function a(a) {
    var b = '<div class="ngn" ng-class="ngNotify.notifyClass"><span ng-if="ngNotify.notifyHtml" class="ngn-message" ng-bind-html="ngNotify.notifyMessage"></span><span ng-if="!ngNotify.notifyHtml" class="ngn-message" ng-bind="ngNotify.notifyMessage"></span><span ng-show="ngNotify.notifyButton" class="ngn-dismiss" ng-click="dismiss()">&times;</span></div>';
    a.put(f, b)
  }

Without underscore:

,function () {
  "use strict";
  function a(a) {
    var b = '<div class="ngn" ng-class="ngNotify.notifyClass"><span ng-if="ngNotify.notifyHtml" class="ngn-message" ng-bind-html="ngNotify.notifyMessage"></span><span ng-if="!ngNotify.notifyHtml" class="ngn-message" ng-bind="ngNotify.notifyMessage"></span><span ng-show="ngNotify.notifyButton" class="ngn-dismiss" ng-click="dismiss()">&times;</span></div>';
    a.put(f, b)
  }

Gruntfile:

// Generated on 2016-02-17 using generator-angular 0.15.1
'use strict';

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/**/*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
var modRewrite = require('connect-modrewrite');
module.exports = function (grunt) {

  // Time how long tasks take. Can help when optimizing build times
  require('time-grunt')(grunt);

  // Automatically load required Grunt tasks
  require('jit-grunt')(grunt, {
    useminPrepare: 'grunt-usemin',
    ngtemplates  : 'grunt-angular-templates',
    cdnify       : 'grunt-google-cdn'
  });

  // Configurable paths for the application
  var appConfig = {
    app : require('./bower.json').appPath || 'app',
    dist: 'dist'
  };

  // Define the configuration for all the tasks
  grunt.initConfig({

    app: {
      // Application variables
      configs    : [
        'app/scripts/configs/**/*.module.js',
        'app/scripts/configs/**/*.js'
      ],
      rootScripts: [
        'app/scripts/*.js'
      ],
      components : [
        'app/scripts/components/**/*.module.js',
        'app/scripts/components/**/*.js'
      ],
      bootstrap : [
        'app/scripts/bootstrap/**/*.module.js',
        'app/scripts/bootstrap/**/*.js'
      ],
      modules    : [
        'app/scripts/modules/**/*.module.js',
        'app/scripts/modules/**/*.js'
      ],
      styles     : [
        'app/scripts/**/*.scss'
      ]
    },

    // Project settings
    yeoman: appConfig,

    ngconstant: {
      options    : {
        name     : 'tnn.cep.backoffice.config',
        wrap     : '\'use strict\';\n\n{%= __ngModule %}',
        space    : '  ',
        deps     : false,
        constants: {
          CONFIG: {
            API: {
              contentType: 'application/vnd.tnncep.v1+json',
            }
          }
        }
      },
      development: {
        options  : {
          dest: '<%= yeoman.app %>/scripts/configs/constants.config.js'
        },
        constants: {
          ENV   : 'development',
          CONFIG: {
            EXTERNAL : {
              ROLLBAR_TOKEN : 'xxxx'
            },
            API: {
              URL   : {

              },
              CLIENT: {
                TOKEN: 'CLIENT_TOKEN'
              }
            }
          }
        }
      },
      production : {
        options  : {
          dest: '<%= yeoman.app %>/scripts/configs/constants.config.js'
        },
        constants: {
          ENV   : 'production',
          CONFIG: {
            EXTERNAL : {
              ROLLBAR_TOKEN : 'xxxxx'
            },
            API: {
              URL   : {

              },
              CLIENT: {
                TOKEN: 'CLIENT_TOKEN'
              }
            }
          }
        }
      }
    },

    // Watches files for changes and runs tasks based on the changed files
    watch: {
      bower        : {
        files: ['bower.json'],
        tasks: ['wiredep']
      },
      js           : {
        files  : ['<%= yeoman.app %>/scripts/**/*.js'],
        tasks  : ['newer:jshint:all', 'newer:jscs:all'],
        options: {
          livereload: '<%= connect.options.livereload %>'
        }
      },
      jsTest       : {
        files: ['test/spec/**/*.js'],
        tasks: ['newer:jshint:test', 'newer:jscs:test', 'karma']
      },
      compass      : {
        files: ['<%= yeoman.app %>/styles/**/*.{scss,sass}'],
        tasks: ['compass:server', 'postcss:server']
      },
      gruntfile    : {
        files: ['Gruntfile.js']
      },
      livereload   : {
        options: {
          livereload: '<%= connect.options.livereload %>'
        },
        files  : [
          '<%= yeoman.app %>/**/*.html',
          '.tmp/styles/**/*.css',
          '<%= yeoman.app %>/images/**/*.{png,jpg,jpeg,gif,webp,svg}'
        ]
      },
      includeSource: {
        // Watch for added and deleted scripts to update index.html
        files  : 'dist/**/*.js',
        tasks  : ['includeSource'],
        options: {
          event: ['added', 'deleted']
        }
      }
    },

    includeSource: {
      // Task to include files into index.html
      options: {
        ordering: 'top-down',
        rename  : function (dest, matchedSrcPath) {

          var path = matchedSrcPath.split('/');
          path.shift();

          return path.join('/');
        }
      },
      app    : {
        files: {
          'app/index.html': 'app/index.html'
          // you can add karma config as well here if want inject to karma as well
        }
      }
    },

    // The actual grunt server settings
    connect: {
      options   : {
        port      : 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname  : 'localhost',
        livereload: 35729
      },
      livereload: {
        options: {
          open      : true,
          middleware: function (connect) {
            return [
              modRewrite(['!\\.html|\\.js|\\.svg|\\.css|\\.png$ /index.html [L]']),
              connect.static('.tmp'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
              connect().use(
                '/app/styles',
                connect.static('./app/styles')
              ),
              connect.static(appConfig.app)
            ];
          }
        }
      },
      test      : {
        options: {
          port      : 9001,
          middleware: function (connect) {
            return [
              connect.static('.tmp'),
              connect.static('test'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
              connect.static(appConfig.app)
            ];
          }
        }
      },
      dist      : {
        options: {
          open: true,
          base: '<%= yeoman.dist %>'
        }
      }
    },

    // Make sure there are no obvious mistakes
    jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      all    : {
        src: [
          'Gruntfile.js',
          '<%= yeoman.app %>/scripts/**/*.js'
        ]
      },
      test   : {
        options: {
          jshintrc: 'test/.jshintrc'
        },
        src    : ['test/spec/**/*.js']
      }
    },

    // Make sure code styles are up to par
    jscs: {
      options: {
        config : '.jscsrc',
        verbose: true
      },
      all    : {
        src: [
          'Gruntfile.js',
          '<%= yeoman.app %>/scripts/**/*.js'
        ]
      },
      test   : {
        src: ['test/spec/**/*.js']
      }
    },

    // Empties folders to start fresh
    clean: {
      dist  : {
        files: [
          {
            dot: true,
            src: [
              '.tmp',
              '<%= yeoman.dist %>/**/*',
              '!<%= yeoman.dist %>/.git**/*'
            ]
          }
        ]
      },
      server: '.tmp'
    },

    // Add vendor prefixed styles
    postcss: {
      options: {
        processors: [
          require('autoprefixer-core')({browsers: ['last 5 versions']})
        ]
      },
      server : {
        options: {
          map: true
        },
        files  : [
          {
            expand: true,
            cwd   : '.tmp/styles/',
            src   : '**/*.css',
            dest  : '.tmp/styles/'
          }
        ]
      },
      dist   : {
        files: [
          {
            expand: true,
            cwd   : '.tmp/styles/',
            src   : '**/*.css',
            dest  : '.tmp/styles/'
          }
        ]
      }
    },

    // Automatically inject Bower components into the app
    wiredep: {
      app : {
        src       : ['<%= yeoman.app %>/index.html'],
        ignorePath: /\.\.\//
      },
      test: {
        devDependencies: true,
        src            : '<%= karma.unit.configFile %>',
        ignorePath     : /\.\.\//,
        fileTypes      : {
          js: {
            block  : /(([\s\t]*)\/{2}\s*?bower:\s*?(\S*))(\n|\r|.)*?(\/{2}\s*endbower)/gi,
            detect : {
              js: /'(.*\.js)'/gi
            },
            replace: {
              js: '\'{{filePath}}\','
            }
          }
        }
      },
      sass: {
        src       : ['<%= yeoman.app %>/styles/**/*.{scss,sass}'],
        ignorePath: /(\.\.\/){1,2}bower_components\//
      }
    },

    // Compiles Sass to CSS and generates necessary files if requested
    compass: {
      options: {
        sassDir                : '<%= yeoman.app %>/styles',
        cssDir                 : '.tmp/styles',
        generatedImagesDir     : '.tmp/images/generated',
        imagesDir              : '<%= yeoman.app %>/images',
        javascriptsDir         : '<%= yeoman.app %>/scripts',
        fontsDir               : '<%= yeoman.app %>/styles/fonts',
        importPath             : './bower_components',
        httpImagesPath         : '/images',
        httpGeneratedImagesPath: '/images/generated',
        httpFontsPath          : '/styles/fonts',
        relativeAssets         : false,
        assetCacheBuster       : false,
        raw                    : 'Sass::Script::Number.precision = 10\n'
      },
      dist   : {
        options: {
          generatedImagesDir: '<%= yeoman.dist %>/images/generated'
        }
      },
      server : {
        options: {
          sourcemap: true
        }
      }
    },

    // Renames files for browser caching purposes
    filerev: {
      dist: {
        src: [
          '<%= yeoman.dist %>/scripts/**/*.js',
          '<%= yeoman.dist %>/styles/**/*.css',
          '<%= yeoman.dist %>/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
          '<%= yeoman.dist %>/styles/fonts/*'
        ]
      }
    },

    // Reads HTML for usemin blocks to enable smart builds that automatically
    // concat, minify and revision files. Creates configurations in memory so
    // additional tasks can operate on them
    useminPrepare: {
      html   : '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>',
        flow: {
          html: {
            steps: {
              js : ['concat', 'uglifyjs'],
              css: ['cssmin']
            },
            post : {}
          }
        }
      }
    },

    // Performs rewrites based on filerev and the useminPrepare configuration
    usemin: {
      html   : ['<%= yeoman.dist %>/**/*.html'],
      css    : ['<%= yeoman.dist %>/styles/**/*.css'],
      js     : ['<%= yeoman.dist %>/scripts/**/*.js'],
      options: {
        assetsDirs: [
          '<%= yeoman.dist %>',
          '<%= yeoman.dist %>/images',
          '<%= yeoman.dist %>/styles'
        ],
        patterns  : {
          js: [[/(images\/[^''""]*\.(png|jpg|jpeg|gif|webp|svg))/g, 'Replacing references to images']]
        }
      }
    },

    // The following *-min tasks will produce minified files in the dist folder
    // By default, your `index.html`'s <!-- Usemin block --> will take care of
    // minification. These next options are pre-configured if you do not wish
    // to use the Usemin blocks.
    // cssmin: {
    //   dist: {
    //     files: {
    //       '<%= yeoman.dist %>/styles/main.css': [
    //         '.tmp/styles/**/*.css'
    //       ]
    //     }
    //   }
    // },
    // uglify: {
    //   dist: {
    //     files: {
    //       '<%= yeoman.dist %>/scripts/scripts.js': [
    //         '<%= yeoman.dist %>/scripts/scripts.js'
    //       ]
    //     }
    //   }
    // },
    // concat: {
    //   dist: {}
    // },

    imagemin: {
      dist: {
        files: [
          {
            expand: true,
            cwd   : '<%= yeoman.app %>/images',
            src   : '**/*.{png,jpg,jpeg,gif}',
            dest  : '<%= yeoman.dist %>/images'
          }
        ]
      }
    },

    svgmin: {
      dist: {
        files: [
          {
            expand: true,
            cwd   : '<%= yeoman.app %>/images',
            src   : '**/*.svg',
            dest  : '<%= yeoman.dist %>/images'
          }
        ]
      }
    },

    htmlmin: {
      dist: {
        options: {
          collapseWhitespace       : true,
          conservativeCollapse     : true,
          collapseBooleanAttributes: true,
          removeCommentsFromCDATA  : true
        },
        files  : [
          {
            expand: true,
            cwd   : '<%= yeoman.dist %>',
            src   : ['*.html'],
            dest  : '<%= yeoman.dist %>'
          }
        ]
      }
    },

    ngtemplates: {
      dist: {
        options: {
          module : 'tnn.cep.backoffice.templates',
          htmlmin: '<%= htmlmin.dist.options %>',
          usemin : 'dist/scripts/app.js'
        },
        cwd    : '<%= yeoman.app %>',
        src    : 'scripts/**/*.html',
        dest   : '.tmp/templateCache.js'
      }
    },

    // ng-annotate tries to make the code safe for minification automatically
    // by using the Angular long form for dependency injection.
    ngAnnotate: {
      dist: {
        files: [
          {
            expand: true,
            cwd   : '.tmp/concat/scripts',
            src   : '*.js',
            dest  : '.tmp/concat/scripts'
          }
        ]
      }
    },

    // Replace Google CDN references
    cdnify: {
      dist: {
        html: ['<%= yeoman.dist %>/*.html']
      }
    },

    // Copies remaining files to places other tasks can use
    copy: {
      dist  : {
        files: [
          {
            expand: true,
            dot   : true,
            cwd   : '<%= yeoman.app %>',
            dest  : '<%= yeoman.dist %>',
            src   : [
              '*.{ico,png,txt}',
              '*.html',
              'images/**/*.{webp}',
              'styles/fonts/**/*.*'
            ]
          },
          {
            expand: true,
            cwd   : '.tmp/images',
            dest  : '<%= yeoman.dist %>/images',
            src   : ['generated/*']
          },
          {
            expand: true,
            cwd   : '.',
            src   : 'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*',
            dest  : '<%= yeoman.dist %>'
          },
          {
            expand: true,
            cwd   : 'bower_components/font-awesome',
            src   : 'fonts/*.*',
            dest  : '<%= yeoman.dist %>'
          }
        ]
      },
      styles: {
        expand: true,
        cwd   : '<%= yeoman.app %>/styles',
        dest  : '.tmp/styles/',
        src   : '**/*.css'
      }
    },

    // Run some tasks in parallel to speed up the build process
    concurrent: {
      server: [
        'compass:server'
      ],
      test  : [
        'compass'
      ],
      dist  : [
        'compass:dist',
        'imagemin',
        'svgmin'
      ]
    },

    // Test settings
    karma: {
      unit: {
        configFile: 'test/karma.conf.js',
        singleRun : true
      }
    }
  });

  grunt.loadNpmTasks('grunt-ng-constant');
  grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
    if (target === 'dist') {
      return grunt.task.run(['build', 'connect:dist:keepalive']);
    }

    grunt.task.run([
      'clean:server',
      'ngconstant:development',
      'wiredep',
      'includeSource',
      'concurrent:server',
      'postcss:server',
      'connect:livereload',
      'watch'
    ]);
  });

  grunt.registerTask('test', [
    'clean:server',
    'wiredep',
    'concurrent:test',
    'postcss',
    'connect:test',
    'karma'
  ]);

  grunt.registerTask('build', [
    'clean:dist',
    'ngconstant:production',
    'wiredep',
    'includeSource',
    'useminPrepare',
    'concurrent:dist',
    'postcss',
    'ngtemplates',
    'concat',
    'ngAnnotate',
    'copy:dist',
    'cdnify',
    'cssmin',
    'uglify',
    'filerev',
    'usemin',
    'htmlmin'
  ]);

  grunt.registerTask('default', [
    'newer:jshint',
    'newer:jscs',
    'test',
    'build'
  ]);
};

This really looks like a problem with build process but ngNotify is the only affected module :(

ngSanitize issue

Hi. I'm getting the following error:

ngNotify warning: 
gSanitize couldn't be located.  In order to use the 'html' option, be sure the ngSanitize source is included in your project.

I've tried including ngSanitize 3 different ways and no matter what I do I still get the error. Any idea what might be causing that?

Thank you!

angular SnotifyModule Show template error

When i add SnotifyModule to the app.module.ts -> imports array [ SnotifyModule ], the page not renders and show the error ( in image below ) to the cmd when using ngsnotifyV4.2.0

This error comes when i install [email protected]
1

This error comes when i install [email protected]
2

as documentation say, import SnotifyModule, SnotifyService } from 'ng-snotify'; and there are imports and providers array in app.module.ts
imports: [
SnotifyModule
],
providers: [
SnotifyService
],

now compiling goes ok, but browsers console showing this error now

4

and this is my ng version result

3

i am new to angular, please guide/help .. thanks

dismiss(), opacity didn't stop at 0

I don't know what happened, but I noticed after dismissal that the notification never showed back when calling set() again. So I went the developer tools and saw the opacity value rapidly decreasing in value. Of course, the CPU went up like crazy.

See attached image.
untitled

EDIT:
It seems to happen whenever I set() and dismiss() very fast.

Callback when after close och duration period?

But is it possible to add some callback after duration period or close of notify message?

Lets say i want to redirect user after close och duration..

Thanks for a great notification ๐Ÿ‘

Default configuration

Hey,

Thanks for ng-notify.

I'm wondering where do you put ngNotify.config()? In a controller?

For some other ng plugins that I've to use, all default options are inside:

app.config(function ($somethingProvider) {
    $somethingProvider.options({ ... });
});

But I can't inject ngNotify there, same in app.run().

So how do you do?

Bests

Angular expressions inside notification

Being able to use HTML tags inside notification is great. How about taking it one step further and allow to use angular expressions inside the template, so instead of:
ngNotify.set('User ' + vm.username + ' was added successfully with id ' + vm.id + '!', 'success');
you'd be able to write:
ngNotify.set('User {{vm.username}} was added successfully with id {{vm.id}}!', 'success');
which is slightly more readable and more 'angular-way'?

Enable animation selection

Hi! I think it'd be nice if you had, as part of the configuration object, a property for setting the message's animation.

Thanks

Notifications may remain opened or dismiss immediately without showing

Notifications may remain opened or dismiss immediately without showing. I'm still investigating those two problems. But, so far can provide such details:

  • Opacity of Notifications that remain opened/visible is constantly increasing.

Usecase:

  • Preview button sends request to the server. If server responds with an error, sticky notification is shown. Button is disable while request is performed.
  • Server always responds with error.
  • When clicking clicking lots of times, notification stops fading-in and is simply displayed. Close button doesn't do anything. Opacity starts increasing without limit.

It's very hard to reproduce when starting a 'grunt serve', but in production environment it is easily reproducible.

Having the notification appear for wait

How can I have the notification appear as long as I am waiting for the current operation to return status like an ajax call. All the examples have a predefined time which we can set. Is there any setting where I want the notification to appear as long as I want and when I have result from the ajax call then I can hide the notification.

Is ng-notify unmaintained?

Hello @matowens,

is ng-notify still maintained or not?

I see that v0.8.0 hasn't been published on NPM and that the last version on master has some bugs.

integrate with form validation?

More of a question than an issue, is it possible to integrate the ng-notify to work with angular form validation? Id like to keep my user notifications uniform using the module if possible.

No Button Visisble

I haven't been able to get dismiss buttons to show up. I tried this in Firefox and Chrome, with and without the { button: true } option. I noticed that the button is not showing up in the demo. Either I'm clearly misunderstanding the meaning of button or there is a bug here - see attached screenshot:

image

Thanks!

Container with `ngn` class can interfere with other fixed-position divs

Currently, ngn class defines a style of display: block. If there is another container on the page with a fixed position (a "full-screen" div, for example) the ng-notify div can interfere with the ability to focus on elements in the other div. Once a notification is displayed/hidden (and the style is set to none) it is no longer an issue.

For my case I was able to fix it by overriding the display style:

div.ngn {
    display: none;
}

For my use case this works fine, though I'm not sure what impacts it might have with other ng-notify configuration options.

Close button with sticky true

There should be an option for making notification true along with close button, sometimes need to make notification sticky but with close button too

Issue on iOS

Hi, i'm facing a scenario where the notification don't dismiss only on iOS systems, Desktop and Android works fine. When a make a request ngNotify starts without a definiton of time in .run block of code, and when the response gets I close the current notification with dismiss() and another one starts to inform the user about the response , so after 3.5s I call dismiss() function again using $timeout. What happens is that the first one notification don't dismiss and don't show the one with response.

I can't provide a demo because as inform, only occurs ond iOS systems. Any workaround?

[UPDATE]

Using sticky with no button and calling dismiss() manually after my promise gets resolved still happens the problem.

disable close button for sticky

i use ng-notify in all my projects its clean n simple , just the way it should be , there is just one minor aesthetic thing which bothers me is, there is a close button during sticky, i agree its useful in many situation but sometime there are instance where it feels more right not to have it , where you would like to programmatically dismiss it after certain events occurred.

I wish it could be included in config

thanks

Occures TypeError when trying to dismiss a notiication.

JS Console log
angular.js:13283 TypeError: Cannot read property 'fadeOut' of null
at Object.dismiss (ng-notify.js:137)
at dismiss (ng-notify.js:552)
at Object.dismiss (ng-notify.js:620)
at jkfe.js:255
at m.$digest (angular.js:16728)
at m.$apply (angular.js:16992)
at HTMLHtmlElement. (angular.js:13032)
at HTMLHtmlElement.dispatch (jquery.min.js:3)
at HTMLHtmlElement.r.handle (jquery.min.js:3)

callback execution

"..The callback fires once the notification has faded out..."

In the case that sticky and button are set to true, isn't logical that the callback is executed upon button click (thus fade out) ?

Angular 1.5

Is ng-notify compatible with Angular 1.5 and higher? If it is - please update bower.json file dependencies section. bower can not install package if angular 1.5 installed

Notification appear on top

I have implemented the ng-notify but I am facing issues when it comes to placing the notification on top of all the content on the page whether its top section or the bottom section. The notification goes behind the content especially when I scroll the page.

Any guidance.

Html button event

How can i insert html button and add ng-click event? I do thath

ngNotify.set('<button class="btn btn-sm btn-default" ng-click="test();"><i class="fa fa-times"</i>No</button>', { type: 'info', sticky: true, button: true });

but does not work

Stack of notifications

Now only one notification can be displayed simultaneously.
But what do you think about feature of stacking of few messages?

Testing with protractor - change $timeout to $interval

Hi,

Is it possible to change the $timeout calls to $interval? Because I'am doing e2e testing and want to check if the notify message is showing correct, but as ng-notify uses $timeout, protractor will wait until the $timeout call is finished to continue with testing, It causes some flakyness because selenium driver will have to catch the message when its hiding.

I don't know if I was clear with my explanation, but here is an issue about this behavior: angular/protractor#169 .

Callback after notify fadeout

I want to do something after the notify fadeout but after I read the code I could hardly find out a way to do so. So, will u do that?

ngNotify circular reference error when accessing in http interceptor

I really like this service an thought of using it to display error globally. To use it globally I created http interceptor and registered it in config but when I try to inject ngNotify in my http interceptor i keep getting circular reference error

my config
angular.module("commonModule", ["ui.router", "ngNotify"]);

angular.module("commonModule").config(config);
config.$inject = ["$httpProvider"];//, "$stateProvider", "$urlRouterProvider", "$locationProvider"];

function config($httpProvider) {//, $stateProvider, $urlRouterProvider, $locationProvider) {
    $httpProvider.interceptors.push('HttpResponseInterceptor');
};

})();

and my http interceptor is

(function (commonModule) {

'use strict';

commonModule.factory("HttpResponseInterceptor", HttpResponseInterceptor);

HttpResponseInterceptor.$inject = ["$q", "ngNotify"];
function HttpResponseInterceptor($q, ngNotify) {
    var deferred = $q.defer();
    return {
        responseError: function (response) {
            deferred.reject(response);

            return deferred.promise;
        }
    }
};

})(angular.module("commonModule"));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.