Skip to content

Commit

Permalink
fix: fix issue where extension breaks sending emails
Browse files Browse the repository at this point in the history
This fixes an issue where, for display languages other than English, such as Magyar or Turkish, the extension highlights correctly but when you click Send on the email, nothing would happen.

Fixes #73
  • Loading branch information
sbrudz committed Apr 16, 2020
1 parent ac91fe0 commit 5f75ffa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
23 changes: 23 additions & 0 deletions spec/JustNotSorrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ describe('JustNotSorry', function () {
dispatchEventOnElement(target, 'focus');
expect(observer.observe).toHaveBeenCalled();
});

describe('when a global id variable is set', function() {
beforeEach(function() {
window.id = 'test value';
});

afterEach(function() {
delete window.id;
});

it('keeps that global variable unchanged', function(done) {
const target = document.getElementById('div-2');
target.addEventListener('focus', addObserver);
dispatchEventOnElement(target, 'focus');

target.innerHTML = '<br/>';

setTimeout(function () {
expect(id).toEqual('test value');
done();
});
});
});
});

describe('#removeObserver', function() {
Expand Down
16 changes: 8 additions & 8 deletions src/JustNotSorry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ var editableDivCount = 0;
var observer = new MutationObserver(function(mutations) {
if (mutations[0]) {
mutations.forEach(function(mutation) {
if (mutation.type != 'characterData' && mutation.target.hasAttribute('contentEditable')) {
id = mutation.target.id;
if (mutation.type !== 'characterData' && mutation.target.hasAttribute('contentEditable')) {
var id = mutation.target.id;
if (id) {
var targetDiv = document.getElementById(id);
// generate input event to fire checkForWarnings again
Expand All @@ -25,33 +25,33 @@ var observer = new MutationObserver(function(mutations) {
var addObserver = function() {
warningChecker.addWarnings(this.parentNode);
observer.observe(this, {characterData: true, subtree: true, childList: true, attributes: true});
}
};

var removeObserver = function() {
warningChecker.removeWarnings(this.parentNode);
observer.disconnect();
}
};

var checkForWarnings = function() {
warningChecker.removeWarnings(this.parentNode);
warningChecker.addWarnings(this.parentNode);
}
};

var applyEventListeners = function(id) {
var targetDiv = document.getElementById(id);
targetDiv.addEventListener('focus', addObserver);
targetDiv.addEventListener('input', checkForWarnings);
targetDiv.addEventListener('blur', removeObserver);
}
};

var documentObserver = new MutationObserver(function(mutations) {
var divCount = getEditableDivs().length;
if (divCount != editableDivCount) {
if (divCount !== editableDivCount) {
editableDivCount = divCount;
var id;
if (mutations[0]) {
mutations.forEach(function(mutation) {
if (mutation.type == 'childList' && mutation.target.hasAttribute('contentEditable')) {
if (mutation.type === 'childList' && mutation.target.hasAttribute('contentEditable')) {
id = mutation.target.id;
if (id) {
applyEventListeners(id);
Expand Down

0 comments on commit 5f75ffa

Please sign in to comment.