Skip to content

Commit

Permalink
Merge pull request #2 from perfectsense/feature/retain-opener-node
Browse files Browse the repository at this point in the history
Modal now retains a reference to its opener node
  • Loading branch information
jpencola authored Sep 27, 2016
2 parents 024cdf6 + 2dcb7b9 commit 73d777e
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/js/bsp-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@ var bsp_modal = {
var self = this;

$('[data-bsp-modal-open=' + self.settings.id + ']').on('click', function() {
// if we have a anchor link, let that through
if($(this).attr('href').indexOf('#') === 0) {
self._openFromDOM({
'hash' : $(this).attr('href')
});
} else {
self._openFromDOM();
}
self._openFromDOM(this);

return false;
});
Expand Down Expand Up @@ -135,17 +128,22 @@ var bsp_modal = {
// private function to open modal from the DOM. Calls the vex open method, but also sets up
// the centering and passes though the events. Lastly, upon close, it puts everything back the
// way it founded, leaving the DOM intact
_openFromDOM: function(options) {
_openFromDOM: function(opener) {
var self = this;
// just in case no options are passed in
options = options || {};
// grab the modal data within that element
var $modalData = self.$el.find('.modal-data').contents();
// save it off, we're going to need to put it back
var $savedContents = $modalData.clone();

if(options.hash) {
window.location.hash = options.hash;
// if opened by a DOM element
if(opener) {
var $opener = $(opener);
var href = $opener.attr('href');
// if we have a anchor link, let that through
if(href && href.indexOf('#') === 0) {
window.location.hash = href;
}
self.$opener = $opener;
}

vex.defaultOptions.className = 'modal-theme-' + self.settings.theme + ' modal-' + self.settings.id;
Expand Down

0 comments on commit 73d777e

Please sign in to comment.