r112148 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112147‎ | r112148 | r112149 >
Date:21:14, 22 February 2012
Author:inez
Status:deferred
Tags:
Comment:
Simple and temporary playground to work on retrieving content changes from content editable element.
Modified paths:
  • /trunk/extensions/VisualEditor/playground (added) (history)
  • /trunk/extensions/VisualEditor/playground/index.html (added) (history)
  • /trunk/extensions/VisualEditor/playground/playground.js (added) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/playground/playground.js
@@ -0,0 +1,79 @@
 2+app = function () {
 3+ var _this = this,
 4+ $document = $( document );
 5+
 6+ this.$editor = $('#editor');
 7+
 8+ this.$editor.bind( {
 9+ 'focus': function( e ) {
 10+ $document.unbind( '.surfaceView' );
 11+ $document.bind( {
 12+ 'keydown.surfaceView': function( e ) {
 13+ return _this.onKeyDown( e );
 14+ }
 15+ } );
 16+ },
 17+ 'blur': function( e ) {
 18+ $document.unbind( '.surfaceView' );
 19+ }
 20+ } );
 21+
 22+ this.$editor.mousedown( function(e) {
 23+ return _this.onMouseDown( e );
 24+ } );
 25+
 26+ // Set initial content for the "editor"
 27+ this.$editor.html("<b>Lorem Ipsum is simply dummy text</b> of the printing and typesetting industry. <b>Lorem Ipsum has been the <i>industry's</i> standard</b> dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it <u>to <b>make <i>a type</i> specimen</b> book.</u>");
 28+
 29+ this.prevText = app.getDOMText(this.$editor[0]);
 30+
 31+ setInterval(function() {
 32+ _this.loopFunc();
 33+ }, 200);
 34+};
 35+
 36+app.prototype.onKeyDown = function() {
 37+ console.log("onKeyDown");
 38+};
 39+
 40+app.prototype.onMouseDown = function() {
 41+ console.log("onMouseDown");
 42+};
 43+
 44+app.prototype.loopFunc = function() {
 45+ var text = app.getDOMText(this.$editor[0]);
 46+
 47+ if(text != this.prevText) {
 48+ console.log(text);
 49+
 50+ this.prevText = text;
 51+ }
 52+};
 53+
 54+app.getDOMText = function( elem ) {
 55+ var nodeType = elem.nodeType,
 56+ ret = '';
 57+
 58+ if ( nodeType === 1 || nodeType === 9 ) {
 59+ // Use textContent || innerText for elements
 60+ if ( typeof elem.textContent === 'string' ) {
 61+ return elem.textContent;
 62+ } else if ( typeof elem.innerText === 'string' ) {
 63+ // Replace IE's carriage returns
 64+ return elem.innerText.replace( /\r\n/g, '' );
 65+ } else {
 66+ // Traverse it's children
 67+ for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
 68+ ret += app.getDOMText( elem );
 69+ }
 70+ }
 71+ } else if ( nodeType === 3 || nodeType === 4 ) {
 72+ return elem.nodeValue;
 73+ }
 74+
 75+ return ret;
 76+};
 77+
 78+$(function() {
 79+ new app();
 80+});
\ No newline at end of file
Index: trunk/extensions/VisualEditor/playground/index.html
@@ -0,0 +1,20 @@
 2+<!DOCTYPE html>
 3+
 4+<html>
 5+ <head>
 6+ <title>Playground</title>
 7+ <style>
 8+ #editor {
 9+ width: 300px;
 10+ height: 300px;
 11+ border: solid 1px;
 12+ }
 13+ </style>
 14+ <script src="../modules/jquery/jquery.js"></script>
 15+ <script src="playground.js"></script>
 16+ </head>
 17+ <body>
 18+ <div contenteditable="true" id="editor">
 19+ </div>
 20+ </body>
 21+</html>
Property changes on: trunk/extensions/VisualEditor/playground/index.html
___________________________________________________________________
Added: svn:mime-type
122 + text/plain

Status & tagging log