ui_alchemy-rails 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +6 -0
- data/Rakefile +21 -0
- data/app/assets/fonts/alchemy/LiberationSans-Bold-webfont.eot +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-Bold-webfont.svg +154 -0
- data/app/assets/fonts/alchemy/LiberationSans-Bold-webfont.ttf +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-Bold-webfont.woff +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-BoldItalic-webfont.eot +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-BoldItalic-webfont.svg +154 -0
- data/app/assets/fonts/alchemy/LiberationSans-BoldItalic-webfont.ttf +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-BoldItalic-webfont.woff +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-Italic-webfont.eot +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-Italic-webfont.svg +154 -0
- data/app/assets/fonts/alchemy/LiberationSans-Italic-webfont.ttf +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-Italic-webfont.woff +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-Regular-webfont.eot +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-Regular-webfont.svg +154 -0
- data/app/assets/fonts/alchemy/LiberationSans-Regular-webfont.ttf +0 -0
- data/app/assets/fonts/alchemy/LiberationSans-Regular-webfont.woff +0 -0
- data/app/assets/fonts/alchemy/Red Hat Liberation License.txt +78 -0
- data/app/assets/fonts/alchemy/overpass_bold-web.eot +0 -0
- data/app/assets/fonts/alchemy/overpass_bold-web.svg +470 -0
- data/app/assets/fonts/alchemy/overpass_bold-web.ttf +0 -0
- data/app/assets/fonts/alchemy/overpass_bold-web.woff +0 -0
- data/app/assets/fonts/alchemy/overpass_regular-web.eot +0 -0
- data/app/assets/fonts/alchemy/overpass_regular-web.svg +470 -0
- data/app/assets/fonts/alchemy/overpass_regular-web.ttf +0 -0
- data/app/assets/fonts/alchemy/overpass_regular-web.woff +0 -0
- data/app/assets/images/alchemy/icons/action-icons.png +0 -0
- data/app/assets/images/alchemy/icons/arrow_icon.png +0 -0
- data/app/assets/images/alchemy/icons/chosen-sprite.png +0 -0
- data/app/assets/images/alchemy/icons/error_icon.png +0 -0
- data/app/assets/images/alchemy/icons/objects.png +0 -0
- data/app/assets/images/alchemy/icons/spinner.gif +0 -0
- data/app/assets/images/alchemy/icons/spinner_head.gif +0 -0
- data/app/assets/images/alchemy/icons/success_icon.png +0 -0
- data/app/assets/images/alchemy/icons/warning_icon.png +0 -0
- data/app/assets/javascripts/alchemy/flash_messages.js +12 -0
- data/app/assets/javascripts/alchemy/forms.js +25 -0
- data/app/assets/javascripts/alchemy/i18n.js +36 -0
- data/app/assets/javascripts/alchemy/login.js +130 -0
- data/app/assets/javascripts/alchemy/password.js +99 -0
- data/app/assets/stylesheets/alchemy/components/_chosen.scss +423 -0
- data/app/assets/stylesheets/alchemy/components/_content.scss +58 -0
- data/app/assets/stylesheets/alchemy/components/_helpers.scss +38 -0
- data/app/assets/stylesheets/alchemy/components/_media.scss +49 -0
- data/app/assets/stylesheets/alchemy/components/_media_object.scss +22 -0
- data/app/assets/stylesheets/alchemy/components/_normalize.scss +396 -0
- data/app/assets/stylesheets/alchemy/components/_shared.scss +18 -0
- data/app/assets/stylesheets/alchemy/components/buttons/_buttons.scss +278 -0
- data/app/assets/stylesheets/alchemy/components/buttons/_buttons_vars.scss +11 -0
- data/app/assets/stylesheets/alchemy/components/flash_messages/_flash_messages.scss +93 -0
- data/app/assets/stylesheets/alchemy/components/flash_messages/_flash_messages_vars.scss +3 -0
- data/app/assets/stylesheets/alchemy/components/fonts/_liberation.scss +44 -0
- data/app/assets/stylesheets/alchemy/components/fonts/_overpass.scss +24 -0
- data/app/assets/stylesheets/alchemy/components/footer/_footer.scss +53 -0
- data/app/assets/stylesheets/alchemy/components/footer/_footer_vars.scss +4 -0
- data/app/assets/stylesheets/alchemy/components/forms/_forms.scss +552 -0
- data/app/assets/stylesheets/alchemy/components/forms/_forms_ie.scss +45 -0
- data/app/assets/stylesheets/alchemy/components/forms/_forms_mixins.scss +18 -0
- data/app/assets/stylesheets/alchemy/components/forms/_forms_responsive.scss +167 -0
- data/app/assets/stylesheets/alchemy/components/forms/_forms_vars.scss +25 -0
- data/app/assets/stylesheets/alchemy/components/header/_header.scss +216 -0
- data/app/assets/stylesheets/alchemy/components/header/_header_vars.scss +11 -0
- data/app/assets/stylesheets/alchemy/components/login/_login.scss +173 -0
- data/app/assets/stylesheets/alchemy/components/login/_login_mixins.scss +7 -0
- data/app/assets/stylesheets/alchemy/components/login/_login_vars.scss +19 -0
- data/app/assets/stylesheets/alchemy/components/sprites/_sprites.scss +110 -0
- data/app/assets/stylesheets/alchemy/components/sprites/_sprites_mixins.scss +9 -0
- data/app/assets/stylesheets/alchemy/components/text/_text.scss +30 -0
- data/app/assets/stylesheets/alchemy/components/text/_text_vars.scss +1 -0
- data/app/assets/stylesheets/alchemy/composites/content_elements.scss +6 -0
- data/app/assets/stylesheets/alchemy/composites/login.scss +9 -0
- data/app/assets/stylesheets/alchemy/composites/shell.scss +4 -0
- data/app/assets/stylesheets/alchemy/partials/_base.scss +8 -0
- data/app/assets/stylesheets/alchemy/partials/_colors.scss +99 -0
- data/app/assets/stylesheets/alchemy/partials/_mixins.scss +24 -0
- data/app/assets/stylesheets/alchemy/partials/_vars.scss +31 -0
- data/app/helpers/ui_alchemy/gettext_translations.rb +28 -0
- data/app/helpers/ui_alchemy/layout_helper.rb +35 -0
- data/app/helpers/ui_alchemy/rails_translations.rb +21 -0
- data/app/helpers/ui_alchemy/translation_helper.rb +19 -0
- data/app/views/alchemy/layouts/_change_password_layout.html.haml +20 -0
- data/app/views/alchemy/layouts/_common_i18n.haml +4 -0
- data/app/views/alchemy/layouts/_header_layout.haml +13 -0
- data/app/views/alchemy/layouts/_login_layout.html.haml +58 -0
- data/app/views/alchemy/layouts/_user_session_layout.haml +17 -0
- data/app/views/alchemy/layouts/base.html.haml +20 -0
- data/app/views/alchemy/layouts/shell_layout.haml +10 -0
- data/lib/ui_alchemy/rails/engine.rb +6 -0
- data/lib/ui_alchemy/rails/version.rb +5 -0
- data/lib/ui_alchemy-rails.rb +2 -0
- data/vendor/assets/javascripts/alchemy/handlebars.js +2201 -0
- data/vendor/assets/javascripts/alchemy/html5shiv.js +298 -0
- data/vendor/assets/javascripts/alchemy/jquery/jquery-1.6.2.js +8981 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/chosen.jquery.js +1003 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/excanvas.js +1427 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/excanvas.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.colorhelpers.js +179 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.colorhelpers.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.crosshair.js +167 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.crosshair.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.fillbetween.js +183 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.fillbetween.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.image.js +238 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.image.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.js +2599 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.min.js +6 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.navigate.js +336 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.navigate.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.pie.js +750 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.pie.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.resize.js +60 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.resize.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.selection.js +344 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.selection.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.stack.js +184 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.stack.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.symbol.js +70 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.symbol.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.threshold.js +103 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.threshold.min.js +1 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/blank.svg +3 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/custom_test.js +67 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svg.css +9 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svg.js +1101 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svg.min.js +7 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svg.pack.js +7 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svgfilter.js +396 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svgfilter.min.js +7 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svgfilter.pack.js +7 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svggraph.js +1337 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svggraph.min.js +7 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svggraph.pack.js +7 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/lion.svg +161 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/test.js +714 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ajaxfileupload.js +205 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ba-bbq.js +1137 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ba-resize.js +246 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.cookie.js +92 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.easing.1.3.js +205 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.fancyqueries.js +106 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.flash.js +288 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.form.js +964 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.hoverIntent.js +106 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jeditable.ajaxupload.js +62 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jeditable.js +556 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jnotify.js +210 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jscrollpane.js +1390 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jscrollpane.min.js +11 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.linkHover.js +89 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.loadmask.min.js +10 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.mousewheel.js +78 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.multiselect.filter.js +176 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.multiselect.js +668 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.pack.js +11 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.periodicalupdater.js +175 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.sortElements.js +75 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.sparkline.min.js +94 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.text-overflow.js +60 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.timepickr.js +214 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.timers.js +142 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.tipsy.js +358 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.treeTable.js +226 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.trunk8.js +203 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ui.multiselect.js +338 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ui.totop.js +58 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.uitablefilter.js +95 -0
- data/vendor/assets/javascripts/alchemy/jquery/plugins/ui.spinner.js +683 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_highlight-hard_75_dadada_1x100.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_highlight-hard_75_e6e6e6_1x100.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_highlight-hard_95_ffffff_1x100.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_highlight-soft_80_e0e0e0_1x100.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_inset-hard_65_ffffff_1x100.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-icons_8f8f8f_256x240.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-icons_97baed_256x240.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/jquery-ui-1.8.11.custom.css +573 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/js/jquery-1.5.1.min.js +16 -0
- data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/js/jquery-ui-1.8.11.custom.min.js +783 -0
- data/vendor/assets/javascripts/alchemy/rails.js +331 -0
- data/vendor/assets/javascripts/alchemy/underscore-1.3.1.js +999 -0
- metadata +252 -0
@@ -0,0 +1,331 @@
|
|
1
|
+
/**
|
2
|
+
* Unobtrusive scripting adapter for jQuery
|
3
|
+
*
|
4
|
+
* Requires jQuery 1.6.0 or later.
|
5
|
+
* https://github.com/rails/jquery-ujs
|
6
|
+
|
7
|
+
* Uploading file using rails.js
|
8
|
+
* =============================
|
9
|
+
*
|
10
|
+
* By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
|
11
|
+
* in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
|
12
|
+
*
|
13
|
+
* The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
|
14
|
+
*
|
15
|
+
* Ex:
|
16
|
+
* $('form').live('ajax:aborted:file', function(event, elements){
|
17
|
+
* // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
|
18
|
+
* // Returning false in this handler tells rails.js to disallow standard form submission
|
19
|
+
* return false;
|
20
|
+
* });
|
21
|
+
*
|
22
|
+
* The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
|
23
|
+
*
|
24
|
+
* Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
|
25
|
+
* techniques like the iframe method to upload the file instead.
|
26
|
+
*
|
27
|
+
* Required fields in rails.js
|
28
|
+
* ===========================
|
29
|
+
*
|
30
|
+
* If any blank required inputs (required="required") are detected in the remote form, the whole form submission
|
31
|
+
* is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
|
32
|
+
*
|
33
|
+
* The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
|
34
|
+
*
|
35
|
+
* !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
|
36
|
+
* get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
|
37
|
+
*
|
38
|
+
* Ex:
|
39
|
+
* $('form').live('ajax:aborted:required', function(event, elements){
|
40
|
+
* // Returning false in this handler tells rails.js to submit the form anyway.
|
41
|
+
* // The blank required inputs are passed to this function in `elements`.
|
42
|
+
* return ! confirm("Would you like to submit the form with missing info?");
|
43
|
+
* });
|
44
|
+
*/
|
45
|
+
|
46
|
+
(function($, undefined) {
|
47
|
+
// Shorthand to make it a little easier to call public rails functions from within rails.js
|
48
|
+
var rails;
|
49
|
+
|
50
|
+
$.rails = rails = {
|
51
|
+
// Link elements bound by jquery-ujs
|
52
|
+
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]',
|
53
|
+
|
54
|
+
// Select elements bound by jquery-ujs
|
55
|
+
selectChangeSelector: 'select[data-remote]',
|
56
|
+
|
57
|
+
// Form elements bound by jquery-ujs
|
58
|
+
formSubmitSelector: 'form',
|
59
|
+
|
60
|
+
// Form input elements bound by jquery-ujs
|
61
|
+
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',
|
62
|
+
|
63
|
+
// Form input elements disabled during form submission
|
64
|
+
disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
|
65
|
+
|
66
|
+
// Form input elements re-enabled after form submission
|
67
|
+
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
|
68
|
+
|
69
|
+
// Form required input elements
|
70
|
+
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
|
71
|
+
|
72
|
+
// Form file input elements
|
73
|
+
fileInputSelector: 'input:file',
|
74
|
+
|
75
|
+
// Make sure that every Ajax request sends the CSRF token
|
76
|
+
CSRFProtection: function(xhr) {
|
77
|
+
var token = $('meta[name="csrf-token"]').attr('content');
|
78
|
+
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
79
|
+
},
|
80
|
+
|
81
|
+
// Triggers an event on an element and returns false if the event result is false
|
82
|
+
fire: function(obj, name, data) {
|
83
|
+
var event = $.Event(name);
|
84
|
+
obj.trigger(event, data);
|
85
|
+
return event.result !== false;
|
86
|
+
},
|
87
|
+
|
88
|
+
// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
|
89
|
+
confirm: function(message) {
|
90
|
+
return confirm(message);
|
91
|
+
},
|
92
|
+
|
93
|
+
// Default ajax function, may be overridden with custom function in $.rails.ajax
|
94
|
+
ajax: function(options) {
|
95
|
+
return $.ajax(options);
|
96
|
+
},
|
97
|
+
|
98
|
+
// Submits "remote" forms and links with ajax
|
99
|
+
handleRemote: function(element) {
|
100
|
+
var method, url, data,
|
101
|
+
crossDomain = element.data('cross-domain') || null,
|
102
|
+
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
|
103
|
+
|
104
|
+
if (rails.fire(element, 'ajax:before')) {
|
105
|
+
|
106
|
+
if (element.is('form')) {
|
107
|
+
method = element.attr('method');
|
108
|
+
url = element.attr('action');
|
109
|
+
data = element.serializeArray();
|
110
|
+
// memoized value from clicked submit button
|
111
|
+
var button = element.data('ujs:submit-button');
|
112
|
+
if (button) {
|
113
|
+
data.push(button);
|
114
|
+
element.data('ujs:submit-button', null);
|
115
|
+
}
|
116
|
+
} else if (element.is('select')) {
|
117
|
+
method = element.data('method');
|
118
|
+
url = element.data('url');
|
119
|
+
data = element.serialize();
|
120
|
+
if (element.data('params')) data = data + "&" + element.data('params');
|
121
|
+
} else {
|
122
|
+
method = element.data('method');
|
123
|
+
url = element.attr('href');
|
124
|
+
data = element.data('params') || null;
|
125
|
+
}
|
126
|
+
|
127
|
+
options = {
|
128
|
+
type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain,
|
129
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
130
|
+
beforeSend: function(xhr, settings) {
|
131
|
+
if (settings.dataType === undefined) {
|
132
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
133
|
+
}
|
134
|
+
return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
|
135
|
+
},
|
136
|
+
success: function(data, status, xhr) {
|
137
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
138
|
+
},
|
139
|
+
complete: function(xhr, status) {
|
140
|
+
element.trigger('ajax:complete', [xhr, status]);
|
141
|
+
},
|
142
|
+
error: function(xhr, status, error) {
|
143
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
144
|
+
}
|
145
|
+
};
|
146
|
+
// Do not pass url to `ajax` options if blank
|
147
|
+
if (url) { $.extend(options, { url: url }); }
|
148
|
+
|
149
|
+
rails.ajax(options);
|
150
|
+
}
|
151
|
+
},
|
152
|
+
|
153
|
+
// Handles "data-method" on links such as:
|
154
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
155
|
+
handleMethod: function(link) {
|
156
|
+
var href = link.attr('href'),
|
157
|
+
method = link.data('method'),
|
158
|
+
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
159
|
+
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
160
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
161
|
+
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
162
|
+
|
163
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
164
|
+
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
165
|
+
}
|
166
|
+
|
167
|
+
form.hide().append(metadata_input).appendTo('body');
|
168
|
+
form.submit();
|
169
|
+
},
|
170
|
+
|
171
|
+
/* Disables form elements:
|
172
|
+
- Caches element value in 'ujs:enable-with' data store
|
173
|
+
- Replaces element text with value of 'data-disable-with' attribute
|
174
|
+
- Adds disabled=disabled attribute
|
175
|
+
*/
|
176
|
+
disableFormElements: function(form) {
|
177
|
+
form.find(rails.disableSelector).each(function() {
|
178
|
+
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
179
|
+
element.data('ujs:enable-with', element[method]());
|
180
|
+
element[method](element.data('disable-with'));
|
181
|
+
element.attr('disabled', 'disabled');
|
182
|
+
});
|
183
|
+
},
|
184
|
+
|
185
|
+
/* Re-enables disabled form elements:
|
186
|
+
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
|
187
|
+
- Removes disabled attribute
|
188
|
+
*/
|
189
|
+
enableFormElements: function(form) {
|
190
|
+
form.find(rails.enableSelector).each(function() {
|
191
|
+
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
192
|
+
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
|
193
|
+
element.removeAttr('disabled');
|
194
|
+
});
|
195
|
+
},
|
196
|
+
|
197
|
+
/* For 'data-confirm' attribute:
|
198
|
+
- Fires `confirm` event
|
199
|
+
- Shows the confirmation dialog
|
200
|
+
- Fires the `confirm:complete` event
|
201
|
+
|
202
|
+
Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
|
203
|
+
Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
|
204
|
+
Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
|
205
|
+
return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
|
206
|
+
*/
|
207
|
+
allowAction: function(element) {
|
208
|
+
var message = element.data('confirm'),
|
209
|
+
answer = false, callback;
|
210
|
+
if (!message) { return true; }
|
211
|
+
|
212
|
+
if (rails.fire(element, 'confirm')) {
|
213
|
+
answer = rails.confirm(message);
|
214
|
+
callback = rails.fire(element, 'confirm:complete', [answer]);
|
215
|
+
}
|
216
|
+
return answer && callback;
|
217
|
+
},
|
218
|
+
|
219
|
+
// Helper function which checks for blank inputs in a form that match the specified CSS selector
|
220
|
+
blankInputs: function(form, specifiedSelector, nonBlank) {
|
221
|
+
var inputs = $(), input,
|
222
|
+
selector = specifiedSelector || 'input,textarea';
|
223
|
+
form.find(selector).each(function() {
|
224
|
+
input = $(this);
|
225
|
+
// Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
|
226
|
+
if (nonBlank ? input.val() : !input.val()) {
|
227
|
+
inputs = inputs.add(input);
|
228
|
+
}
|
229
|
+
});
|
230
|
+
return inputs.length ? inputs : false;
|
231
|
+
},
|
232
|
+
|
233
|
+
// Helper function which checks for non-blank inputs in a form that match the specified CSS selector
|
234
|
+
nonBlankInputs: function(form, specifiedSelector) {
|
235
|
+
return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
|
236
|
+
},
|
237
|
+
|
238
|
+
// Helper function, needed to provide consistent behavior in IE
|
239
|
+
stopEverything: function(e) {
|
240
|
+
$(e.target).trigger('ujs:everythingStopped');
|
241
|
+
e.stopImmediatePropagation();
|
242
|
+
return false;
|
243
|
+
},
|
244
|
+
|
245
|
+
// find all the submit events directly bound to the form and
|
246
|
+
// manually invoke them. If anyone returns false then stop the loop
|
247
|
+
callFormSubmitBindings: function(form) {
|
248
|
+
var events = form.data('events'), continuePropagation = true;
|
249
|
+
if (events !== undefined && events['submit'] !== undefined) {
|
250
|
+
$.each(events['submit'], function(i, obj){
|
251
|
+
if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data);
|
252
|
+
});
|
253
|
+
}
|
254
|
+
return continuePropagation;
|
255
|
+
}
|
256
|
+
};
|
257
|
+
|
258
|
+
$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
|
259
|
+
|
260
|
+
$(rails.linkClickSelector).live('click.rails', function(e) {
|
261
|
+
var link = $(this);
|
262
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
263
|
+
|
264
|
+
if (link.data('remote') !== undefined) {
|
265
|
+
rails.handleRemote(link);
|
266
|
+
return false;
|
267
|
+
} else if (link.data('method')) {
|
268
|
+
rails.handleMethod(link);
|
269
|
+
return false;
|
270
|
+
}
|
271
|
+
});
|
272
|
+
|
273
|
+
$(rails.selectChangeSelector).live('change.rails', function(e) {
|
274
|
+
var link = $(this);
|
275
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
276
|
+
|
277
|
+
rails.handleRemote(link);
|
278
|
+
return false;
|
279
|
+
});
|
280
|
+
|
281
|
+
$(rails.formSubmitSelector).live('submit.rails', function(e) {
|
282
|
+
var form = $(this),
|
283
|
+
remote = form.data('remote') !== undefined,
|
284
|
+
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
|
285
|
+
nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
|
286
|
+
|
287
|
+
if (!rails.allowAction(form)) return rails.stopEverything(e);
|
288
|
+
|
289
|
+
// skip other logic when required values are missing or file upload is present
|
290
|
+
if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
|
291
|
+
return rails.stopEverything(e);
|
292
|
+
}
|
293
|
+
|
294
|
+
if (remote) {
|
295
|
+
if (nonBlankFileInputs) {
|
296
|
+
return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
|
297
|
+
}
|
298
|
+
|
299
|
+
// If browser does not support submit bubbling, then this live-binding will be called before direct
|
300
|
+
// bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
|
301
|
+
if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e);
|
302
|
+
|
303
|
+
rails.handleRemote(form);
|
304
|
+
return false;
|
305
|
+
} else {
|
306
|
+
// slight timeout so that the submit button gets properly serialized
|
307
|
+
setTimeout(function(){ rails.disableFormElements(form); }, 13);
|
308
|
+
}
|
309
|
+
});
|
310
|
+
|
311
|
+
$(rails.formInputClickSelector).live('click.rails', function(event) {
|
312
|
+
var button = $(this);
|
313
|
+
|
314
|
+
if (!rails.allowAction(button)) return rails.stopEverything(event);
|
315
|
+
|
316
|
+
// register the pressed submit button
|
317
|
+
var name = button.attr('name'),
|
318
|
+
data = name ? {name:name, value:button.val()} : null;
|
319
|
+
|
320
|
+
button.closest('form').data('ujs:submit-button', data);
|
321
|
+
});
|
322
|
+
|
323
|
+
$(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) {
|
324
|
+
if (this == event.target) rails.disableFormElements($(this));
|
325
|
+
});
|
326
|
+
|
327
|
+
$(rails.formSubmitSelector).live('ajax:complete.rails', function(event) {
|
328
|
+
if (this == event.target) rails.enableFormElements($(this));
|
329
|
+
});
|
330
|
+
|
331
|
+
})( jQuery );
|