Skip to content

Commit

Permalink
Added $.modal.resize(). All it does at the moment is re-centre the mo…
Browse files Browse the repository at this point in the history
…dal (because there is no fixed height on the modal, it will stretch vertically).
  • Loading branch information
kylefox committed Nov 16, 2010
1 parent a49bf8c commit b191b8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ <h2>Example 3: resizing</h2>

$('#more').click(function() {
$(this).parent().after($(this).parent().next().clone());
// $('#ex3').modal.center();
$('#ex3').modal.resize();
return false;
});

Expand Down
26 changes: 17 additions & 9 deletions jquery.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,12 @@
}

function show() {
$elm.css({
position: 'fixed',
top: "50%",
left: "50%",
marginTop: - ($elm.height() / 2),
marginLeft: - ($elm.outerWidth() / 2),
zIndex: options.zIndex + 1
});
center_modal(current_modal);
$elm.addClass(options.modalClass).addClass('current').show();
$elm.trigger($.fn.modal.OPEN, [current_modal]);
}

current_modal = {elm: $elm};
current_modal = {elm: $elm, options: options};
$elm.trigger($.fn.modal.BEFORE_BLOCK, [current_modal]);
block();
$elm.trigger($.fn.modal.BEFORE_OPEN, [current_modal]);
Expand Down Expand Up @@ -85,12 +78,27 @@
current_modal.elm.hide();
$(document).trigger($.fn.modal.CLOSE, [null]);
};

$.fn.modal.resize = function() {
center_modal(current_modal);
};

function open_modal_from_link(event) {
event.preventDefault();
$($(this).attr('href')).modal();
}

function center_modal(modal) {
modal.elm.css({
position: 'fixed',
top: "50%",
left: "50%",
marginTop: - (modal.elm.height() / 2),
marginLeft: - (modal.elm.outerWidth() / 2),
zIndex: modal.options.zIndex + 1
});
};

// Automatically bind links with rel="modal:close" to, well, close the modal.
$('a[rel="modal:open"]').live('click', open_modal_from_link);
$('a[rel="modal:close"]').live('click', $.fn.modal.close);
Expand Down

0 comments on commit b191b8c

Please sign in to comment.