| | 388 | // do things with CharInsert for example |
| | 389 | |
| | 390 | var edittools_markup = document.getElementById ('editpage-specialchars') ; |
| | 391 | if (edittools_markup) { |
| | 392 | edittools_markup.style.display = 'none' ; |
| | 393 | } |
| | 394 | insertTags = function (tagOpen, tagClose, sampleText) |
| | 395 | { |
| | 396 | var txtarea; |
| | 397 | |
| | 398 | if ( !(typeof(FCK) == "undefined") && !(typeof(FCK.EditingArea) == "undefined") ) |
| | 399 | { |
| | 400 | txtarea = FCK.EditingArea.Textarea ; |
| | 401 | } |
| | 402 | else if (document.editform) |
| | 403 | { |
| | 404 | // if we have FCK enabled, behave differently... |
| | 405 | FCKarea = document.getElementById( oFCKeditor.InstanceName ) ; |
| | 406 | if ( FCKarea.style.display == 'none' ) |
| | 407 | { |
| | 408 | SRCiframe = document.getElementById ('wpTextbox1___Frame') ; |
| | 409 | if ( SRCiframe ) |
| | 410 | { |
| | 411 | if (window.frames[SRCiframe]) |
| | 412 | SRCdoc = window.frames[SRCiframe].document ; |
| | 413 | else |
| | 414 | SRCdoc = SRCiframe.contentDocument ; |
| | 415 | |
| | 416 | var SRCarea = SRCdoc.getElementById ('xEditingArea').firstChild ; |
| | 417 | |
| | 418 | if (SRCarea) |
| | 419 | txtarea = SRCarea ; |
| | 420 | else |
| | 421 | return false ; |
| | 422 | |
| | 423 | } |
| | 424 | else |
| | 425 | { |
| | 426 | return false ; |
| | 427 | } |
| | 428 | } |
| | 429 | else |
| | 430 | { |
| | 431 | txtarea = document.editform.wpTextbox1 ; |
| | 432 | } |
| | 433 | } |
| | 434 | else |
| | 435 | { |
| | 436 | // some alternate form? take the first one we can find |
| | 437 | var areas = document.getElementsByTagName( 'textarea' ) ; |
| | 438 | txtarea = areas[0] ; |
| | 439 | } |
| | 440 | |
| | 441 | var selText, isSample = false ; |
| | 442 | |
| | 443 | if ( document.selection && document.selection.createRange ) |
| | 444 | { // IE/Opera |
| | 445 | |
| | 446 | //save window scroll position |
| | 447 | if ( document.documentElement && document.documentElement.scrollTop ) |
| | 448 | var winScroll = document.documentElement.scrollTop ; |
| | 449 | else if ( document.body ) |
| | 450 | var winScroll = document.body.scrollTop ; |
| | 451 | |
| | 452 | //get current selection |
| | 453 | txtarea.focus() ; |
| | 454 | var range = document.selection.createRange() ; |
| | 455 | selText = range.text ; |
| | 456 | //insert tags |
| | 457 | checkSelectedText() ; |
| | 458 | range.text = tagOpen + selText + tagClose ; |
| | 459 | //mark sample text as selected |
| | 460 | if ( isSample && range.moveStart ) |
| | 461 | { |
| | 462 | if (window.opera) |
| | 463 | tagClose = tagClose.replace(/\\n/g,'') ; //check it out one more time |
| | 464 | range.moveStart('character', - tagClose.length - selText.length) ; |
| | 465 | range.moveEnd('character', - tagClose.length) ; |
| | 466 | } |
| | 467 | range.select(); |
| | 468 | //restore window scroll position |
| | 469 | if ( document.documentElement && document.documentElement.scrollTop ) |
| | 470 | document.documentElement.scrollTop = winScroll ; |
| | 471 | else if ( document.body ) |
| | 472 | document.body.scrollTop = winScroll ; |
| | 473 | |
| | 474 | } |
| | 475 | else if ( txtarea.selectionStart || txtarea.selectionStart == '0' ) |
| | 476 | { // Mozilla |
| | 477 | |
| | 478 | //save textarea scroll position |
| | 479 | var textScroll = txtarea.scrollTop ; |
| | 480 | //get current selection |
| | 481 | txtarea.focus() ; |
| | 482 | var startPos = txtarea.selectionStart ; |
| | 483 | var endPos = txtarea.selectionEnd ; |
| | 484 | selText = txtarea.value.substring( startPos, endPos ) ; |
| | 485 | |
| | 486 | //insert tags |
| | 487 | if (!selText) |
| | 488 | { |
| | 489 | selText = sampleText ; |
| | 490 | isSample = true ; |
| | 491 | } |
| | 492 | else if (selText.charAt(selText.length - 1) == ' ') |
| | 493 | { //exclude ending space char |
| | 494 | selText = selText.substring(0, selText.length - 1) ; |
| | 495 | tagClose += ' ' ; |
| | 496 | } |
| | 497 | txtarea.value = txtarea.value.substring(0, startPos) + tagOpen + selText + tagClose + |
| | 498 | txtarea.value.substring(endPos, txtarea.value.length) ; |
| | 499 | //set new selection |
| | 500 | if (isSample) |
| | 501 | { |
| | 502 | txtarea.selectionStart = startPos + tagOpen.length ; |
| | 503 | txtarea.selectionEnd = startPos + tagOpen.length + selText.length ; |
| | 504 | } |
| | 505 | else |
| | 506 | { |
| | 507 | txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length ; |
| | 508 | txtarea.selectionEnd = txtarea.selectionStart; |
| | 509 | } |
| | 510 | //restore textarea scroll position |
| | 511 | txtarea.scrollTop = textScroll; |
| | 512 | } |
| | 513 | } |