Skip to content

Commit

Permalink
Merge branch 'upper-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Sep 26, 2017
2 parents ada6d53 + 4e60f8e commit 06de4a4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 67 deletions.
6 changes: 5 additions & 1 deletion webextension/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# LanguageTool WebExtension Change Log

### 1.0.22 (2017-xx-xx)
* Some typography rules are now turned off by default because they are not useful
* An icon is now shown in the lower right corner of the text box the user is typing,
to remind them the add-on exists. Text is not checked automatically but only when
clicking on the icon. There are a few sites where the icon is not shown, e.g. Facebook.
(https://github.com/languagetool-org/languagetool-browser-addon/issues/46)
* Some typography-related rules are now turned off by default because they are not useful
in a web context for most users (only affects new installations or those that haven't
saved any rule turn on/off yet)
(https://github.com/languagetool-org/languagetool/issues/798)
Expand Down
2 changes: 2 additions & 0 deletions webextension/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function checkText(callback, request) {
return;
}
} catch (err) {
Tools.logOnServer(`error on checkText for iframe: ${err.message}`)
}
}
const selection = window.getSelection();
Expand All @@ -86,6 +87,7 @@ function checkText(callback, request) {
//console.log(e);
// Fallback e.g. for tinyMCE as used on languagetool.org - document.activeElement simply doesn't
// seem to work if focus is inside the iframe.
Tools.logOnServer(`error on checkText - get selection: ${e.message}`)
const iframes = document.getElementsByTagName("iframe");
let found = false;
for (let i = 0; i < iframes.length; i++) {
Expand Down
26 changes: 8 additions & 18 deletions webextension/popup-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,7 @@ document.addEventListener(
if (chrome && chrome.tabs) {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
if (tabs && tabs.length > 0) {
sendMessageToTab(
tabs[0].id,
{ action: "closePopup" },
response => {
}
);
sendMessageToTab(tabs[0].id, { action: "closePopup" });
}
});
} else {
Expand All @@ -332,18 +327,12 @@ document.addEventListener(
.then(
response => {
if (response && response.tabs && response.tabs.length > 0) {
sendMessageToTab(
response.tabs[0].id,
{
action: "closePopup"
},
result => {
}
);
sendMessageToTab(response.tabs[0].id, { action: "closePopup"});
}
},
error => {
if (error) {
Tools.logOnServer(`error on getActiveTab: ${error.message}`)
}
}
);
Expand All @@ -357,7 +346,7 @@ document.addEventListener(
false
);

function openPowerByLink(evt) {
function openPoweredByLink(evt) {
evt.preventDefault();
chrome.runtime
.sendMessage({
Expand All @@ -369,20 +358,21 @@ function openPowerByLink(evt) {
},
error => {
if (error) {
Tools.logOnServer(`error on openNewTab: ${error.message}`)
}
}
);
}

function openPowerByLinkOnNewTab() {
function openPoweredByLinkOnNewTab() {
// handle edge case for open poweredBy link from popup
const poweredByElements = document.getElementsByClassName(POWER_BY_CLASS);
if (poweredByElements.length) {
for (let counter = 0; counter < poweredByElements.length; counter += 1) {
const element = poweredByElements[counter];
const anchorTag = element.getElementsByTagName("a");
if (anchorTag.length) {
anchorTag[0].addEventListener("click", openPowerByLink);
anchorTag[0].addEventListener("click", openPoweredByLink);
}
}
}
Expand All @@ -393,7 +383,7 @@ if (Tools.isFirefox()) {
// create an observer instance
const observer = new MutationObserver(mutations => {
mutations.forEach(() => {
openPowerByLinkOnNewTab();
openPoweredByLinkOnNewTab();
});
});

Expand Down
3 changes: 3 additions & 0 deletions webextension/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const ruleIdsIgnoredByDefault = [
// German:
{id: 'TYPOGRAFISCHE_ANFUEHRUNGSZEICHEN', language: 'de'},
{id: 'FALSCHE_VERWENDUNG_DES_BINDESTRICHS', language: 'de'},
{id: 'BISSTRICH', language: 'de'},
{id: 'AUSLASSUNGSPUNKTE', language: 'de'},
];

// ask the user for a review in the store if they have used this add-on at least this many times:
Expand Down Expand Up @@ -700,6 +702,7 @@ document.addEventListener('DOMContentLoaded', function() {
},
function(error) {
if (error) {
Tools.logOnServer(`error on getActiveTab: ${error.message}`)
}
}
);
Expand Down
64 changes: 17 additions & 47 deletions webextension/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function offset(el) {
}

/**
* Check tectarea or editor is allow spellcheck
* Check textarea or editor is allow spellcheck
* @param {DOMElement} element
*/
function isAllowSpellcheck(element) {
Expand All @@ -113,7 +113,7 @@ function isEditorElement(focusElement) {
);
}

/** event hanlders */
/** event handlers */

function checkErrorMenu(evt) {
evt.stopPropagation();
Expand Down Expand Up @@ -178,15 +178,10 @@ function disableMenu(evt) {
);
}

/** DOM manupulate */
function remindLanguageToolButton(clickHandler, position) {
const { top, left, offsetHeight, offsetWidth } = position;
const btn = document.createElement("A");
btn.onclick = clickHandler;
btn.className = `${BTN_CLASS} ${REMIND_BTN_CLASS}`;
btn.setAttribute("tooltip", chrome.i18n.getMessage("reminderIconTitle"));
/** DOM manipulate */

// style
function styleRemindButton(btn, position, num) {
const { top, left, offsetHeight, offsetWidth } = position;
btn.style.position = "absolute";
if (isGmail()) {
const tables = document.querySelectorAll("table#undefined");
Expand All @@ -208,16 +203,19 @@ function remindLanguageToolButton(clickHandler, position) {
}
}
} else {
btn.style.top = `${top +
offsetHeight -
REMIND_BTN_SIZE -
MARGIN_TO_CORNER}px`;
btn.style.top = `${top + offsetHeight - REMIND_BTN_SIZE - MARGIN_TO_CORNER}px`;
}
btn.style.left = `${left +
offsetWidth -
REMIND_BTN_SIZE -
MARGIN_TO_CORNER}px`;
btn.style.left = `${left + offsetWidth - (REMIND_BTN_SIZE + MARGIN_TO_CORNER)*num}px`;
}

function remindLanguageToolButton(clickHandler, position) {
const btn = document.createElement("A");
btn.onclick = clickHandler;
btn.className = `${BTN_CLASS} ${REMIND_BTN_CLASS}`;
btn.setAttribute("tooltip", chrome.i18n.getMessage("reminderIconTitle"));

// style
styleRemindButton(btn, position, 1);
return btn;
}

Expand All @@ -231,35 +229,7 @@ function disableLanguageToolButton(clickHandler, position) {
chrome.i18n.getMessage("disableForThisDomainTitle")
);
// style
btn.style.position = "absolute";
if (isGmail()) {
const tables = document.querySelectorAll("table#undefined");
const activeTable = Array.prototype.find.call(tables, table =>
isDescendant(table, document.activeElement)
);
// find parent of active table
const allTables = document.getElementsByTagName("table");
const gmaiComposeToolbarHeight = 155;
for (let counter = allTables.length - 1; counter > 0; counter -= 1) {
const parentTable = allTables[counter];
if (isDescendant(parentTable, activeTable)) {
let topPostion = offset(parentTable).top;
if (topPostion < gmaiComposeToolbarHeight) {
topPostion = gmaiComposeToolbarHeight;
}
btn.style.top = `${topPostion}px`;
break;
}
}
} else {
btn.style.top = `${top +
offsetHeight -
REMIND_BTN_SIZE -
MARGIN_TO_CORNER}px`;
}
btn.style.left = `${left +
offsetWidth -
(REMIND_BTN_SIZE + MARGIN_TO_CORNER) * 2}px`;
styleRemindButton(btn, position, 2);
return btn;
}

Expand Down
2 changes: 1 addition & 1 deletion webextension/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Tools {
return hex;
}

static logOnServer(message, serverUrl) {
static logOnServer(message, serverUrl = 'https://languagetool.org/api/v2') {
if (serverUrl.indexOf("https://languagetool.org") == -1) {
// these logging messages are only useful for the LT dev team
// to improve the add-on, so don't send anywhere else:
Expand Down

0 comments on commit 06de4a4

Please sign in to comment.