Prevent default disabled buttons and links.

This commit is contained in:
Fatih Acet 2016-06-15 00:15:46 +03:00 committed by Jacob Schatz
parent 93a496d270
commit 415b032ba1
5 changed files with 41 additions and 0 deletions

View File

@ -77,6 +77,7 @@ v 8.9.0 (unreleased)
- RepositoryCheck::SingleRepositoryWorker public and private methods are now instrumented
- Improve issuables APIs performance when accessing notes !4471
- External links now open in a new tab
- Prevent default actions of disabled buttons and links
- Markdown editor now correctly resets the input value on edit cancellation !4175
- Toggling a task list item in a issue/mr description does not creates a Todo for mentions
- Improved UX of date pickers on issue & milestone forms

View File

@ -125,6 +125,7 @@ window.onload = ->
setTimeout shiftWindow, 100
$ ->
gl.utils.preventDisabledButtons()
bootstrapBreakpoint = bp.getBreakpointSize()
$(".nicescroll").niceScroll(cursoropacitymax: '0.4', cursorcolor: '#FFF', cursorborder: "1px solid #FFF")

View File

@ -32,5 +32,12 @@
.attr 'title', newTitle
.tooltip 'fixTitle'
gl.utils.preventDisabledButtons = ->
$('.btn').click (e) ->
if $(this).hasClass 'disabled'
e.preventDefault()
e.stopImmediatePropagation()
return false
) window

View File

@ -0,0 +1,30 @@
#= require lib/common_utils
describe 'Application', ->
describe 'disable buttons', ->
fixture.preload('application.html')
beforeEach ->
fixture.load('application.html')
it 'should prevent default action for disabled buttons', ->
gl.utils.preventDisabledButtons()
isClicked = false
$button = $ '#test-button'
$button.click -> isClicked = true
$button.trigger 'click'
expect(isClicked).toBe false
it 'should be on the same page if a disabled link clicked', ->
locationBeforeLinkClick = window.location.href
gl.utils.preventDisabledButtons()
$('#test-link').click()
expect(window.location.href).toBe locationBeforeLinkClick

View File

@ -0,0 +1,2 @@
%a#test-link.btn.disabled{:href => "/foo"} Test link
%button#test-button.btn.disabled Test Button