Commit 93daa8c568cff8c59eb77c7a47b72e0266613d5a

Authored by Robert Speicher
1 parent 1c015368

Move main.js to main.js.coffee

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   -}
app/assets/javascripts/main.js.coffee 0 → 100644
... ... @@ -0,0 +1,130 @@
  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 +}
... ...