r89837 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89836‎ | r89837 | r89838 >
Date:18:24, 10 June 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added support for embedded objects - currently line breaks are rendered as return symbols.
Modified paths:
  • /trunk/parsers/wikidom/demos/surface/index.html (modified) (history)
  • /trunk/parsers/wikidom/lib/jquery.editSurface.css (modified) (history)
  • /trunk/parsers/wikidom/lib/jquery.editSurface.js (modified) (history)
  • /trunk/parsers/wikidom/lib/jquery.flow.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/jquery.flow.js
@@ -76,7 +76,8 @@
7777 .replace( '<', '&lt;' )
7878 .replace( '>', '&gt;' )
7979 .replace( '\'', '&apos;' )
80 - .replace( '"', '&quot;' );
 80+ .replace( '"', '&quot;' )
 81+ .replace( '\n', '<span class="invisible">&#9166;</span>' );
8182 word.html += charHtml;
8283 if ( $.flow.charCache[char] === undefined ) {
8384 // Cache miss
Index: trunk/parsers/wikidom/lib/jquery.editSurface.css
@@ -41,6 +41,10 @@
4242 display: block;
4343 width: 0px;
4444 }
 45+.editSurface-line .invisible {
 46+ color: green;
 47+ padding: 0 0.25em;
 48+}
4549
4650 .editSurface-range {
4751 display: none;
Index: trunk/parsers/wikidom/lib/jquery.editSurface.js
@@ -18,14 +18,29 @@
1919 + '<div class="editSurface-range"></div>'
2020 + '<div class="editSurface-range"></div>');
2121
22 - $(document)
23 - .mousedown( function( e ) {
 22+ // Shortcuts
 23+ var $document = $this.find( '.editSurface-document' );
 24+ var ranges = {
 25+ '$all': $( '.editSurface-range' ),
 26+ '$first': $( '.editSurface-range:eq(0)' ),
 27+ '$fill': $( '.editSurface-range:eq(1)' ),
 28+ '$last': $( '.editSurface-range:eq(2)' )
 29+ };
 30+
 31+ // Events
 32+ $(document).bind( {
 33+ 'mousedown': function( e ) {
2434 var $target = $( e.target );
2535 if ( $target.is( '.editSurface-paragraph' ) ) {
2636 $target = $target.children().closestToOffset( { 'left': e.pageX, 'top': e.pageY } );
2737 }
2838 if ( !$target.is( '.editSurface-line' ) ) {
29 - return;
 39+ var $line = $target.closest( '.editSurface-line' );
 40+ if ( $line.length ) {
 41+ $target = $line;
 42+ } else {
 43+ return;
 44+ }
3045 }
3146 sel = {
3247 'active': true,
@@ -45,8 +60,8 @@
4661 }
4762 e.preventDefault();
4863 return false;
49 - } )
50 - .mouseup( function( e ) {
 64+ },
 65+ 'mouseup': function( e ) {
5166 if ( sel.active ) {
5267 if ( !sel.from || !sel.to
5368 || ( sel.from.line === sel.to.line && sel.from.char === sel.to.char ) ) {
@@ -61,8 +76,8 @@
6277 }
6378 sel.active = false;
6479 }
65 - } )
66 - .mousemove( function( e ) {
 80+ },
 81+ 'mousemove': function( e ) {
6782 if ( sel.active ) {
6883 var $target = $( e.target );
6984 if ( !$target.is( '.editSurface-line' ) ) {
@@ -86,17 +101,9 @@
87102 cursor.hide();
88103 drawSelection( sel.start.$target.parent() );
89104 }
90 - } );
 105+ }
 106+ } );
91107
92 - // Shortcuts
93 - var $document = $this.find( '.editSurface-document' );
94 - var ranges = {
95 - '$all': $( '.editSurface-range' ),
96 - '$first': $( '.editSurface-range:eq(0)' ),
97 - '$fill': $( '.editSurface-range:eq(1)' ),
98 - '$last': $( '.editSurface-range:eq(2)' )
99 - };
100 -
101108 // Functions
102109 function getSelectionText() {
103110 var text;
@@ -124,12 +131,11 @@
125132 l,
126133 r = 0,
127134 cur = x - offset.left;
128 - for ( var w = 0, eol = line.metrics.length; w <= eol; w++ ) {
129 - var wi = Math.min( w, eol - 1 );
 135+ for ( var w = 0, eol = line.metrics.length - 1; w <= eol; w++ ) {
130136 l = r;
131 - r += line.metrics[wi];
 137+ r += line.metrics[w];
132138 if ( ( w === 0 && cur <= l ) || ( cur >= l && cur <= r ) || ( w === eol ) ) {
133 - var word = line.words[wi],
 139+ var word = line.words[w],
134140 a,
135141 b = { 'l': l, 'c': l, 'r': l };
136142 for ( var c = 0, eow = word.metrics.length; c <= eow; c++ ) {
@@ -145,7 +151,7 @@
146152 'char': word.offset + Math.min( c, word.text.length - 1 ),
147153 'word': word.index,
148154 'line': line.index,
149 - 'x': offset.left + ( c < eow ? b.l : a.l ),
 155+ 'x': offset.left + b.l,
150156 'top': offset.top,
151157 'bottom': offset.top + height,
152158 'height': height
@@ -228,7 +234,7 @@
229235 for ( var i = 0; i < paragraph.lines.length; i++ ) {
230236 lines.push( paragraph.lines[i].text );
231237 }
232 - $paragraph.flow( lines.join( ' ' ) );
 238+ $paragraph.flow( lines.join( '\n' ) );
233239 }
234240
235241 function update() {
Index: trunk/parsers/wikidom/demos/surface/index.html
@@ -19,21 +19,18 @@
2020 <!-- Demo -->
2121 <script>
2222 $(document).ready( function() {
23 - var text = [
24 - "In text display, line wrap is the feature of continuing on a new line when a line is full, such that each line fits in the viewable window, allowing text to be read from top to bottom without any horizontal scrolling.",
25 - "Word wrap is the additional feature of most text editors, word processors, and web browsers, of breaking lines between and not within words, except when a single word is longer than a line.",
26 - "It is usually done on the fly when viewing or printing a document, so no line break code is manually entered, or stored.[citation needed] If the user changes the margins, the editor will either automatically reposition the line breaks to ensure that all the text will \"flow\" within the margins and remain visible, or provide the typist some convenient way to reposition the line breaks.",
27 - "A soft return is the break resulting from line wrap or word wrap, whereas a hard return is an intentional break, creating a new paragraph.",
28 - "The soft returns are usually placed after the ends of complete words, or after the punctuation that follows complete words. However, word wrap may also occur following a hyphen.",
29 - "Word wrap following hyphens is sometimes not desired, and can be avoided by using a so-called non-breaking hyphen instead of a regular hyphen. On the other hand, when using word processors, invisible hyphens, called soft hyphens, can also be inserted inside words so that word wrap can occur following the soft hyphens.",
30 - "Sometimes, word wrap is not desirable between words. In such cases, word wrap can usually be avoided by using a hard space or non-breaking space between the words, instead of regular spaces.",
31 - "OccasionallyThereAreWordsThatAreSoLongTheyExceedTheWidthOfTheLineAndEndUpWrappingBetweenMultipleLines.",
32 - ].join( ' ' );
3323 $( '#es' ).editSurface( {
3424 'document': { 'blocks': [ {
3525 'type': 'paragraph',
3626 'lines': [
37 - { 'text': text }
 27+ { 'text': "In text display, line wrap is the feature of continuing on a new line when a line is full, such that each line fits in the viewable window, allowing text to be read from top to bottom without any horizontal scrolling." },
 28+ { 'text': "Word wrap is the additional feature of most text editors, word processors, and web browsers, of breaking lines between and not within words, except when a single word is longer than a line." },
 29+ { 'text': "It is usually done on the fly when viewing or printing a document, so no line break code is manually entered, or stored.[citation needed] If the user changes the margins, the editor will either automatically reposition the line breaks to ensure that all the text will \"flow\" within the margins and remain visible, or provide the typist some convenient way to reposition the line breaks." },
 30+ { 'text': "A soft return is the break resulting from line wrap or word wrap, whereas a hard return is an intentional break, creating a new paragraph." },
 31+ { 'text': "The soft returns are usually placed after the ends of complete words, or after the punctuation that follows complete words. However, word wrap may also occur following a hyphen." },
 32+ { 'text': "Word wrap following hyphens is sometimes not desired, and can be avoided by using a so-called non-breaking hyphen instead of a regular hyphen. On the other hand, when using word processors, invisible hyphens, called soft hyphens, can also be inserted inside words so that word wrap can occur following the soft hyphens." },
 33+ { 'text': "Sometimes, word wrap is not desirable between words. In such cases, word wrap can usually be avoided by using a hard space or non-breaking space between the words, instead of regular spaces." },
 34+ { 'text': "OccasionallyThereAreWordsThatAreSoLongTheyExceedTheWidthOfTheLineAndEndUpWrappingBetweenMultipleLines." }
3835 ]
3936 } ] }
4037 } );

Status & tagging log