Skip to content

Commit

Permalink
client: remove more jQuery-ism
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Sep 5, 2020
1 parent ede3c6d commit 1e593db
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
13 changes: 8 additions & 5 deletions assets/js/selfoss-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,13 @@ var selfoss = {

$(element).find(':input').each(function(i, el) {
// get only input elements with name
if ($.trim($(el).attr('name')).length != 0) {
values[$(el).attr('name')] = $(el).val();
if ($(el).attr('type') == 'checkbox') {
values[$(el).attr('name')] = $(el).attr('checked') ? 1 : 0;
if (el.hasAttribute('name')) {
let name = el.getAttribute('name').trim();
if (name.length != 0) {
values[name] = $(el).val();
if ($(el).attr('type') == 'checkbox') {
values[name] = $(el).attr('checked') ? 1 : 0;
}
}
}
});
Expand Down Expand Up @@ -281,7 +284,7 @@ var selfoss = {
*/
showErrors: function(form, errors) {
$(form).find('span.error').remove();
$.each(errors, function(key, val) {
Object.entries(errors).forEach(([key, val]) => {
form.find("[name='" + key + "']").addClass('error').parent('li').append('<span class="error">' + val + '</span>');
});
},
Expand Down
6 changes: 2 additions & 4 deletions assets/js/selfoss-events-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ selfoss.events.search = function() {
var words = splitTerm(term);
term = joinTerm(words);
$('#search-list').html('');
var itemId = 0;
$.each(words, function(index, item) {
$('#search-list').append('<li id="search-item-' + itemId + '">' + item + ' <i class="fas fa-times"></i></li>');
itemId++;
words.forEach((item, index) => {
$('#search-list').append('<li id="search-item-' + index + '">' + item + ' <i class="fas fa-times"></i></li>');
});

// execute search
Expand Down
7 changes: 3 additions & 4 deletions assets/js/selfoss-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,15 @@ selfoss.events = {
}

// load items
if ($.inArray(selfoss.events.section,
['newest', 'unread', 'starred']) > -1) {
if (['newest', 'unread', 'starred'].includes(selfoss.events.section)) {
selfoss.filter.type = selfoss.events.section;
selfoss.filter.tag = '';
selfoss.filter.source = '';
if (selfoss.events.subsection) {
selfoss.events.lastSubsection = selfoss.events.subsection;
if (selfoss.events.subsection.substr(0, 4) == 'tag-') {
if (selfoss.events.subsection.startsWith('tag-')) {
selfoss.filter.tag = selfoss.events.subsection.substr(4);
} else if (selfoss.events.subsection.substr(0, 7) == 'source-') {
} else if (selfoss.events.subsection.startsWith('source-')) {
var sourceId = parseInt(selfoss.events.subsection.substr(7));
if (sourceId) {
selfoss.filter.source = sourceId;
Expand Down
3 changes: 1 addition & 2 deletions assets/js/selfoss-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ selfoss.ui = {
if (placeholder) {
if (state == 'plural') {
pluralKeyword = buffer.trim();
if ($.inArray(pluralKeyword,
['zero', 'one', 'other']) > -1) {
if (['zero', 'one', 'other'].includes(pluralKeyword)) {
buffer = '';
} else {
pluralKeyword = undefined;
Expand Down

0 comments on commit 1e593db

Please sign in to comment.