Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ), |
74 | 74 | array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ), |
75 | 75 | array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ), |
76 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 99 ), |
| 76 | + array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 100 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 29 ), |
78 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 47 ), |
79 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 12 ), |
— | — | @@ -82,10 +82,10 @@ |
83 | 83 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ), |
84 | 84 | ), |
85 | 85 | 'combined' => array( |
86 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 216 ), |
| 86 | + array( 'src' => 'js/plugins.combined.js', 'version' => 217 ), |
87 | 87 | ), |
88 | 88 | 'minified' => array( |
89 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 216 ), |
| 89 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 217 ), |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -458,15 +458,13 @@ |
459 | 459 | // Converting <p>s is wrong if there's nothing before them, so check that. |
460 | 460 | // .find( '* + p' ) isn't good enough because textnodes aren't considered |
461 | 461 | $pre.find( 'p' ).each( function() { |
462 | | - if ( this.previousSibling || this.parentNode != $pre.get( 0 ) ) { |
463 | 462 | var text = $( this ).text(); |
464 | 463 | // If this <p> is preceded by some text, add a \n at the beginning, and if |
465 | 464 | // it's followed by a textnode, add a \n at the end |
466 | 465 | // We need the traverser because there can be other weird stuff in between |
467 | 466 | |
468 | 467 | // Check for preceding text |
469 | | - // FIXME: Add an option to disable depth checking, -10 is a hack |
470 | | - var t = new context.fn.rawTraverser( this.firstChild, -10, this ).prev(); |
| 468 | + var t = new context.fn.rawTraverser( this.firstChild, 0, this, $pre.get( 0 ) ).prev(); |
471 | 469 | while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) { |
472 | 470 | t = t.prev(); |
473 | 471 | } |
— | — | @@ -475,7 +473,7 @@ |
476 | 474 | } |
477 | 475 | |
478 | 476 | // Check for following text |
479 | | - t = new context.fn.rawTraverser( this.lastChild, -10, this ).next(); |
| 477 | + t = new context.fn.rawTraverser( this.lastChild, 0, this, $pre.get( 0 ) ).next(); |
480 | 478 | while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) { |
481 | 479 | t = t.next(); |
482 | 480 | } |
— | — | @@ -484,7 +482,6 @@ |
485 | 483 | text += "\n"; |
486 | 484 | } |
487 | 485 | $( this ).text( text ); |
488 | | - } |
489 | 486 | } ); |
490 | 487 | var retval; |
491 | 488 | if ( $.browser.msie ) { |
— | — | @@ -508,7 +505,22 @@ |
509 | 506 | * Gets the complete contents of the iframe (in plain text, not HTML) |
510 | 507 | */ |
511 | 508 | 'getContents': function() { |
512 | | - return context.fn.htmlToText( context.$content.html() ); |
| 509 | + // For <p></p>, .html() returns <p> </p> in IE |
| 510 | + // This seems to convince IE while not affecting display |
| 511 | + var html; |
| 512 | + if ( $.browser.msie ) { |
| 513 | + // Don't manipulate the iframe DOM itself, causes cursor jumping issues |
| 514 | + var $c = $( context.$content.get( 0 ).cloneNode( true ) ); |
| 515 | + $c.find( 'p' ).each( function() { |
| 516 | + if ( $(this).html() == '' ) { |
| 517 | + $(this).replaceWith( '<p></p>' ); |
| 518 | + } |
| 519 | + } ); |
| 520 | + html = $c.html(); |
| 521 | + } else { |
| 522 | + html = context.$content.html(); |
| 523 | + } |
| 524 | + return context.fn.htmlToText( html ); |
513 | 525 | }, |
514 | 526 | /** |
515 | 527 | * Gets the currently selected text in the content |
— | — | @@ -737,15 +749,38 @@ |
738 | 750 | if ( sc ) { |
739 | 751 | range.moveToElementText( sc ); |
740 | 752 | } |
741 | | - range.moveStart( 'character', options.start ); |
| 753 | + range.collapse(); |
| 754 | + range.moveEnd( 'character', options.start ); |
| 755 | + |
742 | 756 | var range2 = context.$iframe[0].contentWindow.document.body.createTextRange(); |
743 | 757 | if ( ec ) { |
744 | 758 | range2.moveToElementText( ec ); |
745 | 759 | } |
746 | 760 | range2.collapse(); |
747 | 761 | range2.moveEnd( 'character', options.end ); |
748 | | - range.setEndPoint( 'EndToEnd', range2 ); |
749 | | - range.select(); |
| 762 | + |
| 763 | + // IE does newline emulation for <p>s: <p>foo</p><p>bar</p> becomes foo\nbar just fine |
| 764 | + // but <p>foo</p><br><br><p>bar</p> becomes foo\n\n\n\nbar , one \n too many |
| 765 | + // Correct for this |
| 766 | + var matches, counted = 0; |
| 767 | + // while ( matches = range.htmlText.match( regex ) && matches.length <= counted ) doesn't work |
| 768 | + // because the assignment side effect hasn't happened yet when the second term is evaluated |
| 769 | + while ( matches = range.htmlText.match( /\<\/p\>(\<br[^\>]*\>)+\<p\>/gi ) ) { |
| 770 | + if ( matches.length <= counted ) |
| 771 | + break; |
| 772 | + range.moveEnd( 'character', matches.length ); |
| 773 | + counted += matches.length; |
| 774 | + } |
| 775 | + range2.moveEnd( 'character', counted ); |
| 776 | + while ( matches = range2.htmlText.match( /\<\/p\>(\<br[^\>]*\>)+\<p\>/gi ) ) { |
| 777 | + if ( matches.length <= counted ) |
| 778 | + break; |
| 779 | + range2.moveEnd( 'character', matches.length ); |
| 780 | + counted += matches.length; |
| 781 | + } |
| 782 | + |
| 783 | + range2.setEndPoint( 'StartToEnd', range ); |
| 784 | + range2.select(); |
750 | 785 | } |
751 | 786 | return context.$textarea; |
752 | 787 | }, |
— | — | @@ -863,10 +898,11 @@ |
864 | 899 | /** |
865 | 900 | * Object used by traverser(). Don't use this unless you know what you're doing |
866 | 901 | */ |
867 | | - 'rawTraverser': function( node, depth, inP ) { |
| 902 | + 'rawTraverser': function( node, depth, inP, ancestor ) { |
868 | 903 | this.node = node; |
869 | 904 | this.depth = depth; |
870 | 905 | this.inP = inP; |
| 906 | + this.ancestor = ancestor; |
871 | 907 | this.next = function() { |
872 | 908 | var p = this.node; |
873 | 909 | var nextDepth = this.depth; |
— | — | @@ -874,8 +910,8 @@ |
875 | 911 | while ( p && !p.nextSibling ) { |
876 | 912 | p = p.parentNode; |
877 | 913 | nextDepth--; |
878 | | - if ( nextDepth == 0 ) { |
879 | | - // We're back at the start node |
| 914 | + if ( p == ancestor ) { |
| 915 | + // We're back at the ancestor, stop here |
880 | 916 | p = null; |
881 | 917 | } |
882 | 918 | if ( p && p.nodeName == "P" ) { |
— | — | @@ -901,7 +937,7 @@ |
902 | 938 | } |
903 | 939 | } |
904 | 940 | } while ( p && p.firstChild ); |
905 | | - return p ? new context.fn.rawTraverser( p, nextDepth, nextInP ) : null; |
| 941 | + return p ? new context.fn.rawTraverser( p, nextDepth, nextInP, this.ancestor ) : null; |
906 | 942 | }; |
907 | 943 | this.prev = function() { |
908 | 944 | var p = this.node; |
— | — | @@ -910,8 +946,8 @@ |
911 | 947 | while ( p && !p.previousSibling ) { |
912 | 948 | p = p.parentNode; |
913 | 949 | prevDepth--; |
914 | | - if ( prevDepth == 0 ) { |
915 | | - // We're back at the start node |
| 950 | + if ( p == ancestor ) { |
| 951 | + // We're back at the ancestor, stop here |
916 | 952 | p = null; |
917 | 953 | } |
918 | 954 | if ( p && p.nodeName == "P" ) { |
— | — | @@ -937,7 +973,7 @@ |
938 | 974 | } |
939 | 975 | } |
940 | 976 | } while ( p && p.lastChild ); |
941 | | - return p ? new context.fn.rawTraverser( p, prevDepth, prevInP ) : null; |
| 977 | + return p ? new context.fn.rawTraverser( p, prevDepth, prevInP, this.ancestor ) : null; |
942 | 978 | }; |
943 | 979 | }, |
944 | 980 | /** |
— | — | @@ -971,7 +1007,7 @@ |
972 | 1008 | } |
973 | 1009 | } |
974 | 1010 | } while ( node && node.firstChild ); |
975 | | - return new context.fn.rawTraverser( node, depth, inP ); |
| 1011 | + return new context.fn.rawTraverser( node, depth, inP, node ); |
976 | 1012 | }, |
977 | 1013 | 'getOffset': function( offset ) { |
978 | 1014 | if ( !context.offsets ) { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -6891,15 +6891,13 @@ |
6892 | 6892 | // Converting <p>s is wrong if there's nothing before them, so check that. |
6893 | 6893 | // .find( '* + p' ) isn't good enough because textnodes aren't considered |
6894 | 6894 | $pre.find( 'p' ).each( function() { |
6895 | | - if ( this.previousSibling || this.parentNode != $pre.get( 0 ) ) { |
6896 | 6895 | var text = $( this ).text(); |
6897 | 6896 | // If this <p> is preceded by some text, add a \n at the beginning, and if |
6898 | 6897 | // it's followed by a textnode, add a \n at the end |
6899 | 6898 | // We need the traverser because there can be other weird stuff in between |
6900 | 6899 | |
6901 | 6900 | // Check for preceding text |
6902 | | - // FIXME: Add an option to disable depth checking, -10 is a hack |
6903 | | - var t = new context.fn.rawTraverser( this.firstChild, -10, this ).prev(); |
| 6901 | + var t = new context.fn.rawTraverser( this.firstChild, 0, this, $pre.get( 0 ) ).prev(); |
6904 | 6902 | while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) { |
6905 | 6903 | t = t.prev(); |
6906 | 6904 | } |
— | — | @@ -6908,7 +6906,7 @@ |
6909 | 6907 | } |
6910 | 6908 | |
6911 | 6909 | // Check for following text |
6912 | | - t = new context.fn.rawTraverser( this.lastChild, -10, this ).next(); |
| 6910 | + t = new context.fn.rawTraverser( this.lastChild, 0, this, $pre.get( 0 ) ).next(); |
6913 | 6911 | while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) { |
6914 | 6912 | t = t.next(); |
6915 | 6913 | } |
— | — | @@ -6917,7 +6915,6 @@ |
6918 | 6916 | text += "\n"; |
6919 | 6917 | } |
6920 | 6918 | $( this ).text( text ); |
6921 | | - } |
6922 | 6919 | } ); |
6923 | 6920 | var retval; |
6924 | 6921 | if ( $.browser.msie ) { |
— | — | @@ -6941,7 +6938,22 @@ |
6942 | 6939 | * Gets the complete contents of the iframe (in plain text, not HTML) |
6943 | 6940 | */ |
6944 | 6941 | 'getContents': function() { |
6945 | | - return context.fn.htmlToText( context.$content.html() ); |
| 6942 | + // For <p></p>, .html() returns <p> </p> in IE |
| 6943 | + // This seems to convince IE while not affecting display |
| 6944 | + var html; |
| 6945 | + if ( $.browser.msie ) { |
| 6946 | + // Don't manipulate the iframe DOM itself, causes cursor jumping issues |
| 6947 | + var $c = $( context.$content.get( 0 ).cloneNode( true ) ); |
| 6948 | + $c.find( 'p' ).each( function() { |
| 6949 | + if ( $(this).html() == '' ) { |
| 6950 | + $(this).replaceWith( '<p></p>' ); |
| 6951 | + } |
| 6952 | + } ); |
| 6953 | + html = $c.html(); |
| 6954 | + } else { |
| 6955 | + html = context.$content.html(); |
| 6956 | + } |
| 6957 | + return context.fn.htmlToText( html ); |
6946 | 6958 | }, |
6947 | 6959 | /** |
6948 | 6960 | * Gets the currently selected text in the content |
— | — | @@ -7170,15 +7182,38 @@ |
7171 | 7183 | if ( sc ) { |
7172 | 7184 | range.moveToElementText( sc ); |
7173 | 7185 | } |
7174 | | - range.moveStart( 'character', options.start ); |
| 7186 | + range.collapse(); |
| 7187 | + range.moveEnd( 'character', options.start ); |
| 7188 | + |
7175 | 7189 | var range2 = context.$iframe[0].contentWindow.document.body.createTextRange(); |
7176 | 7190 | if ( ec ) { |
7177 | 7191 | range2.moveToElementText( ec ); |
7178 | 7192 | } |
7179 | 7193 | range2.collapse(); |
7180 | 7194 | range2.moveEnd( 'character', options.end ); |
7181 | | - range.setEndPoint( 'EndToEnd', range2 ); |
7182 | | - range.select(); |
| 7195 | + |
| 7196 | + // IE does newline emulation for <p>s: <p>foo</p><p>bar</p> becomes foo\nbar just fine |
| 7197 | + // but <p>foo</p><br><br><p>bar</p> becomes foo\n\n\n\nbar , one \n too many |
| 7198 | + // Correct for this |
| 7199 | + var matches, counted = 0; |
| 7200 | + // while ( matches = range.htmlText.match( regex ) && matches.length <= counted ) doesn't work |
| 7201 | + // because the assignment side effect hasn't happened yet when the second term is evaluated |
| 7202 | + while ( matches = range.htmlText.match( /\<\/p\>(\<br[^\>]*\>)+\<p\>/gi ) ) { |
| 7203 | + if ( matches.length <= counted ) |
| 7204 | + break; |
| 7205 | + range.moveEnd( 'character', matches.length ); |
| 7206 | + counted += matches.length; |
| 7207 | + } |
| 7208 | + range2.moveEnd( 'character', counted ); |
| 7209 | + while ( matches = range2.htmlText.match( /\<\/p\>(\<br[^\>]*\>)+\<p\>/gi ) ) { |
| 7210 | + if ( matches.length <= counted ) |
| 7211 | + break; |
| 7212 | + range2.moveEnd( 'character', matches.length ); |
| 7213 | + counted += matches.length; |
| 7214 | + } |
| 7215 | + |
| 7216 | + range2.setEndPoint( 'StartToEnd', range ); |
| 7217 | + range2.select(); |
7183 | 7218 | } |
7184 | 7219 | return context.$textarea; |
7185 | 7220 | }, |
— | — | @@ -7296,10 +7331,11 @@ |
7297 | 7332 | /** |
7298 | 7333 | * Object used by traverser(). Don't use this unless you know what you're doing |
7299 | 7334 | */ |
7300 | | - 'rawTraverser': function( node, depth, inP ) { |
| 7335 | + 'rawTraverser': function( node, depth, inP, ancestor ) { |
7301 | 7336 | this.node = node; |
7302 | 7337 | this.depth = depth; |
7303 | 7338 | this.inP = inP; |
| 7339 | + this.ancestor = ancestor; |
7304 | 7340 | this.next = function() { |
7305 | 7341 | var p = this.node; |
7306 | 7342 | var nextDepth = this.depth; |
— | — | @@ -7307,8 +7343,8 @@ |
7308 | 7344 | while ( p && !p.nextSibling ) { |
7309 | 7345 | p = p.parentNode; |
7310 | 7346 | nextDepth--; |
7311 | | - if ( nextDepth == 0 ) { |
7312 | | - // We're back at the start node |
| 7347 | + if ( p == ancestor ) { |
| 7348 | + // We're back at the ancestor, stop here |
7313 | 7349 | p = null; |
7314 | 7350 | } |
7315 | 7351 | if ( p && p.nodeName == "P" ) { |
— | — | @@ -7334,7 +7370,7 @@ |
7335 | 7371 | } |
7336 | 7372 | } |
7337 | 7373 | } while ( p && p.firstChild ); |
7338 | | - return p ? new context.fn.rawTraverser( p, nextDepth, nextInP ) : null; |
| 7374 | + return p ? new context.fn.rawTraverser( p, nextDepth, nextInP, this.ancestor ) : null; |
7339 | 7375 | }; |
7340 | 7376 | this.prev = function() { |
7341 | 7377 | var p = this.node; |
— | — | @@ -7343,8 +7379,8 @@ |
7344 | 7380 | while ( p && !p.previousSibling ) { |
7345 | 7381 | p = p.parentNode; |
7346 | 7382 | prevDepth--; |
7347 | | - if ( prevDepth == 0 ) { |
7348 | | - // We're back at the start node |
| 7383 | + if ( p == ancestor ) { |
| 7384 | + // We're back at the ancestor, stop here |
7349 | 7385 | p = null; |
7350 | 7386 | } |
7351 | 7387 | if ( p && p.nodeName == "P" ) { |
— | — | @@ -7370,7 +7406,7 @@ |
7371 | 7407 | } |
7372 | 7408 | } |
7373 | 7409 | } while ( p && p.lastChild ); |
7374 | | - return p ? new context.fn.rawTraverser( p, prevDepth, prevInP ) : null; |
| 7410 | + return p ? new context.fn.rawTraverser( p, prevDepth, prevInP, this.ancestor ) : null; |
7375 | 7411 | }; |
7376 | 7412 | }, |
7377 | 7413 | /** |
— | — | @@ -7404,7 +7440,7 @@ |
7405 | 7441 | } |
7406 | 7442 | } |
7407 | 7443 | } while ( node && node.firstChild ); |
7408 | | - return new context.fn.rawTraverser( node, depth, inP ); |
| 7444 | + return new context.fn.rawTraverser( node, depth, inP, node ); |
7409 | 7445 | }, |
7410 | 7446 | 'getOffset': function( offset ) { |
7411 | 7447 | if ( !context.offsets ) { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -459,12 +459,13 @@ |
460 | 460 | event.preventDefault();return false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);} |
461 | 461 | if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});} |
462 | 462 | addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'htmlToText':function(html){if(html in context.htmlToTextMap){return context.htmlToTextMap[html];} |
463 | | -var origHTML=html;html=html.replace(/\r?\n/g,"").replace(/ /g," ").replace(/\<br[^\>]*\>/gi,"\n").replace(/\<\/p\>\<p\>/gi,"\n").replace(/\<\/p\>(\n*)\<p\>/gi,"$1\n");var leading=html.match(/^\s*/)[0];var trailing=html.match(/\s*$/)[0];html=html.substr(leading.length,html.length-leading.length-trailing.length);var $pre=$('<pre>'+html+'</pre>');$pre.find('.wikiEditor-noinclude').each(function(){$(this).remove();});$pre.find('.wikiEditor-tab').each(function(){$(this).text("\t");});$pre.find('br').each(function(){$(this).replaceWith("\n");});$pre.find('p').each(function(){if(this.previousSibling||this.parentNode!=$pre.get(0)){var text=$(this).text();var t=new context.fn.rawTraverser(this.firstChild,-10,this).prev();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.prev();} |
| 463 | +var origHTML=html;html=html.replace(/\r?\n/g,"").replace(/ /g," ").replace(/\<br[^\>]*\>/gi,"\n").replace(/\<\/p\>\<p\>/gi,"\n").replace(/\<\/p\>(\n*)\<p\>/gi,"$1\n");var leading=html.match(/^\s*/)[0];var trailing=html.match(/\s*$/)[0];html=html.substr(leading.length,html.length-leading.length-trailing.length);var $pre=$('<pre>'+html+'</pre>');$pre.find('.wikiEditor-noinclude').each(function(){$(this).remove();});$pre.find('.wikiEditor-tab').each(function(){$(this).text("\t");});$pre.find('br').each(function(){$(this).replaceWith("\n");});$pre.find('p').each(function(){var text=$(this).text();var t=new context.fn.rawTraverser(this.firstChild,0,this,$pre.get(0)).prev();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.prev();} |
464 | 464 | if(t){text="\n"+text;} |
465 | | -t=new context.fn.rawTraverser(this.lastChild,-10,this).next();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.next();} |
| 465 | +t=new context.fn.rawTraverser(this.lastChild,0,this,$pre.get(0)).next();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.next();} |
466 | 466 | if(t&&!t.inP&&t.node.nodeName=='#text'&&t.node.nodeValue.charAt(0)!='\n'&&t.node.nodeValue.charAt(0)!='\r'){text+="\n";} |
467 | | -$(this).text(text);}});var retval;if($.browser.msie){retval=$('<pre>'+$pre.html()+'</pre>').text().replace(/\r/g,'\n');}else{retval=$pre.text();} |
468 | | -return context.htmlToTextMap[origHTML]=leading+retval+trailing;},'getContents':function(){return context.fn.htmlToText(context.$content.html());},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();if($.browser.opera){if(retval.rangeCount>0){retval=context.fn.htmlToText($('<pre />').append(retval.getRangeAt(0).cloneContents()).html());}else{retval='';}}}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();} |
| 467 | +$(this).text(text);});var retval;if($.browser.msie){retval=$('<pre>'+$pre.html()+'</pre>').text().replace(/\r/g,'\n');}else{retval=$pre.text();} |
| 468 | +return context.htmlToTextMap[origHTML]=leading+retval+trailing;},'getContents':function(){var html;if($.browser.msie){var $c=$(context.$content.get(0).cloneNode(true));$c.find('p').each(function(){if($(this).html()==''){$(this).replaceWith('<p></p>');}});html=$c.html();}else{html=context.$content.html();} |
| 469 | +return context.fn.htmlToText(html);},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();if($.browser.opera){if(retval.rangeCount>0){retval=context.fn.htmlToText($('<pre />').append(retval.getRangeAt(0).cloneContents()).html());}else{retval='';}}}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();} |
469 | 470 | if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(typeof retval.toString!='undefined'){retval=retval.toString();} |
470 | 471 | return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var selectAfter=false;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';} |
471 | 472 | if(options.splitlines){selTextArr=selText.split(/\n/);} |
— | — | @@ -483,8 +484,12 @@ |
484 | 485 | var sel=context.$iframe[0].contentWindow.getSelection();while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;} |
485 | 486 | while(ec.firstChild&&ec.nodeName!='#text'){ec=ec.firstChild;} |
486 | 487 | var range=context.$iframe[0].contentWindow.document.createRange();range.setStart(sc,start);range.setEnd(ec,end);sel.removeAllRanges();sel.addRange(range);context.$iframe[0].contentWindow.focus();}else if(context.$iframe[0].contentWindow.document.body.createTextRange){var range=context.$iframe[0].contentWindow.document.body.createTextRange();if(sc){range.moveToElementText(sc);} |
487 | | -range.moveStart('character',options.start);var range2=context.$iframe[0].contentWindow.document.body.createTextRange();if(ec){range2.moveToElementText(ec);} |
488 | | -range2.collapse();range2.moveEnd('character',options.end);range.setEndPoint('EndToEnd',range2);range.select();} |
| 488 | +range.collapse();range.moveEnd('character',options.start);var range2=context.$iframe[0].contentWindow.document.body.createTextRange();if(ec){range2.moveToElementText(ec);} |
| 489 | +range2.collapse();range2.moveEnd('character',options.end);var matches,counted=0;while(matches=range.htmlText.match(/\<\/p\>(\<br[^\>]*\>)+\<p\>/gi)){if(matches.length<=counted) |
| 490 | +break;range.moveEnd('character',matches.length);counted+=matches.length;} |
| 491 | +range2.moveEnd('character',counted);while(matches=range2.htmlText.match(/\<\/p\>(\<br[^\>]*\>)+\<p\>/gi)){if(matches.length<=counted) |
| 492 | +break;range2.moveEnd('character',matches.length);counted+=matches.length;} |
| 493 | +range2.setEndPoint('StartToEnd',range);range2.select();} |
489 | 494 | return context.$textarea;},'scrollToCaretPosition':function(options){},'scrollToTop':function($element,force){var html=context.$content.closest('html'),body=context.$content.closest('body'),parentHtml=$('html'),parentBody=$('body');var y=$element.offset().top;if(!$.browser.msie&&!$element.is('body')){y=parentHtml.scrollTop()>0?y+html.scrollTop()-parentHtml.scrollTop():y;y=parentBody.scrollTop()>0?y+body.scrollTop()-parentBody.scrollTop():y;} |
490 | 495 | var topBound=html.scrollTop()>body.scrollTop()?html.scrollTop():body.scrollTop(),bottomBound=topBound+context.$iframe.height();if(force||y<topBound||y>bottomBound){html.scrollTop(y);body.scrollTop(y);} |
491 | 496 | $element.trigger('scrollToTop');},'beforeSelection':function(classname,strict){if(typeof classname=='undefined'){classname='';} |
— | — | @@ -496,16 +501,16 @@ |
497 | 502 | var classStr=' '+classname+' ';while(e){if(!strict&&(!classname||(' '+e.className+' ').indexOf(classStr)!=-1)){return $(e);} |
498 | 503 | var next=e.previousSibling;while(next&&next.lastChild){next=next.lastChild;} |
499 | 504 | e=next||e.parentNode;strict=false;} |
500 | | -return $([]);},'rawTraverser':function(node,depth,inP){this.node=node;this.depth=depth;this.inP=inP;this.next=function(){var p=this.node;var nextDepth=this.depth;var nextInP=this.inP;while(p&&!p.nextSibling){p=p.parentNode;nextDepth--;if(nextDepth==0){p=null;} |
| 505 | +return $([]);},'rawTraverser':function(node,depth,inP,ancestor){this.node=node;this.depth=depth;this.inP=inP;this.ancestor=ancestor;this.next=function(){var p=this.node;var nextDepth=this.depth;var nextInP=this.inP;while(p&&!p.nextSibling){p=p.parentNode;nextDepth--;if(p==ancestor){p=null;} |
501 | 506 | if(p&&p.nodeName=="P"){nextInP=null;}} |
502 | 507 | p=p?p.nextSibling:null;if(p&&p.nodeName=="P"){nextInP=p;} |
503 | 508 | do{while(p&&(' '+p.className+' ').indexOf(' wikiEditor-noinclude ')!=-1){p=p.nextSibling;} |
504 | | -if(p&&p.firstChild){p=p.firstChild;nextDepth++;if(p.nodeName=="P"){nextInP=p;}}}while(p&&p.firstChild);return p?new context.fn.rawTraverser(p,nextDepth,nextInP):null;};this.prev=function(){var p=this.node;var prevDepth=this.depth;var prevInP=this.inP;while(p&&!p.previousSibling){p=p.parentNode;prevDepth--;if(prevDepth==0){p=null;} |
| 509 | +if(p&&p.firstChild){p=p.firstChild;nextDepth++;if(p.nodeName=="P"){nextInP=p;}}}while(p&&p.firstChild);return p?new context.fn.rawTraverser(p,nextDepth,nextInP,this.ancestor):null;};this.prev=function(){var p=this.node;var prevDepth=this.depth;var prevInP=this.inP;while(p&&!p.previousSibling){p=p.parentNode;prevDepth--;if(p==ancestor){p=null;} |
505 | 510 | if(p&&p.nodeName=="P"){prevInP=null;}} |
506 | 511 | p=p?p.previousSibling:null;if(p&&p.nodeName=="P"){prevInP=p;} |
507 | 512 | do{while(p&&(' '+p.className+' ').indexOf(' wikiEditor-noinclude ')!=-1){p=p.previousSibling;} |
508 | | -if(p&&p.lastChild){p=p.lastChild;prevDepth++;if(p.nodeName=="P"){prevInP=p;}}}while(p&&p.lastChild);return p?new context.fn.rawTraverser(p,prevDepth,prevInP):null;};},'traverser':function(start){var node=start.jquery?start.get(0):start;var depth=0;var inP=node.nodeName=="P"?node:null;do{while(node&&(' '+node.className+' ').indexOf(' wikiEditor-noinclude ')!=-1){node=node.nextSibling;} |
509 | | -if(node&&node.firstChild){node=node.firstChild;depth++;if(node.nodeName=="P"){inP=node;}}}while(node&&node.firstChild);return new context.fn.rawTraverser(node,depth,inP);},'getOffset':function(offset){if(!context.offsets){context.fn.refreshOffsets();} |
| 513 | +if(p&&p.lastChild){p=p.lastChild;prevDepth++;if(p.nodeName=="P"){prevInP=p;}}}while(p&&p.lastChild);return p?new context.fn.rawTraverser(p,prevDepth,prevInP,this.ancestor):null;};},'traverser':function(start){var node=start.jquery?start.get(0):start;var depth=0;var inP=node.nodeName=="P"?node:null;do{while(node&&(' '+node.className+' ').indexOf(' wikiEditor-noinclude ')!=-1){node=node.nextSibling;} |
| 514 | +if(node&&node.firstChild){node=node.firstChild;depth++;if(node.nodeName=="P"){inP=node;}}}while(node&&node.firstChild);return new context.fn.rawTraverser(node,depth,inP,node);},'getOffset':function(offset){if(!context.offsets){context.fn.refreshOffsets();} |
510 | 515 | if(offset in context.offsets){return context.offsets[offset];} |
511 | 516 | var lowerBound=-1;for(var o in context.offsets){if(o>offset){break;} |
512 | 517 | lowerBound=o;} |