better_styles 0.0.0.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +33 -0
  4. data/Rakefile +34 -0
  5. data/app/helpers/styles_helper.rb +33 -0
  6. data/assets/fonts/betterfonts/betterwork-icons.eot +0 -0
  7. data/assets/fonts/betterfonts/betterwork-icons.svg +368 -0
  8. data/assets/fonts/betterfonts/betterwork-icons.ttf +0 -0
  9. data/assets/fonts/betterfonts/betterwork-icons.woff +0 -0
  10. data/assets/fonts/betterfonts/icomoon.eot +0 -0
  11. data/assets/fonts/betterfonts/icomoon.svg +461 -0
  12. data/assets/fonts/betterfonts/icomoon.ttf +0 -0
  13. data/assets/fonts/betterfonts/icomoon.woff +0 -0
  14. data/assets/fonts/betterfonts/magicons-regular-webfont.eot +0 -0
  15. data/assets/fonts/betterfonts/magicons-regular-webfont.svg +461 -0
  16. data/assets/fonts/betterfonts/magicons-regular-webfont.ttf +0 -0
  17. data/assets/fonts/betterfonts/magicons-regular-webfont.woff +0 -0
  18. data/assets/fonts/betterfonts/newmagicons-regular-webfont.eot +0 -0
  19. data/assets/fonts/betterfonts/newmagicons-regular-webfont.svg +199 -0
  20. data/assets/fonts/betterfonts/newmagicons-regular-webfont.ttf +0 -0
  21. data/assets/fonts/betterfonts/newmagicons-regular-webfont.woff +0 -0
  22. data/assets/fonts/betterfonts/orderlifticons-webfont.eot +0 -0
  23. data/assets/fonts/betterfonts/orderlifticons-webfont.svg +172 -0
  24. data/assets/fonts/betterfonts/orderlifticons-webfont.ttf +0 -0
  25. data/assets/fonts/betterfonts/orderlifticons-webfont.woff +0 -0
  26. data/assets/images/better/arrows/arrow-round1-a.png +0 -0
  27. data/assets/images/better/arrows/arrow-round1-b.png +0 -0
  28. data/assets/images/better/arrows/arrow-round2-a.png +0 -0
  29. data/assets/images/better/arrows/arrow-round2-b.png +0 -0
  30. data/assets/images/better/arrows/arrow1-a.png +0 -0
  31. data/assets/images/better/arrows/arrow1-b.png +0 -0
  32. data/assets/images/better/arrows/arrow1.png +0 -0
  33. data/assets/images/better/arrows/arrow2-1.png +0 -0
  34. data/assets/images/better/arrows/arrow2-2.png +0 -0
  35. data/assets/images/better/arrows/arrow2-a.png +0 -0
  36. data/assets/images/better/arrows/arrow2-b.png +0 -0
  37. data/assets/images/better/arrows/arrow3-a.png +0 -0
  38. data/assets/images/better/arrows/arrow3-b.png +0 -0
  39. data/assets/images/better/arrows/arrow4-a.png +0 -0
  40. data/assets/images/better/arrows/arrow4-b.png +0 -0
  41. data/assets/images/better/arrows/arrow5-a.png +0 -0
  42. data/assets/images/better/arrows/arrow5-b.png +0 -0
  43. data/assets/images/better/arrows/arrow6-a.png +0 -0
  44. data/assets/images/better/arrows/arrow6-b.png +0 -0
  45. data/assets/images/better/helper/blank_10.png +0 -0
  46. data/assets/images/better/helper/crossed.png +0 -0
  47. data/assets/images/better/helper/white_10.png +0 -0
  48. data/assets/javascripts/better_styles.js.coffee +4 -0
  49. data/assets/javascripts/betterjs/forms/check_switch.js.coffee +25 -0
  50. data/assets/javascripts/betterjs/helper.js.coffee +74 -0
  51. data/assets/javascripts/betterjs/navigations/aside_link.js.coffee +9 -0
  52. data/assets/javascripts/betterjs/navigations/nav_list.js.coffee +19 -0
  53. data/assets/javascripts/betterjs/rails_ext/rails-ujs.js +479 -0
  54. data/assets/javascripts/betterjs/render_eco.js.coffee +9 -0
  55. data/assets/javascripts/betterjs/templates/fixed_aside_to_header.js.coffee +6 -0
  56. data/assets/javascripts/betterjs/templates/icon_aside.js.coffee +12 -0
  57. data/assets/javascripts/betterjs/templates/scroll_to_fix_aside.js +32 -0
  58. data/assets/javascripts/betterjs/twbs_ext/affix_2_1_0.js +103 -0
  59. data/assets/javascripts/betterjs/twbs_ext/affix_3_3_7.js +162 -0
  60. data/assets/javascripts/betterjs/twbs_ext/affix_ext.js +131 -0
  61. data/assets/stylesheets/better/content/_box.scss +46 -0
  62. data/assets/stylesheets/better/content/_buttons.scss +22 -0
  63. data/assets/stylesheets/better/content/_check_switch.scss +78 -0
  64. data/assets/stylesheets/better/content/_divider.scss +65 -0
  65. data/assets/stylesheets/better/content/_helpers.scss +85 -0
  66. data/assets/stylesheets/better/content/_pix.scss +70 -0
  67. data/assets/stylesheets/better/content/_typography.scss +44 -0
  68. data/assets/stylesheets/better/icons/bettericons.scss +419 -0
  69. data/assets/stylesheets/better/icons/icomoon.scss +1392 -0
  70. data/assets/stylesheets/better/icons/magicons.scss +705 -0
  71. data/assets/stylesheets/better/icons/orderlifticons.scss +300 -0
  72. data/assets/stylesheets/better/layout/_corset.scss +57 -0
  73. data/assets/stylesheets/better/layout/_fullpage_table.scss +185 -0
  74. data/assets/stylesheets/better/layout/_positioning.scss +62 -0
  75. data/assets/stylesheets/better/layout/_section.scss +220 -0
  76. data/assets/stylesheets/better/lib/_helpers.scss +67 -0
  77. data/assets/stylesheets/better/lib/_media_querries.scss +43 -0
  78. data/assets/stylesheets/better/lib/_nav.scss +31 -0
  79. data/assets/stylesheets/better/lib/_shadows.scss +247 -0
  80. data/assets/stylesheets/better/lib/_text.scss +66 -0
  81. data/assets/stylesheets/better/navigations/_aside_lnk.scss +100 -0
  82. data/assets/stylesheets/better/navigations/_nav_list.scss +177 -0
  83. data/assets/stylesheets/better/templates/_fixed_aside_to_header.scss +89 -0
  84. data/assets/stylesheets/better/templates/_icon_aside.scss +404 -0
  85. data/assets/stylesheets/better/templates/_scroll_to_fix_aside.scss +104 -0
  86. data/assets/stylesheets/better/variables/_color.scss +87 -0
  87. data/assets/stylesheets/better/variables/_typography.scss +59 -0
  88. data/assets/stylesheets/better/variables/_vars.scss +57 -0
  89. data/assets/stylesheets/better_styles.scss +44 -0
  90. data/assets/stylesheets/better_styles_min.scss +43 -0
  91. data/lib/better_styles.rb +64 -0
  92. data/lib/better_styles/engine.rb +25 -0
  93. data/lib/better_styles/version.rb +3 -0
  94. data/lib/tasks/better_styles_tasks.rake +4 -0
  95. metadata +181 -0
@@ -0,0 +1,25 @@
1
+ $ ->
2
+
3
+ $('body').on 'click', '.check_switch', (event) ->
4
+ if $(@).hasClass("active")
5
+ $(@).removeClass("active")
6
+ $(@).find("input").prop(checked: false)
7
+ else
8
+ $(@).addClass("active")
9
+ $(@).find("input").prop(checked: true)
10
+ # $(@).closest("form").find(".btn.hidden").hide().removeClass("hidden").show()
11
+ # $(@).closest("form").find(".btn.disabled").hide().removeClass("disabled").show()
12
+
13
+
14
+ $('body').on 'click', '.radio_switch', (event) ->
15
+ if $(@).attr("data-radio")
16
+ radios = $(".radio_switch.#{ $(@).attr("data-radio") }")
17
+ else
18
+ radios = $(".radio_switch")
19
+ radios.each ->
20
+ $(@).removeClass("active")
21
+ $(@).find("input").prop(checked: false)
22
+ $(@).find("input").trigger("change")
23
+ $(@).addClass("active")
24
+ $(@).find("input").prop(checked: true)
25
+ $(@).find("input").trigger("change")
@@ -0,0 +1,74 @@
1
+ @to_currency = ( number, delimiter = ",", seperator = "." ) ->
2
+ unless isNaN number
3
+ nmbr = (Math.round( parseFloat( number ) * 100 ) / 100).toFixed(2)
4
+ else
5
+ nmbr = (0).toFixed(2)
6
+ if nmbr >= 1000.0
7
+ end = "#{nmbr}".split(".")[1]
8
+ "#{ (parseInt(nmbr) / 1000).toFixed(3).replace(/\./, seperator) }#{delimiter}#{end}"
9
+ else
10
+ "#{nmbr}".replace(/\./, delimiter)
11
+
12
+ @to_euro = (number) ->
13
+ "#{to_currency(number)} €"
14
+
15
+ @to_dollar = (number) ->
16
+ "$ #{to_currency( number, ".", "," )}"
17
+
18
+
19
+ @getInt = (number = 0) ->
20
+ parseInt( "#{number}".replace(/^[^\d\.]*/, "") ) || 0
21
+
22
+ @getFloat = (number = 0.0) ->
23
+ parseFloat( "#{number}".replace(',','.').replace(/^[^\d\.]*/, "") ) || 0.0
24
+
25
+
26
+ @btricon = (icn, cls = "" ) ->
27
+ "<i class='bettericon-#{ icn }#{ if cls != "" then " #{cls}" else "" }'></i>"
28
+
29
+ @olicon = (icn, cls = "" ) ->
30
+ "<i class='olicons-#{ icn }#{ if cls != "" then " #{cls}" else "" }'></i>"
31
+
32
+
33
+ ##
34
+ ## Usage:
35
+ ## $(".bla").text().chunk(4).join(" ")
36
+ ## 1234 5678 9012 ...
37
+ ##
38
+ String::chunk = (n = 3) ->
39
+ space = []
40
+ i = 0
41
+ len = @length
42
+ while i < len
43
+ space.push @substr(i, n)
44
+ i += n
45
+ space
46
+
47
+ String::chunked = ( n = 3, spc = " ") ->
48
+ @chunk(n).join(spc)
49
+
50
+
51
+ # little string helper
52
+ # http://www.oct4th.com/2013/03/15/titleize-for-javascript/
53
+ String::titleize = ->
54
+ words = @split(' ')
55
+ array = []
56
+ i = 0
57
+ while i < words.length
58
+ array.push words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1)
59
+ ++i
60
+ array.join ' '
61
+
62
+
63
+ if typeof String::trim == 'undefined'
64
+ String::trim = ->
65
+ String(this).replace /^\s+|\s+$/g, ''
66
+
67
+
68
+
69
+ $ ->
70
+
71
+ # replace komma with dot (german uses komma instead of dot)
72
+ $("body").on "keyup", "input.number_field", ->
73
+ if jQuery(@).val().indexOf(",") isnt -1
74
+ jQuery(@).val( jQuery(@).val().replace(',','.') )
@@ -0,0 +1,9 @@
1
+ $ ->
2
+
3
+ $("body").on "click", ".main-aside .aside_lnk.toggler, .main-aside .aside_lnk .toggler", (e) ->
4
+ e.preventDefault()
5
+ if $(@).hasClass("aside_lnk")
6
+ $(@).toggleClass("on")
7
+ else
8
+ $(@).closest(".aside_lnk").toggleClass("on")
9
+ false
@@ -0,0 +1,19 @@
1
+ $ ->
2
+
3
+
4
+ $(document).on "click", ".lst_lnk", ->
5
+ # nav = $(@).closest(".nav")
6
+ nav = $(@).closest(".nav_list")
7
+ ul = $(@).closest("ul")
8
+ li = $(@).closest("li")
9
+ nav.find("li.active" ).removeClass("active")
10
+ nav.find("li.current").removeClass("current")
11
+ until ul.hasClass("nav_list")
12
+ ul.closest("li").addClass("active")
13
+ ul = ul.closest("li").closest("ul")
14
+ li.addClass("current")
15
+ li.addClass("active")
16
+ $(@).blur()
17
+ return false if $(@).attr("href") == "#"
18
+
19
+
@@ -0,0 +1,479 @@
1
+ (function($, undefined) {
2
+
3
+ /**
4
+ * Unobtrusive scripting adapter for jQuery
5
+ * https://github.com/rails/jquery-ujs
6
+ *
7
+ * Requires jQuery 1.8.0 or later.
8
+ *
9
+ * Released under the MIT license
10
+
11
+ # changed to work better with divided and splitted buttons .. twetzel
12
+
13
+ *
14
+ */
15
+
16
+ // Cut down on the number of issues from people inadvertently including jquery_ujs twice
17
+ // by detecting and raising an error when it happens.
18
+ if ( $.rails !== undefined ) {
19
+ $.error('jquery-ujs has already been loaded!');
20
+ }
21
+
22
+ // Shorthand to make it a little easier to call public rails functions from within rails.js
23
+ var rails;
24
+ var $document = $(document);
25
+
26
+ $.rails = rails = {
27
+ // Link elements bound by jquery-ujs
28
+ linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with], a[data-disable]',
29
+
30
+ // Button elements bound by jquery-ujs
31
+ buttonClickSelector: 'button[data-remote]:not(form button), button[data-confirm]:not(form button)',
32
+
33
+ // Select elements bound by jquery-ujs
34
+ inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
35
+
36
+ // Form elements bound by jquery-ujs
37
+ formSubmitSelector: 'form',
38
+
39
+ // Form input elements bound by jquery-ujs
40
+ formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])',
41
+
42
+ // Form input elements disabled during form submission
43
+ disableSelector: 'input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled',
44
+
45
+ // Form input elements re-enabled after form submission
46
+ enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled',
47
+
48
+ // Form required input elements
49
+ requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
50
+
51
+ // Form file input elements
52
+ fileInputSelector: 'input[type=file]',
53
+
54
+ // Link onClick disable selector with possible reenable after remote submission
55
+ linkDisableSelector: 'a[data-disable-with], a[data-disable]',
56
+
57
+ // Button onClick disable selector with possible reenable after remote submission
58
+ buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]',
59
+
60
+ // Make sure that every Ajax request sends the CSRF token
61
+ CSRFProtection: function(xhr) {
62
+ var token = $('meta[name="csrf-token"]').attr('content');
63
+ if (token) xhr.setRequestHeader('X-CSRF-Token', token);
64
+ },
65
+
66
+ // making sure that all forms have actual up-to-date token(cached forms contain old one)
67
+ refreshCSRFTokens: function(){
68
+ var csrfToken = $('meta[name=csrf-token]').attr('content');
69
+ var csrfParam = $('meta[name=csrf-param]').attr('content');
70
+ $('form input[name="' + csrfParam + '"]').val(csrfToken);
71
+ },
72
+
73
+ // Triggers an event on an element and returns false if the event result is false
74
+ fire: function(obj, name, data) {
75
+ var event = $.Event(name);
76
+ obj.trigger(event, data);
77
+ return event.result !== false;
78
+ },
79
+
80
+ // Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
81
+ confirm: function(message) {
82
+ return confirm(message);
83
+ },
84
+
85
+ // Default ajax function, may be overridden with custom function in $.rails.ajax
86
+ ajax: function(options) {
87
+ return $.ajax(options);
88
+ },
89
+
90
+ // Default way to get an element's href. May be overridden at $.rails.href.
91
+ href: function(element) {
92
+ return element.attr('href');
93
+ },
94
+
95
+ // Submits "remote" forms and links with ajax
96
+ handleRemote: function(element) {
97
+ var method, url, data, elCrossDomain, crossDomain, withCredentials, dataType, options;
98
+
99
+ if (rails.fire(element, 'ajax:before')) {
100
+ elCrossDomain = element.data('cross-domain');
101
+ crossDomain = elCrossDomain === undefined ? null : elCrossDomain;
102
+ withCredentials = element.data('with-credentials') || null;
103
+ dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
104
+
105
+ if (element.is('form')) {
106
+ method = element.attr('method');
107
+ url = element.attr('action');
108
+ data = element.serializeArray();
109
+ // memoized value from clicked submit button
110
+ var button = element.data('ujs:submit-button');
111
+ if (button) {
112
+ data.push(button);
113
+ element.data('ujs:submit-button', null);
114
+ }
115
+ } else if (element.is(rails.inputChangeSelector)) {
116
+ method = element.data('method');
117
+ url = element.data('url');
118
+ data = element.serialize();
119
+ if (element.data('params')) data = data + "&" + element.data('params');
120
+ } else if (element.is(rails.buttonClickSelector)) {
121
+ method = element.data('method') || 'get';
122
+ url = element.data('url');
123
+ data = element.serialize();
124
+ if (element.data('params')) data = data + "&" + element.data('params');
125
+ } else {
126
+ method = element.data('method');
127
+ url = rails.href(element);
128
+ data = element.data('params') || null;
129
+ }
130
+
131
+ options = {
132
+ type: method || 'GET', data: data, dataType: dataType,
133
+ // stopping the "ajax:beforeSend" event will cancel the ajax request
134
+ beforeSend: function(xhr, settings) {
135
+ if (settings.dataType === undefined) {
136
+ xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
137
+ }
138
+ if (rails.fire(element, 'ajax:beforeSend', [xhr, settings])) {
139
+ element.trigger('ajax:send', xhr);
140
+ } else {
141
+ return false;
142
+ }
143
+ },
144
+ success: function(data, status, xhr) {
145
+ element.trigger('ajax:success', [data, status, xhr]);
146
+ },
147
+ complete: function(xhr, status) {
148
+ element.trigger('ajax:complete', [xhr, status]);
149
+ },
150
+ error: function(xhr, status, error) {
151
+ element.trigger('ajax:error', [xhr, status, error]);
152
+ },
153
+ crossDomain: crossDomain
154
+ };
155
+
156
+ // There is no withCredentials for IE6-8 when
157
+ // "Enable native XMLHTTP support" is disabled
158
+ if (withCredentials) {
159
+ options.xhrFields = {
160
+ withCredentials: withCredentials
161
+ };
162
+ }
163
+
164
+ // Only pass url to `ajax` options if not blank
165
+ if (url) { options.url = url; }
166
+
167
+ return rails.ajax(options);
168
+ } else {
169
+ return false;
170
+ }
171
+ },
172
+
173
+ // Handles "data-method" on links such as:
174
+ // <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
175
+ handleMethod: function(link) {
176
+ var href = rails.href(link),
177
+ method = link.data('method'),
178
+ target = link.attr('target'),
179
+ csrfToken = $('meta[name=csrf-token]').attr('content'),
180
+ csrfParam = $('meta[name=csrf-param]').attr('content'),
181
+ form = $('<form method="post" action="' + href + '"></form>'),
182
+ metadataInput = '<input name="_method" value="' + method + '" type="hidden" />';
183
+
184
+ if (csrfParam !== undefined && csrfToken !== undefined) {
185
+ metadataInput += '<input name="' + csrfParam + '" value="' + csrfToken + '" type="hidden" />';
186
+ }
187
+
188
+ if (target) { form.attr('target', target); }
189
+
190
+ form.hide().append(metadataInput).appendTo('body');
191
+ form.submit();
192
+ },
193
+
194
+ // Helper function that returns form elements that match the specified CSS selector
195
+ // If form is actually a "form" element this will return associated elements outside the from that have
196
+ // the html form attribute set
197
+ formElements: function(form, selector) {
198
+ return form.is('form') ? $(form[0].elements).filter(selector) : form.find(selector);
199
+ },
200
+
201
+ /* Disables form elements:
202
+ - Caches element value in 'ujs:enable-with' data store
203
+ - Replaces element text with value of 'data-disable-with' attribute
204
+ - Sets disabled property to true
205
+ */
206
+ disableFormElements: function(form) {
207
+ rails.formElements(form, rails.disableSelector).each(function() {
208
+ rails.disableFormElement($(this));
209
+ });
210
+ },
211
+
212
+ disableFormElement: function(element) {
213
+ var method, replacement;
214
+
215
+ method = element.is('button') ? 'html' : 'val';
216
+ replacement = element.data('disable-with');
217
+
218
+ element.data('ujs:enable-with', element[method]());
219
+ if (replacement !== undefined) {
220
+ // element[method](replacement);
221
+ if ( element.hasClass("btn-splited") || element.hasClass("btn-divided") ) {
222
+ element.children("*:not(.icn):first").html(replacement);
223
+ } else {
224
+ element[method](replacement);
225
+ }
226
+ }
227
+
228
+ element.prop('disabled', true);
229
+ element.addClass("disabled");
230
+ },
231
+
232
+ /* Re-enables disabled form elements:
233
+ - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
234
+ - Sets disabled property to false
235
+ */
236
+ enableFormElements: function(form) {
237
+ rails.formElements(form, rails.enableSelector).each(function() {
238
+ rails.enableFormElement($(this));
239
+ });
240
+ },
241
+
242
+ enableFormElement: function(element) {
243
+ var method = element.is('button') ? 'html' : 'val';
244
+ if ( element.data('ujs:enable-with') ) {
245
+ // element[method](element.data('ujs:enable-with'));
246
+ if ( element.hasClass("btn-splited") || element.hasClass("btn-divided") ) {
247
+ element.children("*:not(.icn):first").html(element.data('ujs:enable-with'));
248
+ } else {
249
+ element[method](element.data('ujs:enable-with'));
250
+ }
251
+ }
252
+ element.prop('disabled', false);
253
+ element.removeClass("disabled");
254
+ },
255
+
256
+ /* For 'data-confirm' attribute:
257
+ - Fires `confirm` event
258
+ - Shows the confirmation dialog
259
+ - Fires the `confirm:complete` event
260
+
261
+ Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
262
+ Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
263
+ Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
264
+ return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
265
+ */
266
+ allowAction: function(element) {
267
+ var message = element.data('confirm'),
268
+ answer = false, callback;
269
+ if (!message) { return true; }
270
+
271
+ if (rails.fire(element, 'confirm')) {
272
+ answer = rails.confirm(message);
273
+ callback = rails.fire(element, 'confirm:complete', [answer]);
274
+ }
275
+ return answer && callback;
276
+ },
277
+
278
+ // Helper function which checks for blank inputs in a form that match the specified CSS selector
279
+ blankInputs: function(form, specifiedSelector, nonBlank) {
280
+ var inputs = $(), input, valueToCheck,
281
+ selector = specifiedSelector || 'input,textarea',
282
+ allInputs = form.find(selector);
283
+
284
+ allInputs.each(function() {
285
+ input = $(this);
286
+ valueToCheck = input.is('input[type=checkbox],input[type=radio]') ? input.is(':checked') : input.val();
287
+ // If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey
288
+ if (!valueToCheck === !nonBlank) {
289
+
290
+ // Don't count unchecked required radio if other radio with same name is checked
291
+ if (input.is('input[type=radio]') && allInputs.filter('input[type=radio]:checked[name="' + input.attr('name') + '"]').length) {
292
+ return true; // Skip to next input
293
+ }
294
+
295
+ inputs = inputs.add(input);
296
+ }
297
+ });
298
+ return inputs.length ? inputs : false;
299
+ },
300
+
301
+ // Helper function which checks for non-blank inputs in a form that match the specified CSS selector
302
+ nonBlankInputs: function(form, specifiedSelector) {
303
+ return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
304
+ },
305
+
306
+ // Helper function, needed to provide consistent behavior in IE
307
+ stopEverything: function(e) {
308
+ $(e.target).trigger('ujs:everythingStopped');
309
+ e.stopImmediatePropagation();
310
+ return false;
311
+ },
312
+
313
+ // replace element's html with the 'data-disable-with' after storing original html
314
+ // and prevent clicking on it
315
+ disableElement: function(element) {
316
+
317
+ console.log("***")
318
+ console.log("disableElement !")
319
+ console.log("***")
320
+
321
+ var replacement = element.data('disable-with');
322
+
323
+ element.data('ujs:enable-with', element.html()); // store enabled state
324
+ element.addClass("disabled");
325
+ if (replacement !== undefined) {
326
+ if ( element.hasClass("btn-splited") || element.hasClass("btn-divided") ) {
327
+ element.children("*:not(.icn):first").html(replacement);
328
+ } else {
329
+ element.html(replacement);
330
+ }
331
+ }
332
+
333
+ element.bind('click.railsDisable', function(e) { // prevent further clicking
334
+ return rails.stopEverything(e);
335
+ });
336
+ },
337
+
338
+ // restore element to its original state which was disabled by 'disableElement' above
339
+ enableElement: function(element) {
340
+ element.removeClass("disabled");
341
+ if (element.data('ujs:enable-with') !== undefined) {
342
+ // element.html(element.data('ujs:enable-with')); // set to old enabled state
343
+ if ( element.hasClass("btn-splited") || element.hasClass("btn-divided") ) {
344
+ element.children("*:not(.icn):first").html(element.data('ujs:enable-with'));
345
+ } else {
346
+ element.html(element.data('ujs:enable-with'));
347
+ }
348
+ element.removeData('ujs:enable-with'); // clean up cache
349
+ }
350
+ element.unbind('click.railsDisable'); // enable element
351
+ }
352
+ };
353
+
354
+ if (rails.fire($document, 'rails:attachBindings')) {
355
+
356
+ $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
357
+
358
+ $document.delegate(rails.linkDisableSelector, 'ajax:complete', function() {
359
+ rails.enableElement($(this));
360
+ });
361
+
362
+ $document.delegate(rails.buttonDisableSelector, 'ajax:complete', function() {
363
+ rails.enableFormElement($(this));
364
+ });
365
+
366
+ $document.delegate(rails.linkClickSelector, 'click.rails', function(e) {
367
+ var link = $(this), method = link.data('method'), data = link.data('params'), metaClick = e.metaKey || e.ctrlKey;
368
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
369
+
370
+ if (!metaClick && link.is(rails.linkDisableSelector)) rails.disableElement(link);
371
+
372
+ if (link.data('remote') !== undefined) {
373
+ if (metaClick && (!method || method === 'GET') && !data) { return true; }
374
+
375
+ var handleRemote = rails.handleRemote(link);
376
+ // response from rails.handleRemote() will either be false or a deferred object promise.
377
+ if (handleRemote === false) {
378
+ rails.enableElement(link);
379
+ } else {
380
+ handleRemote.error( function() { rails.enableElement(link); } );
381
+ }
382
+ return false;
383
+
384
+ } else if (link.data('method')) {
385
+ rails.handleMethod(link);
386
+ return false;
387
+ }
388
+ });
389
+
390
+ $document.delegate(rails.buttonClickSelector, 'click.rails', function(e) {
391
+ var button = $(this);
392
+
393
+ if (!rails.allowAction(button)) return rails.stopEverything(e);
394
+
395
+ if (button.is(rails.buttonDisableSelector)) rails.disableFormElement(button);
396
+
397
+ var handleRemote = rails.handleRemote(button);
398
+ // response from rails.handleRemote() will either be false or a deferred object promise.
399
+ if (handleRemote === false) {
400
+ rails.enableFormElement(button);
401
+ } else {
402
+ handleRemote.error( function() { rails.enableFormElement(button); } );
403
+ }
404
+ return false;
405
+ });
406
+
407
+ $document.delegate(rails.inputChangeSelector, 'change.rails', function(e) {
408
+ var link = $(this);
409
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
410
+
411
+ rails.handleRemote(link);
412
+ return false;
413
+ });
414
+
415
+ $document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
416
+ var form = $(this),
417
+ remote = form.data('remote') !== undefined,
418
+ blankRequiredInputs,
419
+ nonBlankFileInputs;
420
+
421
+ if (!rails.allowAction(form)) return rails.stopEverything(e);
422
+
423
+ // skip other logic when required values are missing or file upload is present
424
+ if (form.attr('novalidate') == undefined) {
425
+ blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector);
426
+ if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
427
+ return rails.stopEverything(e);
428
+ }
429
+ }
430
+
431
+ if (remote) {
432
+ nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
433
+ if (nonBlankFileInputs) {
434
+ // slight timeout so that the submit button gets properly serialized
435
+ // (make it easy for event handler to serialize form without disabled values)
436
+ setTimeout(function(){ rails.disableFormElements(form); }, 13);
437
+ var aborted = rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
438
+
439
+ // re-enable form elements if event bindings return false (canceling normal form submission)
440
+ if (!aborted) { setTimeout(function(){ rails.enableFormElements(form); }, 13); }
441
+
442
+ return aborted;
443
+ }
444
+
445
+ rails.handleRemote(form);
446
+ return false;
447
+
448
+ } else {
449
+ // slight timeout so that the submit button gets properly serialized
450
+ setTimeout(function(){ rails.disableFormElements(form); }, 13);
451
+ }
452
+ });
453
+
454
+ $document.delegate(rails.formInputClickSelector, 'click.rails', function(event) {
455
+ var button = $(this);
456
+
457
+ if (!rails.allowAction(button)) return rails.stopEverything(event);
458
+
459
+ // register the pressed submit button
460
+ var name = button.attr('name'),
461
+ data = name ? {name:name, value:button.val()} : null;
462
+
463
+ button.closest('form').data('ujs:submit-button', data);
464
+ });
465
+
466
+ $document.delegate(rails.formSubmitSelector, 'ajax:send.rails', function(event) {
467
+ if (this == event.target) rails.disableFormElements($(this));
468
+ });
469
+
470
+ $document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
471
+ if (this == event.target) rails.enableFormElements($(this));
472
+ });
473
+
474
+ $(function(){
475
+ rails.refreshCSRFTokens();
476
+ });
477
+ }
478
+
479
+ })( jQuery );