Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fixedposition option #86

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 83 additions & 12 deletions jquery.popupoverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
options.background = false;
options.scrolllock = false;
}
if (options.fixedposition) {
options.backgroundactive = true;
}

if (options.backgroundactive) {
options.background = false;
Expand Down Expand Up @@ -156,7 +159,7 @@
if (options.type == 'overlay') {
$el.css({
textAlign: 'left',
position: 'relative',
position: options.fixedposition ? 'fixed' : 'relative',
verticalAlign: 'middle'
});

Expand Down Expand Up @@ -241,6 +244,22 @@
} else {
$wrapper.hide();
}

//we save the initial margins
$el.data('margins', {
top : $el.css('margin-top'),
bottom : $el.css('margin-bottom'),
left : $el.css('margin-left'),
right : $el.css('margin-right'),
});

if (options.backgroundactive &&
(options.horizontal == 'center' || options.vertical != 'top')) {
//we add a resize listner to resize the popup
$(window).resize(function() {
methods.show(el, undefined, true);
});
}
},

/**
Expand All @@ -249,10 +268,11 @@
* @param {object} el - popup instance DOM node
* @param {number} ordinal - order number of an `open` element
*/
show: function (el, ordinal) {
show: function (el, ordinal, resize) {
var $el = $(el);

if ($el.data('popup-visible')) return;
if ($el.data('popup-visible') && !resize) return;
if (!$el.data('popup-visible') && resize) return;

// Initialize if not initialized. Required for: $('#popup').popup('show')
if (!$el.data('popup-initialized')) {
Expand Down Expand Up @@ -343,15 +363,65 @@

if(options.backgroundactive){
//calculates the vertical align
$el.css({
top:(
$window.height() - (
$el.get(0).offsetHeight +
parseInt($el.css('margin-top'), 10) +
parseInt($el.css('margin-bottom'), 10)
)
)/2 +'px'
});
if (options.vertical == 'bottom') {
if (options.fixedposition) {
$el.css({
bottom:0
});
} else {
$el.css({
top:(
$window.height() - (
$el.get(0).offsetHeight +
parseInt($el.css('margin-top'), 10) +
parseInt($el.css('margin-bottom'), 10)
)
) +'px'
});
}
} else if (options.vertical == 'top') {
$el.css({
top:0
});
} else {
$el.css({
top:(
$window.height() - (
$el.get(0).offsetHeight +
parseInt($el.css('margin-top'), 10) +
parseInt($el.css('margin-bottom'), 10)
)
)/2 +'px'
});
}
if (options.fixedposition) {
if (options.horizontal == "left") {
$el.css({
'left':0
});
} else if (options.horizontal == "right") {
$el.css({
'right':0
});
} else {
//reset before calculate outerWidth
$el.css({
'margin-left' : $el.data('margins').left,
'margin-right' : $el.data('margins').right,
'position': 'relative',
'width':'auto'
});
var outerWidth = $el.outerWidth();
//calculates the left margin to center horizontaly
$el.css({
'margin-left' : -(outerWidth/2) +'px',
'margin-right' : (outerWidth*3/4) +'px',
'left':'50%',
'width' : outerWidth,
'position': 'fixed'
});
}
}
}

$el.css({
Expand Down Expand Up @@ -816,6 +886,7 @@
autoopen: false,
background: true,
backgroundactive: false,
fixedposition: false,
color: 'black',
opacity: '0.5',
horizontal: 'center',
Expand Down