r90479 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90478‎ | r90479 | r90480 >
Date:19:17, 20 June 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Got rewrite of EditSurface to render
Modified paths:
  • /trunk/parsers/wikidom/demos/es (added) (history)
  • /trunk/parsers/wikidom/demos/es/index.html (added) (history)
  • /trunk/parsers/wikidom/lib/es/es.Block.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Document.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Surface.css (added) (history)
  • /trunk/parsers/wikidom/lib/es/es.Surface.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.TextFlow.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Document.js
@@ -48,7 +48,8 @@
4949 /**
5050 * Adds a block to the document after an existing block.
5151 *
52 - * @param {Block} Block to insert
 52+ * @param block {Block} Block to insert
 53+ * @param before {Block} Block to insert before, if null then block will be inserted at the end
5354 */
5455 Document.prototype.insertBlockBefore = function( block, before ) {
5556 block.document = this;
Index: trunk/parsers/wikidom/lib/es/es.js
@@ -23,7 +23,7 @@
2424 var base = new src();
2525 for ( i in base ) {
2626 if ( typeof base[i] === 'function' ) {
27 - dst.prototype[i] = base.prototype[i];
 27+ dst.prototype[i] = base[i];
2828 }
2929 }
3030 }
Index: trunk/parsers/wikidom/lib/es/es.Surface.css
@@ -0,0 +1,49 @@
 2+body {
 3+ font-family: "Arial";
 4+ font-size: 0.8em;
 5+}
 6+
 7+.editSurface-container {
 8+ position: absolute;
 9+ left: 3%;
 10+ width: 45%;
 11+ border: solid 1px red;
 12+ cursor: text;
 13+}
 14+
 15+.editSurface-paragraph {
 16+ padding: 2em;
 17+}
 18+
 19+.editSurface-line {
 20+ display: inline-block;
 21+ height: 1.5em;
 22+ line-height: 1.5em;
 23+ cursor: text;
 24+ white-space: nowrap;
 25+}
 26+
 27+.editSurface-line.empty {
 28+ display: block;
 29+ width: 0px;
 30+}
 31+
 32+.editSurface-line .editSurface-whitespace {
 33+ color: #888888;
 34+ padding: 0 0.25em;
 35+}
 36+
 37+.editSurface-range {
 38+ display: none;
 39+ position: absolute;
 40+ background-color: Highlight;
 41+ cursor: text;
 42+}
 43+
 44+.editSurface-cursor {
 45+ position: absolute;
 46+ background-color: black;
 47+ width: 1px;
 48+ height: 1.5em;
 49+ display: none;
 50+}
Property changes on: trunk/parsers/wikidom/lib/es/es.Surface.css
___________________________________________________________________
Added: svn:eol-style
151 + native
Added: svn:mime-type
252 + text/plain
Index: trunk/parsers/wikidom/lib/es/es.Surface.js
@@ -7,6 +7,7 @@
88 function Surface( $container, document ) {
99 this.$container = $container;
1010 this.document = document;
 11+ this.reflow();
1112 }
1213
1314 /**
@@ -167,5 +168,9 @@
168169 * @param from Location: Where to start re-flowing from (optional)
169170 */
170171 Surface.prototype.reflow = function( from ) {
171 - //
 172+ this.$container.empty();
 173+ for ( var i = 0; i < this.document.blocks.length; i++ ) {
 174+ $block = $( '<div></div>' ).appendTo( this.$container );
 175+ this.document.blocks[i].renderContent( $block );
 176+ }
172177 };
Index: trunk/parsers/wikidom/lib/es/es.Block.js
@@ -3,7 +3,7 @@
44 * @returns {Block}
55 */
66 function Block() {
7 - this.document = document;
 7+ this.document = null;
88 }
99
1010 /**
@@ -12,6 +12,9 @@
1313 * @returns {Integer} Index of block
1414 */
1515 Block.prototype.index = function() {
 16+ if ( !this.document ) {
 17+ throw 'Missing document error. Block is not attached to a document.';
 18+ }
1619 return this.document.blocks.indexOf( this );
1720 };
1821
@@ -21,6 +24,9 @@
2225 * @returns {Block|Null} Block directly proceeding this one, or null if none exists
2326 */
2427 Block.prototype.nextBlock = function() {
 28+ if ( !this.document ) {
 29+ throw 'Missing document error. Block is not attached to a document.';
 30+ }
2531 var index = this.index() + 1;
2632 return this.document.blocks.length < index ? this.document.blocks[index] : null;
2733 };
@@ -31,6 +37,9 @@
3238 * @returns {Block|Null} Block directly preceding this one, or null if none exists
3339 */
3440 Block.prototype.previousBlock = function() {
 41+ if ( !this.document ) {
 42+ throw 'Missing document error. Block is not attached to a document.';
 43+ }
3544 var index = this.index() - 1;
3645 return index >= 0 ? this.document.blocks[index] : null;
3746 };
Index: trunk/parsers/wikidom/lib/es/es.TextFlow.js
@@ -8,7 +8,7 @@
99 TextFlow.prototype.render = function( $container, text ) {
1010 //console.time( 'TextFlow.render' );
1111 var metrics = [],
12 - $ruler = $( '<div class="editSurface-line"></div>' ).appendTo( $(this) ),
 12+ $ruler = $( '<div class="editSurface-line"></div>' ).appendTo( $container ),
1313 $line = $( '<div class="editSurface-line"></div>' ),
1414 lines = this.getLines( this.getWords( text, $ruler[0] ), $ruler.innerWidth() );
1515 $container.empty();
@@ -20,14 +20,14 @@
2121 $container.append( $line.clone().html( lines[i].html ) );
2222 }
2323 }
24 - //console.timeEnd( 'TextFlow.render' );
25 - return metrics;
 24+ console.timeEnd( 'TextFlow.render' );
 25+ //return metrics;
2626 };
2727
2828 TextFlow.prototype.getWord = function( text, ruler ) {
2929 var word = {
3030 'text': text,
31 - 'html': word.text
 31+ 'html': text
3232 .replace( /&/g, '&amp;' )
3333 .replace( / /g, '&nbsp;' )
3434 .replace( /</g, '&lt;' )
@@ -35,7 +35,7 @@
3636 .replace( /'/g, '&apos;' )
3737 .replace( /"/g, '&quot;' )
3838 .replace( /\n/g, '<span class="editSurface-whitespace">\\n</span>' )
39 - .replace( /\t/g, '<span class="editSurface-whitespace">\\t</span>' );
 39+ .replace( /\t/g, '<span class="editSurface-whitespace">\\t</span>' )
4040 };
4141 ruler.innerHTML = word.html;
4242 word.width = ruler.clientWidth;
Index: trunk/parsers/wikidom/demos/es/index.html
@@ -0,0 +1,45 @@
 2+<!doctype html>
 3+
 4+<html>
 5+ <head>
 6+ <title>EditSurface Demo</title>
 7+ <link rel="stylesheet" href="../../lib/es/es.Surface.css">
 8+ </head>
 9+ <body>
 10+ <h1>EditSurface Demo</h1>
 11+ <div id="es"></div>
 12+
 13+ <!-- EditSurface -->
 14+ <script type="text/javascript" src="../../lib/jquery.js"></script>
 15+ <script type="text/javascript" src="../../lib/es/es.js"></script>
 16+ <script type="text/javascript" src="../../lib/es/es.Block.js"></script>
 17+ <script type="text/javascript" src="../../lib/es/es.Document.js"></script>
 18+ <script type="text/javascript" src="../../lib/es/es.Surface.js"></script>
 19+ <script type="text/javascript" src="../../lib/es/es.TextFlow.js"></script>
 20+ <script type="text/javascript" src="../../lib/es/es.ParagraphBlock.js"></script>
 21+
 22+ <!-- Demo -->
 23+ <script>
 24+ $(document).ready( function() {
 25+ var doc = new Document([
 26+ new ParagraphBlock([
 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." },
 35+ { 'text': "Text might have \ttabs\t in it too." }
 36+ ])
 37+ ]);
 38+ var surface = new Surface( $('#es'), doc );
 39+
 40+ $(window).resize( function() {
 41+ surface.reflow();
 42+ } );
 43+ } );
 44+ </script>
 45+ </body>
 46+</html>
Property changes on: trunk/parsers/wikidom/demos/es/index.html
___________________________________________________________________
Added: svn:mime-type
147 + text/plain

Status & tagging log