Commit 46921e690ec95fdfb4c38ea1a2dd65261719ba23

Authored by Nihad Abbasov
1 parent b1ef7d7a

cleanup main.coffee

Showing 1 changed file with 16 additions and 16 deletions   Show diff stats
app/assets/javascripts/main.js.coffee
@@ -7,7 +7,7 @@ window.slugify = (text) -> @@ -7,7 +7,7 @@ window.slugify = (text) ->
7 window.ajaxGet = (url) -> 7 window.ajaxGet = (url) ->
8 $.ajax({type: "GET", url: url, dataType: "script"}) 8 $.ajax({type: "GET", url: url, dataType: "script"})
9 9
10 - # Disable button if text field is empty 10 +# Disable button if text field is empty
11 window.disableButtonIfEmptyField = (field_selector, button_selector) -> 11 window.disableButtonIfEmptyField = (field_selector, button_selector) ->
12 field = $(field_selector) 12 field = $(field_selector)
13 closest_submit = field.closest("form").find(button_selector) 13 closest_submit = field.closest("form").find(button_selector)
@@ -15,21 +15,21 @@ window.disableButtonIfEmptyField = (field_selector, button_selector) -> @@ -15,21 +15,21 @@ window.disableButtonIfEmptyField = (field_selector, button_selector) ->
15 closest_submit.disable() if field.val() is "" 15 closest_submit.disable() if field.val() is ""
16 16
17 field.on "keyup", -> 17 field.on "keyup", ->
18 - if $(this).val() is "" 18 + if $(@).val() is ""
19 closest_submit.disable() 19 closest_submit.disable()
20 else 20 else
21 closest_submit.enable() 21 closest_submit.enable()
22 22
23 $ -> 23 $ ->
24 # Click a .one_click_select field, select the contents 24 # Click a .one_click_select field, select the contents
25 - $(".one_click_select").live 'click', -> $(this).select() 25 + $(".one_click_select").on 'click', -> $(@).select()
26 26
27 # Initialize chosen selects 27 # Initialize chosen selects
28 $('select.chosen').chosen() 28 $('select.chosen').chosen()
29 29
30 # Disable form buttons while a form is submitting 30 # Disable form buttons while a form is submitting
31 $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) -> 31 $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) ->
32 - buttons = $('[type="submit"]', this) 32 + buttons = $('[type="submit"]', @)
33 33
34 switch e.type 34 switch e.type
35 when 'ajax:beforeSend', 'submit' 35 when 'ajax:beforeSend', 'submit'
@@ -38,7 +38,7 @@ $ -> @@ -38,7 +38,7 @@ $ ->
38 buttons.enable() 38 buttons.enable()
39 39
40 # Show/Hide the profile menu when hovering the account box 40 # Show/Hide the profile menu when hovering the account box
41 - $('.account-box').hover -> $(this).toggleClass('hover') 41 + $('.account-box').hover -> $(@).toggleClass('hover')
42 42
43 # Focus search field by pressing 's' key 43 # Focus search field by pressing 's' key
44 $(document).keypress (e) -> 44 $(document).keypress (e) ->
@@ -52,22 +52,22 @@ $ -> @@ -52,22 +52,22 @@ $ ->
52 52
53 # Commit show suppressed diff 53 # Commit show suppressed diff
54 $(".supp_diff_link").bind "click", -> 54 $(".supp_diff_link").bind "click", ->
55 - $(this).next('table').show()  
56 - $(this).remove() 55 + $(@).next('table').show()
  56 + $(@).remove()
57 57
58 # Note markdown preview 58 # Note markdown preview
59 $(document).on 'click', '#preview-link', (e) -> 59 $(document).on 'click', '#preview-link', (e) ->
60 - $('#preview-note').text('Loading...') 60 + $('#preview-note').text 'Loading...'
61 61
62 - previewLinkText = if $(this).text() == 'Preview' then 'Edit' else 'Preview'  
63 - $(this).text(previewLinkText) 62 + previewLinkText = if $(@).text() is 'Preview' then 'Edit' else 'Preview'
  63 + $(@).text previewLinkText
64 64
65 note = $('#note_note').val() 65 note = $('#note_note').val()
66 66
67 - if note.trim().length == 0  
68 - $('#preview-note').text("Nothing to preview.") 67 + if note.trim().length is 0
  68 + $('#preview-note').text 'Nothing to preview.'
69 else 69 else
70 - $.post $(this).attr('href'), {note: note}, (data) -> 70 + $.post $(@).attr('href'), {note: note}, (data) ->
71 $('#preview-note').html(data) 71 $('#preview-note').html(data)
72 72
73 $('#preview-note, #note_note').toggle() 73 $('#preview-note, #note_note').toggle()
@@ -79,14 +79,14 @@ $ -> @@ -79,14 +79,14 @@ $ ->
79 $.fn.extend chosen: (options) -> 79 $.fn.extend chosen: (options) ->
80 default_options = search_contains: "true" 80 default_options = search_contains: "true"
81 $.extend default_options, options 81 $.extend default_options, options
82 - _chosen.apply this, [default_options] 82 + _chosen.apply @, [default_options]
83 83
84 # Disable an element and add the 'disabled' Bootstrap class 84 # Disable an element and add the 'disabled' Bootstrap class
85 $.fn.extend disable: -> 85 $.fn.extend disable: ->
86 - $(this).attr('disabled', 'disabled').addClass('disabled') 86 + $(@).attr('disabled', 'disabled').addClass('disabled')
87 87
88 # Enable an element and remove the 'disabled' Bootstrap class 88 # Enable an element and remove the 'disabled' Bootstrap class
89 $.fn.extend enable: -> 89 $.fn.extend enable: ->
90 - $(this).removeAttr('disabled').removeClass('disabled') 90 + $(@).removeAttr('disabled').removeClass('disabled')
91 91
92 )(jQuery) 92 )(jQuery)