Skip to content

Commit

Permalink
Issue #83: Fix jshint nagging, part one (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
indigoxela authored Feb 10, 2024
1 parent 96efec1 commit 9054363
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 60 deletions.
40 changes: 20 additions & 20 deletions js/plugins/backdropimage/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
let node = editor.selection.getNode();
let existingValues = {};

if (node.nodeName == 'IMG') {
if (node.nodeName === 'IMG') {
let attribs = node.getAttributeNames();
for (let i = 0; i < attribs.length; i++) {
let name = attribs[i];
if (name.startsWith('data-mce')) {
continue;
}
existingValues[name] = node.attributes[name]['value'];
existingValues[name] = node.attributes[name].value;
}
let parentFigure = editor.dom.getParents(node, 'FIGURE');
if (parentFigure.length) {
Expand All @@ -33,7 +33,7 @@
}

return existingValues;
}
};

/**
* Opens a Backdrop dialog.
Expand All @@ -46,7 +46,7 @@
let saveCallback = function(returnValues) {
let image = buildImage(editor, returnValues);
let selected = editor.selection.getNode();
if (selected.nodeName == 'IMG') {
if (selected.nodeName === 'IMG') {
let parentFigure = editor.dom.getParents(selected, 'FIGURE');
let parentLink = editor.dom.getParents(selected, 'A');
if (parentFigure.length) {
Expand All @@ -64,13 +64,13 @@
imgToSize.onload = function() {
imgDomnode.setAttribute('width', this.width);
imgDomnode.setAttribute('height', this.height);
}
};
imgToSize.src = src;
}
};

Backdrop.tinymce.openDialog(editor, dialogUrl, existingValues, saveCallback, dialogSettings);
}
};

/**
* Builds the image markup.
Expand Down Expand Up @@ -101,10 +101,10 @@
node = editor.dom.create('figure', figAttrib);
let img = editor.dom.create('img');
for (let key in values) {
if (key == 'data-has-caption') {
if (key === 'data-has-caption') {
continue;
}
if (key == 'data-file-id' && !values[key]) {
if (key === 'data-file-id' && !values[key]) {
continue;
}
img.setAttribute(key, values[key]);
Expand All @@ -123,7 +123,7 @@
if (parentFigure.length) {
let parent = parentFigure[0];
for (let i = 0; i < parent.childNodes.length; i++) {
if (parent.childNodes[i].nodeName == 'FIGCAPTION') {
if (parent.childNodes[i].nodeName === 'FIGCAPTION') {
captiontext = parent.childNodes[i].innerHTML;
break;
}
Expand All @@ -135,10 +135,10 @@
else {
let img = editor.dom.create('img');
for (let key in values) {
if (key == 'data-has-caption') {
if (key === 'data-has-caption') {
continue;
}
if (key == 'data-file-id' && !values[key]) {
if (key === 'data-file-id' && !values[key]) {
continue;
}
img.setAttribute(key, values[key]);
Expand All @@ -152,7 +152,7 @@
}
}
return node.outerHTML;
}
};

/**
* Parses an array of AstNodes into a string.
Expand Down Expand Up @@ -181,7 +181,7 @@
}
}
return dummy.innerHTML;
}
};

/**
* Turns an attribute string into an AstNode instance.
Expand All @@ -198,7 +198,7 @@

for (let i = 0; i < domNode.childNodes.length; i++) {
let n = domNode.childNodes[i];
if (n.nodeName == '#text') {
if (n.nodeName === '#text') {
let text = new tinymce.html.Node('#text', 3);
text.value = n.textContent;
caption.append(text);
Expand All @@ -213,7 +213,7 @@
}
}
return caption;
}
};

/**
* Checks if a dom node is relevant for this plugin.
Expand All @@ -225,7 +225,7 @@
* True if this tag is something, this plugin handles.
*/
const isRegularImg = function (node) {
if (node.nodeName != 'IMG') {
if (node.nodeName !== 'IMG') {
return false;
}
if (node.hasAttribute('data-mce-object') || node.hasAttribute('data-mce-placeholder')) {
Expand All @@ -235,7 +235,7 @@
return false;
}
return true;
}
};

// Register plugin features.
tinymce.PluginManager.add('backdropimage', function(editor, url) {
Expand All @@ -246,11 +246,11 @@
// These "node" are AstNode, not dom node.
// @see https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.html.node/#Node
let link;
if (nodes[i].parent.name == 'a') {
if (nodes[i].parent.name === 'a') {
link = nodes[i].parent.clone();
nodes[i].parent.unwrap();
}
if (nodes[i].parent.name == 'p') {
if (nodes[i].parent.name === 'p') {
nodes[i].parent.unwrap();
}
let img = nodes[i].clone();
Expand Down Expand Up @@ -343,7 +343,7 @@
});
// @see https://github.com/backdrop-contrib/tinymce/issues/56
editor.on('ObjectSelected', function (obj) {
if (obj.target.nodeName != 'IMG') {
if (obj.target.nodeName !== 'IMG') {
return;
}
editor.selection.select(obj.target);
Expand Down
28 changes: 14 additions & 14 deletions js/plugins/backdroplink/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

let saveCallback = function(returnValues) {
let link = buildLink(editor, returnValues);
if (typeof existingValues.href == 'undefined') {
if (typeof existingValues.href === 'undefined') {
editor.execCommand('mceInsertContent', false, link);
}
else {
Expand All @@ -28,7 +28,7 @@
};

Backdrop.tinymce.openDialog(editor, dialogUrl, existingValues, saveCallback, dialogSettings);
}
};

/**
* @param object editor
Expand All @@ -42,11 +42,11 @@
let existingValues = {};

// This image is already wrapped in a link.
if (node.nodeName == 'IMG' && node.parentNode.nodeName == 'A') {
if (node.nodeName === 'IMG' && node.parentNode.nodeName === 'A') {
node = node.parentNode;
}

if (node.nodeName == 'A') {
if (node.nodeName === 'A') {
// Expand selection to whole anchor to prevent inserting a link into a link.
editor.selection.select(node);
if (node.textContent) {
Expand All @@ -59,18 +59,18 @@
if (name.startsWith('data-mce')) {
continue;
}
existingValues[name] = node.attributes[name]['value'];
existingValues[name] = node.attributes[name].value;
}
}
else if (node.nodeName != 'IMG') {
else if (node.nodeName !== 'IMG') {
let content = editor.selection.getContent({ format: 'text' });
existingValues = {
text: content
};
}

return existingValues;
}
};

/**
* Builds link markup.
Expand All @@ -88,23 +88,23 @@

let a = editor.dom.create('a');
for (let key in values) {
if (key == 'text') {
if (key === 'text') {
textContent = values[key];
continue;
}
if (key == 'data-file-id' && !values[key]) {
if (key === 'data-file-id' && !values[key]) {
continue;
}
a.setAttribute(key, values[key]);
}

let node = editor.selection.getNode();
if (node.nodeName == 'IMG') {
if (node.nodeName === 'IMG') {
let clone = node.cloneNode(true);
clone.removeAttribute('data-mce-src');
a.appendChild(clone);
}
else if (node.nodeName == 'A' && node.childNodes.length) {
else if (node.nodeName === 'A' && node.childNodes.length) {
for (let i = 0; i < node.childNodes.length; i++) {
let clone = node.childNodes[i].cloneNode(true);
a.appendChild(clone);
Expand All @@ -121,7 +121,7 @@
return a.innerHTML;
}
return a.outerHTML;
}
};

// Register plugin features.
tinymce.PluginManager.add('backdroplink', function(editor, url) {
Expand All @@ -136,7 +136,7 @@
editor.on('SelectionChange', function () {
let node = editor.selection.getNode();
// The anchor plugin marks its links as not editable.
if (node.nodeName == 'A' && node.isContentEditable) {
if (node.nodeName === 'A' && node.isContentEditable) {
api.setActive(true);
}
else {
Expand All @@ -155,7 +155,7 @@
api.setEnabled(false);
editor.on('SelectionChange', function () {
let node = editor.selection.getNode();
if (node.nodeName == 'A' || node.parentNode.nodeName == 'A') {
if (node.nodeName === 'A' || node.parentNode.nodeName === 'A') {
api.setEnabled(true);
}
else {
Expand Down
6 changes: 3 additions & 3 deletions js/plugins/backdroplistprop/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
api.close();
}
});
}
};

/**
* Get the Dom parent OL if exists.
Expand All @@ -79,11 +79,11 @@
*/
const getOlParent = function (node) {
const closestLi = node.closest('li');
if (closestLi && closestLi.parentNode.nodeName == 'OL') {
if (closestLi && closestLi.parentNode.nodeName === 'OL') {
return closestLi.parentNode;
}
return false;
}
};

// Register plugin features.
tinymce.PluginManager.add('backdroplistprop', function(editor, url) {
Expand Down
6 changes: 3 additions & 3 deletions js/plugins/liststyle/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
let attrValue = nodes[i].attr('data-list-style');
let otherStyles = nodes[i].attr('style');
let listStyle = 'list-style-type: ' + attrValue + ';';
if (typeof otherStyles == 'undefined') {
if (typeof otherStyles === 'undefined') {
nodes[i].attr('style', listStyle);
}
else {
Expand All @@ -24,7 +24,7 @@
});
editor.serializer.addAttributeFilter('style', function (nodes) {
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].name != 'ul' && nodes[i].name != 'ol') {
if (nodes[i].name !== 'ul' && nodes[i].name !== 'ol') {
continue;
}
let styles = nodes[i].attr('style');
Expand All @@ -35,7 +35,7 @@
continue;
}
let keyVal = stylesArr[n].split(':');
if (keyVal[0].trim() == 'list-style-type') {
if (keyVal[0].trim() === 'list-style-type') {
nodes[i].attr('data-list-style', keyVal[1].trim());
}
else {
Expand Down
4 changes: 2 additions & 2 deletions js/tinymce-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Backdrop.behaviors.tinymceAdmin = {
attach: function (context, settings) {
let selectedEditor = $('select[name="editor"]').val();
if (selectedEditor != 'tinymce') {
if (selectedEditor !== 'tinymce') {
return;
}
let selectProfile = $('#edit-editor-settings-tinymce-settings-profile');
Expand All @@ -28,7 +28,7 @@ Backdrop.behaviors.tinymceAdmin = {
},
detach: function () {
let selected = $('#edit-editor-settings-tinymce-settings-profile').val();
if (typeof selected == 'undefined') {
if (typeof selected === 'undefined') {
return;
}
let featureList = Backdrop.behaviors.tinymceAdmin.buildFeatures();
Expand Down
14 changes: 7 additions & 7 deletions js/tinymce-dragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@

// Keyboard navigation.
$('#edit-tb .tinybutton').on('keydown', function (ev) {
if ($(this).parent().attr('id') == 'buttons-active') {
if ($(this).parent().attr('id') === 'buttons-active') {
// 39 = Arrow right.
if (ev.which == 39) {
if (ev.which === 39) {
$(this).insertAfter($(this).next());
$(this).focus();
updateFormItem();
}
// 37 = Arrow left.
else if (ev.which == 37) {
else if (ev.which === 37) {
$(this).insertBefore($(this).prev());
$(this).focus();
updateFormItem();
}
// 173 = "-" key.
else if (ev.which == 173) {
else if (ev.which === 173) {
$(this).next().focus();
$(this).appendTo('#buttons-available');
let message = Backdrop.t('%button removed from active elements.', {
Expand All @@ -52,7 +52,7 @@
}
else {
// 171 = "+" key.
if (ev.which == 171) {
if (ev.which === 171) {
$(this).appendTo('#buttons-active');
$(this).focus();
let message = Backdrop.t('%button added to active elements.', {
Expand Down Expand Up @@ -80,7 +80,7 @@
});
$('#edit-toolbar').val(toolbarconf);
}, 500);
}
};
}
}
};
})(jQuery, Backdrop);
Loading

0 comments on commit 9054363

Please sign in to comment.