diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js
deleted file mode 100644
index bb0a499a..00000000
--- a/app/assets/javascripts/admin.js
+++ /dev/null
@@ -1,11 +0,0 @@
-$(document).ready(function(){
- $('input#user_force_random_password').on('change', function(elem) {
- var elems = $('#user_password, #user_password_confirmation');
-
- if ($(this).attr('checked')) {
- elems.val('').attr('disabled', true);
- } else {
- elems.removeAttr('disabled');
- }
- });
-});
diff --git a/app/assets/javascripts/admin.js.coffee b/app/assets/javascripts/admin.js.coffee
new file mode 100644
index 00000000..269a7a76
--- /dev/null
+++ b/app/assets/javascripts/admin.js.coffee
@@ -0,0 +1,8 @@
+$ ->
+ $('input#user_force_random_password').on 'change', (elem) ->
+ elems = $('#user_password, #user_password_confirmation')
+
+ if $(@).attr 'checked'
+ elems.val('').attr 'disabled', true
+ else
+ elems.removeAttr 'disabled'
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index f69fd6f9..4c487ec1 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -17,134 +17,3 @@
//= require raphael
//= require branch-graph
//= require_tree .
-
-$(document).ready(function(){
-
- $(".one_click_select").live("click", function(){
- $(this).select();
- });
-
- $('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){
- var buttons = $('[type="submit"]', this);
- switch( e.type ){
- case 'ajax:beforeSend':
- case 'submit':
- buttons.attr('disabled', 'disabled');
- break;
- case ' ajax:complete':
- default:
- buttons.removeAttr('disabled');
- break;
- }
- })
-
- $(".account-box").mouseenter(showMenu);
- $(".account-box").mouseleave(resetMenu);
-
- $("#projects-list .project").live('click', function(e){
- if(e.target.nodeName != "A" && e.target.nodeName != "INPUT") {
- location.href = $(this).attr("url");
- e.stopPropagation();
- return false;
- }
- });
-
- /**
- * Focus search field by pressing 's' key
- */
- $(document).keypress(function(e) {
- if( $(e.target).is(":input") ) return;
- switch(e.which) {
- case 115: focusSearch();
- e.preventDefault();
- }
- });
-
- /**
- * Commit show suppressed diff
- *
- */
- $(".supp_diff_link").bind("click", function() {
- showDiff(this);
- });
-
- /**
- * Note markdown preview
- *
- */
- $(document).on('click', '#preview-link', function(e) {
- $('#preview-note').text('Loading...');
-
- var previewLinkText = ($(this).text() == 'Preview' ? 'Edit' : 'Preview');
- $(this).text(previewLinkText);
-
- var note = $('#note_note').val();
- if (note.trim().length === 0) { note = 'Nothing to preview'; }
- $.post($(this).attr('href'), {note: note}, function(data) {
- $('#preview-note').html(data);
- });
-
- $('#preview-note, #note_note').toggle();
- e.preventDefault();
- });
-});
-
-function focusSearch() {
- $("#search").focus();
-}
-
-function updatePage(data){
- $.ajax({type: "GET", url: location.href, data: data, dataType: "script"});
-}
-
-function showMenu() {
- $(this).toggleClass('hover');
-}
-
-function resetMenu() {
- $(this).removeClass("hover");
-}
-
-function slugify(text) {
- return text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase();
-}
-
-function showDiff(link) {
- $(link).next('table').show();
- $(link).remove();
-}
-
-(function($){
- var _chosen = $.fn.chosen;
- $.fn.extend({
- chosen: function(options) {
- var default_options = {'search_contains' : 'true'};
- $.extend(default_options, options);
- return _chosen.apply(this, [default_options]);
- }})
-})(jQuery);
-
-
-function ajaxGet(url) {
- $.ajax({type: "GET", url: url, dataType: "script"});
-}
-
-/**
- * Disable button if text field is empty
- */
-function disableButtonIfEmtpyField(field_selector, button_selector) {
- field = $(field_selector);
- if(field.val() == "") {
- field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled");
- }
-
- field.on('keyup', function(){
- var field = $(this);
- var closest_submit = field.closest("form").find(button_selector);
- if(field.val() == "") {
- closest_submit.attr("disabled", "disabled").addClass("disabled");
- } else {
- closest_submit.removeAttr("disabled").removeClass("disabled");
- }
- })
-}
diff --git a/app/assets/javascripts/graph.js b/app/assets/javascripts/graph.js
deleted file mode 100644
index 434cf70a..00000000
--- a/app/assets/javascripts/graph.js
+++ /dev/null
@@ -1,10 +0,0 @@
-function initGraphNav() {
- $(".graph svg").css("position", "relative");
- $("body").bind("keyup", function(e) {
- if(e.keyCode == 37) { // left
- $(".graph svg").animate({ left: "+=400" });
- } else if(e.keyCode == 39) { // right
- $(".graph svg").animate({ left: "-=400" });
- }
- });
-}
diff --git a/app/assets/javascripts/graph.js.coffee b/app/assets/javascripts/graph.js.coffee
new file mode 100644
index 00000000..5fe8ae3f
--- /dev/null
+++ b/app/assets/javascripts/graph.js.coffee
@@ -0,0 +1,10 @@
+initGraphNav = ->
+ $('.graph svg').css 'position', 'relative'
+
+ $('body').bind 'keyup', (e) ->
+ if e.keyCode is 37 # left
+ $('.graph svg').animate left: '+=400'
+ else if e.keyCode is 39 # right
+ $('.graph svg').animate left: '-=400'
+
+window.initGraphNav = initGraphNav
diff --git a/app/assets/javascripts/loader.js b/app/assets/javascripts/loader.js
deleted file mode 100644
index 6fa0b525..00000000
--- a/app/assets/javascripts/loader.js
+++ /dev/null
@@ -1,11 +0,0 @@
-var Loader = {
- img_src: "/assets/ajax-loader.gif",
-
- html:
- function(width) {
- img = $("");
- img.attr("width", width);
- img.attr("src", this.img_src);
- return img;
- }
-}
diff --git a/app/assets/javascripts/loader.js.coffee b/app/assets/javascripts/loader.js.coffee
new file mode 100644
index 00000000..66f8e8b1
--- /dev/null
+++ b/app/assets/javascripts/loader.js.coffee
@@ -0,0 +1,5 @@
+Loader =
+ html: (width) ->
+ $('').attr src: '/assets/ajax-loader.gif', width: width
+
+window.Loader = Loader
diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js
new file mode 100644
index 00000000..61af1dc3
--- /dev/null
+++ b/app/assets/javascripts/main.js
@@ -0,0 +1,130 @@
+$(document).ready(function(){
+
+ $(".one_click_select").live("click", function(){
+ $(this).select();
+ });
+
+ $('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){
+ var buttons = $('[type="submit"]', this);
+ switch( e.type ){
+ case 'ajax:beforeSend':
+ case 'submit':
+ buttons.attr('disabled', 'disabled');
+ break;
+ case ' ajax:complete':
+ default:
+ buttons.removeAttr('disabled');
+ break;
+ }
+ })
+
+ $(".account-box").mouseenter(showMenu);
+ $(".account-box").mouseleave(resetMenu);
+
+ $("#projects-list .project").live('click', function(e){
+ if(e.target.nodeName != "A" && e.target.nodeName != "INPUT") {
+ location.href = $(this).attr("url");
+ e.stopPropagation();
+ return false;
+ }
+ });
+
+ /**
+ * Focus search field by pressing 's' key
+ */
+ $(document).keypress(function(e) {
+ if( $(e.target).is(":input") ) return;
+ switch(e.which) {
+ case 115: focusSearch();
+ e.preventDefault();
+ }
+ });
+
+ /**
+ * Commit show suppressed diff
+ *
+ */
+ $(".supp_diff_link").bind("click", function() {
+ showDiff(this);
+ });
+
+ /**
+ * Note markdown preview
+ *
+ */
+ $(document).on('click', '#preview-link', function(e) {
+ $('#preview-note').text('Loading...');
+
+ var previewLinkText = ($(this).text() == 'Preview' ? 'Edit' : 'Preview');
+ $(this).text(previewLinkText);
+
+ var note = $('#note_note').val();
+ if (note.trim().length === 0) { note = 'Nothing to preview'; }
+ $.post($(this).attr('href'), {note: note}, function(data) {
+ $('#preview-note').html(data);
+ });
+
+ $('#preview-note, #note_note').toggle();
+ e.preventDefault();
+ });
+});
+
+function focusSearch() {
+ $("#search").focus();
+}
+
+function updatePage(data){
+ $.ajax({type: "GET", url: location.href, data: data, dataType: "script"});
+}
+
+function showMenu() {
+ $(this).toggleClass('hover');
+}
+
+function resetMenu() {
+ $(this).removeClass("hover");
+}
+
+function slugify(text) {
+ return text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase();
+}
+
+function showDiff(link) {
+ $(link).next('table').show();
+ $(link).remove();
+}
+
+(function($){
+ var _chosen = $.fn.chosen;
+ $.fn.extend({
+ chosen: function(options) {
+ var default_options = {'search_contains' : 'true'};
+ $.extend(default_options, options);
+ return _chosen.apply(this, [default_options]);
+ }})
+})(jQuery);
+
+
+function ajaxGet(url) {
+ $.ajax({type: "GET", url: url, dataType: "script"});
+}
+
+/**
+ * Disable button if text field is empty
+ */
+function disableButtonIfEmtpyField(field_selector, button_selector) {
+ field = $(field_selector);
+ if(field.val() == "") {
+ field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled");
+ }
+
+ field.on('keyup', function(){
+ var field = $(this);
+ var closest_submit = field.closest("form").find(button_selector);
+ if(field.val() == "") {
+ closest_submit.attr("disabled", "disabled").addClass("disabled");
+ } else {
+ closest_submit.removeAttr("disabled").removeClass("disabled");
+ }
+ })
+}
diff --git a/app/assets/javascripts/projects.js.coffee b/app/assets/javascripts/projects.js.coffee
index ca8f13f6..7700cf98 100644
--- a/app/assets/javascripts/projects.js.coffee
+++ b/app/assets/javascripts/projects.js.coffee
@@ -1,21 +1,20 @@
window.Projects = ->
- $("#project_name").live "change", ->
- slug = slugify($(this).val())
- $("#project_code").val(slug)
- $("#project_path").val(slug)
+ $('#project_name').on 'change', ->
+ slug = slugify $(@).val()
+ $('#project_code').val slug
- $(".new_project, .edit_project").live "ajax:before", ->
- $(".project_new_holder, .project_edit_holder").hide()
- $(".save-project-loader").show()
+ $('.new_project, .edit_project').on 'ajax:before', ->
+ $('.project_new_holder, .project_edit_holder').hide()
+ $('.save-project-loader').show()
- $("form #project_default_branch").chosen()
- disableButtonIfEmtpyField "#project_name", ".project-submit"
+ $('form #project_default_branch').chosen()
+ disableButtonIfEmtpyField '#project_name', '.project-submit'
# Git clone panel switcher
$ ->
- scope = $('.project_clone_holder')
+ scope = $ '.project_clone_holder'
if scope.length > 0
$('a, button', scope).click ->
- $('a, button', scope).removeClass('active')
- $(this).addClass('active')
- $('#project_clone', scope).val($(this).data('clone'))
+ $('a, button', scope).removeClass 'active'
+ $(@).addClass 'active'
+ $('#project_clone', scope).val $(@).data 'clone'
diff --git a/app/assets/javascripts/snippets.js b/app/assets/javascripts/snippets.js
deleted file mode 100644
index 11e18eb7..00000000
--- a/app/assets/javascripts/snippets.js
+++ /dev/null
@@ -1,9 +0,0 @@
-$(document).ready(function(){
- $("#snippets-table .snippet").live('click', function(e){
- if(e.target.nodeName != "A" && e.target.nodeName != "INPUT") {
- location.href = $(this).attr("url");
- e.stopPropagation();
- return false;
- }
- });
-});
diff --git a/app/assets/javascripts/snippets.js.coffee b/app/assets/javascripts/snippets.js.coffee
new file mode 100644
index 00000000..af4385de
--- /dev/null
+++ b/app/assets/javascripts/snippets.js.coffee
@@ -0,0 +1,6 @@
+$ ->
+ $('#snippets-table .snippet').live 'click', (e) ->
+ if e.target.nodeName isnt 'A' and e.target.nodeName isnt 'INPUT'
+ location.href = $(@).attr 'url'
+ e.stopPropagation()
+ false
diff --git a/app/assets/javascripts/team.js b/app/assets/javascripts/team.js
deleted file mode 100644
index f4b04354..00000000
--- a/app/assets/javascripts/team.js
+++ /dev/null
@@ -1,8 +0,0 @@
-function backToMembers(){
- $("#new_team_member").hide("slide", { direction: "right" }, 150, function(){
- $("#team-table").show("slide", { direction: "left" }, 150, function() {
- $("#new_team_member").remove();
- $(".add_new").show();
- });
- });
-}
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 5e10a1b6..4ab40c30 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -64,19 +64,14 @@ class CommitsController < ApplicationController
@commit.to_patch,
type: "text/plain",
disposition: 'attachment',
- filename: (@commit.id.to_s + ".patch")
+ filename: "#{@commit.id.patch}"
)
end
protected
def load_refs
- if params[:ref].blank?
- @branch = params[:branch].blank? ? nil : params[:branch]
- @tag = params[:tag].blank? ? nil : params[:tag]
- @ref = @branch || @tag || @project.try(:default_branch) || 'master'
- else
- @ref = params[:ref]
- end
+ @ref ||= params[:ref].presence || params[:branch].presence || params[:tag].presence
+ @ref ||= @ref || @project.try(:default_branch) || 'master'
end
end