?
avatar Paladin
Paladin
9 Mar 2016

This is a bit complex to reproduce but it just bit me:

Given:
1) a link on the front-end that triggers a bootstrap modal, such as:

link text

(I'll parse that, to save time: the "data-toggle" attribute sets it up so this link opens a modal dialog box containing the element with the ID "license-modal" which is located elsewhere in the page markup and which has been hidden by the initialization of the modal)

2) javascript that tries to reference this link upon opening the modal (I'm stripping this down as much as possible to simplify it):

(function($) {
$(document).ready( function () {
$("#license-modal").on('show.bs.modal', function (event, "a.continue") {
var button = $(event.relatedTarget)

});

});
})(jQuery);

(Again to save time and energy: when the document is ready set up the bootstrap show event handler, and when the "#license-modal" dialog is shown, get the element that was clicked to cause the event and do something involving it. If you want a quickie test case, this js should work for that, just replace the "var button" line with an alert showing event.relatedTarget -- undefined == bug. Should work so long as you have a properly marked-up bootstrap modal in the page, so long as you change the "license-modal" to the id of whatever modal is in the page.)

Expectation:
the variable event.relatedTarget is supposed to contain the element clicked that opened the modal, as per http://getbootstrap.com/javascript/#modals-events. I verified this behavior by replacing the media/jui/js/bootstrap.js file with the "real" bootstrap.js file from the bootstrap CDN. When using that file, the code performs as expected.

Actually:
When using Joomla's version of the bootstrap.js file, the variable event.relatedTarget is undefined. When using the js directly from the bootstrap CDN, the event.relatedTarget variable has the clicked element in it.

Environment:
Joomla 3.4.8
CentOS 7
PHP 5.6.16
Apache 2.4.17 (using fpm, not mod_php)

Commentary:
The ability to know the click that opened the modal is useful for those times when the modal needs to change slightly depending upon the click. In the particular use-case that bit me, the modal was a bit of boilerplate surrounding a link to file. Same boilerplate, but could be one of several links, so the actual link url was carried in the "data-link" attribute of the originating link, looked up by the "open" event handler and inserted into the resulting modal.

The effect of this gets complicated by the fact that when the bootstrap CDN js is included, form tooltips do not work properly, effectively making one choose between having tooltips or being able to know what click opened the modal.

avatar Paladin Paladin - open - 9 Mar 2016
avatar mbabker
mbabker - comment - 9 Mar 2016

Are you comparing the right Bootstrap versions? That variable is indeed in Bootstrap 3.3.6 but not in 2.3.2 which is what core ships.

avatar Paladin
Paladin - comment - 9 Mar 2016

Ah, the core file that was loaded didn't have a version in it so I didn't know. It just said "custom version for Joomla" not what 'real' version it was based on. OK, then, that explains it not being there. Knock that one off my to-do list, I'll just ignore the core version completely. Now all I need to work on is how to make tooltips work in a useful version of bootstrap. Thanks Mike, I'll close this issue on the way out.

avatar Paladin Paladin - change - 9 Mar 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-03-09 16:26:45
Closed_By Paladin
avatar Paladin Paladin - close - 9 Mar 2016
avatar brianteeman brianteeman - close - 9 Mar 2016
avatar brianteeman brianteeman - change - 22 Apr 2016
Labels Added: ?

Add a Comment

Login with GitHub to post a comment