Commit 66684d6d50e9d8e0ae31db9df6b5bd7626db74ef

Authored by Nihad Abbasov
1 parent 88d394d3

move code from application.js to separate file

app/assets/javascripts/application.js
... ... @@ -17,134 +17,3 @@
17 17 //= require raphael
18 18 //= require branch-graph
19 19 //= require_tree .
20   -
21   -$(document).ready(function(){
22   -
23   - $(".one_click_select").live("click", function(){
24   - $(this).select();
25   - });
26   -
27   - $('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){
28   - var buttons = $('[type="submit"]', this);
29   - switch( e.type ){
30   - case 'ajax:beforeSend':
31   - case 'submit':
32   - buttons.attr('disabled', 'disabled');
33   - break;
34   - case ' ajax:complete':
35   - default:
36   - buttons.removeAttr('disabled');
37   - break;
38   - }
39   - })
40   -
41   - $(".account-box").mouseenter(showMenu);
42   - $(".account-box").mouseleave(resetMenu);
43   -
44   - $("#projects-list .project").live('click', function(e){
45   - if(e.target.nodeName != "A" && e.target.nodeName != "INPUT") {
46   - location.href = $(this).attr("url");
47   - e.stopPropagation();
48   - return false;
49   - }
50   - });
51   -
52   - /**
53   - * Focus search field by pressing 's' key
54   - */
55   - $(document).keypress(function(e) {
56   - if( $(e.target).is(":input") ) return;
57   - switch(e.which) {
58   - case 115: focusSearch();
59   - e.preventDefault();
60   - }
61   - });
62   -
63   - /**
64   - * Commit show suppressed diff
65   - *
66   - */
67   - $(".supp_diff_link").bind("click", function() {
68   - showDiff(this);
69   - });
70   -
71   - /**
72   - * Note markdown preview
73   - *
74   - */
75   - $(document).on('click', '#preview-link', function(e) {
76   - $('#preview-note').text('Loading...');
77   -
78   - var previewLinkText = ($(this).text() == 'Preview' ? 'Edit' : 'Preview');
79   - $(this).text(previewLinkText);
80   -
81   - var note = $('#note_note').val();
82   - if (note.trim().length === 0) { note = 'Nothing to preview'; }
83   - $.post($(this).attr('href'), {note: note}, function(data) {
84   - $('#preview-note').html(data);
85   - });
86   -
87   - $('#preview-note, #note_note').toggle();
88   - e.preventDefault();
89   - });
90   -});
91   -
92   -function focusSearch() {
93   - $("#search").focus();
94   -}
95   -
96   -function updatePage(data){
97   - $.ajax({type: "GET", url: location.href, data: data, dataType: "script"});
98   -}
99   -
100   -function showMenu() {
101   - $(this).toggleClass('hover');
102   -}
103   -
104   -function resetMenu() {
105   - $(this).removeClass("hover");
106   -}
107   -
108   -function slugify(text) {
109   - return text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase();
110   -}
111   -
112   -function showDiff(link) {
113   - $(link).next('table').show();
114   - $(link).remove();
115   -}
116   -
117   -(function($){
118   - var _chosen = $.fn.chosen;
119   - $.fn.extend({
120   - chosen: function(options) {
121   - var default_options = {'search_contains' : 'true'};
122   - $.extend(default_options, options);
123   - return _chosen.apply(this, [default_options]);
124   - }})
125   -})(jQuery);
126   -
127   -
128   -function ajaxGet(url) {
129   - $.ajax({type: "GET", url: url, dataType: "script"});
130   -}
131   -
132   -/**
133   - * Disable button if text field is empty
134   - */
135   -function disableButtonIfEmtpyField(field_selector, button_selector) {
136   - field = $(field_selector);
137   - if(field.val() == "") {
138   - field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled");
139   - }
140   -
141   - field.on('keyup', function(){
142   - var field = $(this);
143   - var closest_submit = field.closest("form").find(button_selector);
144   - if(field.val() == "") {
145   - closest_submit.attr("disabled", "disabled").addClass("disabled");
146   - } else {
147   - closest_submit.removeAttr("disabled").removeClass("disabled");
148   - }
149   - })
150   -}
... ...
app/assets/javascripts/main.js 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 +}
... ...