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

prevent navigating to area href when modal target #20462

Merged
merged 1 commit into from
Nov 26, 2016
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ const Modal = (($) => {
let config = $(target).data(DATA_KEY) ?
'toggle' : $.extend({}, $(target).data(), $(this).data())

if (this.tagName === 'A') {
if (this.tagName === 'A' || this.tagName === 'AREA') {
event.preventDefault()
}

Expand Down
22 changes: 22 additions & 0 deletions js/tests/unit/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,26 @@ $(function () {
})
.bootstrapModal('show')
})

QUnit.test('should not follow link in area tag', function (assert) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'QUnit' is not defined no-undef
Unexpected function expression prefer-arrow-callback

assert.expect(2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No magic number: 2 no-magic-numbers

var done = assert.async()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected var, use let or const instead no-var


$('<map><area id="test" shape="default" data-toggle="modal" data-target="#modal-test" href="demo.html"/></map>')
.appendTo('#qunit-fixture')

$('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>')
.appendTo('#qunit-fixture')

$('#test')
.on('click.bs.modal.data-api', function (event) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected function expression prefer-arrow-callback

assert.notOk(event.isDefaultPrevented(), 'navigating to href will happen')

setTimeout(function () {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected function expression prefer-arrow-callback

assert.ok(event.isDefaultPrevented(), 'model shown instead of navigating to href')
done()
}, 1)
})
.trigger('click')
})
})