diff --git a/.eslintrc.json b/.eslintrc.json index 41a3d51898c..862dd126060 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,6 +4,7 @@ "globals": { }, "rules": { + "indent": ["error", 2], "no-extra-semi": "warn", "eol-last": ["error", "always"] } diff --git a/openlibrary/plugins/openlibrary/js/account.js b/openlibrary/plugins/openlibrary/js/account.js index 2d5c9d836bc..27ebccc9f14 100644 --- a/openlibrary/plugins/openlibrary/js/account.js +++ b/openlibrary/plugins/openlibrary/js/account.js @@ -1,54 +1,54 @@ function setup_account_create() { - $("#signup").validate({ - invalidHandler: function(form, validator) { - var errors = validator.numberOfInvalids(); - if (errors) { - var message = (errors == 1 ? "Hang on... you missed 1 field. It's highlighted below." : "Hang on...you missed some fields.They 're highlighted below."); - $("div#contentMsg span").html(message); - $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); - $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); - } else { - $("div#contentMsg").hide(); - } - }, - errorClass: "invalid", - validClass: "success", - highlight: function(element, errorClass) { - $(element).addClass(errorClass); - $(element.form).find("label[for=" + element.id + "]") - .addClass(errorClass); - } - }); - $("#email").rules("add", { - required: true, - email: true, - messages: { - required: "", - email: "Are you sure that's an email address?" - } - }); - $("#username").rules("add", { - required: true, - minlength: 3, - maxlength: 20, - messages: { - required: "", - minlength: jQuery.format("This has to be at least {0} characters."), - maxlength: jQuery.format("Sorry! This can't exceed {0} characters.") - } - }); - $("#password").rules("add", { - required: true, - messages: { - required: "" - } - }); + $("#signup").validate({ + invalidHandler: function(form, validator) { + var errors = validator.numberOfInvalids(); + if (errors) { + var message = (errors == 1 ? "Hang on... you missed 1 field. It's highlighted below." : "Hang on...you missed some fields.They 're highlighted below."); + $("div#contentMsg span").html(message); + $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); + $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); + } else { + $("div#contentMsg").hide(); + } + }, + errorClass: "invalid", + validClass: "success", + highlight: function(element, errorClass) { + $(element).addClass(errorClass); + $(element.form).find("label[for=" + element.id + "]") + .addClass(errorClass); + } + }); + $("#email").rules("add", { + required: true, + email: true, + messages: { + required: "", + email: "Are you sure that's an email address?" + } + }); + $("#username").rules("add", { + required: true, + minlength: 3, + maxlength: 20, + messages: { + required: "", + minlength: jQuery.format("This has to be at least {0} characters."), + maxlength: jQuery.format("Sorry! This can't exceed {0} characters.") + } + }); + $("#password").rules("add", { + required: true, + messages: { + required: "" + } + }); - // CHECK USERNAME AVAILABILITY - $('#usernameLoading').hide(); - $('#emailLoading').hide(); + // CHECK USERNAME AVAILABILITY + $('#usernameLoading').hide(); + $('#emailLoading').hide(); -}; +} /* function finishAjaxUsername(id, response) { @@ -83,172 +83,172 @@ function setup_account_create() { //RECAPTCHA var RecaptchaOptions = { - theme: 'custom', - tabindex: 4, - custom_theme_widget: 'recaptcha_widget' + theme: 'custom', + tabindex: 4, + custom_theme_widget: 'recaptcha_widget' }; function validateEmail() { - $("form.email").validate({ - invalidHandler: function(form, validator) { - var errors = validator.numberOfInvalids(); - if (errors) { - var message = errors == 1 ? 'Hang on... You forgot to provide an updated email address.' : 'Hang on... You forgot to provide an updated email address.'; - $("div#contentMsg span").html(message); - $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); - $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); - } else { - $("div#contentMsg").hide(); - } - }, - errorClass: "invalid", - validClass: "success", - highlight: function(element, errorClass) { - $(element).addClass(errorClass); - $(element.form).find("label[for=" + element.id + "]") - .addClass(errorClass); - } - }); - $("#email").rules("add", { - required: true, - email: true, - messages: { - required: "", - email: "Are you sure that's an email address?" - } - }); -}; + $("form.email").validate({ + invalidHandler: function(form, validator) { + var errors = validator.numberOfInvalids(); + if (errors) { + var message = errors == 1 ? 'Hang on... You forgot to provide an updated email address.' : 'Hang on... You forgot to provide an updated email address.'; + $("div#contentMsg span").html(message); + $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); + $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); + } else { + $("div#contentMsg").hide(); + } + }, + errorClass: "invalid", + validClass: "success", + highlight: function(element, errorClass) { + $(element).addClass(errorClass); + $(element.form).find("label[for=" + element.id + "]") + .addClass(errorClass); + } + }); + $("#email").rules("add", { + required: true, + email: true, + messages: { + required: "", + email: "Are you sure that's an email address?" + } + }); +} function validateDelete() { - $("form.delete").validate({ - invalidHandler: function(form, validator) { - var errors = validator.numberOfInvalids(); - if (errors) { - var message = (errors == 1 ? 'You need to click the box to delete your account.': 'You need to click the box to delete your account.'); - $("div#contentMsg span").html(message); - $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); - $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); - } else { - $("div#contentMsg").hide(); - } - }, - errorClass: "invalid", - validClass: "success", - highlight: function(element, errorClass) { - $(element).addClass(errorClass); - $(element.form).find("label[for=" + element.id + "]") - .addClass(errorClass); - } - }); - $("#delete").rules("add", { - required: true, - messages: { - required: "" - } - }); -}; + $("form.delete").validate({ + invalidHandler: function(form, validator) { + var errors = validator.numberOfInvalids(); + if (errors) { + var message = (errors == 1 ? 'You need to click the box to delete your account.': 'You need to click the box to delete your account.'); + $("div#contentMsg span").html(message); + $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); + $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); + } else { + $("div#contentMsg").hide(); + } + }, + errorClass: "invalid", + validClass: "success", + highlight: function(element, errorClass) { + $(element).addClass(errorClass); + $(element.form).find("label[for=" + element.id + "]") + .addClass(errorClass); + } + }); + $("#delete").rules("add", { + required: true, + messages: { + required: "" + } + }); +} function validateLogin() { - $(".login").validate({ - invalidHandler: function(form, validator) { - var errors = validator.numberOfInvalids(); - if (errors) { - var message = (errors == 1? "Hang on... you missed 1 field. It's highlighted below.": "Hang on...you missed both fields.They 're highlighted below."); - $("div#contentMsg span").html(message); - $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); - $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); - } else { - $("div#contentMsg").hide(); - } - }, - errorClass: "invalid", - validClass: "success", - highlight: function(element, errorClass) { - $(element).addClass(errorClass); - $(element.form).find("label[for=" + element.id + "]") - .addClass(errorClass); - } - }); - $("#username").rules("add", { - required: true, - minlength: 3, - maxlength: 20, - messages: { - required: "", - minlength: jQuery.format("This has to be at least {0} characters."), - maxlength: jQuery.format("Sorry! This can't exceed {0} characters.") - } - }); - $("#password").rules("add", { - required: true, - messages: { - required: "" - } - }); -}; + $(".login").validate({ + invalidHandler: function(form, validator) { + var errors = validator.numberOfInvalids(); + if (errors) { + var message = (errors == 1? "Hang on... you missed 1 field. It's highlighted below.": "Hang on...you missed both fields.They 're highlighted below."); + $("div#contentMsg span").html(message); + $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); + $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); + } else { + $("div#contentMsg").hide(); + } + }, + errorClass: "invalid", + validClass: "success", + highlight: function(element, errorClass) { + $(element).addClass(errorClass); + $(element.form).find("label[for=" + element.id + "]") + .addClass(errorClass); + } + }); + $("#username").rules("add", { + required: true, + minlength: 3, + maxlength: 20, + messages: { + required: "", + minlength: jQuery.format("This has to be at least {0} characters."), + maxlength: jQuery.format("Sorry! This can't exceed {0} characters.") + } + }); + $("#password").rules("add", { + required: true, + messages: { + required: "" + } + }); +} function validatePassword() { - $("form.password").validate({ - invalidHandler: function(form, validator) { - var errors = validator.numberOfInvalids(); - if (errors) { - var message = (errors == 1? 'Hang on... you missed a field.': 'Hang on... to change your password, we need your current and your new one.'); - $("div#contentMsg span").html(message); - $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); - $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); - } else { - $("div#contentMsg").hide(); - } - }, - errorClass: "invalid", - validClass: "success", - highlight: function(element, errorClass) { - $(element).addClass(errorClass); - $(element.form).find("label[for=" + element.id + "]") - .addClass(errorClass); - } - }); - $("#password").rules("add", { - required: true, - messages: { - required: "." - } - }); - $("#new_password").rules("add", { - required: true, - messages: { - required: "" - } - }); -}; + $("form.password").validate({ + invalidHandler: function(form, validator) { + var errors = validator.numberOfInvalids(); + if (errors) { + var message = (errors == 1? 'Hang on... you missed a field.': 'Hang on... to change your password, we need your current and your new one.'); + $("div#contentMsg span").html(message); + $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); + $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); + } else { + $("div#contentMsg").hide(); + } + }, + errorClass: "invalid", + validClass: "success", + highlight: function(element, errorClass) { + $(element).addClass(errorClass); + $(element.form).find("label[for=" + element.id + "]") + .addClass(errorClass); + } + }); + $("#password").rules("add", { + required: true, + messages: { + required: "." + } + }); + $("#new_password").rules("add", { + required: true, + messages: { + required: "" + } + }); +} function validateReminder() { - $("form.reminder").validate({ - invalidHandler: function(form, validator) { - var errors = validator.numberOfInvalids(); - if (errors) { - var message = (errors == 1 ? 'Hang on... to change your password, we need your email address.' : 'Hang on... to change your password, we need your email address.'); - $("div#contentMsg span").html(message); - $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); - $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); - } else { - $("div#contentMsg").hide(); - } - }, - errorClass: "invalid", - validClass: "success", - highlight: function(element, errorClass) { - $(element).addClass(errorClass); - $(element.form).find("label[for=" + element.id + "]") - .addClass(errorClass); - } - }); - $("#email").rules("add", { - required: true, - email: true, - messages: { - required: "", - email: "Are you sure that's an email address?" - } - }); -}; + $("form.reminder").validate({ + invalidHandler: function(form, validator) { + var errors = validator.numberOfInvalids(); + if (errors) { + var message = (errors == 1 ? 'Hang on... to change your password, we need your email address.' : 'Hang on... to change your password, we need your email address.'); + $("div#contentMsg span").html(message); + $("div#contentMsg").show().fadeTo(3000, 1).slideUp(); + $("span.remind").css("font-weight", "700").css("text-decoration", "underline"); + } else { + $("div#contentMsg").hide(); + } + }, + errorClass: "invalid", + validClass: "success", + highlight: function(element, errorClass) { + $(element).addClass(errorClass); + $(element.form).find("label[for=" + element.id + "]") + .addClass(errorClass); + } + }); + $("#email").rules("add", { + required: true, + email: true, + messages: { + required: "", + email: "Are you sure that's an email address?" + } + }); +} diff --git a/openlibrary/plugins/openlibrary/js/add_new_field.js b/openlibrary/plugins/openlibrary/js/add_new_field.js index 197016dcf38..96fa7150dd3 100644 --- a/openlibrary/plugins/openlibrary/js/add_new_field.js +++ b/openlibrary/plugins/openlibrary/js/add_new_field.js @@ -14,86 +14,86 @@ * - On cancel/close: * - value of the select is set to "" to select "select xxx" */ -;(function($){ - $.fn.add_new_field = function(_options) { - $(this).each(function() { - var options = _options || {href: "#" + this.id + "-popup"}; - var $this = $(this); +(function($){ + $.fn.add_new_field = function(_options) { + $(this).each(function() { + var options = _options || {href: "#" + this.id + "-popup"}; + var $this = $(this); - var $json = $('') - .attr("name", this.id + "-json") - .addClass("repeat-ignore") // tell repeat plugin to ignore this input - .val("[]") - .insertBefore($this); + var $json = $('') + .attr("name", this.id + "-json") + .addClass("repeat-ignore") // tell repeat plugin to ignore this input + .val("[]") + .insertBefore($this); - $this.change(function(){ - var value = $this.val(); - if (value == "__add__") { - if (options.onshow) { - options.onshow.apply($this, []); - } - $.fn.colorbox({ - inline: true, - opacity: "0.5", - href: options.href, - open: true - }); - } - }); + $this.change(function(){ + var value = $this.val(); + if (value == "__add__") { + if (options.onshow) { + options.onshow.apply($this, []); + } + $.fn.colorbox({ + inline: true, + opacity: "0.5", + href: options.href, + open: true + }); + } + }); - // handle cancel - $(options.href).bind("cbox_closed", function() { + // handle cancel + $(options.href).bind("cbox_closed", function() { - if ($this.val() == "__add__") { - $this.val(""); - $this.focus(); - } - if (options.cancel) { - options.cancel(); - } - }); + if ($this.val() == "__add__") { + $this.val(""); + $this.focus(); + } + if (options.cancel) { + options.cancel(); + } + }); - // handle submit - $("form:first", $(options.href)).submit(function(event) { - event.preventDefault(); + // handle submit + $("form:first", $(options.href)).submit(function(event) { + event.preventDefault(); - // extract data - var array = $(this).serializeArray(); - var d = {}; + // extract data + var array = $(this).serializeArray(); + var d = {}; - for (var i in array) { - d[array[i].name] = $.trim(array[i].value); - } + for (var i in array) { + d[array[i].name] = $.trim(array[i].value); + } - // validate - if (options.validate && options.validate.apply($this, [d]) == false) { - return; - } + // validate + if (options.validate && options.validate.apply($this, [d]) == false) { + return; + } - // close popup - $.fn.colorbox.close(); + // close popup + $.fn.colorbox.close(); - // add new option - $("