From 0bbdb6ba76c1db0abd95ce8a395c296376c39c2f Mon Sep 17 00:00:00 2001 From: git Date: Wed, 9 Mar 2016 11:17:48 +0100 Subject: [PATCH] Issue #2683979 by CTaPByK: ESLint check and verify code quality in Entity Browser --- js/entity_browser.common.js | 28 +++++++++---------- js/entity_browser.entity_reference.js | 9 +++--- js/entity_browser.iframe.js | 18 ++++++------ js/entity_browser.iframe_selection.js | 2 +- js/entity_browser.modal.js | 12 ++++---- js/entity_browser.modal_selection.js | 2 +- js/entity_browser.multi_step_display.js | 8 +++--- js/entity_browser.tabs.js | 6 ++-- js/entity_browser.view.js | 6 ++-- .../js/entity_browser_entity_form.js | 4 +-- 10 files changed, 48 insertions(+), 47 deletions(-) diff --git a/js/entity_browser.common.js b/js/entity_browser.common.js index 2502edd..34caf9e 100644 --- a/js/entity_browser.common.js +++ b/js/entity_browser.common.js @@ -5,22 +5,22 @@ */ (function ($, Drupal, drupalSettings) { - "use strict"; + 'use strict'; Drupal.entityBrowser = {}; /** * Reacts on "entities selected" event. * - * @param event + * @param {object} event * Event object. - * @param uuid + * @param {string} uuid * Entity browser UUID. - * @param entities + * @param {array} entities * Array of selected entities. */ - Drupal.entityBrowser.selectionCompleted = function(event, uuid, entities) { - var added_entities_array = $.map(entities, function(item) {return item[0]}); + Drupal.entityBrowser.selectionCompleted = function (event, uuid, entities) { + var added_entities_array = $.map(entities, function (item) {return item[0];}); // @todo Use uuid here. But for this to work we need to move eb uuid // generation from display to eb directly. When we do this, we can change // \Drupal\entity_browser\Plugin\Field\FieldWidget\EntityReference::formElement @@ -32,18 +32,18 @@ // Having more elements than cardinality should never happen, because // server side authentication should prevent it, but we handle it here // anyway. - if (cardinality != -1 && added_entities_array.length > cardinality) { + if (cardinality !== -1 && added_entities_array.length > cardinality) { added_entities_array.splice(0, added_entities_array.length - cardinality); } // Update value form element with new entity IDs. var selector = drupalSettings['entity_browser'][uuid]['selector'] ? $(drupalSettings['entity_browser'][uuid]['selector']) : $(this).parent().parent().find('input[type*=hidden]'); var entity_ids = selector.val(); - if (entity_ids.length != 0) { + if (entity_ids.length !== 0) { var existing_entities_array = entity_ids.split(' '); // We always trim the oldest elements and add the new ones. - if (cardinality == -1 || existing_entities_array.length + added_entities_array.length <= cardinality) { + if (cardinality === -1 || existing_entities_array.length + added_entities_array.length <= cardinality) { existing_entities_array = _.union(existing_entities_array, added_entities_array); } else { @@ -69,14 +69,14 @@ /** * Reacts on "entities selected" event. * - * @param element + * @param {object} element * Element to bind on. - * @param callbacks + * @param {array} callbacks * List of callbacks. - * @param event_name + * @param {string} event_name * Name of event to bind to. */ - Drupal.entityBrowser.registerJsCallbacks = function(element, callbacks, event_name) { + Drupal.entityBrowser.registerJsCallbacks = function (element, callbacks, event_name) { // JS callbacks are registred as strings. We need to split their names and // find actual functions. for (var i = 0; i < callbacks.length; i++) { @@ -91,7 +91,7 @@ $(element).bind(event_name, fn); } } - } + }; }(jQuery, Drupal, drupalSettings)); diff --git a/js/entity_browser.entity_reference.js b/js/entity_browser.entity_reference.js index acfe141..04a85ab 100644 --- a/js/entity_browser.entity_reference.js +++ b/js/entity_browser.entity_reference.js @@ -6,7 +6,8 @@ */ (function ($, Drupal) { - "use strict"; + 'use strict'; + /** * Registers behaviours related to entity reference field widget. */ @@ -25,12 +26,12 @@ /** * Reacts on sorting of the entities. * - * @param event + * @param {object} event * Event object. - * @param ui + * @param {object} ui * Object with detailed information about the sort event. */ - Drupal.entityBrowserEntityReference.entitiesReordered = function(event, ui) { + Drupal.entityBrowserEntityReference.entitiesReordered = function (event, ui) { var items = $(this).find('.item-container'); var ids = []; for (var i = 0; i < items.length; i++) { diff --git a/js/entity_browser.iframe.js b/js/entity_browser.iframe.js index 53c09e3..4c8a879 100644 --- a/js/entity_browser.iframe.js +++ b/js/entity_browser.iframe.js @@ -5,7 +5,7 @@ */ (function ($, Drupal, drupalSettings) { - "use strict"; + 'use strict'; /** * Registers behaviours related to iFrame display. @@ -13,7 +13,7 @@ Drupal.behaviors.entityBrowserIFrame = { attach: function (context) { $(context).find('.entity-browser-handle.entity-browser-iframe').once('iframe-click').on('click', Drupal.entityBrowserIFrame.linkClick); - $(context).find('.entity-browser-handle.entity-browser-iframe').once('iframe-auto-open').each(function() { + $(context).find('.entity-browser-handle.entity-browser-iframe').once('iframe-auto-open').each(function () { var uuid = $(this).attr('data-uuid'); if (drupalSettings.entity_browser.iframe[uuid].auto_open) { $(this).click(); @@ -27,18 +27,18 @@ /** * Handles click on "Select entities" link. */ - Drupal.entityBrowserIFrame.linkClick = function() { + Drupal.entityBrowserIFrame.linkClick = function () { var uuid = $(this).attr('data-uuid'); var original_path = $(this).attr('data-original-path'); var iframe = $( '