Skip to content

Instantly share code, notes, and snippets.

@MorningZ
Last active March 22, 2019 18:04
Show Gist options
  • Save MorningZ/9ebc3cc67c96b832ed077716c43a8c6d to your computer and use it in GitHub Desktop.
Save MorningZ/9ebc3cc67c96b832ed077716c43a8c6d to your computer and use it in GitHub Desktop.
Clean Word Paste
// Code
var CleanWord = {
"_swapCodes": new Array(8211, 8212, 8216, 8217, 8220, 8221, 8226, 8230),
"_swapStrings": new Array("--", "--", "'", "'", "\"", "\"", "*", "..."),
"Control": function (input) {
$(input).val(CleanWord.Text($(input).val(), false));
},
"Text": function (txt, log) {
var output = txt;
for (i = 0; i < CleanWord._swapCodes.length; i++) {
var swapper = new RegExp("\\u" + CleanWord._swapCodes[i].toString(16), "g"); // hex codes
output = output.replace(swapper, CleanWord._swapStrings[i]);
}
return output;
}
};
// Usage (jQuery 1.10 and above)
$(document).on("paste", "<jQuery selector>", function () { CleanWord.Control(this); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment