144 | | } |
| 172 | |
| 173 | dataFilter.addRules( |
| 174 | { |
| 175 | elements : |
| 176 | { |
| 177 | a : function( element ) |
| 178 | { |
| 179 | var mailProtection = editor.config.mailProtection, |
| 180 | encodeProtection = mailProtection == 'encode', |
| 181 | protectFunction = !encodeProtection, |
| 182 | href = element.attributes.href, |
| 183 | unProtectedHref; |
| 184 | |
| 185 | if( protectFunction ) |
| 186 | { |
| 187 | href.replace( /^javascript:([^(]+)\(([^)]+)\)$/, function( match, funcName, args ) |
| 188 | { |
| 189 | if( funcName == functionInfo.name ) |
| 190 | { |
| 191 | var mailInSequence = [], |
| 192 | priority = { name : -2, domain: -1 }, |
| 193 | index = 0, |
| 194 | paramName; |
| 195 | unProtectedHref = [ 'mailto:' ]; |
| 196 | args.replace( /[^,]+/g, function( param ) |
| 197 | { |
| 198 | param = param.replace( /(^')|('$)/g, '' ).replace( /\\'/g, '\'' ); |
| 199 | paramName = functionInfo.params[ index ]; |
| 200 | paramName = paramName && paramName.toLowerCase(); |
| 201 | paramName && mailInSequence.push( [ paramName, param ] ); |
| 202 | index++; |
| 203 | } ); |
| 204 | |
| 205 | mailInSequence.sort( function( a, b ) |
| 206 | { |
| 207 | return ( priority[ a [ 0 ] ] || a [ 0 ].charCodeAt( 0 ) ) |
| 208 | > ( priority[ b [ 0 ] ] || b [ 0 ].charCodeAt( 0 ) ); |
| 209 | } ); |
| 210 | |
| 211 | for ( var i = 0; i < mailInSequence.length; i++ ) |
| 212 | { |
| 213 | if( i < 2 ) |
| 214 | { |
| 215 | if( i == 1 ) |
| 216 | unProtectedHref.push( '@' ); |
| 217 | unProtectedHref.push( mailInSequence[ i ][ 1 ] ); |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | if( i == 2 ) |
| 222 | unProtectedHref.push( '?' ); |
| 223 | else |
| 224 | unProtectedHref.push( '&' ); |
| 225 | unProtectedHref.push( mailInSequence[ i ][ 0 ], '=', mailInSequence[ i ][ 1 ] ); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | unProtectedHref = unProtectedHref.join( '' ); |
| 230 | } |
| 231 | } ); |
| 232 | } |
| 233 | else if( encodeProtection ) |
| 234 | { |
| 235 | href.replace( /^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)\+'(.*)'\)$/, |
| 236 | function ( match, mailAddressCharCodes, rest ) |
| 237 | { |
| 238 | unProtectedHref = 'mailto:' |
| 239 | + String.fromCharCode.apply( String, mailAddressCharCodes.split( ',' ) ) |
| 240 | + rest; |
| 241 | } ); |
| 242 | } |
| 243 | |
| 244 | unProtectedHref && |
| 245 | ( element.attributes[ '_cke_saved_href' ] = element.attributes.href = unProtectedHref ); |
| 246 | } |
| 247 | } |
| 248 | } ); |
| 249 | |
| 250 | htmlFilter.addRules( |
| 251 | { |
| 252 | elements : |
| 253 | { |
| 254 | a : function( element ) |
| 255 | { |
| 256 | var mailProtection = editor.config.mailProtection, |
| 257 | encodeProtection = mailProtection == 'encode', |
| 258 | protectFunction = !encodeProtection && editor.config.mailProtection, |
| 259 | emailInfo = {}, |
| 260 | emailSequence = [], |
| 261 | href = element.attributes[ '_cke_saved_href' ], |
| 262 | protectedHref; |
| 263 | |
| 264 | href.replace( /&/, '&') |
| 265 | .replace( /^mailto:([^?]+)@([^?]+)(.*)$/, |
| 266 | function ( match, name, domain, rest ) |
| 267 | { |
| 268 | if ( protectFunction ) |
| 269 | { |
| 270 | emailInfo[ 'name' ] = name; |
| 271 | emailInfo[ 'domain' ] = domain; |
| 272 | } |
| 273 | else |
| 274 | emailSequence.push( name, domain ); |
| 275 | |
| 276 | rest.replace( /([^?&]+)=([^?&]+)/g, |
| 277 | function ( match, name, value ) |
| 278 | { |
| 279 | if( protectFunction ) |
| 280 | emailInfo[ name ] = value; |
| 281 | else |
| 282 | emailSequence.push( match ); |
| 283 | } ); |
| 284 | } ); |
| 285 | |
| 286 | if( protectFunction && !CKEDITOR.tools.isEmpty( emailInfo ) ) |
| 287 | { |
| 288 | var name = functionInfo.name, |
| 289 | params = functionInfo.params, |
| 290 | paramName; |
| 291 | |
| 292 | protectedHref = [ 'javascript:', name, '(' ]; |
| 293 | |
| 294 | for ( var i = 0; i < params.length; i++ ) |
| 295 | { |
| 296 | paramName = params[ i ].toLowerCase(); |
| 297 | |
| 298 | if ( emailInfo[ paramName ] ) |
| 299 | { |
| 300 | i > 0 && protectedHref.push( ',' ); |
| 301 | protectedHref.push('\'', emailInfo[ paramName ].replace( /'/g, '\\$&' ), '\''); |
| 302 | } |
| 303 | } |
| 304 | protectedHref.push( ')' ); |
| 305 | } |
| 306 | else if( encodeProtection && emailSequence.length ) |
| 307 | { |
| 308 | protectedHref = ['javascript:void(location.href=\'mailto:\'+']; |
| 309 | for ( i = 0; i < emailSequence.length; i++ ) |
| 310 | { |
| 311 | if( i == 1 ) |
| 312 | { |
| 313 | protectedHref.push( 'String.fromCharCode(', |
| 314 | stringCodes( emailSequence[ 0 ] + '@' + emailSequence[ 1 ] ).join( ',' ), |
| 315 | ')' ); |
| 316 | } |
| 317 | else if( i > 1 ) |
| 318 | protectedHref.push( i == 2 ? '+\'?' : '&', emailSequence[ i ] ); |
| 319 | } |
| 320 | |
| 321 | protectedHref.push( '\')' ); |
| 322 | } |
| 323 | |
| 324 | protectedHref && ( element.attributes[ '_cke_saved_href' ] = protectedHref.join( '' ) ); |
| 325 | } |
| 326 | } |
| 327 | } ); |
| 328 | } |