Skip to content

Commit

Permalink
Fix issue with not being able to send emails when SalesforceIQ extens…
Browse files Browse the repository at this point in the history
…ion is also installed

Removed call to api.observe.bind because it mucks with AJAX and
  • Loading branch information
sbrudz committed Dec 18, 2015
1 parent 3434623 commit a3fbc05
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/JustNotSorry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,47 @@ var JustNotSorry = function() {
var gmail;
var warningChecker;

function checkForWarnings(compose, type) {
function addWarningsOnFocusIn(compose) {
var $target = compose.$el;
$target.focusin(function(e) {
var body = compose.dom('body');
if (e.target === body.get(0)) {
warningChecker.addWarnings(body);
}
});
}

function removeWarningsOnFocusOut(compose) {
var $target = compose.$el;
$target.focusout(function(e) {
var body = compose.dom('body');
if (e.target === body.get(0)) {
warningChecker.removeWarnings(body);
}
});
}

function updateWarningsOnMutation(compose) {
var target = compose.$el.get(0);
var observer = new MutationObserver(function() {
var body = compose.dom('body');
var caretPosition = body.caret('pos');
warningChecker.removeWarnings(body);
warningChecker.addWarnings(body);
body.caret('pos', caretPosition);
});

var target = compose.$el.get(0);
var config = {characterData: true, subtree: true};
observer.observe(target, config);
observer.observe(target, {characterData: true, subtree: true});
}

function cleanupWarnings(url, body, data, xhr) {
var bodyParams = xhr.xhrParams.body_params;

var oldCmml = xhr.xhrParams.url.cmml;

var existingBody = bodyParams.body;
var newBody = warningChecker.removeWarnings($(existingBody));

if (newBody.length > oldCmml) {
xhr.xhrParams.url.cmml = newBody.length;
} else {
newBody += '<div>';
while (newBody.length < oldCmml) {
newBody += ' ';
}

newBody += '</div>';
xhr.xhrParams.url.cmml = newBody.length;
}

bodyParams.body = newBody;
function checkForWarnings(compose) {
addWarningsOnFocusIn(compose);
removeWarningsOnFocusOut(compose);
updateWarningsOnMutation(compose);
}

gmail = new Gmail();
warningChecker = new WarningChecker(WARNINGS);
gmail.observe.on('compose', checkForWarnings);
gmail.observe.before('send_message', cleanupWarnings);
};

refresh(JustNotSorry);

0 comments on commit a3fbc05

Please sign in to comment.