Commit 18cb430f authored by Jason Lee's avatar Jason Lee

Replace CoffeeScript block into JavaScript in Views.

For example view: shared/issuable/_context

CoffeeScript: 190ms
JavaScript: 19.7ms
parent 354b69dd
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
= f.submit 'Save', class: 'btn btn-save js-save-button' = f.submit 'Save', class: 'btn btn-save js-save-button'
= link_to "Cancel", admin_labels_path, class: 'btn btn-cancel' = link_to "Cancel", admin_labels_path, class: 'btn btn-cancel'
:coffeescript :javascript
new Labels new Labels();
...@@ -11,15 +11,17 @@ ...@@ -11,15 +11,17 @@
.controls.pull-left.prepend-top-10 .controls.pull-left.prepend-top-10
= submit_tag "Validate", class: 'btn btn-success submit-yml' = submit_tag "Validate", class: 'btn btn-success submit-yml'
%p.text-center.loading %p.text-center.loading
%i.fa.fa-refresh.fa-spin %i.fa.fa-refresh.fa-spin
.results.prepend-top-20 .results.prepend-top-20
:coffeescript :javascript
$(".loading").hide() $(".loading").hide();
$('form').bind 'ajax:beforeSend', -> $('form').bind('ajax:beforeSend', function() {
$(".loading").show() $(".loading").show();
$('form').bind 'ajax:complete', -> });
$(".loading").hide() $('form').bind('ajax:complete', function() {
$(".loading").hide();
});
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
= paginate @members, theme: 'gitlab' = paginate @members, theme: 'gitlab'
:coffeescript :javascript
$('form.member-search-form').on 'submit', (event) -> $('form.member-search-form').on('submit', function(event) {
event.preventDefault() event.preventDefault();
Turbolinks.visit @.action + '?' + $(@).serialize() Turbolinks.visit(this.action + '?' + $(this).serialize());
});
...@@ -222,8 +222,8 @@ ...@@ -222,8 +222,8 @@
:javascript :javascript
$('.js-more-help-button').click(function(e){ $('.js-more-help-button').click(function (e) {
$(this).remove() $(this).remove()l
$('.hidden-shortcut').show() $('.hidden-shortcut').show();
e.preventDefault() e.preventDefault();
}); });
...@@ -66,5 +66,5 @@ ...@@ -66,5 +66,5 @@
again. again.
:coffeescript :javascript
new ImporterStatus("#{jobs_import_bitbucket_path}", "#{import_bitbucket_path}") new ImporterStatus("#{jobs_import_bitbucket_path}", "#{import_bitbucket_path}");
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
%strong Map a FogBugz account ID to a GitLab user %strong Map a FogBugz account ID to a GitLab user
%p %p
Selecting a GitLab user will add a link to the GitLab user in the descriptions Selecting a GitLab user will add a link to the GitLab user in the descriptions
of issues and comments (e.g. "By <a href="#">@johnsmith</a>"). It will also of issues and comments (e.g. "By <a href="#">@johnsmith</a>"). It will also
associate and/or assign these issues and comments with the selected user. associate and/or assign these issues and comments with the selected user.
.table-holder .table-holder
...@@ -46,5 +46,5 @@ ...@@ -46,5 +46,5 @@
.form-actions .form-actions
= submit_tag 'Continue to the next step', class: 'btn btn-create' = submit_tag 'Continue to the next step', class: 'btn btn-create'
:coffeescript :javascript
new UsersSelect() new UsersSelect();
...@@ -48,5 +48,5 @@ ...@@ -48,5 +48,5 @@
%td.import-actions.job-status %td.import-actions.job-status
= button_tag "Import", class: "btn js-add-to-import" = button_tag "Import", class: "btn js-add-to-import"
:coffeescript :javascript
new ImporterStatus("#{jobs_import_fogbugz_path}", "#{import_fogbugz_path}") new ImporterStatus("#{jobs_import_fogbugz_path}", "#{import_fogbugz_path}");
...@@ -43,5 +43,5 @@ ...@@ -43,5 +43,5 @@
%td.import-actions.job-status %td.import-actions.job-status
= button_tag "Import", class: "btn js-add-to-import" = button_tag "Import", class: "btn js-add-to-import"
:coffeescript :javascript
new ImporterStatus("#{jobs_import_github_path}", "#{import_github_path}") new ImporterStatus("#{jobs_import_github_path}", "#{import_github_path}");
...@@ -43,5 +43,5 @@ ...@@ -43,5 +43,5 @@
%td.import-actions.job-status %td.import-actions.job-status
= button_tag "Import", class: "btn js-add-to-import" = button_tag "Import", class: "btn js-add-to-import"
:coffeescript :javascript
new ImporterStatus("#{jobs_import_gitlab_path}", "#{import_gitlab_path}") new ImporterStatus("#{jobs_import_gitlab_path}", "#{import_gitlab_path}");
...@@ -43,5 +43,5 @@ ...@@ -43,5 +43,5 @@
%td.import-actions.job-status %td.import-actions.job-status
= button_tag "Import", class: "btn js-add-to-import" = button_tag "Import", class: "btn js-add-to-import"
:coffeescript :javascript
new ImporterStatus("#{jobs_import_gitorious_path}", "#{import_gitorious_path}") new ImporterStatus("#{jobs_import_gitorious_path}", "#{import_gitorious_path}");
...@@ -67,5 +67,5 @@ ...@@ -67,5 +67,5 @@
= link_to "import flow", new_import_google_code_path = link_to "import flow", new_import_google_code_path
again. again.
:coffeescript :javascript
new ImporterStatus("#{jobs_import_google_code_path}", "#{import_google_code_path}") new ImporterStatus("#{jobs_import_google_code_path}", "#{import_google_code_path}");
...@@ -25,6 +25,6 @@ ...@@ -25,6 +25,6 @@
:javascript :javascript
$('.search-input').on('keyup', function(e) { $('.search-input').on('keyup', function(e) {
if (e.keyCode == 27) { if (e.keyCode == 27) {
$('.search-input').blur() $('.search-input').blur();
} }
}) });
...@@ -8,5 +8,5 @@ ...@@ -8,5 +8,5 @@
.content_list{:"data-href" => activity_project_path(@project)} .content_list{:"data-href" => activity_project_path(@project)}
= spinner = spinner
:coffeescript :javascript
new Activities() new Activities();
...@@ -21,5 +21,5 @@ ...@@ -21,5 +21,5 @@
= submit_tag "Create directory", class: 'btn btn-primary btn-create' = submit_tag "Create directory", class: 'btn btn-primary btn-create'
= link_to "Cancel", '#', class: "btn btn-cancel", "data-dismiss" => "modal" = link_to "Cancel", '#', class: "btn btn-cancel", "data-dismiss" => "modal"
:coffeescript :javascript
disableButtonIfAnyEmptyField($("#dir-create-form"), ".form-control", ".btn-create"); disableButtonIfAnyEmptyField($("#dir-create-form"), ".form-control", ".btn-create");
...@@ -26,6 +26,6 @@ ...@@ -26,6 +26,6 @@
= button_tag button_title, class: 'btn btn-small btn-primary btn-upload-file', id: 'submit-all' = button_tag button_title, class: 'btn btn-small btn-primary btn-upload-file', id: 'submit-all'
= link_to "Cancel", '#', class: "btn btn-cancel", "data-dismiss" => "modal" = link_to "Cancel", '#', class: "btn btn-cancel", "data-dismiss" => "modal"
:coffeescript :javascript
disableButtonIfEmptyField $('.blob-file-upload-form-js').find('#commit_message'), '.btn-upload-file' disableButtonIfEmptyField($('.blob-file-upload-form-js').find('#commit_message'), '.btn-upload-file');
new BlobFileDropzone($('.blob-file-upload-form-js'), '#{method}') new BlobFileDropzone($('.blob-file-upload-form-js'), '#{method}');
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
%span.count %span.count
= @project.star_count = @project.star_count
:coffeescript :javascript
$('.project-home-panel .toggle-star').on 'ajax:success', (e, data, status, xhr) -> $('.project-home-panel .toggle-star').on('ajax:success', function (e, data, status, xhr) {
$(@).replaceWith(data.html) $(this).replaceWith(data.html);
.on 'ajax:error', (e, xhr, status, error) -> })
new Flash('Star toggle failed. Try again later.', 'alert') .on('ajax:error', function (e, xhr, status, error) {
new Flash('Star toggle failed. Try again later.', 'alert');
});
- else - else
= link_to new_user_session_path, class: 'btn has_tooltip star-btn', title: 'You must sign in to star a project' do = link_to new_user_session_path, class: 'btn has_tooltip star-btn', title: 'You must sign in to star a project' do
......
...@@ -55,5 +55,5 @@ ...@@ -55,5 +55,5 @@
%pre.commit-description %pre.commit-description
= preserve(gfm(escape_once(@commit.description))) = preserve(gfm(escape_once(@commit.description)))
:coffeescript :javascript
$(".commit-info-row.branches").load("#{branches_namespace_project_commit_path(@project.namespace, @project, @commit.id)}") $(".commit-info-row.branches").load("#{branches_namespace_project_commit_path(@project.namespace, @project, @commit.id)}");
...@@ -49,26 +49,24 @@ ...@@ -49,26 +49,24 @@
Commits per weekday Commits per weekday
%canvas#weekday-chart %canvas#weekday-chart
:coffeescript :javascript
responsiveChart = (selector, data) -> var responsiveChart = function (selector, data) {
options = { "scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2, maintainAspectRatio: false } var options = { "scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2, maintainAspectRatio: false };
// get selector by context
var ctx = selector.get(0).getContext("2d");
// pointing parent container to make chart.js inherit its width
var container = $(selector).parent();
var generateChart = function() {
selector.attr('width', $(container).width());
return new Chart(ctx).Bar(data, options);
};
// enabling auto-resizing
$(window).resize(generateChart);
return generateChart();
};
# get selector by context var chartData = function (keys, values) {
ctx = selector.get(0).getContext("2d") var data = {
# pointing parent container to make chart.js inherit its width
container = $(selector).parent()
generateChart = ->
selector.attr('width', $(container).width())
new Chart(ctx).Bar(data, options)
# enabling auto-resizing
$(window).resize( generateChart )
generateChart()
chartData = (keys, values) ->
data = {
labels : keys, labels : keys,
datasets : [{ datasets : [{
fillColor : "rgba(220,220,220,0.5)", fillColor : "rgba(220,220,220,0.5)",
...@@ -78,13 +76,15 @@ ...@@ -78,13 +76,15 @@
barDatasetSpacing: 1, barDatasetSpacing: 1,
data : values data : values
}] }]
} };
return data;
};
hourData = chartData(#{@commits_per_time.keys.to_json}, #{@commits_per_time.values.to_json}) var hourData = chartData(#{@commits_per_time.keys.to_json}, #{@commits_per_time.values.to_json});
responsiveChart($('#hour-chart'), hourData) responsiveChart($('#hour-chart'), hourData);
dayData = chartData(#{@commits_per_week_days.keys.to_json}, #{@commits_per_week_days.values.to_json}) var dayData = chartData(#{@commits_per_week_days.keys.to_json}, #{@commits_per_week_days.values.to_json});
responsiveChart($('#weekday-chart'), dayData) responsiveChart($('#weekday-chart'), dayData);
monthData = chartData(#{@commits_per_month.keys.to_json}, #{@commits_per_month.values.to_json}) var monthData = chartData(#{@commits_per_month.keys.to_json}, #{@commits_per_month.values.to_json});
responsiveChart($('#month-chart'), monthData) responsiveChart($('#month-chart'), monthData);
...@@ -28,18 +28,21 @@ ...@@ -28,18 +28,21 @@
:coffeescript :javascript
$.ajax $.ajax({
type: "GET", type: "GET",
url: location.href, url: location.href,
success: (data) -> dataType: "json",
graph = new ContributorsStatGraph() success: function (data) {
graph.init(data) var graph = new ContributorsStatGraph();
graph.init(data);
$("#brush_change").change -> $("#brush_change").change(function(){
graph.change_date_header() graph.change_date_header();
graph.redraw_authors() graph.redraw_authors();
});
$(".stat-graph").fadeIn(); $(".stat-graph").fadeIn();
$(".loading-graph").hide(); $(".loading-graph").hide();
dataType: "json" }
});
...@@ -77,12 +77,13 @@ ...@@ -77,12 +77,13 @@
}); });
:coffeescript :javascript
$(".merge-request-form").on('submit', function () {
$(".merge-request-form").on 'submit', -> if ($("#merge_request_source_branch").val() === "" || $('#merge_request_target_branch').val() === "") {
if $("#merge_request_source_branch").val() is "" or $('#merge_request_target_branch').val() is "" $(".mr-compare-errors").html("You must select source and target branch to proceed");
$(".mr-compare-errors").html("You must select source and target branch to proceed") $(".mr-compare-errors").fadeIn();
$(".mr-compare-errors").fadeIn() event.preventDefault();
event.preventDefault() return;
return }
});
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
= icon("times-circle") = icon("times-circle")
Could not connect to the CI server. Please check your settings and try again. Could not connect to the CI server. Please check your settings and try again.
:coffeescript :javascript
$ -> $(function() {
merge_request_widget.getCiStatus() merge_request_widget.getCiStatus();
});
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
- elsif can_remove_branch?(@merge_request.source_project, @merge_request.source_branch) - elsif can_remove_branch?(@merge_request.source_project, @merge_request.source_branch)
.remove_source_branch_widget .remove_source_branch_widget
%p %p
= succeed '.' do = succeed '.' do
The changes were merged into The changes were merged into
%span.label-branch= @merge_request.target_branch %span.label-branch= @merge_request.target_branch
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
Remove Source Branch Remove Source Branch
.remove_source_branch_widget.failed.hide .remove_source_branch_widget.failed.hide
%p %p
Failed to remove source branch '#{@merge_request.source_branch}'. Failed to remove source branch '#{@merge_request.source_branch}'.
.remove_source_branch_in_progress.hide .remove_source_branch_in_progress.hide
...@@ -33,17 +33,20 @@ ...@@ -33,17 +33,20 @@
= icon('spinner spin') = icon('spinner spin')
Removing source branch '#{@merge_request.source_branch}'. Please wait. This page will be automatically reload. Removing source branch '#{@merge_request.source_branch}'. Please wait. This page will be automatically reload.
:coffeescript :javascript
$('.remove_source_branch').on 'click', -> $('.remove_source_branch').on('click', function() {
$('.remove_source_branch_widget').hide() $('.remove_source_branch_widget').hide();
$('.remove_source_branch_in_progress').show() $('.remove_source_branch_in_progress').show();
});
$(".remove_source_branch").on "ajax:success", (e, data, status, xhr) ->
location.reload() $(".remove_source_branch").on("ajax:success", function (e, data, status, xhr) {
location.reload();
$(".remove_source_branch").on "ajax:error", (e, data, status, xhr) -> });
$('.remove_source_branch_widget').hide()
$('.remove_source_branch_in_progress').hide() $(".remove_source_branch").on("ajax:error", function (e, data, status, xhr) {
$('.remove_source_branch_widget.failed').show() $('.remove_source_branch_widget').hide();
$('.remove_source_branch_in_progress').hide();
$('.remove_source_branch_widget.failed').show();
});
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
text: @merge_request.merge_commit_message, text: @merge_request.merge_commit_message,
rows: 14, hint: true rows: 14, hint: true
:coffeescript :javascript
$('.accept-mr-form').on 'ajax:before', -> $('.accept-mr-form').on('ajax:before', function() {
btn = $('.accept_merge_request') var btn = $('.accept_merge_request');
btn.disable() btn.disable();
btn.html("<i class='fa fa-spinner fa-spin'></i> Merge in progress") btn.html("<i class='fa fa-spinner fa-spin'></i> Merge in progress");
});
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
= icon("spinner spin") = icon("spinner spin")
Checking ability to merge automatically&hellip; Checking ability to merge automatically&hellip;
:coffeescript :javascript
$ -> $(function() {
merge_request_widget.getMergeStatus() merge_request_widget.getMergeStatus();
});
...@@ -124,9 +124,11 @@ ...@@ -124,9 +124,11 @@
Creating project &amp; repository. Creating project &amp; repository.
%p Please wait a moment, this page will automatically refresh when ready. %p Please wait a moment, this page will automatically refresh when ready.
:coffeescript :javascript
$('.how_to_import_link').bind 'click', (e) -> $('.how_to_import_link').bind('click', function (e) {
e.preventDefault() e.preventDefault();
import_modal = $(this).next(".modal").show() var import_modal = $(this).next(".modal").show();
$('.modal-header .close').bind 'click', -> });
$(".modal").hide() $('.modal-header .close').bind('click', function() {
$(".modal").hide();
});
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
- if @group - if @group
= render "group_members", members: @group_members = render "group_members", members: @group_members
:coffeescript :javascript
$('form.member-search-form').on 'submit', (event) -> $('form.member-search-form').on('submit', function (event) {
event.preventDefault() event.preventDefault();
Turbolinks.visit @.action + '?' + $(@).serialize() Turbolinks.visit(this.action + '?' + $(this).serialize());
});
...@@ -45,6 +45,6 @@ ...@@ -45,6 +45,6 @@
.description-block.subscribed{class: ( 'hidden' unless subscribed )} .description-block.subscribed{class: ( 'hidden' unless subscribed )}
You're receiving notifications because you're subscribed to this thread. You're receiving notifications because you're subscribed to this thread.
:coffeescript :javascript
new Subscription("#{toggle_subscription_path(issuable)}") new Subscription("#{toggle_subscription_path(issuable)}");
new IssuableContext() new IssuableContext();
...@@ -60,9 +60,9 @@ ...@@ -60,9 +60,9 @@
= hidden_field_tag :state_event, params[:state_event] = hidden_field_tag :state_event, params[:state_event]
= button_tag "Update issues", class: "btn update_selected_issues btn-save" = button_tag "Update issues", class: "btn update_selected_issues btn-save"
:coffeescript :javascript
new UsersSelect() new UsersSelect();
$('form.filter-form').on('submit', function (event) {
$('form.filter-form').on 'submit', (event) -> event.preventDefault();
event.preventDefault() Turbolinks.visit(this.action + '&' + $(this).serialize());
Turbolinks.visit @.action + '&' + $(@).serialize() });
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
= link_to '#', class: 'js-expand' do = link_to '#', class: 'js-expand' do
Show all Show all
:coffeescript :javascript
new ProjectsList() new ProjectsList();
...@@ -115,5 +115,5 @@ ...@@ -115,5 +115,5 @@
projects: @projects.sort_by(&:star_count).reverse, projects: @projects.sort_by(&:star_count).reverse,
projects_limit: 10, stars: true, avatar: true projects_limit: 10, stars: true, avatar: true
:coffeescript :javascript
$(".user-calendar").load("#{user_calendar_path}") $(".user-calendar").load("#{user_calendar_path}");
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