r61097 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61096‎ | r61097 | r61098 >
Date:19:05, 15 January 2010
Author:tparscal
Status:ok
Tags:
Comment:
Whitespace and comment alignment changes.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -184,7 +184,6 @@
185185 // The wikiEditor context is stored in the element's data, so when this function gets called again we can pick up right
186186 // where we left off
187187 var context = $(this).data( 'wikiEditor-context' );
188 -
189188 // On first call, we need to set things up, but on all following calls we can skip right to the API handling
190189 if ( typeof context == 'undefined' ) {
191190
@@ -374,26 +373,24 @@
375374 .appendTo( context.$ui );
376375 },
377376
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.
383382 */
384383
385384 /**
386385 * Gets the complete contents of the iframe (in plain text, not HTML)
387386 */
388387 'getContents': function() {
 388+ console.log( 'getContents' );
389389 // FIXME: Evil ua-sniffing action!
390390 if ( $.browser.name == 'msie' ) {
391391 return context.$content.text();
392392 }
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
398395 var $dummyDiv = $( '<div />' ).html( context.$content.html().replace( /\<br\>/g, "\n" ) );
399396 $dummyDiv.find( ".wikiEditor-noinclude" ).each( function() { $( this ).remove(); } );
400397 return $dummyDiv.text();
@@ -464,9 +461,8 @@
465462 var insertText = pre + selText + post;
466463 var insertLines = insertText.split( "\n" );
467464 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
471467 var lastNode;
472468 for ( var i = insertLines.length - 1; i >= 0; i-- ) {
473469 range.insertNode( document.createTextNode( insertLines[i] ) );
@@ -478,8 +474,7 @@
479475 context.fn.scrollToTop( lastNode );
480476 }
481477 } else if ( context.$iframe[0].contentWindow.document.selection ) {
482 - // IE
483 - // TODO
 478+ // TODO: IE
484479 }
485480 // Trigger the encapsulateSelection event (this might need to get named something else/done differently)
486481 context.$content.trigger(
@@ -492,9 +487,7 @@
493488 * DO NOT CALL THESE DIRECTLY, use .textSelection( 'functionname', options ) instead
494489 */
495490 '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?
499492 },
500493 /**
501494 * Sets the selection of the content
@@ -518,7 +511,6 @@
519512 while ( ec.firstChild && ec.nodeName != '#text' ) {
520513 ec = ec.firstChild;
521514 }
522 -
523515 var range = document.createRange();
524516 range.setStart( sc, options.start );
525517 range.setEnd( ec, options.end );
@@ -526,8 +518,7 @@
527519 sel.addRange( range );
528520 context.$iframe[0].contentWindow.focus();
529521 } 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
532523 var range = document.selection.createRange();
533524 range.moveToElementText( sc );
534525 range.moveStart( 'character', options.start );
@@ -543,8 +534,7 @@
544535 * DO NOT CALL THESE DIRECTLY, use .textSelection( 'functionname', options ) instead
545536 */
546537 'scrollToCaretPosition': function( options ) {
547 - // ...
548 - //context.$textarea.trigger( 'scrollToPosition' );
 538+ // FIXME: context.$textarea.trigger( 'scrollToPosition' ) ?
549539 },
550540 /**
551541 * Scroll an element to the top of the iframe
@@ -571,8 +561,9 @@
572562 * @return jQuery object
573563 */
574564 'beforeSelection': function( selector, strict ) {
575 - if ( typeof selector == 'undefined' )
 565+ if ( typeof selector == 'undefined' ) {
576566 selector = '*';
 567+ }
577568 var e;
578569 if ( context.$iframe[0].contentWindow.getSelection ) {
579570 // Firefox and Opera
@@ -612,10 +603,9 @@
613604 return $( [] );
614605 }
615606
616 - /**
617 - * End of "wonky" textSelection "compatible" section that needs attention.
 607+ /*
 608+ * End of wonky textSelection "compatible" section that needs attention.
618609 */
619 -
620610 };
621611
622612 /*
@@ -661,7 +651,8 @@
662652 // Create an iframe in place of the text area
663653 context.$iframe = $( '<iframe></iframe>' )
664654 .attr( {
665 - 'frameborder': 0,
 655+ 'frameBorder': 0,
 656+ 'border': 0,
666657 'src': wgScriptPath + '/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html?' +
667658 'instance=' + context.instance + '&ts=' + ( new Date() ).getTime(),
668659 'id': 'wikiEditor-iframe-' + context.instance
@@ -675,23 +666,24 @@
676667 'overflow-x': 'hidden'
677668 } )
678669 .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 ) {
683678 this.isSecondRun = true;
684679 return;
685680 }
686681 }
687 -
688 - // Turn the document's design mode on
689 - context.$iframe[0].contentWindow.document.designMode = 'on';
690682 // Get a reference to the content area of the iframe
691683 context.$content = $( context.$iframe[0].contentWindow.document.body );
692 - // We need to properly escape any HTML entities like &amp;, &lt; and &gt; 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
694686 context.$content.append(
695 - context.$textarea.val().replace( /</g, '&lt;' ).replace( />/g, '&gt;' )
 687+ context.$textarea.val().replace( /\</g, '&lt;' ).replace( /\>/g, '&gt;' ).replace( /\n/g, '<br />' )
696688 );
697689 // Reflect direction of parent frame into child
698690 if ( $( 'body' ).is( '.rtl' ) ) {

Status & tagging log