Skip to content

Commit

Permalink
Add developer alert when no url is found; remove enable_with data whe…
Browse files Browse the repository at this point in the history
…n no longer in use; standardise 'form' finder with Prototype library for consistency
  • Loading branch information
Josh Delsman committed Feb 4, 2010
1 parent bc1caf7 commit eff1864
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/rails.js
Expand Up @@ -10,6 +10,7 @@ jQuery(function ($) {
*/
triggerAndReturn: function (name, data) {
var event = new jQuery.Event(name);

this.trigger(event, data);

return event.result !== false;
Expand All @@ -25,12 +26,13 @@ jQuery(function ($) {
method = el.attr('method') || el.attr('data-method') || 'GET',
url = el.attr('action') || el.attr('href');

if (el.context.tagName.toUpperCase() === 'FORM') {
if (el.context.tagName.toLowerCase() === 'form') {
data = el.serializeArray();
}

// TODO: should let the developer know no url was found
if (url !== undefined) {
if (url === undefined) {
alert("URL cannot be undefined");
} else {
if (el.triggerAndReturn('ajax:before')) {
$.ajax({
url: url,
Expand Down Expand Up @@ -60,8 +62,9 @@ jQuery(function ($) {
/**
* confirmation handler
*/
$('a[data-confirm],input[data-confirm]').live('click', function () {
$('a[data-confirm], input[data-confirm]').live('click', function () {
var el = $(this);

if (el.triggerAndReturn('confirm')) {
if (!confirm(el.attr('data-confirm'))) {
return false;
Expand All @@ -77,7 +80,7 @@ jQuery(function ($) {
e.preventDefault();
});

$('a[data-remote="true"],input[data-remote="true"]').live('click', function (e) {
$('a[data-remote="true"], input[data-remote="true"]').live('click', function (e) {
$(this).callRemote();
e.preventDefault();
});
Expand All @@ -98,7 +101,8 @@ jQuery(function ($) {
$(this).children('input[data-disable-with]').each(function (i, el) {
var input = $(el);
input.removeAttr('disabled')
.val(input.data('enable_with'));
.val(input.data('enable_with'))
.removeData('enable_with');
});
});
});

0 comments on commit eff1864

Please sign in to comment.