/* --- description: jBox is a powerful and flexible jQuery plugin, taking care of all your modal windows, tooltips, notices and more. authors: Stephan Wagner (http://stephanwagner.me) license: MIT (http://www.opensource.org/licenses/mit-license.php) requires: jQuery 1.11.0 (http://code.jquery.com/jquery-1.11.0.min.js) jQuery 2.1.0 (http://code.jquery.com/jquery-2.1.0.min.js) documentation: http://stephanwagner.me/jBox/documentation ... */ function jBox(type, options) { this.options = { // jBox ID id: null, // Choose a unique id, otherwise jBox will set one for you (jBox1, jBox2, ...) // Dimensions width: 'auto', // Width of container (e.g. 'auto', 100) height: 'auto', // Height of container // Attach attach: null, // Attach jBox to elements (if no target element is provided, jBox will use the attached element as target) trigger: 'click', // The event to open or close your jBoxes, use 'click' or 'mouseenter' preventDefault: false, // Prevent default event when opening jBox (e.g. don't follow the href in a link when clicking on it) // Content title: null, // Adds a title to your jBox content: null, // You can use a string to set text or HTML as content, or an element selector (e.g. jQuery('#jBox-content')) to append one or several elements (elements appended will get style display: 'block', so hide them with CSS style display: 'none' beforehand) getTitle: null, // Get the title from an attribute when jBox opens getContent: null, // Get the content from an attribute when jBox opens // Content from Ajax ajax: null, // Set a url to get content from an ajax call and inject into content area data: '', // Ajax data to send with your ajax call (e.g. 'id=82') reload: false, // Each time jBox is opened, reload the ajax call // Position target: null, // The target element where jBox will be opened position: { x: 'center', // Horizontal Position (Use a number, 'left', 'right' or 'center') y: 'center' // Vertical Position (Use a number, 'top', 'bottom' or 'center') }, outside: null, // Use 'x', 'y', or 'xy' to move your jBox outside of the target element offset: 0, // Offset to final position, you can set different values for x and y with an object e.g. {x: 15, y: 0} attributes: { // Note that attributes can only be 'left' or 'right' when using numbers for position, e.g. {x: 300, y: 20} x: 'left', // Horizontal position, use 'left' or 'right' y: 'top' // Vertical position, use 'top' or 'bottom' }, adjustPosition: false, // Adjusts the position when there is not enough space (use true, 'flip' or 'move') adjustTracker: false, // By default jBox adjusts the position when opening, to adjust when scrolling or resizing, use 'scroll', 'resize' or 'true' (both events) adjustDistance: 5, // How far from the window edge we start adjusting, use an object to set different values: {bottom: 5, top: 50, left: 5, right: 20} fixed: false, // Your jBox will stay on position when scrolling reposition: false, // Calculates new position when the window-size changes // Pointer pointer: false, // Your pointer will always point towards the target element, so the option outside should be 'x' or 'y' // Animations fade: 180, // Fade duration in ms, set to 0 or false to disable animation: null, // Animation when opening or closing (use 'pulse', 'zoomIn', 'zoomOut', 'move', 'slide', 'flip', 'tada') (CSS inspired from Daniel Edens Animate.css: http://daneden.me/animate) // Appearance theme: 'Default', // Set a jBox theme class addClass: '', // Adds classes to the wrapper overlay: false, // Adds an overlay when jBox opens (set color and opacity with CSS) zIndex: 10000, // Use a high zIndex (your overlay will have the lowest zIndex of all your jBoxes (with overlays) minus one) // Delays delayOpen: 0, // Delay opening in ms (Note that the delay will be ignored if your jBox didn't finish closing) delayClose: 0, // Delay closing in ms (Note that there is always a closing delay of at least 10ms to ensure jBox won't be closed when opening right away) // Closing events closeOnEsc: false, // Close jBox when pressing [esc] key closeOnClick: false, // Close jBox with mouseclick, use 'true' (click anywhere), 'box' (click on jBox itself), 'body' (click anywhere but jBox) closeOnMouseleave: false, // Close jBox when the mouse leaves the jBox area or the area of the attached element closeButton: false, // Adds a close button to your jBox, use 'true', 'title' or 'box' ('true' will put the button in title when there is one, otherwise in box) // Other options constructOnInit: false, // Construct jBox when it's being initialized blockScroll: false, // When jBox is open, block scrolling appendTo: jQuery('body'), // Provide an element if you want the jBox to be positioned inside a specific element (only useful for fixed positions or when position values are numbers) draggable: null, // Make your jBox draggable (use 'true', 'title' or provide an element as handle) (inspired from Chris Coyiers CSS-Tricks http://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/) // Events // Note: You can use 'this' in the event functions, it refers to your jBox object (e.g. onInit: function() { this.open(); }) onInit: function () { }, // Triggered when jBox is initialized, just before it's being created onCreated: function () { }, // Triggered when jBox is created and is availible in DOM onOpen: function () { }, // Triggered when jBox is opened onClose: function () { }, // Triggered when jBox is closed onAjax: function () { }, // Triggered when the ajax call starts onAjaxComplete: function () { }, // Triggered when the ajax call is completed // Only for Notices: autoClose: 7000, // Time when jBox should close automatically color: null, // Makes your notices colorful, use 'black', 'red', 'green', 'blue', 'yellow' stack: true, // Set to false to disable notice-stacking audio: false, // Set the url to an audio file without extention, e.g. '/url/filename'. jBox will look for an .mp3 and an .ogg file volume: 100 // Percent of volume for audio files }; // Default type options this.defaultOptions = { // Default options for tooltips 'Tooltip': { getContent: 'title', trigger: 'mouseenter', position: { x: 'center', y: 'top' }, outside: 'y', pointer: true, adjustPosition: true, reposition: true }, // Default options for mouse tooltips 'Mouse': { target: 'mouse', position: { x: 'right', y: 'bottom' }, offset: 15, trigger: 'mouseenter', adjustPosition: 'flip' }, // Default options for modal windows 'Modal': { target: jQuery(window), fixed: true, blockScroll: true, closeOnEsc: true, closeOnClick: 'body', closeButton: 'title', overlay: true, animation: 'zoomOut' }, // Default options for notices 'Notice': { target: jQuery(window), fixed: true, position: { x: 20, y: 20 }, attributes: { x: 'right', y: 'top' }, animation: 'zoomIn', closeOnClick: 'box', _onInit: function () { this.open(); this.options.delayClose = this.options.autoClose; this.options.delayClose && this.close(); }.bind(this), _onCreated: function () { this.options.color && this.wrapper.addClass('jBox-Notice-color jBox-Notice-' + this.options.color); }, _onOpen: function () { // Loop through notices at same window corner and either move or destroy them jQuery.each(jQuery('.jBox-Notice'), function (index, el) { el = jQuery(el); if (el.attr('id') == this.id || el.css(this.options.attributes.y) == 'auto' || el.css(this.options.attributes.x) == 'auto') return; if (!this.options.stack) { el.data('jBox').close({ ignoreDelay: true }); return; } el.css('margin-' + this.options.attributes.y, parseInt(el.css('margin-' + this.options.attributes.y)) + this.dimensions.y + 10); }.bind(this)); // Play audio file, IE8 doesn't support audio if (this.options.audio && !this.IE8) { this.audio = jQuery('