Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -184,7 +184,6 @@ |
185 | 185 | // The wikiEditor context is stored in the element's data, so when this function gets called again we can pick up right |
186 | 186 | // where we left off |
187 | 187 | var context = $(this).data( 'wikiEditor-context' ); |
188 | | - |
189 | 188 | // On first call, we need to set things up, but on all following calls we can skip right to the API handling |
190 | 189 | if ( typeof context == 'undefined' ) { |
191 | 190 | |
— | — | @@ -374,26 +373,24 @@ |
375 | 374 | .appendTo( context.$ui ); |
376 | 375 | }, |
377 | 376 | |
378 | | - /** |
379 | | - * FIXME: This section is a bit of a "wonky" section given it's supposed to keep compatibility with the |
380 | | - * textSelection plugin, which works on character-based manipulations as opposed to the node-based manipulations |
381 | | - * we use for the iframe. It's debatable whether compatibility with this plugin is even being done well, or for |
382 | | - * that matter should be done at all. |
| 377 | + /* |
| 378 | + * FIXME: This section needs attention! It doesn't really make sense given it's supposed to keep compatibility |
| 379 | + * with the textSelection plugin, which works on character-based manipulations as opposed to the node-based |
| 380 | + * manipulations we use for the iframe. It's debatable whether compatibility with this plugin is even being done |
| 381 | + * well, or for that matter should be done at all. |
383 | 382 | */ |
384 | 383 | |
385 | 384 | /** |
386 | 385 | * Gets the complete contents of the iframe (in plain text, not HTML) |
387 | 386 | */ |
388 | 387 | 'getContents': function() { |
| 388 | + console.log( 'getContents' ); |
389 | 389 | // FIXME: Evil ua-sniffing action! |
390 | 390 | if ( $.browser.name == 'msie' ) { |
391 | 391 | return context.$content.text(); |
392 | 392 | } |
393 | | - // We use .html() instead of .text() so HTML entities are handled right |
394 | | - // Setting the HTML of the textarea doesn't work on all browsers, use a dummy <div> instead |
395 | | - |
396 | | - |
397 | | - //get rid of the noincludes when getting text |
| 393 | + // Get rid of the noincludes when getting text - we use .html() instead of .text() so HTML entities are |
| 394 | + // handled right - setting the HTML of the textarea doesn't work on all browsers, use a dummy <div> instead |
398 | 395 | var $dummyDiv = $( '<div />' ).html( context.$content.html().replace( /\<br\>/g, "\n" ) ); |
399 | 396 | $dummyDiv.find( ".wikiEditor-noinclude" ).each( function() { $( this ).remove(); } ); |
400 | 397 | return $dummyDiv.text(); |
— | — | @@ -464,9 +461,8 @@ |
465 | 462 | var insertText = pre + selText + post; |
466 | 463 | var insertLines = insertText.split( "\n" ); |
467 | 464 | range.extractContents(); |
468 | | - // Insert the contents one line at a time |
469 | | - // insertNode() inserts at the beginning, so this has |
470 | | - // to happen in reverse order |
| 465 | + // Insert the contents one line at a time - insertNode() inserts at the beginning, so this has to happen |
| 466 | + // in reverse order |
471 | 467 | var lastNode; |
472 | 468 | for ( var i = insertLines.length - 1; i >= 0; i-- ) { |
473 | 469 | range.insertNode( document.createTextNode( insertLines[i] ) ); |
— | — | @@ -478,8 +474,7 @@ |
479 | 475 | context.fn.scrollToTop( lastNode ); |
480 | 476 | } |
481 | 477 | } else if ( context.$iframe[0].contentWindow.document.selection ) { |
482 | | - // IE |
483 | | - // TODO |
| 478 | + // TODO: IE |
484 | 479 | } |
485 | 480 | // Trigger the encapsulateSelection event (this might need to get named something else/done differently) |
486 | 481 | context.$content.trigger( |
— | — | @@ -492,9 +487,7 @@ |
493 | 488 | * DO NOT CALL THESE DIRECTLY, use .textSelection( 'functionname', options ) instead |
494 | 489 | */ |
495 | 490 | 'getCaretPosition': function( options ) { |
496 | | - // FIXME: Character-based functions aren't useful for the magic iframe |
497 | | - // ... |
498 | | - //reurn character position |
| 491 | + // FIXME: Character-based functions aren't useful for the magic iframe - return character position? |
499 | 492 | }, |
500 | 493 | /** |
501 | 494 | * Sets the selection of the content |
— | — | @@ -518,7 +511,6 @@ |
519 | 512 | while ( ec.firstChild && ec.nodeName != '#text' ) { |
520 | 513 | ec = ec.firstChild; |
521 | 514 | } |
522 | | - |
523 | 515 | var range = document.createRange(); |
524 | 516 | range.setStart( sc, options.start ); |
525 | 517 | range.setEnd( ec, options.end ); |
— | — | @@ -526,8 +518,7 @@ |
527 | 519 | sel.addRange( range ); |
528 | 520 | context.$iframe[0].contentWindow.focus(); |
529 | 521 | } else if ( context.$iframe[0].contentWindow.document.selection ) { |
530 | | - // IE |
531 | | - // FIXME still broken for when sc or ec is the <body>, needs more tweaking |
| 522 | + // FIXME: IE is still broken for when sc or ec is the <body>, needs more tweaking |
532 | 523 | var range = document.selection.createRange(); |
533 | 524 | range.moveToElementText( sc ); |
534 | 525 | range.moveStart( 'character', options.start ); |
— | — | @@ -543,8 +534,7 @@ |
544 | 535 | * DO NOT CALL THESE DIRECTLY, use .textSelection( 'functionname', options ) instead |
545 | 536 | */ |
546 | 537 | 'scrollToCaretPosition': function( options ) { |
547 | | - // ... |
548 | | - //context.$textarea.trigger( 'scrollToPosition' ); |
| 538 | + // FIXME: context.$textarea.trigger( 'scrollToPosition' ) ? |
549 | 539 | }, |
550 | 540 | /** |
551 | 541 | * Scroll an element to the top of the iframe |
— | — | @@ -571,8 +561,9 @@ |
572 | 562 | * @return jQuery object |
573 | 563 | */ |
574 | 564 | 'beforeSelection': function( selector, strict ) { |
575 | | - if ( typeof selector == 'undefined' ) |
| 565 | + if ( typeof selector == 'undefined' ) { |
576 | 566 | selector = '*'; |
| 567 | + } |
577 | 568 | var e; |
578 | 569 | if ( context.$iframe[0].contentWindow.getSelection ) { |
579 | 570 | // Firefox and Opera |
— | — | @@ -612,10 +603,9 @@ |
613 | 604 | return $( [] ); |
614 | 605 | } |
615 | 606 | |
616 | | - /** |
617 | | - * End of "wonky" textSelection "compatible" section that needs attention. |
| 607 | + /* |
| 608 | + * End of wonky textSelection "compatible" section that needs attention. |
618 | 609 | */ |
619 | | - |
620 | 610 | }; |
621 | 611 | |
622 | 612 | /* |
— | — | @@ -661,7 +651,8 @@ |
662 | 652 | // Create an iframe in place of the text area |
663 | 653 | context.$iframe = $( '<iframe></iframe>' ) |
664 | 654 | .attr( { |
665 | | - 'frameborder': 0, |
| 655 | + 'frameBorder': 0, |
| 656 | + 'border': 0, |
666 | 657 | 'src': wgScriptPath + '/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html?' + |
667 | 658 | 'instance=' + context.instance + '&ts=' + ( new Date() ).getTime(), |
668 | 659 | 'id': 'wikiEditor-iframe-' + context.instance |
— | — | @@ -675,23 +666,24 @@ |
676 | 667 | 'overflow-x': 'hidden' |
677 | 668 | } ) |
678 | 669 | .insertAfter( context.$textarea ) |
679 | | - .load( function() { |
680 | | - //IE8 runs this twice, the second time is valid |
681 | | - if( $.browser.msie && $.browser.version >= 8 ) { |
682 | | - if(!this.isSecondRun){ |
| 670 | + .load( function() { |
| 671 | + // Internet Explorer will reload the iframe once we turn on design mode, so we need to only turn it on |
| 672 | + // durring the first run, and then bail |
| 673 | + if ( !this.isSecondRun ) { |
| 674 | + // Turn the document's design mode on |
| 675 | + context.$iframe[0].contentWindow.document.designMode = 'on'; |
| 676 | + // Let the rest of this function happen next time around |
| 677 | + if ( $.browser.msie ) { |
683 | 678 | this.isSecondRun = true; |
684 | 679 | return; |
685 | 680 | } |
686 | 681 | } |
687 | | - |
688 | | - // Turn the document's design mode on |
689 | | - context.$iframe[0].contentWindow.document.designMode = 'on'; |
690 | 682 | // Get a reference to the content area of the iframe |
691 | 683 | context.$content = $( context.$iframe[0].contentWindow.document.body ); |
692 | | - // We need to properly escape any HTML entities like &, < and > so they end up as visible |
693 | | - // characters rather than actual HTML tags in the code editor container. |
| 684 | + // If we just do "context.$content.text( context.$textarea.val() )", Internet Explorer will strip out the |
| 685 | + // whitespace charcters, specifically "\n" - so we must manually encode the text and append it |
694 | 686 | context.$content.append( |
695 | | - context.$textarea.val().replace( /</g, '<' ).replace( />/g, '>' ) |
| 687 | + context.$textarea.val().replace( /\</g, '<' ).replace( /\>/g, '>' ).replace( /\n/g, '<br />' ) |
696 | 688 | ); |
697 | 689 | // Reflect direction of parent frame into child |
698 | 690 | if ( $( 'body' ).is( '.rtl' ) ) { |