Commit 45609544 authored by Robert Speicher's avatar Robert Speicher

Move jQuery enable/disable extensions to extensions/jquery

Removes redundant enableButton/disableButton extensions, and adds specs
for the jQuery extensions.
parent 2313d42b
......@@ -196,14 +196,3 @@ $ ->
new ConfirmDangerModal(form, text)
new Aside()
(($) ->
# Disable an element and add the 'disabled' Bootstrap class
$.fn.extend disable: ->
$(@).attr('disabled', 'disabled').addClass('disabled')
# Enable an element and remove the 'disabled' Bootstrap class
$.fn.extend enable: ->
$(@).removeAttr('disabled').removeClass('disabled')
)(jQuery)
......@@ -3,11 +3,14 @@ $.fn.showAndHide = ->
delay(3000).
fadeOut()
$.fn.enableButton = ->
$(@).removeAttr('disabled').
removeClass('disabled')
$.fn.disableButton = ->
$(@).attr('disabled', 'disabled').
addClass('disabled')
# Disable an element and add the 'disabled' Bootstrap class
$.fn.extend disable: ->
$(@)
.attr('disabled', 'disabled')
.addClass('disabled')
# Enable an element and remove the 'disabled' Bootstrap class
$.fn.extend enable: ->
$(@)
.removeAttr('disabled')
.removeClass('disabled')
......@@ -12,11 +12,11 @@ class @Profile
$(this).find('.update-failed').hide()
$('.update-username form').on 'ajax:complete', ->
$(this).find('.btn-save').enableButton()
$(this).find('.btn-save').enable()
$(this).find('.loading-gif').hide()
$('.update-notifications').on 'ajax:complete', ->
$(this).find('.btn-save').enableButton()
$(this).find('.btn-save').enable()
$('.js-choose-user-avatar-button').bind "click", ->
......
......@@ -6,4 +6,4 @@
$(".project-edit-errors").html("#{escape_javascript(render('errors'))}");
$('.save-project-loader').hide();
$('.project-edit-container').show();
$('.project-edit-content .btn-save').enableButton();
$('.project-edit-content .btn-save').enable();
#= require extensions/jquery
describe 'jQuery extensions', ->
describe 'disable', ->
beforeEach ->
fixture.set '<input type="text" />'
it 'adds the disabled attribute', ->
$input = $('input').first()
$input.disable()
expect($input).toHaveAttr('disabled', 'disabled')
it 'adds the disabled class', ->
$input = $('input').first()
$input.disable()
expect($input).toHaveClass('disabled')
describe 'enable', ->
beforeEach ->
fixture.set '<input type="text" disabled="disabled" class="disabled" />'
it 'removes the disabled attribute', ->
$input = $('input').first()
$input.enable()
expect($input).not.toHaveAttr('disabled')
it 'removes the disabled class', ->
$input = $('input').first()
$input.enable()
expect($input).not.toHaveClass('disabled')
# Teaspoon includes some support files, but you can use anything from your own
# support path too.
# require support/jasmine-jquery-1.7.0
# require support/jasmine-jquery-2.0.0
# require support/jasmine-jquery-2.1.0
# require support/sinon
# require support/your-support-file
# PhantomJS (Teaspoons default driver) doesn't have support for
# Function.prototype.bind, which has caused confusion. Use this polyfill to
# avoid the confusion.
......@@ -21,6 +12,15 @@
#= require bootstrap
#= require underscore
# Teaspoon includes some support files, but you can use anything from your own
# support path too.
# require support/jasmine-jquery-1.7.0
# require support/jasmine-jquery-2.0.0
#= require support/jasmine-jquery-2.1.0
# require support/sinon
# require support/your-support-file
# Deferring execution
# If you're using CommonJS, RequireJS or some other asynchronous library you can
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment