r100767 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100766‎ | r100767 | r100768 >
Date:00:20, 26 October 2011
Author:inez
Status:deferred
Tags:
Comment:
Beta support for auto scrolling up when mouse is above the window
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
@@ -6,6 +6,7 @@
77 */
88 es.SurfaceView = function( $container, model ) {
99 this.$ = $container.addClass( 'editSurface' );
 10+ this.$window = $( window );
1011 this.model = model;
1112
1213 // Initialize document view
@@ -96,11 +97,11 @@
9798 this.dimensions = {
9899 width: this.$.width(),
99100 height: this.$.height(),
100 - scrollTop: $(window).scrollTop()
 101+ scrollTop: this.$window.scrollTop()
101102 };
102103
103104 // Re-render when resizing horizontally
104 - $( window ).resize( function() {
 105+ this.$window.resize( function() {
105106 surfaceView.hideCursor();
106107 surfaceView.dimensions.height = surfaceView.$.height();
107108 var width = surfaceView.$.width();
@@ -110,8 +111,8 @@
111112 }
112113 } );
113114
114 - $( window ).scroll( function() {
115 - surfaceView.dimensions.scrollTop = $( window ).scrollTop()
 115+ this.$window.scroll( function() {
 116+ surfaceView.dimensions.scrollTop = surfaceView.$window.scrollTop();
116117 } );
117118 };
118119
@@ -203,8 +204,13 @@
204205 es.SurfaceView.prototype.onMouseMove = function( e ) {
205206 if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) {
206207
207 - if ( e.pageY - $(window).scrollTop() <= window.innerHeight ) {
 208+
 209+ if ( e.pageY - $(window).scrollTop() < 0 ) {
 210+ lastEventPosition = es.Position.newFromEventPagePosition( e );
208211 stopScrolling();
 212+ startScrolling(true);
 213+ } else if ( e.pageY - $(window).scrollTop() <= window.innerHeight ) {
 214+ stopScrolling();
209215 } else {
210216 lastEventPosition = es.Position.newFromEventPagePosition( e );
211217 stopScrolling();
@@ -347,16 +353,13 @@
348354 }
349355
350356 // Auto scroll to cursor
351 - var $window = $(window),
352 - scrollTop = $window.scrollTop(),
353 - windowHeight = $window.height(),
354 - inputTop = this.$input.offset().top,
 357+ var inputTop = this.$input.offset().top,
355358 inputBottom = inputTop + this.$input.height();
356 - if (inputTop < scrollTop) {
357 - $window.scrollTop(inputTop);
358 - } else if (inputBottom > (scrollTop + windowHeight)) {
359 - $window.scrollTop(inputBottom - windowHeight);
360 - }
 359+ if ( inputTop < this.dimensions.scrollTop ) {
 360+ this.$window.scrollTop( inputTop );
 361+ } else if ( inputBottom > ( this.dimensions.scrollTop + this.dimensions.height ) ) {
 362+ this.$window.scrollTop( inputBottom - this.dimensions.height );
 363+ }
361364
362365 return;
363366 };
@@ -374,7 +377,7 @@
375378
376379
377380
378 -var scrollStep = function() {
 381+var scrollStepDown = function() {
379382 lastEventPosition.top += 20;
380383 lastEventPosition.bottom += 20;
381384
@@ -385,10 +388,29 @@
386389
387390 $(window).scrollTop( $(window).scrollTop() + 20 );
388391 };
 392+
 393+var scrollStepUp = function() {
 394+ lastEventPosition.top -= 20;
 395+ lastEventPosition.bottom -= 20;
 396+
 397+ fakelastEventPosition = new es.Position(lastEventPosition.left, lastEventPosition.top, lastEventPosition.bottom);
 398+
 399+ surfaceView.selection.to = surfaceView.documentView.getOffsetFromPosition( fakelastEventPosition );
 400+ surfaceView.drawSelection();
 401+
 402+ $(window).scrollTop( $(window).scrollTop() - 20 );
 403+};
 404+
389405 var scrollInterval = null;
390 -var startScrolling = function( interval ) {
391 - scrollStep();
392 - scrollInterval = setInterval(scrollStep, interval || 50);
 406+var startScrolling = function( up ) {
 407+ if ( up ) {
 408+ console.log('t');
 409+ scrollStepUp();
 410+ scrollInterval = setInterval(scrollStepUp, 50);
 411+ } else {
 412+ scrollStepDown();
 413+ scrollInterval = setInterval(scrollStepDown, 50);
 414+ }
393415 };
394416 var stopScrolling = function() {
395417 clearInterval( scrollInterval );

Status & tagging log