View on GitHub

Jquery-popup-box

jQuery plugin to replace popup boxes (alert, confirm and prompt) based on deferred objects

Download this project as a .zip file Download this project as a tar.gz file

Intro

Jquery-popup-box is a simple jQuery plugin that can be used to replace build in popups. This plugin was written because:

jQuery Deferred

jQuery introduced Deffered objects in 1.5. They are easy way to stash functions that will be executed after something else eventually happen.

Since this plugin uses jQuery Deferred objects, showing popup window will not stop executing script. Also, you can provide callback that will be executed if user cancels and close the window (in fail method) and the callback for execution if she/he clicks OK.

Dependencies

Demo

$("#alert").click(function () {
  $.alert("This is simple alert message", "Title");
});
$("#prompt").click(function () {
  $.prompt("Enter your name", "John")
    // execute this if user clicks ok
    .done(function (name) {
      $.alert("Hi " + name, "Greeting");
    })
    // execute this if user cancels
    .fail(function () {
      $.alert("You didn't want to input your name", "See you next time");
    });
});
$("#confirm").click(function () {
  $.confirm("Confirm this action", "Please make choice")
    .done(function () {
      $.alert("You said OK", "Yupiii");
    })
    .fail(function () {
      $.alert("You canceled!", "Noooo");
    })
});