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' => 26 ), |
76 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 80 ), |
| 76 | + array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 81 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 25 ), |
78 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 45 ), |
79 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 11 ), |
— | — | @@ -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' => 193 ), |
| 86 | + array( 'src' => 'js/plugins.combined.js', 'version' => 194 ), |
87 | 87 | ), |
88 | 88 | 'minified' => array( |
89 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 193 ), |
| 89 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 194 ), |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -447,17 +447,38 @@ |
448 | 448 | // Firefox and Opera |
449 | 449 | var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 ); |
450 | 450 | if ( options.ownline ) { |
| 451 | + // We need to figure out if the cursor is at the start or end of a line |
| 452 | + var atStart = false, atEnd = false; |
451 | 453 | var body = context.$content.get( 0 ); |
452 | | - // TODO: This'll probably break with syntax highlighting |
453 | | - // When the selection starts at the beginning of a line, it'll have either |
454 | | - // startOffset == 0 or startContainer == body |
455 | | - if ( range.startOffset != 0 && range.startContainer != body ) { |
| 454 | + console.log(range); |
| 455 | + if ( range.startOffset == 0 ) { |
| 456 | + // Start of a line |
| 457 | + // FIXME: Not necessarily the case with syntax highlighting or |
| 458 | + // template collapsing |
| 459 | + atStart = true; |
| 460 | + } else if ( range.startContainer == body ) { |
| 461 | + // Look up the node just before the start of the selection |
| 462 | + // If it's a <BR>, we're at the start of a line that starts with a |
| 463 | + // block element; if not, we're at the end of a line |
| 464 | + var n = body.firstChild; |
| 465 | + for ( var i = 0; i < range.startOffset - 1 && n; i++ ) { |
| 466 | + n = n.nextSibling; |
| 467 | + } |
| 468 | + if ( n && n.nodeName == 'BR' ) { |
| 469 | + atStart = true; |
| 470 | + } else { |
| 471 | + atEnd = true; |
| 472 | + } |
| 473 | + } else if ( range.startContainer.nodeName == '#text' && |
| 474 | + range.startOffset == range.startContainer.nodeValue.length ) { |
| 475 | + // Apparently this happens when splitting text nodes |
| 476 | + atEnd = true; |
| 477 | + } |
| 478 | + |
| 479 | + if ( !atStart ) { |
456 | 480 | pre = "\n" + options.pre; |
457 | 481 | } |
458 | | - // TODO: Will this still work with syntax highlighting? |
459 | | - // When the selection ends at the end of a line, it'll have endContainer == body |
460 | | - // and endOffset != 0 |
461 | | - if ( range.endContainer != body || range.endOffset == 0 ) { |
| 482 | + if ( !atEnd ) { |
462 | 483 | post += "\n"; |
463 | 484 | } |
464 | 485 | } |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -6871,17 +6871,38 @@ |
6872 | 6872 | // Firefox and Opera |
6873 | 6873 | var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 ); |
6874 | 6874 | if ( options.ownline ) { |
| 6875 | + // We need to figure out if the cursor is at the start or end of a line |
| 6876 | + var atStart = false, atEnd = false; |
6875 | 6877 | var body = context.$content.get( 0 ); |
6876 | | - // TODO: This'll probably break with syntax highlighting |
6877 | | - // When the selection starts at the beginning of a line, it'll have either |
6878 | | - // startOffset == 0 or startContainer == body |
6879 | | - if ( range.startOffset != 0 && range.startContainer != body ) { |
| 6878 | + console.log(range); |
| 6879 | + if ( range.startOffset == 0 ) { |
| 6880 | + // Start of a line |
| 6881 | + // FIXME: Not necessarily the case with syntax highlighting or |
| 6882 | + // template collapsing |
| 6883 | + atStart = true; |
| 6884 | + } else if ( range.startContainer == body ) { |
| 6885 | + // Look up the node just before the start of the selection |
| 6886 | + // If it's a <BR>, we're at the start of a line that starts with a |
| 6887 | + // block element; if not, we're at the end of a line |
| 6888 | + var n = body.firstChild; |
| 6889 | + for ( var i = 0; i < range.startOffset - 1 && n; i++ ) { |
| 6890 | + n = n.nextSibling; |
| 6891 | + } |
| 6892 | + if ( n && n.nodeName == 'BR' ) { |
| 6893 | + atStart = true; |
| 6894 | + } else { |
| 6895 | + atEnd = true; |
| 6896 | + } |
| 6897 | + } else if ( range.startContainer.nodeName == '#text' && |
| 6898 | + range.startOffset == range.startContainer.nodeValue.length ) { |
| 6899 | + // Apparently this happens when splitting text nodes |
| 6900 | + atEnd = true; |
| 6901 | + } |
| 6902 | + |
| 6903 | + if ( !atStart ) { |
6880 | 6904 | pre = "\n" + options.pre; |
6881 | 6905 | } |
6882 | | - // TODO: Will this still work with syntax highlighting? |
6883 | | - // When the selection ends at the end of a line, it'll have endContainer == body |
6884 | | - // and endOffset != 0 |
6885 | | - if ( range.endContainer != body || range.endOffset == 0 ) { |
| 6906 | + if ( !atEnd ) { |
6886 | 6907 | post += "\n"; |
6887 | 6908 | } |
6888 | 6909 | } |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -454,8 +454,10 @@ |
455 | 455 | if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(retval.toString){retval=retval.toString();} |
456 | 456 | 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+=' ';} |
457 | 457 | if(options.splitlines){selTextArr=selText.split(/\n/);} |
458 | | -if(context.$iframe[0].contentWindow.getSelection){var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(options.ownline){var body=context.$content.get(0);if(range.startOffset!=0&&range.startContainer!=body){pre="\n"+options.pre;} |
459 | | -if(range.endContainer!=body||range.endOffset==0){post+="\n";}} |
| 458 | +if(context.$iframe[0].contentWindow.getSelection){var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(options.ownline){var atStart=false,atEnd=false;var body=context.$content.get(0);console.log(range);if(range.startOffset==0){atStart=true;}else if(range.startContainer==body){var n=body.firstChild;for(var i=0;i<range.startOffset-1&&n;i++){n=n.nextSibling;} |
| 459 | +if(n&&n.nodeName=='BR'){atStart=true;}else{atEnd=true;}}else if(range.startContainer.nodeName=='#text'&&range.startOffset==range.startContainer.nodeValue.length){atEnd=true;} |
| 460 | +if(!atStart){pre="\n"+options.pre;} |
| 461 | +if(!atEnd){post+="\n";}} |
460 | 462 | var insertText="";if(options.splitlines){for(var i=0;i<selTextArr.length;i++){insertText=insertText+pre+selTextArr[i]+post;if(i!=selTextArr.length-1)insertText+="\n";}}else{insertText=pre+selText+post;} |
461 | 463 | var insertLines=insertText.split("\n");range.extractContents();var lastNode;for(var i=insertLines.length-1;i>=0;i--){range.insertNode(context.$iframe[0].contentWindow.document.createTextNode(insertLines[i]));if(i>0){lastNode=range.insertNode(context.$iframe[0].contentWindow.document.createElement('br'));}} |
462 | 464 | if(lastNode){context.fn.scrollToTop(lastNode);}}else if(context.$iframe[0].contentWindow.document.selection){context.$iframe[0].contentWindow.focus();var range=context.$iframe[0].contentWindow.document.selection.createRange();if(options.ownline&&range.moveStart){var range2=context.$iframe[0].contentWindow.document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range2.text!=""){pre="\n"+pre;} |