+ function unescapeSingleQuote( str )\r
+ {\r
+ return str.replace( /\\'/g, '\'' );\r
+ }\r
+\r
+ function escapeSingleQuote( str )\r
+ {\r
+ return str.replace( /'/g, '\\$&' );\r
+ }\r
+\r
+ var emailProtection = editor.config.emailProtection || '';\r
+\r
+ // Compile the protection function pattern.\r
+ if ( emailProtection && emailProtection != 'encode' )\r
+ {\r
+ var compiledProtectionFunction = {};\r
+\r
+ emailProtection.replace( /^([^(]+)\(([^)]+)\)$/, function( match, funcName, params )\r
+ {\r
+ compiledProtectionFunction.name = funcName;\r
+ compiledProtectionFunction.params = [];\r
+ params.replace( /[^,\s]+/g, function( param )\r
+ {\r
+ compiledProtectionFunction.params.push( param );\r
+ } );\r
+ } );\r
+ }\r
+\r
+ function protectEmailLinkAsFunction( email )\r
+ {\r
+ var retval,\r
+ name = compiledProtectionFunction.name,\r
+ params = compiledProtectionFunction.params,\r
+ paramName,\r
+ paramValue;\r
+\r
+ retval = [ name, '(' ];\r
+ for ( var i = 0; i < params.length; i++ )\r
+ {\r
+ paramName = params[ i ].toLowerCase();\r
+ paramValue = email[ paramName ];\r
+\r
+ i > 0 && retval.push( ',' );\r
+ retval.push( '\'',\r
+ paramValue ?\r
+ escapeSingleQuote( encodeURIComponent( email[ paramName ] ) )\r
+ : '',\r
+ '\'');\r
+ }\r
+ retval.push( ')' );\r
+ return retval.join( '' );\r
+ }\r
+\r
+ function protectEmailAddressAsEncodedString( address )\r
+ {\r
+ var charCode,\r
+ length = address.length,\r
+ encodedChars = [];\r
+ for ( var i = 0; i < length; i++ )\r
+ {\r
+ charCode = address.charCodeAt( i );\r
+ encodedChars.push( charCode );\r
+ }\r
+ return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';\r
+ }\r
+\r