Skip to content

Commit

Permalink
1.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Oct 2, 2016
1 parent 21bf629 commit 0731f80
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#1.1.10
* Fix: bugs on words inside ()
* Fix: other sanitizations
* Improvement: Now check if the content is different to avoid many DOM operations
* Improvement: Now validate the HTML to avoid broken strings
* Improvement: Now there is a file for tests the extension

#1.1.9
* Fix: bugs on single words

#1.1.8
* Fix: bugs on multiple cases on french and german

Expand Down
24 changes: 20 additions & 4 deletions glotdict.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,40 @@ jQuery(document).ready(function () {
if (item !== '') {
word = word.replace(/\)/g, "\\)");
word = word.replace(/\(/g, "\\(");
// The magic
// The first part in [] check for term that don't have at the left that symbol
// The secondo search for the term
// The third like the first part
// The last is to check that is not contained between that terms
var rgxp = new RegExp('[^\/\.\-?\=\(]\\b(' + word + ')\\b[^\-\.\=\)](?![^<>()\"]*>)', 'gi');
var print = JSON.stringify(item);
print = print.replace(/\'/g, "");
print = print.replace(/\'/g, "").replace(/\"/g, "&quot;");
if (!item.length) {
print = '[' + print + ']';
}
var repl = ' <a target="_blank" href="https://translate.wordpress.org/consistency?search=$1&set=' + gd_get_lang_consistency() + '%2Fdefault"><span class="glossary-word-glotdict" data-translations=\'' + print + '\'>$1</span></a> ';
var repl = ' <a target="_blank" href="https://translate.wordpress.org/consistency?search=$1&amp;set=' + gd_get_lang_consistency() + '%2Fdefault"><span class="glossary-word-glotdict" data-translations="' + print + '">$1</span></a> ';
// Hack to check also the first and last word
var content = ' ' + jQuery(element).html() + ' ';
// Remove the double space and init and at the end of the string
content = content.replace(rgxp, repl).replace(/ +/g, ' ').replace(/ lt\;/g, '&lt;').substring(1).substring(-1);
if (content !== jQuery(element).html()) {
jQuery(element).html(content);
if (checkHTML(content)) {
jQuery(element).html(content);
}
}
}
}

/**
* Easy way to validate the html to avoid horrible errors
* @param {String} html
* @returns {Boolean}
*/
function checkHTML(html) {
var doc = document.createElement('div');
doc.innerHTML = html;
return (doc.innerHTML === html);
}

/**
* Add links for Translation global status and Language projects archive
* @returns void
Expand Down

0 comments on commit 0731f80

Please sign in to comment.