Giter VIP home page Giter VIP logo

overhang.js's Introduction

overhang

npm version

A simple jQuery plugin to display sleek, instant notifications, confirmations or prompts inside a given element.

See it in action!

Installation

You can install overhang through npm:

$ npm install overhang

Alternatively, you can download the files in the dist/ folder manually.

Usage

Include a reference to the latest version of jQuery and jQuery UI. — The specific jQuery UI components required are: "effect.js" (Effects Core)

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>

Include references to the Javascript and CSS files.

<link rel="stylesheet" type="text/css" href="dist/overhang.min.css" />
<script type="text/javascript" src="dist/overhang.min.js"></script>

Configuration Parameters

overhang.js has 3 primary features - notifications, prompts and confirmations. Most of the options are customizable for all of these features.

Defaults

type

This is the type of the notification that you want to display. The preset types are success, error, warn, info, prompt and confirm.

If you would like to use a custom theme, leave this parameter blank and follow the rules for setting a custom theme.

$("body").overhang({
  custom: true, // Set custom to true
  primary: "#34495E", // Your custom primary color
  accent: "#F4B350" // Your custom accent color
});

primary - The background color of the alert.

accent - The bottom border color.

If you want to display either a prompt or confirmation alert, set the type to prompt or confirm, respectively. Prompts and confirmations both have preset themes, but you can customize them by using the custom option.

customClasses

Any additional CSS classes to add to the overhang element, separated by spaces. Useful for specifying fonts and further customizations. The default is "".

textColor

The color of the text. The default is set to white.

message

The message to be displayed in your alert.

duration

The duration in seconds to show the alert for. The default is 1.5 seconds.

speed

The speed to drop and raise the alert in milliseconds. The default is set to 500.

closeConfirm

Set this to true if you would like the user to have to close the alert rather than it disappearing by itself. The default is set to false.

upper

Set this to true if you would like your message in all uppercase letters. The default is set to false.

easing

jQuery UI easing option for the drop effect. The default is set to "easeOutBounce"

html

This is a boolean if the message argument should be interpreted as HTML. The default value is set to false.

overlay

Set this to true if you would like to have an overlay displayed with your alert. The default value is set to false. You can also pass in a value to the overlayColor argument to specify the color of the overlay. The default is set to black.

$("body").overhang({
  type: "confirm",
  message: "Do you want to continue?",
  closeConfirm: "true",
  overlay: true,
  overlayColor: "#1B1B1B"
});

Basic Alert Notification Example

// Some error notification
$("body").overhang({
  type: "error",
  message: "You could not be logged in at this time.",
  closeConfirm: "true",
  customClasses: "class1 class2"
});

Prompts

When using prompts, all you need to do is set the type parameter to "prompt".

Prompt Example

// Some prompt notification
$("body").overhang({
  type: "prompt",
  message: "What is your name"
});

Confirmations

When using confirmations, there are additional options that you can customize.

yesMessage

This is the text on the "true" button that would to display. The default is set to "Yes".

noMessage

This is the text on the "false" button that would to display. The default is set to "No".

yesColor

This is the color of the "true" button. The default is set to "#2ECC71".

noColor

This is the color of the "false" button. The default is set to "#E74C3C".

Confirmation Example

// Some confirmation
$("body").overhang({
  type: "confirm",
  yesMessage: "Yes please!",
  noMessage: "No thanks."
});

Retrieving Data

The prompt and confirm features both allow you to get data from the user. The responses are stored as data in the DOM of the target element that overhang.js has been applied to.

To retrieve the data, you simply pass in a callback function with one parameter:

$("body").overhang({
  type: "prompt",
  message: "What is your name",
  callback: function (value) {
    alert("You entered " + value);
  }
});

or you manually access the data from the DOM:

alert($("target-element").data("overhangPrompt")); // From a prompt
alert($("target-element").data("overhangConfirm")); // From a confirmation

If the user has not yet given a response, the default values will be set to null.

Callbacks

The option callback argument is a function that will run once the user has made an action on the overhang notification. The callback will run after any of these cases:

  • The submission of a prompt
  • The selection on a confirmation
  • The close button on a normal notification with a true closeConfirm
  • The raise of a normal notification

Note: For confirmations or prompts, the callback will not run when the close button is clicked and nothing is selected.

Example

$("body").overhang({
  type: "confirm",
  message: "Are you sure?",

  // This code will run once an option is clicked.
  callback: function (selection) {
    alert("You made your selection of " + selection);
  }
});

overhang.js's People

Contributors

benguild avatar markbao avatar paulkr avatar ricket 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

overhang.js's Issues

Don't require Roboto

Hi and thank you for this nice lib!

I'm using it from npm and overriding the CSS to use my own fonts. Problem is that the base CSS downloads the Roboto font that I'm not using at all.

While I know that I can simply not include the CSS and make up my own file, I was wondering if you'd consider adding an option to select the font instead. That would make it easier to upgrade for the user.

accent or accute don't work with upper true

$("body").overhang({ custom: true, primary: "#be380a", accent: "rgb(150, 44, 8)", type: "error", message: message, duration: 1.8, upper: true });

message = operación or operaci&oacute;n

in first case operación look like OPERACIóN and last case OPERACI&OACUTE;N

Dealing with accented characters

Hi,

I tried overHang this morning (which is damn' nice) and i got some trouble with accented characters who's converted to html entities.

I suggest you to use p.html() instead p.text() to deal with it.

See ya!

how to close the overhang programmatically (in JS)

Hi folks, how would I use jquery to programmatically close an overhang that is already open by clicking anywhere on the overhang itslef. I'm doing the below ( 1. finding the overhang by its class, and 2. creating a click event on overhang's close button), and while its working I suspect its a poor method since its throwing some jquery errors and its not very elegant.

$('.overhang-overrides').on('click', function(event){ $('.overhang-close').trigger('click'); });

Button on prompts

Related to #27
Opening as it was not solved.

Screenshot 2020-05-13 at 1 59 36 PM

Issue was How to add a button to a "prompt" type message, not "confirm" type message.

Duration plus confirmClose?

In my app (Chrome Extension) a long-ish (3s) duration is necessary but can get in the way after a while - would like it to be "dismissable" early. I tried adding both duration and confirmClose options but confirmClose overrides duration. I tried to modify the code to allow this but my Javascript Fu is weak. Would be sweet to just click anywhere on the overhang to dismiss it or on $close if it's present before the duration runs out.

The close icon missed and html: true not work in the mini js file

Hi,
  I got 2 issues in the course of my use:

   1. when I include bootstrap.css file, the close icon X will not show. It means if closeConfirm: true, user will have no where to click to close the notify.
   2. Based on issue #4, I saw you added html: true to solve it. It did work when I use overhang.js, but seems still not work the mini file: overhang.min.js.

  BTW, the version of bootstrap.css is 3.3.5, and the browser is Firefox v36.0.4.

  Anyway thank you for sharing this pretty plugin 😊!

bower

Can you add bower?

duration and close confirmation under Custom mode

How can I add duration time and close cross when I use custom mode? Error occurs if I do so.

   custom: true,
   textColor: "#FFFAFA",
   primary: "#222222",
   accent: "#555555",
   message: "Across the Great Wall we can reach every corner in the world."
  duration: 10,
  closeConfirm: true
});

Styling css and js

Just curious. Looked at the source code, and I liked how you formatted it. E.g. in css the ':' are vertically simmetrical. How did you do that? Did you use any tool? I couldn't find any. It really helps with readability

Typewriter text introduction?

Hi - great work ! Any thoughts on best way to get a typewriter effect on the text of overhang notification? Using a lib such as: https://github.com/tameemsafi/typewriterjs ..
Thanks for insights or caveats..

update
Sorry, this can be closed ; a bit of investigation resolves this: simply use a span element in the message content and then reference this span or div with whatever typewriter library you may be using.. Worked for me with aforementioned library.

overlay: true not working

Hi, I use XAMP, all work fine but "overlay: true" didn´t

I open overhang/index to see the examples, all work but overlay not workin here too

Option to insert notification on top of page, instead of overhang

Dear paulkr,

thanks first for your awesome library!

I'd like to have an option, where the notification is inserted on top of the page (instead of overhang).
If you could point me in the right direction about what should be implemented to achieve this, I could try myself.
As far as I can tell, only line 165 of overhang.js needs to be changed. From append() to sth. like insertBefore().

Best regards,

OliEfr

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.