Skip to content

Commit

Permalink
Issue #2683979 by CTaPByK: ESLint check and verify code quality in En…
Browse files Browse the repository at this point in the history
…tity Browser
  • Loading branch information
git authored and slashrsm committed Mar 9, 2016
1 parent 10c2fa9 commit 0bbdb6b
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 47 deletions.
28 changes: 14 additions & 14 deletions js/entity_browser.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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++) {
Expand All @@ -91,7 +91,7 @@
$(element).bind(event_name, fn);
}
}
}
};

}(jQuery, Drupal, drupalSettings));

Expand Down
9 changes: 5 additions & 4 deletions js/entity_browser.entity_reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/
(function ($, Drupal) {

"use strict";
'use strict';

/**
* Registers behaviours related to entity reference field widget.
*/
Expand All @@ -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++) {
Expand Down
18 changes: 9 additions & 9 deletions js/entity_browser.iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/
(function ($, Drupal, drupalSettings) {

"use strict";
'use strict';

/**
* Registers behaviours related to iFrame display.
*/
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();
Expand All @@ -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 = $(
'<iframe />',
{
'src' : drupalSettings['entity_browser']['iframe'][uuid]['src'],
'width' : drupalSettings['entity_browser']['iframe'][uuid]['width'],
'height' : drupalSettings['entity_browser']['iframe'][uuid]['height'],
'data-uuid' : uuid,
'data-original-path' : original_path,
'name' : 'entity-browser-iframe-' + drupalSettings['entity_browser']['iframe'][uuid]['entity_browser_id'].replace('_', '-')
'src': drupalSettings['entity_browser']['iframe'][uuid]['src'],
'width': drupalSettings['entity_browser']['iframe'][uuid]['width'],
'height': drupalSettings['entity_browser']['iframe'][uuid]['height'],
'data-uuid': uuid,
'data-original-path': original_path,
'name': 'entity-browser-iframe-' + drupalSettings['entity_browser']['iframe'][uuid]['entity_browser_id'].replace('_', '-')
}
);

Expand Down
2 changes: 1 addition & 1 deletion js/entity_browser.iframe_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
(function (drupalSettings) {

"use strict";
'use strict';

// We need to access parent window, get it's jquery and find correct iFrame
// element to trigger event on.
Expand Down
12 changes: 6 additions & 6 deletions js/entity_browser.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* Defines the behavior of the entity browser's modal display.
*/
(function ($, Drupal, drupalSettings) {
"use strict";

'use strict';

Drupal.AjaxCommands.prototype.select_entities = function (ajax, response, status) {
var uuid = drupalSettings.entity_browser.modal.uuid;

Expand All @@ -22,19 +22,19 @@
_.each(drupalSettings.entity_browser.modal, function (instance) {
_.each(instance.js_callbacks, function (callback) {
// Get the callback.
var callback = callback.split('.');
callback = callback.split('.');
var fn = window;

for (var j = 0; j < callback.length; j++) {
fn = fn[callback[j]];
}

if (typeof fn === 'function') {
$('input[data-uuid="' +instance.uuid + '"]').not('.entity-browser-processed')
$('input[data-uuid="' + instance.uuid + '"]').not('.entity-browser-processed')
.bind('entities-selected', fn).addClass('entity-browser-processed');
}
});
});
}
}
};
}(jQuery, Drupal, drupalSettings));
2 changes: 1 addition & 1 deletion js/entity_browser.modal_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
(function (drupalSettings) {

"use strict";
'use strict';

// We need to access parent window, get it's jquery and find correct modal
// element to trigger event on.
Expand Down
8 changes: 4 additions & 4 deletions js/entity_browser.multi_step_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
(function ($, Drupal) {

"use strict";
'use strict';

/**
* Registers behaviours related to selected entities.
Expand All @@ -22,12 +22,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.entityBrowserMultiStepDisplay.entitiesReordered = function(event, ui) {
Drupal.entityBrowserMultiStepDisplay.entitiesReordered = function (event, ui) {
var items = $(this).find('.item-container');
for (var i = 0; i < items.length; i++) {
$(items[i]).find('.weight').val(i);
Expand Down
6 changes: 3 additions & 3 deletions js/entity_browser.tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
(function ($, Drupal, drupalSettings) {

"use strict";
'use strict';

/**
* Registers behaviours related to tab display.
Expand Down Expand Up @@ -56,7 +56,7 @@
*/
Drupal.theme.entityTabs = function (tabsClass) {
return $('<ul role="navigation" aria-label="Tabs"></ul>')
.addClass(tabsClass)
.addClass(tabsClass);
};

/**
Expand All @@ -78,7 +78,7 @@
return $('<li class="tabs__tab" tabindex="-1"></li>')
.addClass(settings.class)
.append($('<a href="#"></a>').addClass(settings.class).attr('data-button-id', settings.id)
.append(settings.title)
.append(settings.title)
);
};

Expand Down
6 changes: 3 additions & 3 deletions js/entity_browser.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
(function ($, Drupal, drupalSettings) {

"use strict";
'use strict';

/**
* Registers behaviours related to view widget.
Expand All @@ -30,10 +30,10 @@
form_values = form_values.splice(form_values.length - 3, 3);
ajax.ajaxing = true;
return ajax.beforeSubmit(form_values, element_settings, options);
}
};
}
}
}
}
};

}(jQuery, Drupal, drupalSettings));
4 changes: 2 additions & 2 deletions modules/entity_form/js/entity_browser_entity_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
(function ($, Drupal, drupalSettings) {

"use strict";
'use strict';

/**
* Registers behaviours related to IEF "use existing" feature.
Expand All @@ -22,7 +22,7 @@
/**
* Reacts on entities being selected via entity form.
*/
Drupal.entityBrowserEntityForm.valuesUpdated = function() {
Drupal.entityBrowserEntityForm.valuesUpdated = function () {
$(this).parent().find('.ief-entity-submit').trigger('entities-selected');
};

Expand Down

0 comments on commit 0bbdb6b

Please sign in to comment.