Merge branch 'jquery-1.10'

This commit is contained in:
r888888888
2013-06-18 18:38:28 -07:00
14 changed files with 469 additions and 311 deletions

View File

@@ -1,10 +1,8 @@
//= require jquery-1.7.1.min.js //= require jquery-1.10.1.min.js
//= require jquery-ui-1.8.12.custom.min.js //= require jquery-ui-1.10.3.min.js
//= require jquery.hotkeys.js //= require jquery.hotkeys.js
//= require jquery.timeout.js //= require jquery.timeout.js
//= require typeahead.min.js
//= require rails.js //= require rails.js
//= require common.js //= require common.js
//= require_self //= require_self
//= require_tree . //= require_tree .

View File

@@ -6,19 +6,30 @@
Danbooru.Artist.initialize_check_name_link(); Danbooru.Artist.initialize_check_name_link();
if (Danbooru.meta("enable-auto-complete") === "true") { if (Danbooru.meta("enable-auto-complete") === "true") {
Danbooru.Artist.initialize_typeahead(); Danbooru.Artist.initialize_auto_complete();
} }
} }
} }
Danbooru.Artist.initialize_typeahead = function() { Danbooru.Artist.initialize_auto_complete = function() {
$("#quick_search_name").typeahead({ $("#quick_search_name").autocomplete({
name: "artists", source: function(req, resp) {
remote: "/artists.json?search[name]=*%QUERY*", $.ajax({
limit: 10, url: "/artists.json",
valueKey: "name", data: {
template: function(context) { "search[name]": "*" + req.term + "*"
return "<p>" + context.name.replace(/_/g, " ") + "</p>"; },
method: "get",
minLength: 2,
success: function(data) {
resp($.map(data, function(tag) {
return {
label: tag.name,
value: tag.name
};
}));
}
});
} }
}); });
} }

View File

@@ -14,13 +14,25 @@
Danbooru.Pool.initialize_add_to_pool_link = function() { Danbooru.Pool.initialize_add_to_pool_link = function() {
$("#add-to-pool-dialog").dialog({autoOpen: false}); $("#add-to-pool-dialog").dialog({autoOpen: false});
$("#c-pool-elements #a-new input[type=text]").typeahead({ $("#c-pool-elements #a-new input[type=text]").autocomplete({
name: "pools", source: function(req, resp) {
remote: "/pools.json?search[is_active]=true&search[name_matches]=%QUERY", $.ajax({
limit: 10, url: "/pools.json",
valueKey: "name", data: {
template: function(context) { "search[is_active]": "true"
return "<p>" + context.name.replace(/_/g, " ") + "</p>"; "search[name_matches]": req.term
},
method: "get",
minLength: 2,
success: function(data) {
resp($.map(data, function(tag) {
return {
label: tag.name.replace(/_/g, " "),
value: tag.name
};
}));
}
});
} }
}); });

View File

@@ -6,7 +6,7 @@
Danbooru.Post.initialize_all = function() { Danbooru.Post.initialize_all = function() {
this.initialize_post_previews(); this.initialize_post_previews();
if (Danbooru.meta("enable-tag-autocomplete") === "true") { if (Danbooru.meta("enable-auto-complete") === "true") {
this.initialize_tag_autocomplete(); this.initialize_tag_autocomplete();
} }
@@ -36,13 +36,36 @@
} }
Danbooru.Post.initialize_tag_autocomplete = function() { Danbooru.Post.initialize_tag_autocomplete = function() {
$("#tags").typeahead({ $("#tags,#post_tag_string,#upload_tag_string").autocomplete({
name: "tags", focus: function() {
remote: "/tags.json?search[order]=count&search[name_matches]=%QUERY*", return false;
limit: 10, },
valueKey: "name", select: function(event, ui) {
template: function(context) { var terms = this.value.match(/\S+/g);
return "<p class=\"category-" + context.category + "\"><a>" + context.name + "</a></p>"; terms.pop();
terms.push(ui.item.value);
this.value = terms.join(" ") + " ";
return false;
},
source: function(req, resp) {
var term = req.term.match(/\S+/g).pop();
$.ajax({
url: "/tags.json",
data: {
"search[order]": "count",
"search[name_matches]": term + "*"
},
method: "get",
minLength: 2,
success: function(data) {
resp($.map(data, function(tag) {
return {
label: tag.name,
value: tag.name
};
}));
}
});
} }
}); });
} }

View File

@@ -3,17 +3,32 @@
Danbooru.WikiPage.initialize_all = function() { Danbooru.WikiPage.initialize_all = function() {
if ($("#c-wiki-pages").length) { if ($("#c-wiki-pages").length) {
if (Danbooru.meta("enable-tag-autocomplete") === "true") { this.initialize_typeahead();
$("#quick_search_title,#wiki_page_title").typeahead({ }
name: "wiki_pages", }
remote: "/wiki_pages.json?search[title]=*%QUERY*",
limit: 10, Danbooru.WikiPage.initialize_typeahead = function() {
valueKey: "title", if (Danbooru.meta("enable-auto-complete") === "true") {
template: function(context) { $("#quick_search_title,#wiki_page_title").autocomplete({
return "<p>" + context.title.replace(/_/g, " ") + "</p>"; source: function(req, resp) {
} $.ajax({
}); url: "/wiki_pages.json",
} data: {
"search[title]": "*" + req.term + "*"
},
method: "get",
minLength: 2,
success: function(data) {
resp($.map(data, function(tag) {
return {
label: tag.title.replace(/_/g, " "),
value: tag.title
};
}));
}
});
}
});
} }
} }
})(); })();

View File

@@ -1,5 +1,5 @@
/* /*
*= require "smoothness/jquery-ui-1.8.5.custom.css" *= require "smoothness/jquery-ui-1.10.3.min.css"
*= require_self *= require_self
*= require_tree "./common" *= require_tree "./common"
*= require_tree "./specific" *= require_tree "./specific"

View File

@@ -50,27 +50,6 @@ a.blacklisted-active {
background-color: rgba(0,0,0,0.1); background-color: rgba(0,0,0,0.1);
} }
.tt-suggestions {
background: white;
display: block;
border: 1px solid black;
margin: 0;
padding: 0;
}
.tt-suggestion {
background: white;
padding: 0.25em 0.5em;
}
.tt-is-under-cursor {
background: $highlight_color;
}
.tt-suggestion p {
margin: 0;
}
#has-parent-relationship-preview, #has-children-relationship-preview { #has-parent-relationship-preview, #has-children-relationship-preview {
overflow-x: auto; overflow-x: auto;
white-space: nowrap; white-space: nowrap;
@@ -84,6 +63,14 @@ a.blacklisted-active {
} }
} }
.category-0 a, a.tag-type-0 {
color: $link_color;
&:hover {
color: $link_hover_color;
}
}
.category-1 a, a.tag-type-1 { .category-1 a, a.tag-type-1 {
color: #A00; color: #A00;

View File

@@ -1,4 +1,4 @@
<%= simple_form_for(comment) do |f| %> <%= simple_form_for(comment, :html => {:class => "edit_comment"}) do |f| %>
<%= dtext_field "comment", "body", :value => comment.body, :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %> <%= dtext_field "comment", "body", :value => comment.body, :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %>
<%= f.button :submit, "Submit" %> <%= f.button :submit, "Submit" %>
<%= dtext_preview_button "comment", "body", :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %> <%= dtext_preview_button "comment", "body", :input_id => "comment_body_for_#{comment.id}", :preview_id => "dtext-preview-for-#{comment.id}" %>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 208 B

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,291 +1,393 @@
(function($, undefined) {
/** /**
* Unobtrusive scripting adapter for jQuery * Unobtrusive scripting adapter for jQuery
*
* Requires jQuery 1.4.3 or later.
* https://github.com/rails/jquery-ujs * https://github.com/rails/jquery-ujs
* Uploading file using rails.js
* =============================
* *
* By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields * Requires jQuery 1.7.0 or later.
* in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
* *
* The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish. * Released under the MIT license
* *
* Ex:
* $('form').live('ajax:aborted:file', function(event, elements){
* // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
* // Returning false in this handler tells rails.js to disallow standard form submission
* return false;
* });
*
* The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
*
* Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
* techniques like the iframe method to upload the file instead.
*
* Required fields in rails.js
* ===========================
*
* If any blank required inputs (required="required") are detected in the remote form, the whole form submission
* is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
*
* The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
*
* !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
* get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
*
* Ex:
* $('form').live('ajax:aborted:required', function(event, elements){
* // Returning false in this handler tells rails.js to submit the form anyway.
* // The blank required inputs are passed to this function in `elements`.
* return ! confirm("Would you like to submit the form with missing info?");
* });
*/ */
(function($) { // Cut down on the number of issues from people inadvertently including jquery_ujs twice
// by detecting and raising an error when it happens.
if ( $.rails !== undefined ) {
$.error('jquery-ujs has already been loaded!');
}
// Shorthand to make it a little easier to call public rails functions from within rails.js // Shorthand to make it a little easier to call public rails functions from within rails.js
var rails; var rails;
$.rails = rails = { $.rails = rails = {
// Link elements bound by jquery-ujs
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
// Link elements bound by jquery-ujs // Button elements boud jquery-ujs
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]', buttonClickSelector: 'button[data-remote]',
// Form elements bound by jquery-ujs // Select elements bound by jquery-ujs
formSubmitSelector: 'form', inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
// Form input elements bound by jquery-ujs // Form elements bound by jquery-ujs
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])', formSubmitSelector: 'form',
// Form input elements disabled during form submission // Form input elements bound by jquery-ujs
disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]', formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',
// Form input elements re-enabled after form submission // Form input elements disabled during form submission
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled', disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
// Form required input elements // Form input elements re-enabled after form submission
requiredInputSelector: 'input[name][required],textarea[name][required]', enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
// Form file input elements // Form required input elements
fileInputSelector: 'input:file', requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
// Make sure that every Ajax request sends the CSRF token // Form file input elements
CSRFProtection: function(xhr) { fileInputSelector: 'input[type=file]',
var token = $('meta[name="csrf-token"]').attr('content');
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
},
// Triggers an event on an element and returns false if the event result is false // Link onClick disable selector with possible reenable after remote submission
fire: function(obj, name, data) { linkDisableSelector: 'a[data-disable-with]',
var event = $.Event(name);
obj.trigger(event, data);
return event.result !== false;
},
// Submits "remote" forms and links with ajax // Make sure that every Ajax request sends the CSRF token
handleRemote: function(element) { CSRFProtection: function(xhr) {
var method, url, data, var token = $('meta[name="csrf-token"]').attr('content');
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType); if (token) xhr.setRequestHeader('X-CSRF-Token', token);
},
if (rails.fire(element, 'ajax:before')) { // Triggers an event on an element and returns false if the event result is false
fire: function(obj, name, data) {
var event = $.Event(name);
obj.trigger(event, data);
return event.result !== false;
},
if (element.is('form')) { // Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
method = element.attr('method'); confirm: function(message) {
url = element.attr('action'); return confirm(message);
data = element.serializeArray(); },
// memoized value from clicked submit button
var button = element.data('ujs:submit-button');
if (button) {
data.push(button);
element.data('ujs:submit-button', null);
}
} else {
method = element.data('method');
url = element.attr('href');
data = null;
}
$.ajax({ // Default ajax function, may be overridden with custom function in $.rails.ajax
url: url, type: method || 'GET', data: data, dataType: dataType, ajax: function(options) {
// stopping the "ajax:beforeSend" event will cancel the ajax request return $.ajax(options);
beforeSend: function(xhr, settings) { },
if (settings.dataType === undefined) {
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
}
return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
},
success: function(data, status, xhr) {
element.trigger('ajax:success', [data, status, xhr]);
},
complete: function(xhr, status) {
element.trigger('ajax:complete', [xhr, status]);
},
error: function(xhr, status, error) {
element.trigger('ajax:error', [xhr, status, error]);
}
});
}
},
// Handles "data-method" on links such as: // Default way to get an element's href. May be overridden at $.rails.href.
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a> href: function(element) {
handleMethod: function(link) { return element.attr('href');
var href = link.attr('href'), },
method = link.data('method'),
csrf_token = $('meta[name=csrf-token]').attr('content'),
csrf_param = $('meta[name=csrf-param]').attr('content'),
form = $('<form method="post" action="' + href + '"></form>'),
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
if (csrf_param !== undefined && csrf_token !== undefined) { // Submits "remote" forms and links with ajax
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />'; handleRemote: function(element) {
} var method, url, data, elCrossDomain, crossDomain, withCredentials, dataType, options;
form.hide().append(metadata_input).appendTo('body'); if (rails.fire(element, 'ajax:before')) {
form.submit(); elCrossDomain = element.data('cross-domain');
}, crossDomain = elCrossDomain === undefined ? null : elCrossDomain;
withCredentials = element.data('with-credentials') || null;
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
/* Disables form elements: if (element.is('form')) {
- Caches element value in 'ujs:enable-with' data store method = element.attr('method');
- Replaces element text with value of 'data-disable-with' attribute url = element.attr('action');
- Adds disabled=disabled attribute data = element.serializeArray();
*/ // memoized value from clicked submit button
disableFormElements: function(form) { var button = element.data('ujs:submit-button');
form.find(rails.disableSelector).each(function() { if (button) {
var element = $(this), method = element.is('button') ? 'html' : 'val'; data.push(button);
element.data('ujs:enable-with', element[method]()); element.data('ujs:submit-button', null);
element[method](element.data('disable-with')); }
element.attr('disabled', 'disabled'); } else if (element.is(rails.inputChangeSelector)) {
}); method = element.data('method');
}, url = element.data('url');
data = element.serialize();
if (element.data('params')) data = data + "&" + element.data('params');
} else if (element.is(rails.buttonClickSelector)) {
method = element.data('method') || 'get';
url = element.data('url');
data = element.serialize();
if (element.data('params')) data = data + "&" + element.data('params');
} else {
method = element.data('method');
url = rails.href(element);
data = element.data('params') || null;
}
/* Re-enables disabled form elements: options = {
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) type: method || 'GET', data: data, dataType: dataType,
- Removes disabled attribute // stopping the "ajax:beforeSend" event will cancel the ajax request
*/ beforeSend: function(xhr, settings) {
enableFormElements: function(form) { if (settings.dataType === undefined) {
form.find(rails.enableSelector).each(function() { xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
var element = $(this), method = element.is('button') ? 'html' : 'val'; }
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with')); return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
element.removeAttr('disabled'); },
}); success: function(data, status, xhr) {
}, element.trigger('ajax:success', [data, status, xhr]);
},
complete: function(xhr, status) {
element.trigger('ajax:complete', [xhr, status]);
},
error: function(xhr, status, error) {
element.trigger('ajax:error', [xhr, status, error]);
},
crossDomain: crossDomain
};
// If message provided in 'data-confirm' attribute, fires `confirm` event and returns result of confirm dialog. // There is no withCredentials for IE6-8 when
// Attaching a handler to the element's `confirm` event that returns false cancels the confirm dialog. // "Enable native XMLHTTP support" is disabled
allowAction: function(element) { if (withCredentials) {
var message = element.data('confirm'); options.xhrFields = {
return !message || (rails.fire(element, 'confirm') && confirm(message)); withCredentials: withCredentials
}, };
}
// Helper function which checks for blank inputs in a form that match the specified CSS selector // Only pass url to `ajax` options if not blank
blankInputs: function(form, specifiedSelector, nonBlank) { if (url) { options.url = url; }
var inputs = $(), input,
selector = specifiedSelector || 'input,textarea';
form.find(selector).each(function() {
input = $(this);
// Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
if (nonBlank ? input.val() : !input.val()) {
inputs = inputs.add(input);
}
});
return inputs.length ? inputs : false;
},
// Helper function which checks for non-blank inputs in a form that match the specified CSS selector var jqxhr = rails.ajax(options);
nonBlankInputs: function(form, specifiedSelector) { element.trigger('ajax:send', jqxhr);
return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank return jqxhr;
}, } else {
return false;
}
},
// Helper function, needed to provide consistent behavior in IE // Handles "data-method" on links such as:
stopEverything: function(e) { // <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
e.stopImmediatePropagation(); handleMethod: function(link) {
return false; var href = rails.href(link),
}, method = link.data('method'),
target = link.attr('target'),
csrf_token = $('meta[name=csrf-token]').attr('content'),
csrf_param = $('meta[name=csrf-param]').attr('content'),
form = $('<form method="post" action="' + href + '"></form>'),
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
// find all the submit events directly bound to the form and if (csrf_param !== undefined && csrf_token !== undefined) {
// manually invoke them. If anyone returns false then stop the loop metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
callFormSubmitBindings: function(form) { }
var events = form.data('events'), continuePropagation = true;
if (events !== undefined && events['submit'] !== undefined) {
$.each(events['submit'], function(i, obj){
if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data);
});
}
return continuePropagation;
}
};
// ajaxPrefilter is a jQuery 1.5 feature if (target) { form.attr('target', target); }
if ('ajaxPrefilter' in $) {
$.ajaxPrefilter(function(options, originalOptions, xhr){ rails.CSRFProtection(xhr); });
} else {
$(document).ajaxSend(function(e, xhr){ rails.CSRFProtection(xhr); });
}
$(rails.linkClickSelector).live('click.rails', function(e) { form.hide().append(metadata_input).appendTo('body');
var link = $(this); form.submit();
if (!rails.allowAction(link)) return rails.stopEverything(e); },
if (link.data('remote') !== undefined) { /* Disables form elements:
rails.handleRemote(link); - Caches element value in 'ujs:enable-with' data store
return false; - Replaces element text with value of 'data-disable-with' attribute
} else if (link.data('method')) { - Sets disabled property to true
rails.handleMethod(link); */
return false; disableFormElements: function(form) {
} form.find(rails.disableSelector).each(function() {
}); var element = $(this), method = element.is('button') ? 'html' : 'val';
element.data('ujs:enable-with', element[method]());
element[method](element.data('disable-with'));
element.prop('disabled', true);
});
},
$(rails.formSubmitSelector).live('submit.rails', function(e) { /* Re-enables disabled form elements:
var form = $(this), - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
remote = form.data('remote') !== undefined, - Sets disabled property to false
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector), */
nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector); enableFormElements: function(form) {
form.find(rails.enableSelector).each(function() {
var element = $(this), method = element.is('button') ? 'html' : 'val';
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
element.prop('disabled', false);
});
},
if (!rails.allowAction(form)) return rails.stopEverything(e); /* For 'data-confirm' attribute:
- Fires `confirm` event
- Shows the confirmation dialog
- Fires the `confirm:complete` event
// skip other logic when required values are missing or file upload is present Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) { Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
return !remote; Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
} return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
*/
allowAction: function(element) {
var message = element.data('confirm'),
answer = false, callback;
if (!message) { return true; }
if (remote) { if (rails.fire(element, 'confirm')) {
if (nonBlankFileInputs) { answer = rails.confirm(message);
return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]); callback = rails.fire(element, 'confirm:complete', [answer]);
} }
return answer && callback;
},
// If browser does not support submit bubbling, then this live-binding will be called before direct // Helper function which checks for blank inputs in a form that match the specified CSS selector
// bindings. Therefore, we should directly call any direct bindings before remotely submitting form. blankInputs: function(form, specifiedSelector, nonBlank) {
if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e); var inputs = $(), input, valueToCheck,
selector = specifiedSelector || 'input,textarea',
allInputs = form.find(selector);
rails.handleRemote(form); allInputs.each(function() {
return false; input = $(this);
} else { valueToCheck = input.is('input[type=checkbox],input[type=radio]') ? input.is(':checked') : input.val();
// slight timeout so that the submit button gets properly serialized // If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey
setTimeout(function(){ rails.disableFormElements(form); }, 13); if (!valueToCheck === !nonBlank) {
}
});
$(rails.formInputClickSelector).live('click.rails', function(event) { // Don't count unchecked required radio if other radio with same name is checked
var button = $(this); if (input.is('input[type=radio]') && allInputs.filter('input[type=radio]:checked[name="' + input.attr('name') + '"]').length) {
return true; // Skip to next input
}
if (!rails.allowAction(button)) return rails.stopEverything(event); inputs = inputs.add(input);
}
});
return inputs.length ? inputs : false;
},
// register the pressed submit button // Helper function which checks for non-blank inputs in a form that match the specified CSS selector
var name = button.attr('name'), nonBlankInputs: function(form, specifiedSelector) {
data = name ? {name:name, value:button.val()} : null; return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
},
button.closest('form').data('ujs:submit-button', data); // Helper function, needed to provide consistent behavior in IE
}); stopEverything: function(e) {
$(e.target).trigger('ujs:everythingStopped');
e.stopImmediatePropagation();
return false;
},
$(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) { // replace element's html with the 'data-disable-with' after storing original html
if (this == event.target) rails.disableFormElements($(this)); // and prevent clicking on it
}); disableElement: function(element) {
element.data('ujs:enable-with', element.html()); // store enabled state
element.html(element.data('disable-with')); // set to disabled state
element.bind('click.railsDisable', function(e) { // prevent further clicking
return rails.stopEverything(e);
});
},
$(rails.formSubmitSelector).live('ajax:complete.rails', function(event) { // restore element to its original state which was disabled by 'disableElement' above
if (this == event.target) rails.enableFormElements($(this)); enableElement: function(element) {
}); if (element.data('ujs:enable-with') !== undefined) {
element.html(element.data('ujs:enable-with')); // set to old enabled state
element.removeData('ujs:enable-with'); // clean up cache
}
element.unbind('click.railsDisable'); // enable element
}
};
if (rails.fire($(document), 'rails:attachBindings')) {
$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
$(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() {
rails.enableElement($(this));
});
$(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {
var link = $(this), method = link.data('method'), data = link.data('params');
if (!rails.allowAction(link)) return rails.stopEverything(e);
if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
if (link.data('remote') !== undefined) {
if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
var handleRemote = rails.handleRemote(link);
// response from rails.handleRemote() will either be false or a deferred object promise.
if (handleRemote === false) {
rails.enableElement(link);
} else {
handleRemote.error( function() { rails.enableElement(link); } );
}
return false;
} else if (link.data('method')) {
rails.handleMethod(link);
return false;
}
});
$(document).delegate(rails.buttonClickSelector, 'click.rails', function(e) {
var button = $(this);
if (!rails.allowAction(button)) return rails.stopEverything(e);
rails.handleRemote(button);
return false;
});
$(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) {
var link = $(this);
if (!rails.allowAction(link)) return rails.stopEverything(e);
rails.handleRemote(link);
return false;
});
$(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
var form = $(this),
remote = form.data('remote') !== undefined,
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
if (!rails.allowAction(form)) return rails.stopEverything(e);
// skip other logic when required values are missing or file upload is present
if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
return rails.stopEverything(e);
}
if (remote) {
if (nonBlankFileInputs) {
// slight timeout so that the submit button gets properly serialized
// (make it easy for event handler to serialize form without disabled values)
setTimeout(function(){ rails.disableFormElements(form); }, 13);
var aborted = rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
// re-enable form elements if event bindings return false (canceling normal form submission)
if (!aborted) { setTimeout(function(){ rails.enableFormElements(form); }, 13); }
return aborted;
}
rails.handleRemote(form);
return false;
} else {
// slight timeout so that the submit button gets properly serialized
setTimeout(function(){ rails.disableFormElements(form); }, 13);
}
});
$(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
var button = $(this);
if (!rails.allowAction(button)) return rails.stopEverything(event);
// register the pressed submit button
var name = button.attr('name'),
data = name ? {name:name, value:button.val()} : null;
button.closest('form').data('ujs:submit-button', data);
});
$(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
if (this == event.target) rails.disableFormElements($(this));
});
$(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
if (this == event.target) rails.enableFormElements($(this));
});
$(function(){
// making sure that all forms have actual up-to-date token(cached forms contain old one)
var csrf_token = $('meta[name=csrf-token]').attr('content');
var csrf_param = $('meta[name=csrf-param]').attr('content');
$('form input[name="' + csrf_param + '"]').val(csrf_token);
});
}
})( jQuery ); })( jQuery );

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long