Skip to content

Commit

Permalink
Refactor JS assets to use Yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodacious committed Sep 7, 2018
1 parent b42470a commit ea456fc
Show file tree
Hide file tree
Showing 114 changed files with 10,776 additions and 13,205 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/assets/javascripts/locale/de/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/locale/en_GB/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/locale/en_US/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/locale/es/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/locale/fr/app.js

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions app/assets/javascripts/packs/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Rails setup
import 'jquery-ujs';
import 'jquery-accessible-autocomplete-list-aria/jquery-accessible-autocomplete-list-aria';

// Generic JS that is applicable across multiple pages
import 'utils/array';
import 'utils/paginable';
Expand All @@ -6,17 +10,13 @@ import 'utils/links';
import 'utils/tabHelper';
import 'utils/tooltipHelper';
import 'utils/popoverHelper';
import 'utils/requiredField';

// Page specific JS
import 'views/answers/edit';
import 'views/answers/rda_metadata';
import 'views/contacts/new';
import 'views/devise/invitations/edit';
import 'views/devise/passwords/edit';
import 'views/devise/passwords/new';
import 'views/devise/registrations/edit';
import 'views/guidance_groups/admin_edit';
import 'views/guidance_groups/admin_new';
import 'views/guidances/new_edit';
import 'views/notes/index';
import 'views/org_admin/phases/new_edit';
Expand Down Expand Up @@ -45,5 +45,3 @@ import 'views/usage/index';
import 'views/users/notification_preferences';
import 'views/users/admin_grant_permissions';
import 'views/super_admin/notifications/edit';

alert('it works!');
File renamed without changes.
File renamed without changes.
File renamed without changes.
248 changes: 0 additions & 248 deletions app/assets/javascripts/utils/ariatiseForm.js

This file was deleted.

26 changes: 1 addition & 25 deletions app/assets/javascripts/utils/links.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import 'number-to-text/converters/en-us';
import { convertToText } from 'number-to-text/index';
import { isFunction, isString } from './isType';
import { enableValidations, disableValidations } from './validation';

const toggleValidations = (el) => {
const linkVal = el.find('input[name="link_link"]').val();
const textVal = el.find('input[name="link_text"]').val();
if (isString(linkVal) && isString(textVal)) {
// Validations are enabled if non-empty value is found
if (linkVal.length > 0 || textVal.length > 0) {
enableValidations(el);
} else {
disableValidations(el);
}
}
};
import { isFunction } from './isType';

const getLinks = elem =>
$(elem).find('.link').map((i, el) => {
Expand All @@ -23,7 +9,6 @@ const getLinks = elem =>
const linkVal = link.find('input[name="link_link"]').val();
const textVal = link.find('input[name="link_text"]').val();
if (linkVal || textVal) {
enableValidations(el);
return { link: linkVal, text: textVal };
}
// If linkVal and textVal are empty trigger delete handler
Expand Down Expand Up @@ -78,11 +63,7 @@ $(() => {
const clonedLink = lastLink.clone();
changeIds(clonedLink);
clearVals(clonedLink);
// disableVaidations since a cloned element might contain invalid value for link_{link|text}
disableValidations(clonedLink);
lastLink.after(clonedLink);
// enableValidations for the newly added inputs
// enableValidations(clonedLink);
// Hide the add link if we have now reached the limit
if (nbrLinks + 1 >= max) {
$(target).closest('.links').find('a.new').addClass('hide');
Expand All @@ -104,18 +85,13 @@ $(() => {
} else {
const link = target.closest('.link');
clearVals(link);
disableValidations(link);
}
});
$('.links').find('.max-number-links').each((i, el) => {
const target = $(el);
const max = target.closest('.links').attr('data-max-number-links');
target.text(convertToText(max).toLowerCase());
});

$('.links').on('blur', 'input', (e) => {
toggleValidations($(e.target).closest('.link'));
});
});

export { eachLinks as default };

0 comments on commit ea456fc

Please sign in to comment.