From 719809bd682298502c469aebf0482690f0a0b274 Mon Sep 17 00:00:00 2001 From: goldquest Date: Wed, 6 Jul 2016 09:31:36 +0200 Subject: [PATCH] fix eslint errors and warnings --- js/hm_newsletter.js | 44 +++++++++++++++++++++++++------------------- js/thsixty.load.js | 2 ++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/js/hm_newsletter.js b/js/hm_newsletter.js index 6d26e40..2921a4b 100644 --- a/js/hm_newsletter.js +++ b/js/hm_newsletter.js @@ -1,10 +1,11 @@ /** - * @file * Extend Number functions and add pad function to * allow leading zeros. */ Number.prototype.pad = function (size) { + 'use strict'; + var s = String(this); while (s.length < (size || 2)) { s = '0' + s; @@ -13,11 +14,12 @@ Number.prototype.pad = function (size) { }; (function ($, Drupal, window, document) { + 'use strict'; /** * Harbourmaster Newsletter object. * - * @param context + * @param {Object} context The context in DOM, in which the HmNewsletter should be attached * @constructor */ function HmNewsletter(context) { @@ -201,9 +203,10 @@ Number.prototype.pad = function (size) { } var promises = []; + var data; // Send subscribe request with newsletters. if (valid && client_groups.length) { - var data = {}; + data = {}; // Send request for every client and it's subscribed groups. client_groups.forEach(function (value, index, arr) { data.client = index; @@ -216,7 +219,7 @@ Number.prototype.pad = function (size) { // Send subscribe request for agreements.. if (valid && agreements.length) { - var data = {}; + data = {}; data.client = parseInt(client_id); data.groups = []; data.user = user; @@ -250,11 +253,11 @@ Number.prototype.pad = function (size) { }; /** - * Adds alert to the newsletter form's alert section. + * Adds alert to the alert section of the form. * - * @param type - * @param field - * @param message + * @param {string} type - The type of the alert, added as class + * @param {string} field - The name of the field, which triggers this function + * @param {string} message - A message, which will be shown in the alert */ HmNewsletter.prototype.addAlert = function (type, field, message) { @@ -271,17 +274,17 @@ Number.prototype.pad = function (size) { }; /** - * Adds alert to the newsletter form's alert section. + * Sets the state as class, the form is in. * - * @param el - * @param state + * @param {Object} el - The element, which triggers this function + * @param {string} state - The state, as class */ HmNewsletter.prototype.setValidationState = function (el, state) { el.parents('.form-group').addClass(state); }; /** - * Removes all alerts from the newsletter form allert section. + * Removes all alerts from the newsletter form alert section. */ HmNewsletter.prototype.removeAlerts = function () { this.$alerts.html(''); @@ -291,7 +294,7 @@ Number.prototype.pad = function (size) { /** * Sets classes according to states, the view can be in. * - * @param pState + * @param {string} pState - The state, the view should be in. */ HmNewsletter.prototype.setViewState = function (pState) { this.$wrapper.removeClass(HmNewsletter.STATE_PRIVACY + ' ' + HmNewsletter.STATE_SUCCESS); @@ -307,9 +310,9 @@ Number.prototype.pad = function (size) { /** * Get the given form field. * - * @param {string} field + * @param {string} field - The name of the field * - * @returns {*} + * @return {Object[]} - A jQuery object containing the formField */ HmNewsletter.prototype.formField = function (field) { return this.$form.find('[name="' + field + '"]'); @@ -328,9 +331,11 @@ Number.prototype.pad = function (size) { /** * Show error after failed subscribtion to newsletter. + * + * @param {Object} err - The error from the thsixty API */ HmNewsletter.prototype.showError = function (err) { - var responseData = BaseNewsletterView.responseInterpreter(err); + var responseData = HmNewsletter.responseInterpreter(err); this.addAlert('danger', responseData.field, responseData.message); this.setViewState(HmNewsletter.STATE_INITIAL); @@ -341,10 +346,10 @@ Number.prototype.pad = function (size) { /** * Sends subscribe request with given data. * - * @param data + * @param {Object} data - The data, which should be sent to the thsixty API (and therefore to the Harbourmaster) + * @return {Object} - A jQuery deferred promise */ HmNewsletter.prototype.sendSubscribeRequest = function (data) { - var $thisObj = this; var deferred = $.Deferred(); window.thsixtyQ.push(['newsletter.subscribe', { @@ -391,7 +396,8 @@ Number.prototype.pad = function (size) { }); }, error: function (err) { - console.error(err); + // TODO Handle errors + // console.error(err); } }]); }; diff --git a/js/thsixty.load.js b/js/thsixty.load.js index 7582811..da437a8 100644 --- a/js/thsixty.load.js +++ b/js/thsixty.load.js @@ -3,6 +3,8 @@ */ (function ($, window, document) { + 'use strict'; + Drupal.behaviors.thsixty = { attach: function (context) { var config = {