diff --git a/index.html b/index.html
index 0213979..9ea4eed 100644
--- a/index.html
+++ b/index.html
@@ -143,6 +143,13 @@
Options
Enables background cover.
Disabled for tooltips. |
+
+ | backgroundclass |
+ string (CSS selector) |
+ |
+ Adds a class to the background of the overlay to enable custom animations for it.
+ Disabled for tooltips. |
+
| color |
string (CSS color) |
diff --git a/jquery.popupoverlay.js b/jquery.popupoverlay.js
index cdc51bf..b43fb6a 100644
--- a/jquery.popupoverlay.js
+++ b/jquery.popupoverlay.js
@@ -1,247 +1,258 @@
/*!
- * jQuery Popup Overlay
- *
- * @version 1.6.0
- * @requires jQuery v1.7.1+
- * @link http://vast-eng.github.com/jquery-popup-overlay/
- */
-(function ($) {
-
- var $window = $(window);
- var options = {};
- var zindexvalues = [];
- var lastclicked = [];
- var onevisible = false;
- var oneormorevisible = false;
- var scrollbarwidth;
- var focushandler = null;
- var blurhandler = null;
- var escapehandler = null;
- var bodymarginright = null;
- var opensuffix = '_open';
- var closesuffix = '_close';
- var focusedelementbeforepopup = null;
-
- var methods = {
-
- _init: function (el) {
- var $el = $(el);
- var options = $el.data('popupoptions');
- lastclicked[el.id] = false;
- zindexvalues[el.id] = 0;
-
- if (!$el.data('popup-initialized')) {
- $el.attr('data-popup-initialized', 'true');
- methods._initonce(el);
- }
+ * jQuery Popup Overlay
+ *
+ * @version 1.6.0
+ * @requires jQuery v1.7.1+
+ * @link http://vast-eng.github.com/jquery-popup-overlay/
+ */
+ (function ($) {
+
+ var $window = $(window),
+ options = {},
+ zindexvalues = [],
+ lastclicked = [],
+ onevisible = false,
+ oneormorevisible = false,
+ scrollbarwidth,
+ focushandler = null,
+ blurhandler = null,
+ escapehandler = null,
+ bodymarginright = null,
+ opensuffix = '_open',
+ closesuffix = '_close',
+ focusedelementbeforepopup = null,
+ visibleScrollLocks = 0;
+
+ var methods = {
+
+ _init: function (el) {
+ var $el = $(el);
+ var options = $el.data('popupoptions');
+ lastclicked[el.id] = false;
+ zindexvalues[el.id] = 0;
+
+ if (!$el.data('popup-initialized')) {
+ $el.attr('data-popup-initialized', 'true');
+ methods._initonce(el);
+ }
- if (options.autoopen) {
- setTimeout(function() {
+ if (options.autoopen) {
methods.show(el, 0);
- }, 0);
- }
- },
-
- _initonce: function (el) {
- var $body = $('body');
- var $wrapper;
- var options = $el.data('popupoptions');
- bodymarginright = parseInt($body.css('margin-right'), 10);
-
- if (options.type == 'tooltip') {
- options.background = false;
- options.scrolllock = false;
- }
-
- if (options.scrolllock) {
- // Calculate the browser's scrollbar width dynamically
- var parent;
- var child;
- if (typeof scrollbarwidth === 'undefined') {
- parent = $('').appendTo('body');
- child = parent.children();
- scrollbarwidth = child.innerWidth() - child.height(99).innerWidth();
- parent.remove();
}
- }
-
- if (!$el.attr('id')) {
- $el.attr('id', 'j-popup-' + parseInt(Math.random() * 100000000));
- }
-
- $el.addClass('popup_content');
-
- $body.prepend(el);
+ },
- $el.wrap('');
+ _initonce: function (el) {
+ var $body = $('body');
+ var $wrapper;
+ var options = $el.data('popupoptions');
+ bodymarginright = parseInt($body.css('margin-right'), 10);
- $wrapper = $('#' + el.id + '_wrapper');
-
- $wrapper.css({
- opacity: 0,
- visibility: 'hidden',
- position: 'absolute',
- overflow: 'auto'
- });
-
- $el.css({
- opacity: 0,
- visibility: 'hidden',
- display: 'inline-block'
- });
-
- if (options.setzindex && !options.autozindex) {
- $wrapper.css('z-index', '2001');
- }
+ if (options.type == 'tooltip') {
+ options.background = false;
+ options.scrolllock = false;
+ }
- if (!options.outline) {
- $el.css('outline', 'none');
- }
+ if (options.scrolllock) {
+ // Calculate the browser's scrollbar width dynamically
+ var parent;
+ var child;
+ if (typeof scrollbarwidth === 'undefined') {
+ parent = $('').appendTo('body');
+ child = parent.children();
+ scrollbarwidth = child.innerWidth() - child.height(99).innerWidth();
+ parent.remove();
+ }
+ }
- if (options.transition) {
- $el.css('transition', options.transition);
- $wrapper.css('transition', options.transition);
- }
+ if (!$el.attr('id')) {
+ $el.attr('id', 'j-popup-' + parseInt(Math.random() * 100000000));
+ }
- // Hide popup content from screen readers initially
- $(el).attr('aria-hidden', true);
+ $el.addClass('popup_content');
- if ((options.background) && (!$('#' + el.id + '_background').length)) {
+ $body.prepend(el);
- var popupbackground = '';
+ $el.wrap('');
- $body.prepend(popupbackground);
+ $wrapper = $('#' + el.id + '_wrapper');
- var $background = $('#' + el.id + '_background');
+ $wrapper.css({
+ opacity: 0,
+ visibility: 'hidden',
+ position: 'absolute',
+ overflow: 'auto'
+ });
- $background.css({
+ $el.css({
opacity: 0,
visibility: 'hidden',
- backgroundColor: options.color,
- position: 'fixed',
- top: 0,
- right: 0,
- bottom: 0,
- left: 0
+ display: 'inline-block'
});
if (options.setzindex && !options.autozindex) {
- $background.css('z-index', '2000');
+ $wrapper.css('z-index', '2001');
+ }
+
+ if (!options.outline) {
+ $el.css('outline', 'none');
}
if (options.transition) {
- $background.css('transition', options.transition);
+ $el.css('transition', options.transition);
+ $wrapper.css('transition', options.transition);
}
- }
- if (options.type == 'overlay') {
- $el.css({
- textAlign: 'left',
- position: 'relative',
- verticalAlign: 'middle'
- });
+ // Hide popup content from screen readers initially
+ $(el).attr('aria-hidden', true);
- $wrapper.css({
- position: 'fixed',
- top: 0,
- right: 0,
- left: 0,
- bottom: 0,
- textAlign: 'center'
- });
+ if ((options.background) && (!$('#' + el.id + '_background').length)) {
- // CSS vertical align helper
- $wrapper.append('');
+ var popupbackground = '';
- $('.popup_align').css({
- display: 'inline-block',
- verticalAlign: 'middle',
- height: '100%'
- });
- }
+ $body.prepend(popupbackground);
- // Add WAI ARIA role to announce dialog to screen readers
- $el.attr('role', 'dialog');
+ var $background = $('#' + el.id + '_background');
- var openelement = (options.openelement) ? options.openelement : ('.' + el.id + opensuffix);
+ $background.css({
+ opacity: 0,
+ visibility: 'hidden',
+ backgroundColor: options.color,
+ position: 'fixed',
+ top: 0,
+ right: 0,
+ bottom: 0,
+ left: 0
+ });
- $(openelement).each(function (i, item) {
- $(item).attr('data-popup-ordinal', i);
+ if (options.backgroundclass) {
+ $background.addClass(options.backgroundclass);
+ }
+
+ if (options.setzindex && !options.autozindex) {
+ $background.css('z-index', '2000');
+ }
- if (!$(item).attr('id')) {
- $(item).attr('id', 'open_' + parseInt((Math.random() * 100000000), 10));
+ if (options.transition) {
+ $background.css('transition', options.transition);
+ }
}
- });
- // Set aria-labelledby (if aria-label or aria-labelledby is not set in html)
- if (!($el.attr('aria-labelledby') || $el.attr('aria-label'))) {
- $el.attr('aria-labelledby', $(openelement).attr('id'));
- }
+ if (options.type == 'overlay') {
+ $el.css({
+ textAlign: 'left',
+ position: 'relative',
+ verticalAlign: 'middle'
+ });
- $(document).on('click', openelement, function (e) {
- if (!($el.data('popup-visible'))) {
- var ord = $(this).data('popup-ordinal');
+ $wrapper.css({
+ position: 'fixed',
+ top: 0,
+ right: 0,
+ left: 0,
+ bottom: 0,
+ textAlign: 'center'
+ });
- // Show element when clicked on `open` link.
- // setTimeout is to allow `close` method to finish (for issues with multiple tooltips)
- setTimeout(function() {
- methods.show(el, ord);
- }, 0);
+ // CSS vertical align helper
+ $wrapper.append('');
- e.preventDefault();
+ $('.popup_align').css({
+ display: 'inline-block',
+ verticalAlign: 'middle',
+ height: '100%'
+ });
}
- });
- // Handler: `close` element
- var closeelement = (options.closeelement) ? options.closeelement : ('.' + el.id + closesuffix);
- $(document).on('click', closeelement, function (e) {
- methods.hide(el);
- e.preventDefault();
- });
+ // Add WAI ARIA role to announce dialog to screen readers
+ $el.attr('role', 'dialog');
- if (options.detach) {
- $el.hide().detach();
- } else {
- $wrapper.hide();
- }
- },
+ var openelement = (options.openelement) ? options.openelement : ('.' + el.id + opensuffix);
- /**
- * Show method
- *
- * @param {object} el - popup instance DOM node
- * @param {number} ordinal - order number of an `open` element
- */
- show: function (el, ordinal) {
- var $el = $(el);
+ $(openelement).each(function (i, item) {
+ $(item).attr('data-popup-ordinal', i);
- if ($el.data('popup-visible')) return;
+ if (!$(item).attr('id')) {
+ $(item).attr('id', 'open_' + parseInt((Math.random() * 100000000), 10));
+ }
+ });
- // Initialize if not initialized. Required for: $('#popup').popup('show')
- if (!$el.data('popup-initialized')) {
- methods._init(el);
- }
- $el.attr('data-popup-initialized', 'true');
+ // Set aria-labelledby (if aria-label or aria-labelledby is not set in html)
+ if (!($el.attr('aria-labelledby') || $el.attr('aria-label'))) {
+ $el.attr('aria-labelledby', $(openelement).attr('id'));
+ }
- var $body = $('body');
- var options = $el.data('popupoptions');
- var $wrapper = $('#' + el.id + '_wrapper');
- var $background = $('#' + el.id + '_background');
+ $(document).on('click', openelement, function (e) {
+ if (!($el.data('popup-visible'))) {
+ var ord = $(this).data('popup-ordinal');
- // `beforeopen` callback event
- callback(el, ordinal, options.beforeopen);
+ // Show element when clicked on `open` link.
+ methods.show(el, ord);
- // Remember last clicked place
- lastclicked[el.id] = ordinal;
+ e.preventDefault();
+ }
+ });
- if (options.detach) {
- $wrapper.prepend(el);
- $el.show();
- } else {
- $wrapper.show();
- }
+ // Handler: `close` element
+ var closeelement = (options.closeelement) ? options.closeelement : ('.' + el.id + closesuffix);
+ $(document).on('click', closeelement, function (e) {
+ methods.hide(el);
+ e.preventDefault();
+ });
+
+ if (options.detach) {
+ $el.hide().detach();
+ } else {
+ $wrapper.hide();
+ }
+
+ // Bind callbacks
+ if (typeof options.beforeopen == 'function')
+ $el.on("jquery-popup-overlay.beforeopen", options.beforeopen)
+ if (typeof options.onopen == 'function')
+ $el.on("jquery-popup-overlay.onopen", options.onopen)
+ if (typeof options.onclose == 'function')
+ $el.on("jquery-popup-overlay.onclose", options.onclose)
+ if (typeof options.opentransitionend == 'function')
+ $el.on("jquery-popup-overlay.opentransitionend", options.opentransitionend)
+ if (typeof options.closetransitionend == 'function')
+ $el.on("jquery-popup-overlay.closetransitionend", options.closetransitionend)
+ },
+
+ /**
+ * Show method
+ *
+ * @param {object} el - popup instance DOM node
+ * @param {number} ordinal - order number of an `open` element
+ */
+ show: function (el, ordinal) {
+ var $el = $(el);
+
+ if ($el.data('popup-visible')) return;
+
+ // Initialize if not initialized. Required for: $('#popup').popup('show')
+ if (!$el.data('popup-initialized')) {
+ methods._init(el);
+ }
+ $el.attr('data-popup-initialized', 'true');
+
+ var $body = $('body');
+ var options = $el.data('popupoptions');
+ var $wrapper = $('#' + el.id + '_wrapper');
+ var $background = $('#' + el.id + '_background');
+
+ // `beforeopen` callback event
+ callback(el, ordinal, "beforeopen");
+
+ // Remember last clicked place
+ lastclicked[el.id] = ordinal;
+
+ if (options.detach) {
+ $wrapper.prepend(el);
+ $el.show();
+ } else {
+ $wrapper.show();
+ }
- setTimeout(function() {
$wrapper.css({
visibility: 'visible',
opacity: 1
@@ -249,28 +260,29 @@
$('html').addClass('popup_visible').addClass('popup_visible_' + el.id);
$el.addClass('popup_content_visible');
- }, 20);
- $el.css({
- 'visibility': 'visible',
- 'opacity': 1
- });
+ $el.css({
+ 'visibility': 'visible',
+ 'opacity': 1
+ });
- // Disable background layer scrolling when popup is opened
- if (options.scrolllock) {
- $body.css('overflow', 'hidden');
- if ($body.height() > $window.height()) {
- $body.css('margin-right', bodymarginright + scrollbarwidth);
+ // Disable background layer scrolling when popup is opened
+ if (options.scrolllock) {
+ $body.css('overflow', 'hidden');
+ if ($body.height() > $window.height()) {
+ $body.css('margin-right', bodymarginright + scrollbarwidth);
+ }
+
+ visibleScrollLocks++;
}
- }
- setTimeout(function () {
// Set event handlers
- if(!onevisible) {
+ if (!onevisible) {
if (options.keepfocus) {
$(document).on('focusin', focushandler)
- };
+ }
+ ;
if (options.blur) {
$(document).on('click', blurhandler);
@@ -287,209 +299,223 @@
} else {
oneormorevisible = true;
}
- }, 0);
- $el.data('popup-visible', true);
+ $el.data('popup-visible', true);
- // Position popup
- methods.reposition(el, ordinal);
+ // Position popup
+ methods.reposition(el, ordinal);
- // Show background
- if (options.background) {
- $background.css({
- 'visibility': 'visible',
- 'opacity': options.opacity
- });
+ // Show background
+ if (options.background) {
+ $background.css({
+ 'visibility': 'visible',
+ 'opacity': options.opacity
+ });
- // Fix IE8 issue with background not appearing
- setTimeout(function() {
$background.css({
'opacity': options.opacity
});
- }, 0);
- }
+ }
- // Remember which element had focus before opening a popup
- focusedelementbeforepopup = document.activeElement;
+ // Remember which element had focus before opening a popup
+ try {
+ focusedelementbeforepopup = document.activeElement;
+ }
+ catch (e) {
+ focusedelementbeforepopup = document.body;
+ }
- // Handler: Keep focus inside dialog box
- if (options.keepfocus) {
+ // Handler: Keep focus inside dialog box
+ if (options.keepfocus) {
- // Make holder div focusable
- $el.attr('tabindex', -1);
+ // Make holder div focusable
+ $el.attr('tabindex', -1);
- // Focus popup or user specified element.
- // Initial timeout of 50ms is set to give some time to popup to show after clicking on
- // `open` element, and after animation is complete to prevent background scrolling.
- setTimeout(function() {
+ // Focus popup or user specified element.
if (options.focuselement) {
$(options.focuselement).focus();
} else {
$el.focus();
}
- }, options.focusdelay);
-
- // Handler for keyboard focus
- focushandler = function(event) {
- var dialog = document.getElementById(el.id);
- if (!dialog.contains(event.target)) {
- event.stopPropagation();
- dialog.focus();
- }
- };
- }
- // Calculating maximum z-index
- if (options.autozindex) {
+ // Handler for keyboard focus
+ focushandler = function(event) {
+ var dialog = document.getElementById(el.id);
+ if (!dialog.contains(event.target)) {
+ event.stopPropagation();
+ dialog.focus();
+ }
+ };
+ }
- var elements = document.getElementsByTagName('*');
- var len = elements.length;
- var maxzindex = 0;
+ // Calculating maximum z-index
+ if (options.autozindex) {
- for(var i=0; i 0) {
- $wrapper.css({
- zIndex: (zindexvalues[el.id] + 2)
- });
- }
-
- // Add z-index to the background
- if (options.background) {
+ // Add z-index to the wrapper
if (zindexvalues[el.id] > 0) {
- $('#' + el.id + '_background').css({
- zIndex: (zindexvalues[el.id] + 1)
+ $wrapper.css({
+ zIndex: (zindexvalues[el.id] + 2)
});
}
- }
- }
- // Handler: Hide popup if clicked outside of it
- if (options.blur) {
- blurhandler = function (e) {
- if (!$(e.target).parents().andSelf().is('#' + el.id)) {
- methods.hide(el);
+ // Add z-index to the background
+ if (options.background) {
+ if (zindexvalues[el.id] > 0) {
+ $('#' + el.id + '_background').css({
+ zIndex: (zindexvalues[el.id] + 1)
+ });
+ }
}
- };
- }
+ }
- // Handler: Close popup on ESC key
- if (options.escape) {
- escapehandler = function (e) {
- if (e.keyCode == 27 && $el.data('popup-visible')) {
- methods.hide(el);
- }
- };
- }
+ // Handler: Hide popup if clicked outside of it
+ if (options.blur) {
+ blurhandler = function (e) {
+ if (!$(e.target).parents().andSelf().is('#' + el.id)) {
+ methods.hide(el);
+ }
+ };
+ }
- // Hide main content from screen readers
- $(options.pagecontainer).attr('aria-hidden', true);
+ // Handler: Close popup on ESC key
+ if (options.escape) {
+ escapehandler = function (e) {
+ if (e.keyCode == 27 && $el.data('popup-visible')) {
+ methods.hide(el);
+ }
+ };
+ }
- // Reveal popup content to screen readers
- $el.attr('aria-hidden', false);
+ // Hide main content from screen readers
+ $(options.pagecontainer).attr('aria-hidden', true);
- $wrapper.one('transitionend', function() {
- callback(el, ordinal, options.opentransitionend);
- });
+ // Reveal popup content to screen readers
+ $el.attr('aria-hidden', false);
- callback(el, ordinal, options.onopen);
- },
+ $wrapper.one('transitionend', function() {
+ callback(el, ordinal, "opentransitionend");
+ });
- /**
- * Hide method
- *
- * @param {object} el - popup instance DOM node
- */
- hide: function (el) {
-
- var $body = $('body');
- var $el = $(el);
- var options = $el.data('popupoptions');
- var $wrapper = $('#' + el.id + '_wrapper');
- var $background = $('#' + el.id + '_background');
-
- $el.data('popup-visible', false);
-
- if (oneormorevisible) {
- $('html').removeClass('popup_visible_' + el.id);
- oneormorevisible = false;
- } else {
- $('html').removeClass('popup_visible').removeClass('popup_visible_' + el.id);
- onevisible = false;
- }
+ callback(el, ordinal, "onopen");
+ },
+
+ /**
+ * Hide method
+ *
+ * @param {object} el - popup instance DOM node
+ */
+ hide: function (el) {
+ //debugger;
+ var $body = $('body');
+ var $el = $(el);
+ var options = $el.data('popupoptions');
+ var $wrapper = $('#' + el.id + '_wrapper');
+ var $background = $('#' + el.id + '_background');
- $el.removeClass('popup_content_visible');
+ $el.data('popup-visible', false);
+
+ if (oneormorevisible) {
+ $('html').removeClass('popup_visible_' + el.id);
+ oneormorevisible = false;
+ } else {
+ $('html').removeClass('popup_visible').removeClass('popup_visible_' + el.id);
+ onevisible = false;
+ }
+
+ $el.removeClass('popup_content_visible');
+
+ // Re-enable scrolling of background layer
+ if (options.scrolllock && --visibleScrollLocks <= 0) {
- // Re-enable scrolling of background layer
- if (options.scrolllock) {
- setTimeout(function() {
$body.css({
overflow: 'visible',
'margin-right': bodymarginright
});
- }, 10); // 10ms added for CSS transition in Firefox which doesn't like overflow:auto
- }
+ }
- // Unbind blur handler
- if (options.blur) {
- $(document).off('click', blurhandler);
- }
+ // Unbind blur handler
+ if (options.blur) {
+ $(document).off('click', blurhandler);
+ }
- if (options.keepfocus) {
+ if (options.keepfocus) {
- // Unbind focus handler
- $(document).off('focusin', focushandler);
+ // Unbind focus handler
+ $(document).off('focusin', focushandler);
- // Focus back on saved element
- setTimeout(function() {
+ // Focus back on saved element
if ($(focusedelementbeforepopup).is(':visible')) {
focusedelementbeforepopup.focus();
}
- }, 0);
- }
-
- // Unbind ESC key handler
- if (options.escape) {
- $(document).off('keydown', escapehandler);
- }
+ }
- // Hide popup
- $wrapper.css({
- 'visibility': 'hidden',
- 'opacity': 0
- });
- $el.css({
- 'visibility': 'hidden',
- 'opacity': 0
- });
+ // Unbind ESC key handler
+ if (options.escape) {
+ $(document).off('keydown', escapehandler);
+ }
- // Hide background
- if (options.background) {
- $background.css({
+ // Hide popup
+ $wrapper.css({
+ 'visibility': 'hidden',
+ 'opacity': 0
+ });
+ $el.css({
'visibility': 'hidden',
'opacity': 0
});
- }
- // After closing CSS transition is over... (if transition is set and supported)
- $el.one('transitionend', function(e) {
+ // Hide background
+ if (options.background) {
+ $background.css({
+ 'visibility': 'hidden',
+ 'opacity': 0
+ });
+
+ // After background closing CSS transition is over... (if transition is set and supported)
+ $background.one('transitionend', function(e) {
+ if (!options.notransitiondetach) {
+ callback(el, lastclicked[el.id], "backgroundclosetransitionend");
+ }
+ });
+ }
+
+ // After closing CSS transition is over... (if transition is set and supported)
+ $el.one('transitionend', function(e) {
+
+ if (!($el.data('popup-visible'))) {
+ if (options.detach) {
+ $el.hide().detach();
+ } else {
+ $wrapper.hide();
+ }
+ }
+
+ if (!options.notransitiondetach) {
+ callback(el, lastclicked[el.id], "closetransitionend");
+ }
+ });
- if (!($el.data('popup-visible'))) {
+ if (options.notransitiondetach) {
if (options.detach) {
$el.hide().detach();
} else {
@@ -497,196 +523,183 @@
}
}
- if (!options.notransitiondetach) {
- callback(el, lastclicked[el.id], options.closetransitionend);
- }
- });
+ // Reveal main content to screen readers
+ $(options.pagecontainer).attr('aria-hidden', false);
- if (options.notransitiondetach) {
- if (options.detach) {
- $el.hide().detach();
+ // Hide popup content from screen readers
+ $el.attr('aria-hidden', true);
+
+ if(!options.transitions)
+ callback(el, lastclicked[el.id], "closetransitionend");
+
+ // `onclose` callback event
+ callback(el, lastclicked[el.id], "onclose");
+ },
+
+ /**
+ * Toggle method
+ *
+ * @param {object} el - popup instance DOM node
+ * @param {number} ordinal - order number of an `open` element
+ */
+ toggle: function (el, ordinal) {
+ if ($el.data('popup-visible')) {
+ methods.hide(el);
} else {
- $wrapper.hide();
+ methods.show(el, ordinal);
}
- }
+ },
+
+ /**
+ * Reposition method
+ *
+ * @param {object} el - popup instance DOM node
+ * @param {number} ordinal - order number of an `open` element
+ */
+ reposition: function (el, ordinal) {
+ var $el = $(el);
+ var options = $el.data('popupoptions');
+ var $wrapper = $('#' + el.id + '_wrapper');
+ var $background = $('#' + el.id + '_background');
- // Reveal main content to screen readers
- $(options.pagecontainer).attr('aria-hidden', false);
+ ordinal = ordinal || 0;
- // Hide popup content from screen readers
- $el.attr('aria-hidden', true);
+ // Tooltip type
+ if (options.type == 'tooltip') {
+ $wrapper.css({
+ 'position': 'absolute'
+ });
+ var openelement = (options.openelement) ? options.openelement : ('.' + el.id + opensuffix);
+ var $elementclicked = $(openelement + '[data-popup-ordinal="' + ordinal + '"]');
+ var linkOffset = $elementclicked.offset();
+
+ // Horizontal position for tooltip
+ if (options.horizontal == 'right') {
+ $wrapper.css('left', linkOffset.left + $elementclicked.outerWidth() + options.offsetleft);
+ } else if (options.horizontal == 'leftedge') {
+ $wrapper.css('left', linkOffset.left + $elementclicked.outerWidth() - $elementclicked.outerWidth() + options.offsetleft);
+ } else if (options.horizontal == 'left') {
+ $wrapper.css('right', $(window).width() - linkOffset.left - options.offsetleft);
+ } else if (options.horizontal == 'rightedge') {
+ $wrapper.css('right', $(window).width() - linkOffset.left - $elementclicked.outerWidth() - options.offsetleft);
+ } else {
+ $wrapper.css('left', linkOffset.left + ($elementclicked.outerWidth() / 2) - ($el.outerWidth() / 2) - parseFloat($el.css('marginLeft')) + options.offsetleft);
+ }
- // `onclose` callback event
- callback(el, lastclicked[el.id], options.onclose);
- },
+ // Vertical position for tooltip
+ if (options.vertical == 'bottom') {
+ $wrapper.css('top', linkOffset.top + $elementclicked.outerHeight() + options.offsettop);
+ } else if (options.vertical == 'bottomedge') {
+ $wrapper.css('top', linkOffset.top + $elementclicked.outerHeight() - $el.outerHeight() + options.offsettop);
+ } else if (options.vertical == 'top') {
+ $wrapper.css('bottom', $(window).height() - linkOffset.top - options.offsettop);
+ } else if (options.vertical == 'topedge') {
+ $wrapper.css('bottom', $(window).height() - linkOffset.top - $el.outerHeight() - options.offsettop);
+ } else {
+ $wrapper.css('top', linkOffset.top + ($elementclicked.outerHeight() / 2) - ($el.outerHeight() / 2) - parseFloat($el.css('marginTop')) + options.offsettop);
+ }
- /**
- * Toggle method
- *
- * @param {object} el - popup instance DOM node
- * @param {number} ordinal - order number of an `open` element
- */
- toggle: function (el, ordinal) {
- if ($el.data('popup-visible')) {
- methods.hide(el);
- } else {
- setTimeout(function() {
- methods.show(el, ordinal);
- }, 0);
+ // Overlay type
+ } else if (options.type == 'overlay') {
+
+ // Horizontal position for overlay
+ if (options.horizontal) {
+ $wrapper.css('text-align', options.horizontal);
+ } else {
+ $wrapper.css('text-align', 'center');
+ }
+
+ // Vertical position for overlay
+ if (options.vertical) {
+ $el.css('vertical-align', options.vertical);
+ } else {
+ $el.css('vertical-align', 'middle');
+ }
+ }
}
- },
+
+ };
/**
- * Reposition method
+ * Callback event calls
*
* @param {object} el - popup instance DOM node
* @param {number} ordinal - order number of an `open` element
+ * @param {string} event - event name
*/
- reposition: function (el, ordinal) {
- var $el = $(el);
- var options = $el.data('popupoptions');
- var $wrapper = $('#' + el.id + '_wrapper');
- var $background = $('#' + el.id + '_background');
-
- ordinal = ordinal || 0;
-
- // Tooltip type
- if (options.type == 'tooltip') {
- $wrapper.css({
- 'position': 'absolute'
- });
- var openelement = (options.openelement) ? options.openelement : ('.' + el.id + opensuffix);
- var $elementclicked = $(openelement + '[data-popup-ordinal="' + ordinal + '"]');
- var linkOffset = $elementclicked.offset();
-
- // Horizontal position for tooltip
- if (options.horizontal == 'right') {
- $wrapper.css('left', linkOffset.left + $elementclicked.outerWidth() + options.offsetleft);
- } else if (options.horizontal == 'leftedge') {
- $wrapper.css('left', linkOffset.left + $elementclicked.outerWidth() - $elementclicked.outerWidth() + options.offsetleft);
- } else if (options.horizontal == 'left') {
- $wrapper.css('right', $(window).width() - linkOffset.left - options.offsetleft);
- } else if (options.horizontal == 'rightedge') {
- $wrapper.css('right', $(window).width() - linkOffset.left - $elementclicked.outerWidth() - options.offsetleft);
- } else {
- $wrapper.css('left', linkOffset.left + ($elementclicked.outerWidth() / 2) - ($el.outerWidth() / 2) - parseFloat($el.css('marginLeft')) + options.offsetleft);
- }
-
- // Vertical position for tooltip
- if (options.vertical == 'bottom') {
- $wrapper.css('top', linkOffset.top + $elementclicked.outerHeight() + options.offsettop);
- } else if (options.vertical == 'bottomedge') {
- $wrapper.css('top', linkOffset.top + $elementclicked.outerHeight() - $el.outerHeight() + options.offsettop);
- } else if (options.vertical == 'top') {
- $wrapper.css('bottom', $(window).height() - linkOffset.top - options.offsettop);
- } else if (options.vertical == 'topedge') {
- $wrapper.css('bottom', $(window).height() - linkOffset.top - $el.outerHeight() - options.offsettop);
- } else {
- $wrapper.css('top', linkOffset.top + ($elementclicked.outerHeight() / 2) - ($el.outerHeight() / 2) - parseFloat($el.css('marginTop')) + options.offsettop);
- }
-
- // Overlay type
- } else if (options.type == 'overlay') {
-
- // Horizontal position for overlay
- if (options.horizontal) {
- $wrapper.css('text-align', options.horizontal);
- } else {
- $wrapper.css('text-align', 'center');
- }
+ var callback = function (el, ordinal, event) {
+ var openelement = (options.openelement) ? options.openelement : ('.' + el.id + opensuffix);
+ var elementclicked = $(openelement + '[data-popup-ordinal="' + ordinal + '"]');
+ $(el).trigger("jquery-popup-overlay." + event, [elementclicked]);
+ };
- // Vertical position for overlay
- if (options.vertical) {
- $el.css('vertical-align', options.vertical);
- } else {
- $el.css('vertical-align', 'middle');
- }
- }
- }
+ /**
+ * Plugin API
+ */
+ $.fn.popup = function (customoptions) {
+ return this.each(function () {
- };
+ $el = $(this);
- /**
- * Callback event calls
- *
- * @param {object} el - popup instance DOM node
- * @param {number} ordinal - order number of an `open` element
- * @param {function} func - callback function
- */
- var callback = function (el, ordinal, func) {
- var openelement = (options.openelement) ? options.openelement : ('.' + el.id + opensuffix);
- var elementclicked = $(openelement + '[data-popup-ordinal="' + ordinal + '"]');
- if (typeof func == 'function') {
- func(elementclicked);
- }
- };
-
- /**
- * Plugin API
- */
- $.fn.popup = function (customoptions) {
- return this.each(function () {
+ if (typeof customoptions === 'object') { // e.g. $('#popup').popup({'color':'blue'})
+ var opt = $.extend({}, $.fn.popup.defaults, customoptions);
+ $el.data('popupoptions', opt);
+ options = $el.data('popupoptions');
- $el = $(this);
+ methods._init(this);
- if (typeof customoptions === 'object') { // e.g. $('#popup').popup({'color':'blue'})
- var opt = $.extend({}, $.fn.popup.defaults, customoptions);
- $el.data('popupoptions', opt);
- options = $el.data('popupoptions');
+ } else if (typeof customoptions === 'string') { // e.g. $('#popup').popup('hide')
+ if (!($el.data('popupoptions'))) {
+ $el.data('popupoptions', $.fn.popup.defaults);
+ options = $el.data('popupoptions');
+ }
- methods._init(this);
+ methods[customoptions].call(this, this);
- } else if (typeof customoptions === 'string') { // e.g. $('#popup').popup('hide')
- if (!($el.data('popupoptions'))) {
- $el.data('popupoptions', $.fn.popup.defaults);
- options = $el.data('popupoptions');
- }
+ } else { // e.g. $('#popup').popup()
+ if (!($el.data('popupoptions'))) {
+ $el.data('popupoptions', $.fn.popup.defaults);
+ options = $el.data('popupoptions');
+ }
- methods[customoptions].call(this, this);
+ methods._init(this);
- } else { // e.g. $('#popup').popup()
- if (!($el.data('popupoptions'))) {
- $el.data('popupoptions', $.fn.popup.defaults);
- options = $el.data('popupoptions');
}
- methods._init(this);
-
- }
-
- });
- };
-
- $.fn.popup.defaults = {
- type: 'overlay',
- autoopen: false,
- background: true,
- color: 'black',
- opacity: '0.5',
- horizontal: 'center',
- vertical: 'middle',
- offsettop: 0,
- offsetleft: 0,
- escape: true,
- blur: true,
- setzindex: true,
- autozindex: false,
- scrolllock: false,
- keepfocus: true,
- focuselement: null,
- focusdelay: 50,
- outline: false,
- pagecontainer: null,
- detach: false,
- openelement: null,
- closeelement: null,
- transition: null,
- notransitiondetach: false,
- beforeopen: function(){},
- onclose: function(){},
- onopen: function(){},
- opentransitionend: function(){},
- closetransitionend: function(){}
- };
-
-})(jQuery);
\ No newline at end of file
+ });
+ };
+
+ $.fn.popup.defaults = {
+ type: 'overlay',
+ autoopen: false,
+ background: true,
+ color: 'black',
+ opacity: '0.5',
+ horizontal: 'center',
+ vertical: 'middle',
+ offsettop: 0,
+ offsetleft: 0,
+ escape: true,
+ blur: true,
+ setzindex: true,
+ autozindex: false,
+ scrolllock: false,
+ keepfocus: true,
+ focuselement: null,
+ focusdelay: 50,
+ outline: false,
+ pagecontainer: null,
+ detach: false,
+ openelement: null,
+ closeelement: null,
+ transition: null,
+ notransitiondetach: false,
+ beforeopen: function(){},
+ onclose: function(){},
+ onopen: function(){},
+ opentransitionend: function(){},
+ closetransitionend: function(){},
+ transitions: true
+ };
+
+ })(jQuery);
diff --git a/package.json b/package.json
index efbb37e..20a23af 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jquery-popup-overlay",
- "version": "1.6.0",
+ "version": "1.7.1",
"description": "Lightweight modal popup overlay for jquery",
"main": "index.js",
"scripts": {