summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/after-the-deadline/jquery.atd.js')
-rw-r--r--plugins/jetpack/modules/after-the-deadline/jquery.atd.js179
1 files changed, 99 insertions, 80 deletions
diff --git a/plugins/jetpack/modules/after-the-deadline/jquery.atd.js b/plugins/jetpack/modules/after-the-deadline/jquery.atd.js
index ee2ef6be..7d7e7682 100644
--- a/plugins/jetpack/modules/after-the-deadline/jquery.atd.js
+++ b/plugins/jetpack/modules/after-the-deadline/jquery.atd.js
@@ -14,26 +14,26 @@
* Contact : willis.rh@gmail.com
*/
+/* jshint onevar: false, sub: true, smarttabs: true */
+/* global AtDCore, AtD_proofread_click_count, CSSHttpRequest, ActiveXObject */
+
var AtD =
{
rpc : '', /* see the proxy.php that came with the AtD/TinyMCE plugin */
rpc_css : 'http://www.polishmywriting.com/atd-jquery/server/proxycss.php?data=', /* you may use this, but be nice! */
rpc_css_lang : 'en',
api_key : '',
- i18n : {},
+ i18n : {}, // Back-compat
listener : {}
};
-AtD.getLang = function(key, defaultk) {
- if (AtD.i18n[key] == undefined)
- return defaultk;
-
- return AtD.i18n[key];
+AtD.getLang = function( key, defaultk ) {
+ return ( window.AtD_l10n_r0ar && window.AtD_l10n_r0ar[key] ) || defaultk;
};
-AtD.addI18n = function(localizations) {
- AtD.i18n = localizations;
- AtD.core.addI18n(localizations);
+AtD.addI18n = function( obj ) {
+ // Back-compat
+ window.AtD_l10n_r0ar = obj;
};
AtD.setIgnoreStrings = function(string) {
@@ -46,43 +46,44 @@ AtD.showTypes = function(string) {
AtD.checkCrossAJAX = function(container_id, callback_f) {
/* checks if a global var for click stats exists and increments it if it does... */
- if (typeof AtD_proofread_click_count != "undefined")
+ if (typeof AtD_proofread_click_count !== 'undefined') {
AtD_proofread_click_count++;
+ }
AtD.callback_f = callback_f; /* remember the callback for later */
AtD.remove(container_id);
var container = jQuery('#' + container_id);
- var html = container.html();
- text = jQuery.trim(container.html());
+ var text = jQuery.trim(container.html());
text = text.replace(/\&lt;/g, '<').replace(/\&gt;/g, '>').replace(/\&amp;/g, '&');
text = encodeURIComponent( text.replace( /\%/g, '%25' ) ); /* % not being escaped here creates problems, I don't know why. */
/* do some sanity checks based on the browser */
- if ((text.length > 2000 && navigator.appName == 'Microsoft Internet Explorer') || text.length > 7800) {
- if (callback_f != undefined && callback_f.error != undefined)
- callback_f.error("Maximum text length for this browser exceeded");
+ if ((text.length > 2000 && navigator.appName === 'Microsoft Internet Explorer') || text.length > 7800) {
+ if (callback_f !== undefined && callback_f.error !== undefined) {
+ callback_f.error('Maximum text length for this browser exceeded');
+ }
return;
}
/* do some cross-domain AJAX action with CSSHttpRequest */
- CSSHttpRequest.get(AtD.rpc_css + text + "&lang=" + AtD.rpc_css_lang + "&nocache=" + (new Date().getTime()), function(response) {
+ CSSHttpRequest.get(AtD.rpc_css + text + '&lang=' + AtD.rpc_css_lang + '&nocache=' + (new Date().getTime()), function(response) {
/* do some magic to convert the response into an XML document */
var xml;
- if (navigator.appName == 'Microsoft Internet Explorer') {
- xml = new ActiveXObject("Microsoft.XMLDOM");
+ if (navigator.appName === 'Microsoft Internet Explorer') {
+ xml = new ActiveXObject('Microsoft.XMLDOM');
xml.async = false;
xml.loadXML(response);
- }
- else {
+ } else {
xml = (new DOMParser()).parseFromString(response, 'text/xml');
}
/* check for and display error messages from the server */
if (AtD.core.hasErrorMessage(xml)) {
- if (AtD.callback_f != undefined && AtD.callback_f.error != undefined)
+ if (AtD.callback_f !== undefined && AtD.callback_f.error !== undefined) {
AtD.callback_f.error(AtD.core.getErrorMessage(xml));
+ }
return;
}
@@ -90,13 +91,15 @@ AtD.checkCrossAJAX = function(container_id, callback_f) {
/* highlight the errors */
AtD.container = container_id;
- var count = AtD.processXML(container_id, xml);
+ var count = Number( AtD.processXML(container_id, xml) );
- if (AtD.callback_f != undefined && AtD.callback_f.ready != undefined)
+ if (AtD.callback_f !== undefined && AtD.callback_f.ready !== undefined) {
AtD.callback_f.ready(count);
+ }
- if (count == 0 && AtD.callback_f != undefined && AtD.callback_f.success != undefined)
+ if (count === 0 && AtD.callback_f !== undefined && AtD.callback_f.success !== undefined) {
AtD.callback_f.success(count);
+ }
AtD.counter = count;
AtD.count = count;
@@ -106,8 +109,9 @@ AtD.checkCrossAJAX = function(container_id, callback_f) {
/* check a div for any incorrectly spelled words */
AtD.check = function(container_id, callback_f) {
/* checks if a global var for click stats exists and increments it if it does... */
- if (typeof AtD_proofread_click_count != "undefined")
+ if (typeof AtD_proofread_click_count !== 'undefined') {
AtD_proofread_click_count++;
+ }
AtD.callback_f = callback_f; /* remember the callback for later */
@@ -115,21 +119,21 @@ AtD.check = function(container_id, callback_f) {
var container = jQuery('#' + container_id);
- var html = container.html();
- text = jQuery.trim(container.html());
+ var text = jQuery.trim(container.html());
text = text.replace(/\&lt;/g, '<').replace(/\&gt;/g, '>').replace(/\&amp;/g, '&');
text = encodeURIComponent( text ); /* re-escaping % is not necessary here. don't do it */
jQuery.ajax({
- type : "POST",
+ type : 'POST',
url : AtD.rpc + '/checkDocument',
data : 'key=' + AtD.api_key + '&data=' + text,
format : 'raw',
- dataType : (jQuery.browser.msie) ? "text" : "xml",
+ dataType : (jQuery.browser.msie) ? 'text' : 'xml',
error : function(XHR, status, error) {
- if (AtD.callback_f != undefined && AtD.callback_f.error != undefined)
- AtD.callback_f.error(status + ": " + error);
+ if (AtD.callback_f !== undefined && AtD.callback_f.error !== undefined) {
+ AtD.callback_f.error(status + ': ' + error);
+ }
},
success : function(data) {
@@ -137,8 +141,8 @@ AtD.check = function(container_id, callback_f) {
http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests */
var xml;
- if (typeof data == "string") {
- xml = new ActiveXObject("Microsoft.XMLDOM");
+ if (typeof data === 'string') {
+ xml = new ActiveXObject('Microsoft.XMLDOM');
xml.async = false;
xml.loadXML(data);
}
@@ -147,8 +151,9 @@ AtD.check = function(container_id, callback_f) {
}
if (AtD.core.hasErrorMessage(xml)) {
- if (AtD.callback_f != undefined && AtD.callback_f.error != undefined)
+ if (AtD.callback_f !== undefined && AtD.callback_f.error !== undefined) {
AtD.callback_f.error(AtD.core.getErrorMessage(xml));
+ }
return;
}
@@ -156,13 +161,15 @@ AtD.check = function(container_id, callback_f) {
/* on with the task of processing and highlighting errors */
AtD.container = container_id;
- var count = AtD.processXML(container_id, xml);
+ var count = Number( AtD.processXML(container_id, xml) );
- if (AtD.callback_f != undefined && AtD.callback_f.ready != undefined)
+ if (AtD.callback_f !== undefined && AtD.callback_f.ready !== undefined) {
AtD.callback_f.ready(count);
+ }
- if (count == 0 && AtD.callback_f != undefined && AtD.callback_f.success != undefined)
+ if (count === 0 && AtD.callback_f !== undefined && AtD.callback_f.success !== undefined) {
AtD.callback_f.success(count);
+ }
AtD.counter = count;
AtD.count = count;
@@ -175,16 +182,18 @@ AtD.remove = function(container_id) {
};
AtD.clickListener = function(event) {
- if (AtD.core.isMarkedNode(event.target))
+ if (AtD.core.isMarkedNode(event.target)) {
AtD.suggest(event.target);
+ }
};
AtD.processXML = function(container_id, responseXML) {
var results = AtD.core.processXML(responseXML);
- if (results.count > 0)
+ if (results.count > 0) {
results.count = AtD.core.markMyWords(jQuery('#' + container_id).contents(), results.errors);
+ }
jQuery('#' + container_id).unbind('click', AtD.clickListener);
jQuery('#' + container_id).click(AtD.clickListener);
@@ -196,20 +205,23 @@ AtD.useSuggestion = function(word) {
this.core.applySuggestion(AtD.errorElement, word);
AtD.counter --;
- if (AtD.counter == 0 && AtD.callback_f != undefined && AtD.callback_f.success != undefined)
+ if (AtD.counter === 0 && AtD.callback_f !== undefined && AtD.callback_f.success !== undefined) {
AtD.callback_f.success(AtD.count);
+ }
};
AtD.editSelection = function() {
var parent = AtD.errorElement.parent();
- if (AtD.callback_f != undefined && AtD.callback_f.editSelection != undefined)
+ if (AtD.callback_f !== undefined && AtD.callback_f.editSelection !== undefined) {
AtD.callback_f.editSelection(AtD.errorElement);
+ }
- if (AtD.errorElement.parent() != parent) {
+ if (AtD.errorElement.parent() !== parent) {
AtD.counter --;
- if (AtD.counter == 0 && AtD.callback_f != undefined && AtD.callback_f.success != undefined)
+ if (AtD.counter === 0 && AtD.callback_f !== undefined && AtD.callback_f.success !== undefined) {
AtD.callback_f.success(AtD.count);
+ }
}
};
@@ -217,8 +229,9 @@ AtD.ignoreSuggestion = function() {
AtD.core.removeParent(AtD.errorElement);
AtD.counter --;
- if (AtD.counter == 0 && AtD.callback_f != undefined && AtD.callback_f.success != undefined)
+ if (AtD.counter === 0 && AtD.callback_f !== undefined && AtD.callback_f.success !== undefined) {
AtD.callback_f.success(AtD.count);
+ }
};
AtD.ignoreAll = function(container_id) {
@@ -227,35 +240,37 @@ AtD.ignoreAll = function(container_id) {
AtD.counter -= removed;
- if (AtD.counter == 0 && AtD.callback_f != undefined && AtD.callback_f.success != undefined)
+ if (AtD.counter === 0 && AtD.callback_f !== undefined && AtD.callback_f.success !== undefined) {
AtD.callback_f.success(AtD.count);
+ }
- if (AtD.callback_f != undefined && AtD.callback_f.ignore != undefined) {
+ if (AtD.callback_f !== undefined && AtD.callback_f.ignore !== undefined) {
AtD.callback_f.ignore(target);
AtD.core.setIgnoreStrings(target);
}
};
AtD.explainError = function() {
- if (AtD.callback_f != undefined && AtD.callback_f.explain != undefined)
+ if (AtD.callback_f !== undefined && AtD.callback_f.explain !== undefined) {
AtD.callback_f.explain(AtD.explainURL);
+ }
};
AtD.suggest = function(element) {
/* construct the menu if it doesn't already exist */
+ var suggest;
- if (jQuery('#suggestmenu').length == 0) {
- var suggest = jQuery('<div id="suggestmenu"></div>');
+ if (jQuery('#suggestmenu').length === 0) {
+ suggest = jQuery('<div id="suggestmenu"></div>');
suggest.prependTo('body');
- }
- else {
- var suggest = jQuery('#suggestmenu');
+ } else {
+ suggest = jQuery('#suggestmenu');
suggest.hide();
}
/* find the correct suggestions object */
- errorDescription = AtD.core.findSuggestion(element);
+ var errorDescription = AtD.core.findSuggestion(element);
/* build up the menu y0 */
@@ -263,25 +278,23 @@ AtD.suggest = function(element) {
suggest.empty();
- if (errorDescription == undefined) {
+ if (errorDescription === undefined) {
suggest.append('<strong>' + AtD.getLang('menu_title_no_suggestions', 'No suggestions') + '</strong>');
- }
- else if (errorDescription["suggestions"].length == 0) {
+ } else if (errorDescription['suggestions'].length === 0) {
suggest.append('<strong>' + errorDescription['description'] + '</strong>');
- }
- else {
+ } else {
suggest.append('<strong>' + errorDescription['description'] + '</strong>');
- for (var i = 0; i < errorDescription["suggestions"].length; i++) {
+ for (var i = 0; i < errorDescription['suggestions'].length; i++) {
(function(sugg) {
suggest.append('<a href="javascript:AtD.useSuggestion(\'' + sugg.replace(/'/, '\\\'') + '\')">' + sugg + '</a>');
- })(errorDescription["suggestions"][i]);
+ })(errorDescription['suggestions'][i]); // jshint ignore:line
}
}
/* do the explain menu if configured */
- if (AtD.callback_f != undefined && AtD.callback_f.explain != undefined && errorDescription['moreinfo'] != undefined) {
+ if (AtD.callback_f !== undefined && AtD.callback_f.explain !== undefined && errorDescription['moreinfo'] !== undefined) {
suggest.append('<a href="javascript:AtD.explainError()" class="spell_sep_top">' + AtD.getLang('menu_option_explain', 'Explain...') + '</a>');
AtD.explainURL = errorDescription['moreinfo'];
}
@@ -292,19 +305,21 @@ AtD.suggest = function(element) {
/* add the edit in place and ignore always option */
- if (AtD.callback_f != undefined && AtD.callback_f.editSelection != undefined) {
- if (AtD.callback_f != undefined && AtD.callback_f.ignore != undefined)
+ if (AtD.callback_f !== undefined && AtD.callback_f.editSelection !== undefined) {
+ if (AtD.callback_f !== undefined && AtD.callback_f.ignore !== undefined) {
suggest.append('<a href="javascript:AtD.ignoreAll(\'' + AtD.container + '\')">' + AtD.getLang('menu_option_ignore_always', 'Ignore always') + '</a>');
- else
+ } else {
suggest.append('<a href="javascript:AtD.ignoreAll(\'' + AtD.container + '\')">' + AtD.getLang('menu_option_ignore_all', 'Ignore all') + '</a>');
+ }
suggest.append('<a href="javascript:AtD.editSelection(\'' + AtD.container + '\')" class="spell_sep_bottom spell_sep_top">' + AtD.getLang('menu_option_edit_selection', 'Edit Selection...') + '</a>');
}
else {
- if (AtD.callback_f != undefined && AtD.callback_f.ignore != undefined)
+ if (AtD.callback_f !== undefined && AtD.callback_f.ignore !== undefined) {
suggest.append('<a href="javascript:AtD.ignoreAll(\'' + AtD.container + '\')" class="spell_sep_bottom">' + AtD.getLang('menu_option_ignore_always', 'Ignore always') + '</a>');
- else
+ } else {
suggest.append('<a href="javascript:AtD.ignoreAll(\'' + AtD.container + '\')" class="spell_sep_bottom">' + AtD.getLang('menu_option_ignore_all', 'Ignore all') + '</a>');
+ }
}
/* show the menu */
@@ -313,8 +328,9 @@ AtD.suggest = function(element) {
var width = jQuery(element).width();
/* a sanity check for Internet Explorer--my favorite browser in every possible way */
- if (width > 100)
- width = 50;
+ if (width > 100) {
+ width = 50;
+ }
jQuery(suggest).css({ left: (pos.left + width) + 'px', top: pos.top + 'px' });
@@ -325,9 +341,10 @@ AtD.suggest = function(element) {
AtD.suggestShow = true;
setTimeout(function() {
- jQuery("body").bind("click", function() {
- if (!AtD.suggestShow)
+ jQuery('body').bind('click', function() {
+ if (!AtD.suggestShow) {
jQuery('#suggestmenu').fadeOut(200);
+ }
});
}, 1);
@@ -361,22 +378,23 @@ AtD.initCoreModule = function() {
};
core.findSpans = function(parent) {
- return jQuery.makeArray(parent.find('span'));
+ return jQuery.makeArray(parent.find('span'));
};
- core.create = function(string, isTextNode) {
+ core.create = function(string/*, isTextNode*/) {
// replace out all tags with &-equivalents so that we preserve tag text.
string = string.replace(/\&/g, '&amp;');
- string = string.replace(/\</g, '&lt;').replace(/\>/g, '&gt;');
+ string = string.replace(/</g, '&lt;').replace(/\>/g, '&gt;');
// find all instances of AtD-created spans
var matches = string.match(/\&lt;span class="hidden\w+?" pre="[^"]*"\&gt;.*?\&lt;\/span\&gt;/g);
+ var x;
// ... and fix the tags in those substrings.
if (matches) {
- for (var x = 0; x < matches.length; x++) {
+ for (x = 0; x < matches.length; x++) {
string = string.replace(matches[x], matches[x].replace(/\&lt;/gi, '<').replace(/\&gt;/gi, '>'));
- };
+ }
}
if (core.isIE()) {
@@ -384,13 +402,13 @@ AtD.initCoreModule = function() {
matches = string.match(/\&lt;span class="mceItemHidden"\&gt;\&amp;nbsp;\&lt;\/span&gt;/g, string);
//|&lt;BR.*?class.*?atd_remove_me.*?\&gt;/gi, string);
if (matches) {
- for (var x = 0; x < matches.length; x++) {
+ for (x = 0; x < matches.length; x++) {
string = string.replace(matches[x], matches[x].replace(/\&lt;/gi, '<').replace(/\&gt;/gi, '>').replace(/\&amp;/gi, '&'));
- };
+ }
}
}
- node = jQuery('<span class="mceItemHidden"></span>');
+ var node = jQuery('<span class="mceItemHidden"></span>');
node.html(string);
return node;
};
@@ -401,10 +419,11 @@ AtD.initCoreModule = function() {
core.removeParent = function(node) {
/* unwrap exists in jQuery 1.4+ only. Thankfully because replaceWith as-used here won't work in 1.4 */
- if (jQuery(node).unwrap)
+ if (jQuery(node).unwrap) {
return jQuery(node).contents().unwrap();
- else
+ } else {
return jQuery(node).replaceWith(jQuery(node).html());
+ }
};
core.getAttrib = function(node, name) {