Ads

Tuesday, 1 July 2014

jQuery msgbox

Download   Demo


Msgbox is an versatile jQuery popup plugin for creating modals, dialogs, message boxes that are draggable, themable, resizable and fully customizable.


Why another jquery popup plugin ?


Most of the exising jquery popup plugins are lacking some of the features:


  • Multiple instances support

  • Resize handler to resize the popup box

  • Maximization/Minimization of the popup box

  • Dragging support

  • Theme customization

  • Key bindings support

  • Working as a photo slideshow

  • Fourth party library indenpendent (some may dependent on jQuery UI, etc)

If you are looking for a plugin with most of the above features, here it is


Features


(c) could be customized


  • Key bindings (c)

  • Overlay events (c)

  • Draggable

  • Resizable

  • Icons, (prev,play,next,min,max,close) (c)

  • Buttons in footer, and their events could be fully customized (c)

  • Working as a photo viewer

  • Themes (c)

  • Multiple instances (task tar simulation)

  • Internationalization (c)

  • API

1. INCLUDE CSS AND JS FILES


<link rel="stylesheet" href="../themes/metro/css/jquery.msgbox.css" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="../jquery.msgbox.i18n.js"></script>
<script type="text/javascript" src="../jquery.msgbox.js"></script>

2. HTML


<a href="javascript:;" class="msgbox basic">Open basic msgbox</a>

3. JAVASCRIPT


$(".msgbox.basic").msgbox(
content: 'Hello world',
padding: 12
);

4. OPTIONS


jquery.msgbox could be either initialized by $.msgbox(arguments) or $(SELECTOR).msgbox(arguments)


The arguments is an javascript object with key-value pairs (e.g. title: ‘Hello’, content: ‘Hello world!’):


NOTICE: Although no arguments is required, to initialize a msgbox, an object, even an empty object (), is needed.


Because we use $.msgbox() and $(SELECTOR).msgbox() to retrieve the object.


 

































































































































































































KeyValue typeDefault valueDescription
fixedbooleantrueWhether the position of the box is fixed
overlaybooleantrueWhether to show the overlay or not
overlayEventstring|function‘flash’The event when clicking the overlayIf a string is given, the API will be called; otherwise, the function will be fired.
idstring|number0The identity of the instance, used for multiple instancesMultiple instances are only available by using $.msgbox(…)with a unique id
openboolean$(SELECTOR).msgbox: false

$.msgbox: true
Whether to open the msgbox after initialized.When using $(SELECTOR).msgbox, the msgbox will not be opened until the trigger is clicked or the .open() API is called. When using $.msgbox, it will be opened by default.
dragboolean|jquery selectorwindowWhether to enable the dragging of msgobx.If a jquery selector is given, the msgbox will be allowed only dragged in the element.
resizeboolean|objecttrueWhether to enable the resizing of msgobx.If true is given, it will use width: minWidth, height: titleHeight as default. It defines the minimal scale of msgbox can be resized.
titleboolean|stringfalseThe title of msgboxIf false is given, it will be replace by the attribute “title” of the trigger when in photo/image/gallery/album mode.
typestring‘html’The type of msgboxSupported types: text, ajax, html, iframe, confirm, alert, prompt, warning, info, error, success, photo, image=photo, album, gallery=album
contentboolean|stringfalseThe content of msgboxIf false is given, the content will be replaced by jquery.msgbox version information. Different types have different contents. For text, html, confirm, alert, prompt, warning, info, error, success, the content is the content which will be display in the box. For ajax, iframe, the content is the url to be loaded. Forphoto, image, album, gallery, the content is the jquery selector of the triggers, which are usually links like <a href=”photo.jpg” class=”photo” title=”A photo”>click to show photo</a>.
iconsarraytype=confirm, alert, prompt, warning, info, error, success, photo, image: ['close']

type=album, gallery: ['prev', 'play', 'next', 'min', 'max', 'close']

type=other: ['max', 'close']
The icons of msgboxSupported icons: prev, play, next, min, max, close
buttonsarraytype=confirm, alert, prompt, warning, info, error, success, photo, image: ['OK']

type=confirm, prompt: ['OK', 'Cancel']

type=other: []
The buttons in the footerThis could be fully customized. The events could be specify by buttonEvents
buttonEventsobject
The events bond to the buttonsThe key should exist in buttons, ‘OK’, ‘Cancel’ will override the default actions of the two buttons. When specify a function, this will refer to the msgbox itself. If a string specified to a key, the API will be called. E.g. ‘OK’:’close’ means when click OK button, it will call API close()
keyEventsobject Esc: ‘close’,

Space: ‘play’,

Left: ‘prev’,

Right: ‘next’,

Enter: ‘play’
The key events.Only takes effects on the focusing msgbox. The meaning of the value is the same as buttonEvents
prefixstringjMsgboxThe class prefix or the jquery events binding namespace.E.g. the class of overlay: jMsgbox-overlay (see css file). The event bond to overlay: ‘click.jMsgbox’
widthnumber600The width of msgbox
heightnumber450The height of msgbox
initialWidthnumber350The initial width of msgboxSee initialHeight
initialHeightnumber220The initial height of msgbox1. the initial dimension to be zoomed in/out to width, height

2.If width and height are not given, or exactly the same as the default width and height, they will be specified as initialWidth and initialHeight , respectively, when the type is one of alert, info, prompt, confirm, success, warning, error.
topboolean|numberfalseThe initial top position of the msgboxIf false, it will be placed in the middle of the window
leftboolean|numberfalseThe inital left position of the msgboxIf false, it will be placed in the center of the window
titleHeightnumber40The height of the title wrapperIf the height of .jMsgbox-title is not indicated in css, this value will be used. If you want to override it in css, please use !important
footHeightnumber30The height of the footerSimilar as titleHeight, the class name is .jMsgbox-foot
transitionstringswingThe transition when opening or closing msgboxOnly jquery built-in transition supported: swing, linear
speednumber300The speed of the opening or closing animation
opacitynumber0.9The opacity of the overlayOf course you can use css, but this is an easy way to make it supported by cross-browsers
zIndexnumber99The z-index of overlay and the box wrapperUse it just in case of some elements with greater z-index in the page (, if you want to cover them with msgbox).
langstringenThe language of the msgboxSee Internationalization
minPosstringtopThe position of the “task bar”When create multiple instances, you are able to minimize all of them to simulate a task bar.
minWidthnumber200The minimal width of msgbox1. the width of msgbox when minimized 2. the minimal width when resize msgbox
paddingnumber0The padding of the contentSometimes you need a padding of the content, e.g.: for text type or html type. However, you don’t need them for photos in most cases. CSS cannot differentiate the types, so you can define them here. Remember to use !important to override if you’d like to define it in CSS.
photoAutobooleantrueWhether to start playing the gallery when open it
photoSpeednumber2500The interval of showing a photo in gallery
photoScaledbooleanfalseWhether to scale the photo to width, height. If not, it will show its original dimension.
photoFadebooleantrueWhether to use fadeIn to show the photo after loaded
imgErrorstring‘Failed to load image.’The error message when failed to load image.This could be override by $.msgboxI18N.en.imgError
xhrErrorstringFailed to load URL.The error message when failed to load an ajax URL.This could be override by $.msgboxI18N.en.xhrError
onOpenfunction
The callback when msgbox is opened
onClosefunction
The callback when msgbox is closed
onLoadfunction
The callback when the content is loaded
onBeforeClosefunction
The callback just before the close triggers. The close will be cancelled when it returns false.

5. API


As in Full Settings mentioned, we use $.msgbox() and $(SELECTOR).msgbox() to retrieve the msgbox. We can also use $.msgbox(id) to retrieve a msgbox when deal with multiple instances. Once got the object, we can call the API in this wah: $.msgbox().close() or $(SELECTOR).msgbox().close()


In all the callbacks, this will refer to the msgbox object.


NOTICE: When initialize a msgbox: $(SELECTOR).msgbox(…), it will return a jQuery object to keep chaining, instead of a msgbox object.


























































APIArgumentsDescription
enableDrag
To enable dragging
disableDrag
To disable dragging
enableResize
To enable resizing
disableResize
To disable resizing
flashopacity(number): the opacity to change,

interval(number): the interval between each opacity change

callback(function): the callback
To flash the title by changing the opacity 2 times (simulation of windows)
playcallback(function): the callbackTo play the gallery. If the gallery is already playing, it will pause.
nextcallback(function): the callbackTo show the next photo in the gallery.
prevcallback(function): the callbackTo show the previous photo in the gallery
pause
To pause the gallery playing
opencallback(function): the callbackTo open the msgbox
val
To return the value of msgbox. The value is set in prompt or confirm
closecallback(function): the callbackTo close the msgbox
remove
To remove the msgbox. (click the trigger, msgbox will no show any more and new msgbox will not be generated either.)
titlet(string): the new titleTo return the title (if t is not specified), or to set a new title.
reloadcallback(function): the callbackTo reload the content of the msgbox
focuscallback(function): the callbackIf msgbox is minimized, restore it; if it is closed, open it; if it is opened, flash the title.
restorecallback(function): the callbackTo restore the msgbox from minimized or maximized.
mincallback(function): the callbackTo minimize the msgbox. If it is already minimized, restore it.
maxcallback(function): the callbackTo maximize the msgbox. If it is already minimized, restore it.
contentc(string): the new contentTo get the content(html) (if c is not specified), or to set the new content(html).

Static

















APIArgumentsDescription
$.msgbox.defaultsoptions(object)=Change the default settings
$.msgbox.closeAllcallback(function)Close all the msgboxes generated by $.msgbox. Callback will be called after all msgboxes closed.
$.msgbox.restoreAllcallback(function)Restore all the msgboxes generated by $.msgbox. Callback will be called after all msgboxes restored from minimized or maximized.
$.msgbox.minAllcallback(function)Minimize all the msgboxes generated by $.msgbox. Callback will be called after all msgboxes minimized.

6. INTERNATIONALIZATION


Refer the file jquery.msgbox.i18n.js and specify a language lang to use i18n.


























KeyDescription
OKThe value of the ‘OK’ button
CancelThe value of the ‘Cancel’ button
LoadingThe message when an iframe is loading
Play/PauseThe title of the ‘play’ icon
NextThe title of the ‘next’ icon
PrevThe title of the ‘prev’ icon
MinimizeThe title of the ‘min’ icon
MaximizeThe title of the ‘max’ icon
CloseThe title of the ‘close’ icon
xhrErrorThe error message when failed to load the ajax URL.
imgErrorThe error message when failed to load the image.

7. EXAMPLES


text: Open msgbox


$(".jmb-text").msgbox(
type: 'text',
content: 'Text content'
);

html (default): Open msgbox


$(".jmb-html").msgbox(
type: 'html',
content: '<p>HTML content</p><p style="color: #f33;">HTML content</p>'
);

ajax: Open msgbox


$(".jmb-ajax").msgbox(
type: 'ajax',
content: 'index.html'
);

iframe: Open msgbox


$(".jmb-iframe").msgbox(
type: 'iframe',
content: 'index.html'
);

confirm: Open msgbox


$(".jmb-confirm").msgbox(
type: 'confirm',
content: 'Are you sure',
onClose: function()
alert(!!this.val());

);

alert: Open msgbox


$(".jmb-alert").msgbox(
type: 'alert',
content: 'Message',
title: 'Alert'
);

prompt: Open msgbox


$(".jmb-prompt").msgbox(
type: 'prompt',
content: 'Please input: ',
onClose: function()
alert(this.val());

);

photo: Open msgbox Open msgbox by $.msgbox


//<a href="https://www.google.com.hk/images/srpr/logo11w.png" title="Google Logo" class="jmb-photo">Open msgbox</a>
$(".jmb-photo").msgbox(
type: 'photo'
);
$(".jmg-photo-opener").click(function()
$.msgbox(
type: 'photo',
content: '.jmb-photo'
);
);

gallery: Open msgbox (1st photo) Open msgbox (2nd photo) Open msgbox (3rd photo) Open msgbox by $.msgbox


$(".jmb-gallery").msgbox(
type: 'gallery'
);
$(".jmg-gallery-opener").click(function()
$.msgbox(
type: 'gallery',
content: '.jmb-gallery'
);
);


jQuery msgbox

No comments:

Post a Comment