http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89837

Revision: 89837
Author:   tparscal
Date:     2011-06-10 18:24:18 +0000 (Fri, 10 Jun 2011)
Log Message:
-----------
Added support for embedded objects - currently line breaks are rendered as 
return symbols.

Modified Paths:
--------------
    trunk/parsers/wikidom/demos/surface/index.html
    trunk/parsers/wikidom/lib/jquery.editSurface.css
    trunk/parsers/wikidom/lib/jquery.editSurface.js
    trunk/parsers/wikidom/lib/jquery.flow.js

Modified: trunk/parsers/wikidom/demos/surface/index.html
===================================================================
--- trunk/parsers/wikidom/demos/surface/index.html      2011-06-10 17:57:35 UTC 
(rev 89836)
+++ trunk/parsers/wikidom/demos/surface/index.html      2011-06-10 18:24:18 UTC 
(rev 89837)
@@ -19,21 +19,18 @@
                <!-- Demo -->
                <script>
                        $(document).ready( function() {
-                               var 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.",
-                                       "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.",
-                                       "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.",
-                                       "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.",
-                                       "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.",
-                                       "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.",
-                                       "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.",
-                                       
"OccasionallyThereAreWordsThatAreSoLongTheyExceedTheWidthOfTheLineAndEndUpWrappingBetweenMultipleLines.",
-                               ].join( ' ' );
                                $( '#es' ).editSurface( {
                                        'document': { 'blocks': [ {
                                                'type': 'paragraph',
                                                'lines': [
-                                                       { 'text': text }
+                                                       { '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." },
+                                                       { '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." },
+                                                       { '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." },
+                                                       { '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." },
+                                                       { '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." },
+                                                       { '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." 
},
+                                                       { '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." },
+                                                       { 'text': 
"OccasionallyThereAreWordsThatAreSoLongTheyExceedTheWidthOfTheLineAndEndUpWrappingBetweenMultipleLines."
 }
                                                ]
                                        } ] }
                                } );

Modified: trunk/parsers/wikidom/lib/jquery.editSurface.css
===================================================================
--- trunk/parsers/wikidom/lib/jquery.editSurface.css    2011-06-10 17:57:35 UTC 
(rev 89836)
+++ trunk/parsers/wikidom/lib/jquery.editSurface.css    2011-06-10 18:24:18 UTC 
(rev 89837)
@@ -41,6 +41,10 @@
        display: block;
        width: 0px;
 }
+.editSurface-line .invisible {
+       color: green;
+       padding: 0 0.25em;
+}
 
 .editSurface-range {
        display: none;

Modified: trunk/parsers/wikidom/lib/jquery.editSurface.js
===================================================================
--- trunk/parsers/wikidom/lib/jquery.editSurface.js     2011-06-10 17:57:35 UTC 
(rev 89836)
+++ trunk/parsers/wikidom/lib/jquery.editSurface.js     2011-06-10 18:24:18 UTC 
(rev 89837)
@@ -18,14 +18,29 @@
                                + '<div class="editSurface-range"></div>'
                                + '<div class="editSurface-range"></div>');
        
-       $(document)
-               .mousedown( function( e ) {
+       // Shortcuts
+       var $document = $this.find( '.editSurface-document' );
+       var ranges = {
+               '$all': $( '.editSurface-range' ),
+               '$first': $( '.editSurface-range:eq(0)' ),
+               '$fill': $( '.editSurface-range:eq(1)' ),
+               '$last': $( '.editSurface-range:eq(2)' )
+       };
+       
+       // Events
+       $(document).bind( {
+               'mousedown': function( e ) {
                        var $target = $( e.target );
                        if ( $target.is( '.editSurface-paragraph' ) ) {
                                $target = $target.children().closestToOffset( { 
'left': e.pageX, 'top': e.pageY } );
                        }
                        if ( !$target.is( '.editSurface-line' ) ) {
-                               return;
+                               var $line = $target.closest( 
'.editSurface-line' );
+                               if ( $line.length ) {
+                                       $target = $line;
+                               } else {
+                                       return;
+                               }
                        }
                        sel = {
                                'active': true,
@@ -45,8 +60,8 @@
                        }
                        e.preventDefault();
                        return false;
-               } )
-               .mouseup( function( e ) {
+               },
+               'mouseup': function( e ) {
                        if ( sel.active ) {
                                if ( !sel.from || !sel.to
                                                || ( sel.from.line === 
sel.to.line && sel.from.char === sel.to.char ) ) {
@@ -61,8 +76,8 @@
                                }
                                sel.active = false;
                        }
-               } )
-               .mousemove( function( e ) {
+               },
+               'mousemove': function( e ) {
                        if ( sel.active ) {
                                var $target = $( e.target );
                                if ( !$target.is( '.editSurface-line' ) ) {
@@ -86,17 +101,9 @@
                                cursor.hide();
                                drawSelection( sel.start.$target.parent() );
                        }
-               } );
+               }
+       } );
        
-       // Shortcuts
-       var $document = $this.find( '.editSurface-document' );
-       var ranges = {
-               '$all': $( '.editSurface-range' ),
-               '$first': $( '.editSurface-range:eq(0)' ),
-               '$fill': $( '.editSurface-range:eq(1)' ),
-               '$last': $( '.editSurface-range:eq(2)' )
-       };
-       
        // Functions
        function getSelectionText() {
                var text;
@@ -124,12 +131,11 @@
                        l,
                        r = 0,
                        cur = x - offset.left;
-               for ( var w = 0, eol = line.metrics.length; w <= eol; w++ ) {
-                       var wi = Math.min( w, eol - 1 );
+               for ( var w = 0, eol = line.metrics.length - 1; w <= eol; w++ ) 
{
                        l = r;
-                       r += line.metrics[wi];
+                       r += line.metrics[w];
                        if ( ( w === 0 && cur <= l ) || ( cur >= l && cur <= r 
) || ( w === eol ) ) {
-                               var word = line.words[wi],
+                               var word = line.words[w],
                                        a,
                                        b = { 'l': l, 'c': l, 'r': l };
                                for ( var c = 0, eow = word.metrics.length; c 
<= eow; c++ ) {
@@ -145,7 +151,7 @@
                                                        'char': word.offset + 
Math.min( c, word.text.length - 1 ),
                                                        'word': word.index,
                                                        'line': line.index,
-                                                       'x': offset.left + ( c 
< eow ? b.l : a.l ),
+                                                       'x': offset.left + b.l,
                                                        'top': offset.top,
                                                        'bottom': offset.top + 
height,
                                                        'height': height
@@ -228,7 +234,7 @@
                for ( var i = 0; i < paragraph.lines.length; i++ ) {
                        lines.push( paragraph.lines[i].text );
                }
-               $paragraph.flow( lines.join( ' ' ) );
+               $paragraph.flow( lines.join( '\n' ) );
        }
        
        function update() {

Modified: trunk/parsers/wikidom/lib/jquery.flow.js
===================================================================
--- trunk/parsers/wikidom/lib/jquery.flow.js    2011-06-10 17:57:35 UTC (rev 
89836)
+++ trunk/parsers/wikidom/lib/jquery.flow.js    2011-06-10 18:24:18 UTC (rev 
89837)
@@ -76,7 +76,8 @@
                                                .replace( '<', '&lt;' )
                                                .replace( '>', '&gt;' )
                                                .replace( '\'', '&apos;' )
-                                               .replace( '"', '&quot;' );
+                                               .replace( '"', '&quot;' )
+                                               .replace( '\n', '<span 
class="invisible">&#9166;</span>' );
                                word.html += charHtml;
                                if ( $.flow.charCache[char] === undefined ) {
                                        // Cache miss


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to