| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | InternetExplorer._pluginInfo = { |
|---|
| 35 | name : "Internet Explorer", |
|---|
| 36 | origin : "Xinha Core", |
|---|
| 37 | version : "$LastChangedRevision$".replace(/^[^:]*:\s*(.*)\s*\$$/, '$1'), |
|---|
| 38 | developer : "The Xinha Core Developer Team", |
|---|
| 39 | developer_url : "$HeadURL$".replace(/^[^:]*:\s*(.*)\s*\$$/, '$1'), |
|---|
| 40 | sponsor : "", |
|---|
| 41 | sponsor_url : "", |
|---|
| 42 | license : "htmlArea" |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | function InternetExplorer(editor) { |
|---|
| 46 | this.editor = editor; |
|---|
| 47 | editor.InternetExplorer = this; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | InternetExplorer.prototype.onKeyPress = function(ev) |
|---|
| 54 | { |
|---|
| 55 | |
|---|
| 56 | if(this.editor.isShortCut(ev)) |
|---|
| 57 | { |
|---|
| 58 | switch(this.editor.getKey(ev).toLowerCase()) |
|---|
| 59 | { |
|---|
| 60 | case 'n': |
|---|
| 61 | { |
|---|
| 62 | this.editor.execCommand('formatblock', false, '<p>'); |
|---|
| 63 | Xinha._stopEvent(ev); |
|---|
| 64 | return true; |
|---|
| 65 | } |
|---|
| 66 | break; |
|---|
| 67 | |
|---|
| 68 | case '1': |
|---|
| 69 | case '2': |
|---|
| 70 | case '3': |
|---|
| 71 | case '4': |
|---|
| 72 | case '5': |
|---|
| 73 | case '6': |
|---|
| 74 | { |
|---|
| 75 | this.editor.execCommand('formatblock', false, '<h'+this.editor.getKey(ev).toLowerCase()+'>'); |
|---|
| 76 | Xinha._stopEvent(ev); |
|---|
| 77 | return true; |
|---|
| 78 | } |
|---|
| 79 | break; |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | switch(ev.keyCode) |
|---|
| 84 | { |
|---|
| 85 | case 8: |
|---|
| 86 | case 46: |
|---|
| 87 | { |
|---|
| 88 | if(this.handleBackspace()) |
|---|
| 89 | { |
|---|
| 90 | Xinha._stopEvent(ev); |
|---|
| 91 | return true; |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | break; |
|---|
| 95 | |
|---|
| 96 | case 9: |
|---|
| 97 | { |
|---|
| 98 | Xinha._stopEvent(ev); |
|---|
| 99 | return true; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | return false; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | InternetExplorer.prototype.handleBackspace = function() |
|---|
| 117 | { |
|---|
| 118 | var editor = this.editor; |
|---|
| 119 | var sel = editor.getSelection(); |
|---|
| 120 | if ( sel.type == 'Control' ) |
|---|
| 121 | { |
|---|
| 122 | var elm = editor.activeElement(sel); |
|---|
| 123 | Xinha.removeFromParent(elm); |
|---|
| 124 | return true; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | var range = editor.createRange(sel); |
|---|
| 133 | var r2 = range.duplicate(); |
|---|
| 134 | r2.moveStart("character", -1); |
|---|
| 135 | var a = r2.parentElement(); |
|---|
| 136 | |
|---|
| 137 | if ( a != range.parentElement() && ( /^a$/i.test(a.tagName) ) ) |
|---|
| 138 | { |
|---|
| 139 | r2.collapse(true); |
|---|
| 140 | r2.moveEnd("character", 1); |
|---|
| 141 | r2.pasteHTML(''); |
|---|
| 142 | r2.select(); |
|---|
| 143 | return true; |
|---|
| 144 | } |
|---|
| 145 | }; |
|---|
| 146 | |
|---|
| 147 | InternetExplorer.prototype.inwardHtml = function(html) |
|---|
| 148 | { |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | html = html.replace(/<(\/?)del(\s|>|\/)/ig, "<$1strike$2"); |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | html = html.replace(/(<script|<!--)/i," $1"); |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | html = html.replace(/<span[^>]+id="__InsertSpan_Workaround_[a-z]+".*?>([\s\S]*?)<\/span>/i,"$1"); |
|---|
| 160 | |
|---|
| 161 | return html; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | InternetExplorer.prototype.outwardHtml = function(html) |
|---|
| 165 | { |
|---|
| 166 | |
|---|
| 167 | html = html.replace(/ (\s*)(<script|<!--)/i,"$1$2"); |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | html = html.replace(/<span[^>]+id="__InsertSpan_Workaround_[a-z]+".*?>([\s\S]*?)<\/span>/i,"$1"); |
|---|
| 173 | |
|---|
| 174 | return html; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | InternetExplorer.prototype.onExecCommand = function(cmdID, UI, param) |
|---|
| 178 | { |
|---|
| 179 | switch(cmdID) |
|---|
| 180 | { |
|---|
| 181 | |
|---|
| 182 | case 'saveas': |
|---|
| 183 | var doc = null; |
|---|
| 184 | var editor = this.editor; |
|---|
| 185 | var iframe = document.createElement("iframe"); |
|---|
| 186 | iframe.src = "about:blank"; |
|---|
| 187 | iframe.style.display = 'none'; |
|---|
| 188 | document.body.appendChild(iframe); |
|---|
| 189 | try |
|---|
| 190 | { |
|---|
| 191 | if ( iframe.contentDocument ) |
|---|
| 192 | { |
|---|
| 193 | doc = iframe.contentDocument; |
|---|
| 194 | } |
|---|
| 195 | else |
|---|
| 196 | { |
|---|
| 197 | doc = iframe.contentWindow.document; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | catch(ex) |
|---|
| 201 | { |
|---|
| 202 | |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | doc.open("text/html","replace"); |
|---|
| 206 | var html = ''; |
|---|
| 207 | if ( editor.config.browserQuirksMode === false ) |
|---|
| 208 | { |
|---|
| 209 | var doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'; |
|---|
| 210 | } |
|---|
| 211 | else if ( editor.config.browserQuirksMode === true ) |
|---|
| 212 | { |
|---|
| 213 | var doctype = ''; |
|---|
| 214 | } |
|---|
| 215 | else |
|---|
| 216 | { |
|---|
| 217 | var doctype = Xinha.getDoctype(document); |
|---|
| 218 | } |
|---|
| 219 | if ( !editor.config.fullPage ) |
|---|
| 220 | { |
|---|
| 221 | html += doctype + "\n"; |
|---|
| 222 | html += "<html>\n"; |
|---|
| 223 | html += "<head>\n"; |
|---|
| 224 | html += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + editor.config.charSet + "\">\n"; |
|---|
| 225 | if ( typeof editor.config.baseHref != 'undefined' && editor.config.baseHref !== null ) |
|---|
| 226 | { |
|---|
| 227 | html += "<base href=\"" + editor.config.baseHref + "\"/>\n"; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | if ( typeof editor.config.pageStyleSheets !== 'undefined' ) |
|---|
| 231 | { |
|---|
| 232 | for ( var i = 0; i < editor.config.pageStyleSheets.length; i++ ) |
|---|
| 233 | { |
|---|
| 234 | if ( editor.config.pageStyleSheets[i].length > 0 ) |
|---|
| 235 | { |
|---|
| 236 | html += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + editor.config.pageStyleSheets[i] + "\">"; |
|---|
| 237 | |
|---|
| 238 | } |
|---|
| 239 | } |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | if ( editor.config.pageStyle ) |
|---|
| 243 | { |
|---|
| 244 | html += "<style type=\"text/css\">\n" + editor.config.pageStyle + "\n</style>"; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | html += "</head>\n"; |
|---|
| 248 | html += "<body>\n"; |
|---|
| 249 | html += editor.getEditorContent(); |
|---|
| 250 | html += "</body>\n"; |
|---|
| 251 | html += "</html>"; |
|---|
| 252 | } |
|---|
| 253 | else |
|---|
| 254 | { |
|---|
| 255 | html = editor.getEditorContent(); |
|---|
| 256 | if ( html.match(Xinha.RE_doctype) ) |
|---|
| 257 | { |
|---|
| 258 | editor.setDoctype(RegExp.$1); |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | doc.write(html); |
|---|
| 262 | doc.close(); |
|---|
| 263 | doc.execCommand(cmdID, UI, param); |
|---|
| 264 | document.body.removeChild(iframe); |
|---|
| 265 | return true; |
|---|
| 266 | break; |
|---|
| 267 | case 'removeformat': |
|---|
| 268 | var editor = this.editor; |
|---|
| 269 | var sel = editor.getSelection(); |
|---|
| 270 | var selSave = editor.saveSelection(sel); |
|---|
| 271 | |
|---|
| 272 | var i, el, els; |
|---|
| 273 | |
|---|
| 274 | function clean (el) |
|---|
| 275 | { |
|---|
| 276 | if (el.nodeType != 1) return; |
|---|
| 277 | el.removeAttribute('style'); |
|---|
| 278 | for (var j=0; j<el.childNodes.length;j++) |
|---|
| 279 | { |
|---|
| 280 | clean(el.childNodes[j]); |
|---|
| 281 | } |
|---|
| 282 | if ( (el.tagName.toLowerCase() == 'span' && !el.attributes.length ) || el.tagName.toLowerCase() == 'font') |
|---|
| 283 | { |
|---|
| 284 | el.outerHTML = el.innerHTML; |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | if ( editor.selectionEmpty(sel) ) |
|---|
| 288 | { |
|---|
| 289 | els = editor._doc.body.childNodes; |
|---|
| 290 | for (i = 0; i < els.length; i++) |
|---|
| 291 | { |
|---|
| 292 | el = els[i]; |
|---|
| 293 | if (el.nodeType != 1) continue; |
|---|
| 294 | if (el.tagName.toLowerCase() == 'span') |
|---|
| 295 | { |
|---|
| 296 | newNode = editor.convertNode(el, 'div'); |
|---|
| 297 | el.parentNode.replaceChild(newNode, el); |
|---|
| 298 | el = newNode; |
|---|
| 299 | } |
|---|
| 300 | clean(el); |
|---|
| 301 | } |
|---|
| 302 | } |
|---|
| 303 | editor._doc.execCommand(cmdID, UI, param); |
|---|
| 304 | |
|---|
| 305 | editor.restoreSelection(selSave); |
|---|
| 306 | return true; |
|---|
| 307 | break; |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | return false; |
|---|
| 311 | }; |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | Xinha.prototype.insertNodeAtSelection = function(toBeInserted) |
|---|
| 321 | { |
|---|
| 322 | this.insertHTML(toBeInserted.outerHTML); |
|---|
| 323 | }; |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | Xinha.prototype.getParentElement = function(sel) |
|---|
| 332 | { |
|---|
| 333 | if ( typeof sel == 'undefined' ) |
|---|
| 334 | { |
|---|
| 335 | sel = this.getSelection(); |
|---|
| 336 | } |
|---|
| 337 | var range = this.createRange(sel); |
|---|
| 338 | switch ( sel.type ) |
|---|
| 339 | { |
|---|
| 340 | case "Text": |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | var parent = range.parentElement(); |
|---|
| 344 | while ( true ) |
|---|
| 345 | { |
|---|
| 346 | var TestRange = range.duplicate(); |
|---|
| 347 | TestRange.moveToElementText(parent); |
|---|
| 348 | if ( TestRange.inRange(range) ) |
|---|
| 349 | { |
|---|
| 350 | break; |
|---|
| 351 | } |
|---|
| 352 | if ( ( parent.nodeType != 1 ) || ( parent.tagName.toLowerCase() == 'body' ) ) |
|---|
| 353 | { |
|---|
| 354 | break; |
|---|
| 355 | } |
|---|
| 356 | parent = parent.parentElement; |
|---|
| 357 | } |
|---|
| 358 | return parent; |
|---|
| 359 | case "None": |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | try |
|---|
| 366 | { |
|---|
| 367 | return range.parentElement(); |
|---|
| 368 | } |
|---|
| 369 | catch(e) |
|---|
| 370 | { |
|---|
| 371 | return this._doc.body; |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | case "Control": |
|---|
| 375 | return range.item(0); |
|---|
| 376 | default: |
|---|
| 377 | return this._doc.body; |
|---|
| 378 | } |
|---|
| 379 | }; |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | Xinha.prototype.activeElement = function(sel) |
|---|
| 390 | { |
|---|
| 391 | if ( ( sel === null ) || this.selectionEmpty(sel) ) |
|---|
| 392 | { |
|---|
| 393 | return null; |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | if ( sel.type.toLowerCase() == "control" ) |
|---|
| 397 | { |
|---|
| 398 | return sel.createRange().item(0); |
|---|
| 399 | } |
|---|
| 400 | else |
|---|
| 401 | { |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | var range = sel.createRange(); |
|---|
| 406 | var p_elm = this.getParentElement(sel); |
|---|
| 407 | if ( p_elm.innerHTML == range.htmlText ) |
|---|
| 408 | { |
|---|
| 409 | return p_elm; |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | return null; |
|---|
| 433 | } |
|---|
| 434 | }; |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | Xinha.prototype.selectionEmpty = function(sel) |
|---|
| 443 | { |
|---|
| 444 | if ( !sel ) |
|---|
| 445 | { |
|---|
| 446 | return true; |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | return this.createRange(sel).htmlText === ''; |
|---|
| 450 | }; |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | Xinha.prototype.saveSelection = function(sel) |
|---|
| 459 | { |
|---|
| 460 | return this.createRange(sel ? sel : this.getSelection()) |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | |
|---|
| 465 | |
|---|
| 466 | Xinha.prototype.restoreSelection = function(savedSelection) |
|---|
| 467 | { |
|---|
| 468 | if (!savedSelection) return; |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | |
|---|
| 472 | |
|---|
| 473 | |
|---|
| 474 | |
|---|
| 475 | |
|---|
| 476 | |
|---|
| 477 | |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | var savedParentElement = null; |
|---|
| 483 | if (savedSelection.parentElement) |
|---|
| 484 | { |
|---|
| 485 | savedParentElement = savedSelection.parentElement(); |
|---|
| 486 | } |
|---|
| 487 | else |
|---|
| 488 | { |
|---|
| 489 | savedParentElement = savedSelection.item(0); |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | var range = this.createRange(this.getSelection()); |
|---|
| 496 | |
|---|
| 497 | var rangeParentElement = null; |
|---|
| 498 | if (range.parentElement) |
|---|
| 499 | { |
|---|
| 500 | rangeParentElement = range.parentElement(); |
|---|
| 501 | } |
|---|
| 502 | else |
|---|
| 503 | { |
|---|
| 504 | rangeParentElement = range.item(0); |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | var findDoc = function(el) |
|---|
| 510 | { |
|---|
| 511 | for (var root=el; root; root=root.parentNode) |
|---|
| 512 | { |
|---|
| 513 | if (root.tagName.toLowerCase() == 'html') |
|---|
| 514 | { |
|---|
| 515 | return root.parentNode; |
|---|
| 516 | } |
|---|
| 517 | } |
|---|
| 518 | return null; |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | if (savedSelection.parentElement && findDoc(savedParentElement) == findDoc(rangeParentElement)) |
|---|
| 522 | { |
|---|
| 523 | if (range.isEqual(savedSelection)) |
|---|
| 524 | { |
|---|
| 525 | |
|---|
| 526 | return; |
|---|
| 527 | } |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | try { savedSelection.select() } catch (e) {}; |
|---|
| 531 | range = this.createRange(this.getSelection()); |
|---|
| 532 | |
|---|
| 533 | if (range.parentElement) |
|---|
| 534 | { |
|---|
| 535 | rangeParentElement = range.parentElement(); |
|---|
| 536 | } |
|---|
| 537 | else |
|---|
| 538 | { |
|---|
| 539 | rangeParentElement = range.item(0); |
|---|
| 540 | } |
|---|
| 541 | |
|---|
| 542 | if (rangeParentElement != savedParentElement) |
|---|
| 543 | { |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | var solution = this.config.selectWorkaround || 'VisibleCue'; |
|---|
| 551 | switch (solution) |
|---|
| 552 | { |
|---|
| 553 | case 'SimulateClick': |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | case 'InsertSpan': |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | var parentDoc = findDoc(savedParentElement); |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | var randLetters = function(count) |
|---|
| 566 | { |
|---|
| 567 | |
|---|
| 568 | var Letters = ''; |
|---|
| 569 | for (var index = 0; index<26; ++index) |
|---|
| 570 | { |
|---|
| 571 | Letters += String.fromCharCode('a'.charCodeAt(0) + index); |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | var result = ''; |
|---|
| 575 | for (var index=0; index<count; ++index) |
|---|
| 576 | { |
|---|
| 577 | result += Letters.substr(Math.floor(Math.random()*Letters.length + 1), 1); |
|---|
| 578 | } |
|---|
| 579 | return result; |
|---|
| 580 | } |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | var keyLength = 1; |
|---|
| 584 | var tempId = '__InsertSpan_Workaround_' + randLetters(keyLength); |
|---|
| 585 | while (parentDoc.getElementById(tempId)) |
|---|
| 586 | { |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | keyLength += 1; |
|---|
| 590 | tempId = '__InsertSpan_Workaround_' + randLetters(keyLength); |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | savedSelection.pasteHTML('<span id="' + tempId + '"></span>'); |
|---|
| 596 | var tempSpan = parentDoc.getElementById(tempId); |
|---|
| 597 | savedSelection.moveToElementText(tempSpan); |
|---|
| 598 | savedSelection.select(); |
|---|
| 599 | break; |
|---|
| 600 | case 'JustificationHack': |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | var magicString = String.fromCharCode(1); |
|---|
| 608 | savedSelection.pasteHTML(magicString); |
|---|
| 609 | savedSelection.findText(magicString,-1); |
|---|
| 610 | savedSelection.select(); |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | savedSelection.execCommand('JustifyNone'); |
|---|
| 616 | savedSelection.pasteHTML(''); |
|---|
| 617 | break; |
|---|
| 618 | case 'VisibleCue': |
|---|
| 619 | default: |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | var magicString = String.fromCharCode(1); |
|---|
| 624 | savedSelection.pasteHTML(magicString); |
|---|
| 625 | savedSelection.findText(magicString,-1); |
|---|
| 626 | savedSelection.select(); |
|---|
| 627 | } |
|---|
| 628 | } |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | Xinha.prototype.selectNodeContents = function(node, collapseToStart) |
|---|
| 640 | { |
|---|
| 641 | this.focusEditor(); |
|---|
| 642 | this.forceRedraw(); |
|---|
| 643 | var range; |
|---|
| 644 | var collapsed = typeof collapseToStart == "undefined" ? true : false; |
|---|
| 645 | |
|---|
| 646 | if ( collapsed && node.tagName && node.tagName.toLowerCase().match(/table|img|input|select|textarea/) ) |
|---|
| 647 | { |
|---|
| 648 | range = this._doc.body.createControlRange(); |
|---|
| 649 | range.add(node); |
|---|
| 650 | } |
|---|
| 651 | else |
|---|
| 652 | { |
|---|
| 653 | range = this._doc.body.createTextRange(); |
|---|
| 654 | if (3 == node.nodeType) |
|---|
| 655 | { |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | if (node.parentNode) |
|---|
| 663 | { |
|---|
| 664 | range.moveToElementText(node.parentNode); |
|---|
| 665 | } else |
|---|
| 666 | { |
|---|
| 667 | range.moveToElementText(this._doc.body); |
|---|
| 668 | } |
|---|
| 669 | var trimmingRange = this._doc.body.createTextRange(); |
|---|
| 670 | |
|---|
| 671 | |
|---|
| 672 | |
|---|
| 673 | |
|---|
| 674 | |
|---|
| 675 | var texthackOffset = 0; |
|---|
| 676 | var borderElement=node.previousSibling; |
|---|
| 677 | for (; borderElement && (1 != borderElement.nodeType); borderElement = borderElement.previousSibling) |
|---|
| 678 | { |
|---|
| 679 | if (3 == borderElement.nodeType) |
|---|
| 680 | { |
|---|
| 681 | |
|---|
| 682 | texthackOffset += borderElement.nodeValue.length-borderElement.nodeValue.split('\r').length-1; |
|---|
| 683 | } |
|---|
| 684 | } |
|---|
| 685 | if (borderElement && (1 == borderElement.nodeType)) |
|---|
| 686 | { |
|---|
| 687 | trimmingRange.moveToElementText(borderElement); |
|---|
| 688 | range.setEndPoint('StartToEnd', trimmingRange); |
|---|
| 689 | } |
|---|
| 690 | if (texthackOffset) |
|---|
| 691 | { |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | range.moveStart('character',texthackOffset); |
|---|
| 696 | } |
|---|
| 697 | |
|---|
| 698 | |
|---|
| 699 | texthackOffset = 0; |
|---|
| 700 | borderElement=node.nextSibling; |
|---|
| 701 | for (; borderElement && (1 != borderElement.nodeType); borderElement = borderElement.nextSibling) |
|---|
| 702 | { |
|---|
| 703 | if (3 == borderElement.nodeType) |
|---|
| 704 | { |
|---|
| 705 | |
|---|
| 706 | texthackOffset += borderElement.nodeValue.length-borderElement.nodeValue.split('\r').length-1; |
|---|
| 707 | if (!borderElement.nextSibling) |
|---|
| 708 | { |
|---|
| 709 | |
|---|
| 710 | |
|---|
| 711 | |
|---|
| 712 | texthackOffset += 1; |
|---|
| 713 | } |
|---|
| 714 | } |
|---|
| 715 | } |
|---|
| 716 | if (borderElement && (1 == borderElement.nodeType)) |
|---|
| 717 | { |
|---|
| 718 | trimmingRange.moveToElementText(borderElement); |
|---|
| 719 | range.setEndPoint('EndToStart', trimmingRange); |
|---|
| 720 | } |
|---|
| 721 | if (texthackOffset) |
|---|
| 722 | { |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | |
|---|
| 726 | range.moveEnd('character',-texthackOffset); |
|---|
| 727 | } |
|---|
| 728 | if (!node.nextSibling) |
|---|
| 729 | { |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | range.moveEnd('character',-1); |
|---|
| 734 | } |
|---|
| 735 | } |
|---|
| 736 | else |
|---|
| 737 | { |
|---|
| 738 | range.moveToElementText(node); |
|---|
| 739 | } |
|---|
| 740 | } |
|---|
| 741 | if (typeof collapseToStart != "undefined") |
|---|
| 742 | { |
|---|
| 743 | range.collapse(collapseToStart); |
|---|
| 744 | if (!collapseToStart) |
|---|
| 745 | { |
|---|
| 746 | range.moveStart('character',-1); |
|---|
| 747 | range.moveEnd('character',-1); |
|---|
| 748 | } |
|---|
| 749 | } |
|---|
| 750 | range.select(); |
|---|
| 751 | }; |
|---|
| 752 | |
|---|
| 753 | |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | |
|---|
| 757 | |
|---|
| 758 | Xinha.prototype.insertHTML = function(html) |
|---|
| 759 | { |
|---|
| 760 | this.focusEditor(); |
|---|
| 761 | var sel = this.getSelection(); |
|---|
| 762 | var range = this.createRange(sel); |
|---|
| 763 | range.pasteHTML(html); |
|---|
| 764 | }; |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | |
|---|
| 771 | |
|---|
| 772 | Xinha.prototype.getSelectedHTML = function() |
|---|
| 773 | { |
|---|
| 774 | var sel = this.getSelection(); |
|---|
| 775 | if (this.selectionEmpty(sel)) return ''; |
|---|
| 776 | var range = this.createRange(sel); |
|---|
| 777 | |
|---|
| 778 | |
|---|
| 779 | if( range.htmlText ) |
|---|
| 780 | { |
|---|
| 781 | return range.htmlText; |
|---|
| 782 | } |
|---|
| 783 | else if(range.length >= 1) |
|---|
| 784 | { |
|---|
| 785 | return range.item(0).outerHTML; |
|---|
| 786 | } |
|---|
| 787 | |
|---|
| 788 | return ''; |
|---|
| 789 | }; |
|---|
| 790 | |
|---|
| 791 | |
|---|
| 792 | |
|---|
| 793 | |
|---|
| 794 | |
|---|
| 795 | |
|---|
| 796 | Xinha.prototype.getSelection = function() |
|---|
| 797 | { |
|---|
| 798 | return this._doc.selection; |
|---|
| 799 | }; |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | Xinha.prototype.createRange = function(sel) |
|---|
| 808 | { |
|---|
| 809 | if (!sel) sel = this.getSelection(); |
|---|
| 810 | |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | return sel.createRange(); |
|---|
| 825 | }; |
|---|
| 826 | |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | |
|---|
| 832 | |
|---|
| 833 | Xinha.prototype.isKeyEvent = function(event) |
|---|
| 834 | { |
|---|
| 835 | return event.type == "keydown"; |
|---|
| 836 | } |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | |
|---|
| 842 | |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | Xinha.prototype.getKey = function(keyEvent) |
|---|
| 846 | { |
|---|
| 847 | return String.fromCharCode(keyEvent.keyCode); |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | |
|---|
| 857 | Xinha.getOuterHTML = function(element) |
|---|
| 858 | { |
|---|
| 859 | return element.outerHTML; |
|---|
| 860 | }; |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | Xinha.cc = String.fromCharCode(0x2009); |
|---|
| 864 | |
|---|
| 865 | Xinha.prototype.setCC = function ( target ) |
|---|
| 866 | { |
|---|
| 867 | var cc = Xinha.cc; |
|---|
| 868 | if ( target == "textarea" ) |
|---|
| 869 | { |
|---|
| 870 | var ta = this._textArea; |
|---|
| 871 | var pos = document.selection.createRange(); |
|---|
| 872 | pos.collapse(); |
|---|
| 873 | pos.text = cc; |
|---|
| 874 | var index = ta.value.indexOf( cc ); |
|---|
| 875 | var before = ta.value.substring( 0, index ); |
|---|
| 876 | var after = ta.value.substring( index + cc.length , ta.value.length ); |
|---|
| 877 | |
|---|
| 878 | if ( after.match(/^[^<]*>/) ) |
|---|
| 879 | { |
|---|
| 880 | var tagEnd = after.indexOf(">") + 1; |
|---|
| 881 | ta.value = before + after.substring( 0, tagEnd ) + cc + after.substring( tagEnd, after.length ); |
|---|
| 882 | } |
|---|
| 883 | else ta.value = before + cc + after; |
|---|
| 884 | ta.value = ta.value.replace(new RegExp ('(&[^'+cc+']*?)('+cc+')([^'+cc+']*?;)'), "$1$3$2"); |
|---|
| 885 | ta.value = ta.value.replace(new RegExp ('(<script[^>]*>[^'+cc+']*?)('+cc+')([^'+cc+']*?<\/script>)'), "$1$3$2"); |
|---|
| 886 | ta.value = ta.value.replace(new RegExp ('^([^'+cc+']*)('+cc+')([^'+cc+']*<body[^>]*>)(.*?)'), "$1$3$2$4"); |
|---|
| 887 | } |
|---|
| 888 | else |
|---|
| 889 | { |
|---|
| 890 | var sel = this.getSelection(); |
|---|
| 891 | var r = sel.createRange(); |
|---|
| 892 | if ( sel.type == 'Control' ) |
|---|
| 893 | { |
|---|
| 894 | var control = r.item(0); |
|---|
| 895 | control.outerHTML += cc; |
|---|
| 896 | } |
|---|
| 897 | else |
|---|
| 898 | { |
|---|
| 899 | r.collapse(); |
|---|
| 900 | r.text = cc; |
|---|
| 901 | } |
|---|
| 902 | } |
|---|
| 903 | }; |
|---|
| 904 | |
|---|
| 905 | Xinha.prototype.findCC = function ( target ) |
|---|
| 906 | { |
|---|
| 907 | var findIn = ( target == 'textarea' ) ? this._textArea : this._doc.body; |
|---|
| 908 | range = findIn.createTextRange(); |
|---|
| 909 | |
|---|
| 910 | |
|---|
| 911 | if( range.findText( escape(Xinha.cc) ) ) |
|---|
| 912 | { |
|---|
| 913 | range.select(); |
|---|
| 914 | range.text = ''; |
|---|
| 915 | range.select(); |
|---|
| 916 | } |
|---|
| 917 | if( range.findText( Xinha.cc ) ) |
|---|
| 918 | { |
|---|
| 919 | range.select(); |
|---|
| 920 | range.text = ''; |
|---|
| 921 | range.select(); |
|---|
| 922 | } |
|---|
| 923 | if ( target == 'textarea' ) this._textArea.focus(); |
|---|
| 924 | }; |
|---|
| 925 | |
|---|
| 926 | |
|---|
| 927 | |
|---|
| 928 | |
|---|
| 929 | |
|---|
| 930 | |
|---|
| 931 | |
|---|
| 932 | Xinha.getDoctype = function (doc) |
|---|
| 933 | { |
|---|
| 934 | return (doc.compatMode == "CSS1Compat" && Xinha.ie_version < 8 ) ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' : ''; |
|---|
| 935 | }; |
|---|