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

Revision: 89787
Author:   tparscal
Date:     2011-06-09 18:54:44 +0000 (Thu, 09 Jun 2011)
Log Message:
-----------
Improved accuracy by placing each measurement on it's own line.

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

Modified: trunk/parsers/wikidom/demos/surface/index.html
===================================================================
--- trunk/parsers/wikidom/demos/surface/index.html      2011-06-09 18:43:00 UTC 
(rev 89786)
+++ trunk/parsers/wikidom/demos/surface/index.html      2011-06-09 18:54:44 UTC 
(rev 89787)
@@ -28,7 +28,7 @@
                                        "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( ' ' );
+                               ].join( '\n\n' );
                                $( '#es' ).editSurface( {
                                        'document': { 'blocks': [ {
                                                'type': 'paragraph',

Modified: trunk/parsers/wikidom/lib/jquery.editSurface.css
===================================================================
--- trunk/parsers/wikidom/lib/jquery.editSurface.css    2011-06-09 18:43:00 UTC 
(rev 89786)
+++ trunk/parsers/wikidom/lib/jquery.editSurface.css    2011-06-09 18:54:44 UTC 
(rev 89787)
@@ -1,12 +1,12 @@
 body {
        font-family: "Arial";
-       font-size: 1em;
+       font-size: 0.8em;
 }
 
 #selection {
        position: absolute;
-       left: 26em;
-       width: 24em;
+       right: 3%;
+       width: 45%;
        border: solid 1px Highlight;
        line-height: 1.5em;
        cursor: text;
@@ -19,8 +19,8 @@
 
 .editSurface-container {
        position: absolute;
-       left: 1em;
-       width: 24em;
+       left: 3%;
+       width: 45%;
        border: solid 1px red;
        cursor: text;
 }
@@ -37,6 +37,10 @@
        white-space: nowrap;
        background-color: rgba(204, 204, 204, 0.25);
 }
+.editSurface-line.empty {
+       display: block;
+       width: 0px;
+}
 
 .editSurface-range {
        display: none;

Modified: trunk/parsers/wikidom/lib/jquery.flow-a.js
===================================================================
--- trunk/parsers/wikidom/lib/jquery.flow-a.js  2011-06-09 18:43:00 UTC (rev 
89786)
+++ trunk/parsers/wikidom/lib/jquery.flow-a.js  2011-06-09 18:54:44 UTC (rev 
89787)
@@ -2,11 +2,14 @@
  * Flow jQuery plugin
  */
 
-$.flow = { 'widthCache': {} };
+$.flow = { 'cache': { 'chars': {}, 'words': {} } };
 
 $.fn.flow = function( text ) {
-       var lineLimit = $(this).innerWidth();
+       console.time( 'flow' );
        
+       var $this = $(this);
+       var lineLimit = $this.innerWidth();
+       
        // Wordify
        var words = [],
                word = { 'text': '', 'width': 0, 'metrics': [] };
@@ -24,11 +27,12 @@
                        .replace( '"', '"' );
         // Measurement
                var charWidth;
-               if ( typeof $.flow.widthCache[char] === 'undefined' ) {
-                       charWidth = $.flow.widthCache[char] =
-                               $( '<span>' + charHtml + '</span>' ).appendTo( 
$(this) ).width();
+               if ( typeof $.flow.cache.chars[char] === 'undefined' ) {
+                       charWidth = $.flow.cache.chars[char] =
+                               $( '<div class="editSurface-line">' + charHtml 
+ '</div>' )
+                                       .appendTo( $this ).width();
                } else {
-                       charWidth = $.flow.widthCache[char];
+                       charWidth = $.flow.cache.chars[char];
                }
                // Virtual boundary
                if ( word.width + charWidth >= lineLimit ) {
@@ -72,7 +76,7 @@
        }
        
        // Flow
-       $(this).empty();
+       $this.empty();
        for ( var i = 0; i < lines.length; i++ ) {
                var $line = $( '<div class="editSurface-line"></div>' )
                        .data( 'metrics', lines[i].metrics )
@@ -84,8 +88,10 @@
                        $line.html( '&nbsp;' );
                        $line.addClass( 'empty' );
                }
-               $(this).append( $line );
+               $this.append( $line );
        }
+
+       console.timeEnd( 'flow' );
        
-       return $(this);
+       return $this;
 };
\ No newline at end of file


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

Reply via email to