Commit 1f5e2658f53b1214cd197ecad544ba2bd2975766
Exists in
master
and in
4 other branches
Merge pull request #1412 from tsigo/more_coffeescript
Convert main.js to CoffeeScript
Showing
8 changed files
with
98 additions
and
147 deletions
Show diff stats
app/assets/javascripts/issues.js
... | ... | @@ -5,7 +5,7 @@ function switchToNewIssue(form){ |
5 | 5 | $('select#issue_milestone_id').chosen(); |
6 | 6 | $("#new_issue_dialog").show("fade", { direction: "right" }, 150); |
7 | 7 | $('.top-tabs .add_new').hide(); |
8 | - disableButtonIfEmtpyField("#issue_title", ".save-btn"); | |
8 | + disableButtonIfEmptyField("#issue_title", ".save-btn"); | |
9 | 9 | }); |
10 | 10 | } |
11 | 11 | |
... | ... | @@ -16,7 +16,7 @@ function switchToEditIssue(form){ |
16 | 16 | $('select#issue_milestone_id').chosen(); |
17 | 17 | $("#edit_issue_dialog").show("fade", { direction: "right" }, 150); |
18 | 18 | $('.add_new').hide(); |
19 | - disableButtonIfEmtpyField("#issue_title", ".save-btn"); | |
19 | + disableButtonIfEmptyField("#issue_title", ".save-btn"); | |
20 | 20 | }); |
21 | 21 | } |
22 | 22 | ... | ... |
app/assets/javascripts/main.js
... | ... | @@ -1,130 +0,0 @@ |
1 | -$(document).ready(function(){ | |
2 | - | |
3 | - $(".one_click_select").live("click", function(){ | |
4 | - $(this).select(); | |
5 | - }); | |
6 | - | |
7 | - $('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){ | |
8 | - var buttons = $('[type="submit"]', this); | |
9 | - switch( e.type ){ | |
10 | - case 'ajax:beforeSend': | |
11 | - case 'submit': | |
12 | - buttons.attr('disabled', 'disabled'); | |
13 | - break; | |
14 | - case ' ajax:complete': | |
15 | - default: | |
16 | - buttons.removeAttr('disabled'); | |
17 | - break; | |
18 | - } | |
19 | - }) | |
20 | - | |
21 | - $(".account-box").mouseenter(showMenu); | |
22 | - $(".account-box").mouseleave(resetMenu); | |
23 | - | |
24 | - $("#projects-list .project").live('click', function(e){ | |
25 | - if(e.target.nodeName != "A" && e.target.nodeName != "INPUT") { | |
26 | - location.href = $(this).attr("url"); | |
27 | - e.stopPropagation(); | |
28 | - return false; | |
29 | - } | |
30 | - }); | |
31 | - | |
32 | - /** | |
33 | - * Focus search field by pressing 's' key | |
34 | - */ | |
35 | - $(document).keypress(function(e) { | |
36 | - if( $(e.target).is(":input") ) return; | |
37 | - switch(e.which) { | |
38 | - case 115: focusSearch(); | |
39 | - e.preventDefault(); | |
40 | - } | |
41 | - }); | |
42 | - | |
43 | - /** | |
44 | - * Commit show suppressed diff | |
45 | - * | |
46 | - */ | |
47 | - $(".supp_diff_link").bind("click", function() { | |
48 | - showDiff(this); | |
49 | - }); | |
50 | - | |
51 | - /** | |
52 | - * Note markdown preview | |
53 | - * | |
54 | - */ | |
55 | - $(document).on('click', '#preview-link', function(e) { | |
56 | - $('#preview-note').text('Loading...'); | |
57 | - | |
58 | - var previewLinkText = ($(this).text() == 'Preview' ? 'Edit' : 'Preview'); | |
59 | - $(this).text(previewLinkText); | |
60 | - | |
61 | - var note = $('#note_note').val(); | |
62 | - if (note.trim().length === 0) { note = 'Nothing to preview'; } | |
63 | - $.post($(this).attr('href'), {note: note}, function(data) { | |
64 | - $('#preview-note').html(data); | |
65 | - }); | |
66 | - | |
67 | - $('#preview-note, #note_note').toggle(); | |
68 | - e.preventDefault(); | |
69 | - }); | |
70 | -}); | |
71 | - | |
72 | -function focusSearch() { | |
73 | - $("#search").focus(); | |
74 | -} | |
75 | - | |
76 | -function updatePage(data){ | |
77 | - $.ajax({type: "GET", url: location.href, data: data, dataType: "script"}); | |
78 | -} | |
79 | - | |
80 | -function showMenu() { | |
81 | - $(this).toggleClass('hover'); | |
82 | -} | |
83 | - | |
84 | -function resetMenu() { | |
85 | - $(this).removeClass("hover"); | |
86 | -} | |
87 | - | |
88 | -function slugify(text) { | |
89 | - return text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase(); | |
90 | -} | |
91 | - | |
92 | -function showDiff(link) { | |
93 | - $(link).next('table').show(); | |
94 | - $(link).remove(); | |
95 | -} | |
96 | - | |
97 | -(function($){ | |
98 | - var _chosen = $.fn.chosen; | |
99 | - $.fn.extend({ | |
100 | - chosen: function(options) { | |
101 | - var default_options = {'search_contains' : 'true'}; | |
102 | - $.extend(default_options, options); | |
103 | - return _chosen.apply(this, [default_options]); | |
104 | - }}) | |
105 | -})(jQuery); | |
106 | - | |
107 | - | |
108 | -function ajaxGet(url) { | |
109 | - $.ajax({type: "GET", url: url, dataType: "script"}); | |
110 | -} | |
111 | - | |
112 | -/** | |
113 | - * Disable button if text field is empty | |
114 | - */ | |
115 | -function disableButtonIfEmtpyField(field_selector, button_selector) { | |
116 | - field = $(field_selector); | |
117 | - if(field.val() == "") { | |
118 | - field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled"); | |
119 | - } | |
120 | - | |
121 | - field.on('keyup', function(){ | |
122 | - var field = $(this); | |
123 | - var closest_submit = field.closest("form").find(button_selector); | |
124 | - if(field.val() == "") { | |
125 | - closest_submit.attr("disabled", "disabled").addClass("disabled"); | |
126 | - } else { | |
127 | - closest_submit.removeAttr("disabled").removeClass("disabled"); | |
128 | - } | |
129 | - }) | |
130 | -} |
... | ... | @@ -0,0 +1,89 @@ |
1 | +window.updatePage = (data) -> | |
2 | + $.ajax({type: "GET", url: location.href, data: data, dataType: "script"}) | |
3 | + | |
4 | +window.slugify = (text) -> | |
5 | + text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase() | |
6 | + | |
7 | +window.ajaxGet = (url) -> | |
8 | + $.ajax({type: "GET", url: url, dataType: "script"}) | |
9 | + | |
10 | + # Disable button if text field is empty | |
11 | +window.disableButtonIfEmptyField = (field_selector, button_selector) -> | |
12 | + field = $(field_selector) | |
13 | + closest_submit = field.closest("form").find(button_selector) | |
14 | + | |
15 | + closest_submit.disable() if field.val() is "" | |
16 | + | |
17 | + field.on "keyup", -> | |
18 | + if $(this).val() is "" | |
19 | + closest_submit.disable() | |
20 | + else | |
21 | + closest_submit.enable() | |
22 | + | |
23 | +$ -> | |
24 | + # Click a .one_click_select field, select the contents | |
25 | + $(".one_click_select").live 'click', -> $(this).select() | |
26 | + | |
27 | + # Disable form buttons while a form is submitting | |
28 | + $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) -> | |
29 | + buttons = $('[type="submit"]', this) | |
30 | + | |
31 | + switch e.type | |
32 | + when 'ajax:beforeSend', 'submit' | |
33 | + buttons.disable() | |
34 | + else | |
35 | + buttons.enable() | |
36 | + | |
37 | + # Show/Hide the profile menu when hovering the account box | |
38 | + $('.account-box').hover -> $(this).toggleClass('hover') | |
39 | + | |
40 | + # Focus search field by pressing 's' key | |
41 | + $(document).keypress (e) -> | |
42 | + # Don't do anything if typing in an input | |
43 | + return if $(e.target).is(":input") | |
44 | + | |
45 | + switch e.which | |
46 | + when 115 | |
47 | + $("#search").focus() | |
48 | + e.preventDefault() | |
49 | + | |
50 | + # Commit show suppressed diff | |
51 | + $(".supp_diff_link").bind "click", -> | |
52 | + $(this).next('table').show() | |
53 | + $(this).remove() | |
54 | + | |
55 | + # Note markdown preview | |
56 | + $(document).on 'click', '#preview-link', (e) -> | |
57 | + $('#preview-note').text('Loading...') | |
58 | + | |
59 | + previewLinkText = if $(this).text() == 'Preview' then 'Edit' else 'Preview' | |
60 | + $(this).text(previewLinkText) | |
61 | + | |
62 | + note = $('#note_note').val() | |
63 | + | |
64 | + if note.trim().length == 0 | |
65 | + $('#preview-note').text("Nothing to preview.") | |
66 | + else | |
67 | + $.post $(this).attr('href'), {note: note}, (data) -> | |
68 | + $('#preview-note').html(data) | |
69 | + | |
70 | + $('#preview-note, #note_note').toggle() | |
71 | + e.preventDefault() | |
72 | + false | |
73 | + | |
74 | +(($) -> | |
75 | + _chosen = $.fn.chosen | |
76 | + $.fn.extend chosen: (options) -> | |
77 | + default_options = search_contains: "true" | |
78 | + $.extend default_options, options | |
79 | + _chosen.apply this, [default_options] | |
80 | + | |
81 | + # Disable an element and add the 'disabled' Bootstrap class | |
82 | + $.fn.extend disable: -> | |
83 | + $(this).attr('disabled', 'disabled').addClass('disabled') | |
84 | + | |
85 | + # Enable an element and remove the 'disabled' Bootstrap class | |
86 | + $.fn.extend enable: -> | |
87 | + $(this).removeAttr('disabled').removeClass('disabled') | |
88 | + | |
89 | +)(jQuery) | ... | ... |
app/assets/javascripts/note.js
... | ... | @@ -25,14 +25,14 @@ var NoteList = { |
25 | 25 | $(this).closest('li').fadeOut(); }); |
26 | 26 | |
27 | 27 | $(".note-form-holder").live("ajax:before", function(){ |
28 | - $(".submit_note").attr("disabled", "disabled"); | |
28 | + $(".submit_note").disable() | |
29 | 29 | }) |
30 | 30 | |
31 | 31 | $(".note-form-holder").live("ajax:complete", function(){ |
32 | - $(".submit_note").removeAttr("disabled"); | |
32 | + $(".submit_note").enable() | |
33 | 33 | }) |
34 | 34 | |
35 | - disableButtonIfEmtpyField(".note-text", ".submit_note"); | |
35 | + disableButtonIfEmptyField(".note-text", ".submit_note"); | |
36 | 36 | |
37 | 37 | $(".note-text").live("focus", function(){ |
38 | 38 | $(this).css("height", "80px"); |
... | ... | @@ -177,6 +177,6 @@ var PerLineNotes = { |
177 | 177 | form.show(); |
178 | 178 | return false; |
179 | 179 | }); |
180 | - disableButtonIfEmtpyField(".line-note-text", ".submit_inline_note"); | |
180 | + disableButtonIfEmptyField(".line-note-text", ".submit_inline_note"); | |
181 | 181 | } |
182 | 182 | } | ... | ... |
app/assets/javascripts/projects.js.coffee
... | ... | @@ -8,7 +8,7 @@ window.Projects = -> |
8 | 8 | $('.save-project-loader').show() |
9 | 9 | |
10 | 10 | $('form #project_default_branch').chosen() |
11 | - disableButtonIfEmtpyField '#project_name', '.project-submit' | |
11 | + disableButtonIfEmptyField '#project_name', '.project-submit' | |
12 | 12 | |
13 | 13 | # Git clone panel switcher |
14 | 14 | $ -> | ... | ... |
app/views/layouts/_head_panel.html.haml
... | ... | @@ -34,12 +34,4 @@ |
34 | 34 | source: #{raw search_autocomplete_source}, |
35 | 35 | select: function(event, ui) { location.href = ui.item.url } |
36 | 36 | }); |
37 | - | |
38 | - $(document).keypress(function(e) { | |
39 | - if($(e.target).is(":input")) return; | |
40 | - switch(e.which) { | |
41 | - case 115: focusSearch(); | |
42 | - e.preventDefault(); | |
43 | - } | |
44 | - }); | |
45 | 37 | }); | ... | ... |
app/views/merge_requests/_form.html.haml
... | ... | @@ -60,7 +60,7 @@ |
60 | 60 | |
61 | 61 | :javascript |
62 | 62 | $(function(){ |
63 | - disableButtonIfEmtpyField("#merge_request_title", ".save-btn"); | |
63 | + disableButtonIfEmptyField("#merge_request_title", ".save-btn"); | |
64 | 64 | $('select#merge_request_assignee_id').chosen(); |
65 | 65 | $('select#merge_request_source_branch').chosen(); |
66 | 66 | $('select#merge_request_target_branch').chosen(); | ... | ... |
app/views/milestones/_form.html.haml
... | ... | @@ -41,7 +41,7 @@ |
41 | 41 | |
42 | 42 | :javascript |
43 | 43 | $(function() { |
44 | - disableButtonIfEmtpyField("#milestone_title", ".save-btn"); | |
44 | + disableButtonIfEmptyField("#milestone_title", ".save-btn"); | |
45 | 45 | $( ".datepicker" ).datepicker({ |
46 | 46 | dateFormat: "yy-mm-dd", |
47 | 47 | onSelect: function(dateText, inst) { $("#milestone_due_date").val(dateText) } | ... | ... |