Giter Club home page Giter Club logo

notie's Introduction

notie

npm cdnjs

notie is a clean and simple notification, input, and selection suite for javascript, with no dependencies

Live demo: https://jaredreich.com/notie

With notie you can:

  • Alert users
  • Confirm user choices
  • Allow users to input information
  • Allow users to select choices
  • Allow users to select dates

Alt text

Features

  • Pure JavaScript, no dependencies, written in ES6
  • Easily customizable
  • Change colors to match your style/brand
  • Modify styling with the sass file (notie.scss) or overwrite the CSS
  • Font size auto-adjusts based on screen size

Browser Support

  • IE 10+
  • Chrome 11+
  • Firefox 4+
  • Safari 5.1+
  • Opera 11.5+

Installation

HTML:

<head>
  ...
  <link rel="stylesheet" type="text/css" href="https://unpkg.com/notie/dist/notie.min.css">
  <style>
    /* override styles here */
    .notie-container {
      box-shadow: none;
    }
  </style>
</head>
<body>
  ...
  <!-- Bottom of body -->
  <script src="https://unpkg.com/notie"></script>
</body>

npm:

npm install notie

Usage

ES6:

import notie from 'notie'
// or
import { alert, force, confirm, input, select, date, setOptions, hideAlerts } from 'notie'

Browser:

notie
// or
window.notie

Available methods:

notie.alert({
  type: Number|String, // optional, default = 4, enum: [1, 2, 3, 4, 5, 'success', 'warning', 'error', 'info', 'neutral']
  text: String,
  stay: Boolean, // optional, default = false
  time: Number, // optional, default = 3, minimum = 1,
  position: String // optional, default = 'top', enum: ['top', 'bottom']
})

notie.force({
  type: Number|String, // optional, default = 5, enum: [1, 2, 3, 4, 5, 'success', 'warning', 'error', 'info', 'neutral']
  text: String,
  buttonText: String, // optional, default = 'OK'
  position: String, // optional, default = 'top', enum: ['top', 'bottom']
  callback: Function // optional
}, callbackOptional())

notie.confirm({
  text: String,
  submitText: String, // optional, default = 'Yes'
  cancelText: String, // optional, default = 'Cancel'
  position: String, // optional, default = 'top', enum: ['top', 'bottom']
  submitCallback: Function, // optional
  cancelCallback: Function // optional
}, submitCallbackOptional(), cancelCallbackOptional())

notie.input({
  text: String,
  submitText: String, // optional, default = 'Submit'
  cancelText: String, // optional, default = 'Cancel'
  position: String, // optional, default = 'top', enum: ['top', 'bottom']
  submitCallback: Function(value), // optional
  cancelCallback: Function(value), // optional
  autocapitalize: 'words', // default: 'none'
  autocomplete: 'on', // default: 'off'
  autocorrect: 'off', // default: 'off'
  autofocus: 'true', // default: 'true'
  inputmode: 'latin', // default: 'verbatim'
  max: '10000',// default: ''
  maxlength: '10', // default: ''
  min: '5', // default: ''
  minlength: '1', // default: ''
  placeholder: 'Jane Smith', // default: ''
  value: String, // default: ''
  spellcheck: 'false', // default: 'default'
  step: '5', // default: 'any'
  type: 'text', // default: 'text'
  allowed: ['an', 's'] // Default: null, 'an' = alphanumeric, 'a' = alpha, 'n' = numeric, 's' = spaces allowed. Can be custom RegExp, ex. allowed: new RegExp('[^0-9]', 'g')
}, submitCallbackOptional(value), cancelCallbackOptional(value))

notie.select({
  text: String,
  cancelText: String, // optional, default = 'Cancel'
  position: String, // optional, default = 'bottom', enum: ['top', 'bottom']
  choices: [
    {
      type: Number|String, // optional, default = 1
      text: String,
      handler: Function
    }
    ...
  ],
  cancelCallback: Function // optional
}, cancelCallbackOptional())

notie.date({
  value: Date,
  submitText: String, // optional, default = 'OK'
  cancelText: String, // optional, default = 'Cancel'
  position: String, // optional, default = 'top', enum: ['top', 'bottom']
  submitCallback: Function(date), // optional
  cancelCallback: Function(date) // optional
}, submitCallbackOptional(date), cancelCallbackOptional(date))

For example:

notie.alert({ text: 'Info!' })
notie.alert({ type: 1, text: 'Success!', stay: true }) // Never hides unless clicked, or escape or enter is pressed
notie.alert({ type: 'success', text: 'Success!', time: 2 }) // Hides after 2 seconds
notie.alert({ type: 2, text: 'Warning<br><b>with</b><br><i>HTML</i><br><u>included.</u>' })
notie.alert({ type: 'warning', text: 'Watch it...' })
notie.alert({ type: 3, text: 'Error.', position: 'bottom' })
notie.alert({ type: 'error', text: 'Oops!' })
notie.alert({ type: 4, text: 'Information.' })
notie.alert({ type: 'info', text: 'FYI, blah blah blah.' })

notie.force({
  type: 3,
  text: 'You cannot do that, sending you back.',
  buttonText: 'OK',
  callback: function () {
    notie.alert({ type: 3, text: 'Maybe when you\'re older...' })
  }
})

notie.confirm({
  text: 'Are you sure you want to do that?<br><b>That\'s a bold move...</b>',
  cancelCallback: function () {
    notie.alert({ type: 3, text: 'Aw, why not? :(', time: 2 })
  },
  submitCallback: function () {
    notie.alert({ type: 1, text: 'Good choice! :D', time: 2 })
  }
})
notie.confirm({ text: 'Are you sure?' }, function() {
  notie.confirm({ text: 'Are you <b>really</b> sure?' }, function() {
    notie.confirm({ text: 'Are you <b>really</b> <i>really</i> sure?' }, function() {
      notie.alert({ text: 'Okay, jeez...' })
    })
  })
})

notie.input({
  text: 'Please enter your email:',
  submitText: 'Submit',
  cancelText: 'Cancel',
  cancelCallback: function (value) {
    notie.alert({ type: 3, text: 'You cancelled with this value: ' + value })
  },
  submitCallback: function (value) {
    notie.alert({ type: 1, text: 'You entered: ' + value })
  },
  value: '[email protected]',
  type: 'email',
  placeholder: '[email protected]'
})

notie.input({
  text: 'Please enter your name:',
  type: 'text',
  placeholder: 'Jane Doe',
  allowed: ['a', 's']
}, function(value) {
  notie.alert({ type: 1, text: 'You entered: ' + value })
}, function(value) {
  notie.alert({ type: 3, text: 'You cancelled with this value: ' + value })
})

notie.input({
  text: 'Please enter the price:',
  cancelCallback: function (value) {
    notie.alert({ type: 3, text: 'You cancelled with this value: ' + value })
  },
  submitCallback: function (value) {
    notie.alert({ type: 1, text: 'You entered: ' + value })
  },
  type: 'text',
  placeholder: '500',
  allowed: new RegExp('[^0-9]', 'g')
})

notie.select({
  text: 'Demo item #1, owner is Jane Smith',
  cancelText: 'Close',
  cancelCallback: function () {
    notie.alert({ type: 5, text: 'Cancel!' })
  },
  choices: [
    {
      text: 'Share',
      handler: function () {
        notie.alert({ type: 1, text: 'Share item!' })
      }
    },
    {
      text: 'Open',
      handler: function () {
        notie.alert({ type: 1, text: 'Open item!' })
      }
    },
    {
      type: 2,
      text: 'Edit',
      handler: function () {
        notie.alert({ type: 2, text: 'Edit item!' })
      }
    },
    {
      type: 3,
      text: 'Delete',
      handler: function () {
        notie.alert({ type: 3, text: 'Delete item!' })
      }
    }
  ]
})

function date() {
  notie.date({
    value: new Date(2015, 8, 27),
    cancelCallback: function (date) {
      notie.alert({ type: 3, text: 'You cancelled: ' + date.toISOString() })
    },
    submitCallback: function (date) {
      notie.alert({ type: 1, text: 'You selected: ' + date.toISOString() })
    }
  })
}

Use ES6 for nicer code and to inherit this:

notie.confirm({
  text: 'Leave the page?',
  submitCallback: () => this.location.href = 'https://google.com'
})

notie.confirm({
  text: 'Is ES6 great?',
  cancelCallback: () => notie.alert({ type: 3, text: 'Why not?' }),
  submitCallback: () => notie.alert({ type: 1, text: 'I Agree' })
})

notie.force({
  type: 3,
  text: 'You cannot do that, sending you back.',
  buttonText: 'OK',
  callback: () => notie.alert({ type: 3, text: 'Maybe when you\'re older...' })
})

Custom Styles

SASS:

// Before notie is imported:
$notie-color-success: #57BF57;
$notie-color-warning: #D6A14D;
$notie-color-error: #E1715B;
$notie-color-info: #4D82D6;
$notie-color-neutral: #A0A0A0;
// See all overwriteable variables in src/notie.scss

// Then import notie:
@import '../../node_modules/notie/src/notie';

CSS:

/* After notie styles are applied to DOM: */
.notie-container {
  box-shadow: none;
}

Options & Methods

// Showing all available options with defaults
notie.setOptions({
  alertTime: 3,
  dateMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
  overlayClickDismiss: true,
  overlayOpacity: 0.75,
  transitionCurve: 'ease',
  transitionDuration: 0.3,
  transitionSelector: 'all'
  classes: {
    container: 'notie-container',
    textbox: 'notie-textbox',
    textboxInner: 'notie-textbox-inner',
    button: 'notie-button',
    element: 'notie-element',
    elementHalf: 'notie-element-half',
    elementThird: 'notie-element-third',
    overlay: 'notie-overlay',
    backgroundSuccess: 'notie-background-success',
    backgroundWarning: 'notie-background-warning',
    backgroundError: 'notie-background-error',
    backgroundInfo: 'notie-background-info',
    backgroundNeutral: 'notie-background-neutral',
    backgroundOverlay: 'notie-background-overlay',
    alert: 'notie-alert',
    inputField: 'notie-input-field',
    selectChoiceRepeated: 'notie-select-choice-repeated',
    dateSelectorInner: 'notie-date-selector-inner',
    dateSelectorUp: 'notie-date-selector-up'
  },
  ids: {
    overlay: 'notie-overlay'
  },
  positions: {
    alert: 'top',
    force: 'top',
    confirm: 'top',
    input: 'top',
    select: 'bottom',
    date: 'top'
  }
})
// programmatically hide all alerts with an optional callback function
notie.hideAlerts(callbackOptional)

License

MIT

notie's People

Contributors

abejfehr avatar boris-glumpler avatar codepo8 avatar fabianschwarzfritz avatar gitter-badger avatar jaredreich avatar poke19962008 avatar rabenhorst avatar rrdelaney 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  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

notie's Issues

worked wrong

I used with ajax submit:

in beforeSubmit called notie.alert(4, 'Starting...', 1)

in * success* called notie.alert(1, 'success')

the success callback called, but the alert was not display...

Bower

Hey @jaredreich ,

Anychance you could put this on bower / npm for people to use?

I think it will increase the usage of notie.js

Thanks

Remove styles from JS, add CSS classes instead

Hello,

To allow users to easily customize the design of Notie.js, I suggest to remove every styles from JS and use a CSS instead - SCSS would be even better. Then use JS to add/remove CSS classes (not styles) from HTML.

An external CSS is easier to customize and override than DOM style attributes; it does not require "!important" in front of each CSS property value, you can change CSS without editing JS, ...

Add AMD, Common modules support and Notie methods should be prototype of Notie function.

Will be good to add support for modern projects where people use Browserify, ES6 modules etc.
Example

var notie = require('notie');

notie.confirm();

// or ES6

import notie from '/notie';

notie.confirm();

In my opinion from perfomance reasons and code quality reasons notie should be rewrited to "class" and all methods should be prototype.

var notie = new Notie({//config});
Notie.confirm();

// Implementation example

function Notie (config) {
    this.config = config;
}

Notie.prototype.confirm = function (msg) {
   alert(msg);
};

πŸ‘

Examples

Make methods return Promises

Could you make the methods return a promise, so that devs who want to use Promise#then method could use that over callbacks, so the callbacks would be optional. It'll allow much more flexibility and get rid of spaghetti code

Use notie.alert with an enum for types?

I find it easier to remember enums than numbers.

README.md

notie.alert(notie.types.SUCCESS, 'Success!', 1.5);
notie.alert(notie.types.WARNING, 'Warning<br><b>with</b><br><i>HTML</i><br><u>included.</u>', 2);
notie.alert(notie.types.ERROR, 'Error.', 2.5);
notie.alert(notie.types.INFO, 'Information.' 2);

notie.js

var types = {
    SUCCESS: 1,
    WARNING: 2,
    ERROR: 3,
    INFO: 4
}
.....
return {
   alert: alert,
   confirm: confirm,
   input: input,
   types: types
};

Input demo should focus text field

On https://jaredreich.com/projects/notie.js/, pressing the Input button opens an overlay, but the input element in the dialog is not automatically focused. This unnecessarily forces the user to click/tap on said input element to start using it.

Btw, I think this functionality should be provided by the library, automatically. Also, please see if you can integrate keyboard accessibility; after activating the Confirm/Input buttons, the dialog should be focused and the focus order should be trapped inside said dialog (so that the user doesn’t accidentally focus other page elements that are behind the overlay).

"Confirm" demo should not disappear when tapped or clicked somewhere else other than cancel

In the demo "Conform" appears as an overlay and it has Yes and Cancel (or we can use "No" which sounds more mandatory in some cases) option. The "Conform notie" should not get disappear when tap or click somewhere else other than "Cancel" option.

https://jaredreich.com/projects/notie.js/

In cases if a conformation is mandatory and the user tap somewhere else the "notie" will disappear and the user may not able to conform it again :)

Unable to get a specific version of Notie using bower

Hello,

We use notie in our project. I have version 2.1.0 on my local server, but version 3.0.0 is now on production server, for it does a bower install upon deployment.

In bower.json:

...
  "dependencies": {
    "jquery": "= 2.1.4",
    "modernizr": "~2.8.2",
    "notie": "*"
  },
...

We would like to force to version ~2.1.0 to be sure to not see untested features on production server. But "notie": "~2.1.0" doesn't work as it seems there is no versioning available for Notie.js (bower info notie returns "No versions available", as there is no releases on Notie repository).

addEventListener polyfill position

The position of the addEventListener polyfill may be causing issues as it is below an addEventListener call which means the aforementioned call would not have the polyfill applied.

The polyfill needs to be above all calls of addEventListener

Suggestion: Persistent alerts or notifiable-alerts

Great plugin, clean and simple Just loving it.
I think a a great feature could be to have the ability for showing alerts that are not time-dependant so can be manually dismissed.
Just like a confirmation but with only one button so user aknowledges has read the alert (but no decission is required)
It's like an hybrid between alert and confirmation.

Provide Tags

Hi! First of all: great Script - I love it!

But why don't you provide tags of your plugin? Using bower it would helpful to have version numbers. If I install your script now I get the master branch. It's best practice to have version numbers of your repo, done with the help of git tags.
Or am I getting something wrong?

Thank you.

Input box on screen

Since updating to 3.0 via npm, there's now a random input box on my screen and the notifications are now unstyled. Any tips?

I suggest using the tag and release feature of Github so the changes between major releases are clearly laid out.

Thanks!

Add ARIA to make it accessible

Currently the alerts don't get picked up by screen readers like VoiceOver. Adding in ARIA will enable this to be a tool used by anyone with assistive technology, not just visual users.

Each dialog with a button in it should have a role="alertdialog",if it is just informational it should get role="dialog". Each dialog needs aria-labelledby="ID OF TITLE" and aria-describedby="ID OF CONTENT"

For role="dialog" the focus must move to the title of the dialog allowing it to be read, then returned to the trigger once dismissed.

For role="alertdialog", there must be one focusable element in the dialog (button or link perhaps) and focus goes to the title of the dialog. Upon dismissal if the action on the elements inside the dialog do not direct the user to a new page, they should return the user to the trigger element.

Reference:
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_alertdialog_role
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_dialog_role

Consider addding .npmignore

Please consider adding a .npmignore file that ignores things like tests and other dot-files so when notie is published that stuff is left out. I would simply use the same ignore list as bower.json has.

Thanks!

Add/Remove Listeners on Show/Hide

Currently, the script will add event handlers on the window's resize event. It is a lot of event handlers, and even worse is that they persist regardless of whether or not the user has actually implemented the notification type.

My proposal is to only add the respective listener when the notification is showing, and remove the listener once the notification is hidden.

if you think this is a reasonable change, I'll be more than happy to raise a PR. Thanks!

Bind polyfill IE8.

Just realised the PR I made for denouncing rezize breaks ie8 because of .bind. Needs a polyfill

Make confirms / notie responsive (on mobile)

When a notie confirm is displayed on mobile an the text for yes / no is too long, the text is being shown in several rows, but the boxes do not expand. By that issue the user is not able to (clearly) read the whole text when on mobile.
Screenshot attached.
screenshot_2016-06-01-14-24-00

Check if HTML body is ready

It would be good, to check if the document is loaded & ready. If I include notie.js in my HTML header it ends up with the error "Uncaught TypeError: Cannot read property 'appendChild' of null" caused by

// Attach notie to the body element
document.body.appendChild(alert_outer);

My recommendation would be to do something like jQuery does to check if the body is ready:
http://stackoverflow.com/questions/978740/javascript-how-to-detect-if-document-has-loaded-ie-7-firefox-3

Ok maybe I would have to do this with a pull request, but I'm not a git pro :-)
Thanks

Minified version

Would be good to provide a minfied version of notie.js within the repo. All of my other bower vendor dependencies provide a minified version so I can concat all of them together in one file. If I want to use notie.js I have to do a minification task only for notie.js.

Thanks

Separate Logic and Styles

This is a nice library but it really suffers when customising. For example, rather than a background colour, I'd like to add bottom border (different colour for each type of alert). This isn't possible without modifying the code. This will make updates painful.

I'd recommending removing all the settings variables and creating a default CSS file. The code would just need to change classes of the dom elements based on the status. i.e. To show an alert the CSS would have a class (maybe) classed "notie-show" which would have the CSS animation and this class would be added to the notification container. Also, each alert style should have it's own class. etc...

resizeListener could also be replaced with media queries.

This gives far more flexibility and easier upgrades

Edit notie.input as-you-type to restrict inputs

Options should include:

  • alphanumeric (regex: /[^0-9a-zA-Z]/g)
  • numeric (regex: /[^0-9]/g)
  • alpha (regex: /[^a-zA-Z]/g)
  • spaces
  • custom regex

Pseudo-code:

var regexString = '0-9a-zA-Z'
if (spacesAllowed) regexString += ' '
var regex = new RegExp('[^' + regexString + ']', 'g')
oninput = function () {
  inputField.value.replace(regex, '')
}

Should work for copy-paste as well.

Parametrize Cancel option label in the select function

Hi @jaredreich and many compliments for notie,

I would only suggest to consider parametrization of the Cancel option label in the select function. This is especially useful with language other than english.

Currently I'm manually modifying the label with this raw code:

setTimeout(() => { document.getElementById("notie-select-cancel").innerHTML = 'Annuler' });

Thanks.

Best regards,
Luca

Suggestion: modular features

This library is nice and small. but it could be even smaller if it gives the option to only use plain alerts (no confirm/prompt functionality or vice versa). There are several ways to achieve this. Happy to help if you see the value.

camelCase

Please consider using camelCase for naming variables, etc. All major JavaScript style guides advise this.

Thank you so much.

confirm with one button

That would be cool for cases when you want to deliver information but not make it disappear based on time but the user presses ok when he is done reading.

Input Box Out Of Focus

when the user is typing and notie.alert are called simultaneously then the input box gets out of focus during typing.

Suggestion: define constants inside de module

It would be nice to have some constants defined inside notie itself for choosing the alert's background. For instance, we could have notie.SUCCESS = 1 to be used as notie.alert(notie.SUCCESS, 'text');. I know many people will argue that we could just put the number, but I always find myself forgetting which number is each.

Uncaught TypeError: Cannot read property 'appendChild' of null

Hi, i want to add this into my func.js wich is beeing loaded in the head section.
I need the func js in the head section beause of functions while html is running.
But then i get following error:
Uncaught TypeError: Cannot read property 'appendChild' of null

No manual close/dismiss functionality + subsequent alerts don't work.

First of all, nice clean library, thanks.

Some feedback:

Showing an alert while a previous one is still visible does nothing. Scenario: I show an alert to notify the user that the changes are being saved, however if the transaction fails i would like to show an error alert but this doesn't work and there is no way I can see of manually closing an active alert.

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.