summaryrefslogtreecommitdiff
blob: bb1a49b83ecd73c4ab1632c95c7c194f010d9822 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*!
 * Translate editor shortcuts
 */
( function ( $, mw ) {
	'use strict';

	var translateEditorShortcuts = {
		showShortcuts: function () {
			var editorOffset, minTop, maxTop, maxLeft, middle, rtl;

			// Any better way?
			rtl = $( 'body' ).is( '.rtl' );

			editorOffset = this.$editor.offset();
			minTop = editorOffset.top;
			maxTop = minTop + this.$editor.outerHeight();
			middle = minTop + ( maxTop - minTop ) / 2;

			maxLeft = editorOffset.left;
			if ( !rtl ) {
				maxLeft += this.$editor.outerWidth();
			}

			this.hideShortcuts();

			// For scrolling up and down
			$( '<div>' )
				.text( '↑' )
				.addClass( 'shortcut-popup' )
				.appendTo( 'body' )
				.offset( { top: middle - 10, left: maxLeft - 10 } );

			$( '<div>' )
				.text( '↓' )
				.addClass( 'shortcut-popup' )
				.appendTo( 'body' )
				.offset( { top: middle + 10, left: maxLeft - 10 } );

			this.$editor.find( '.shortcut-activated:visible' ).each( function ( index ) {
				var $this = $( this ),
					offset = $this.offset();

				if ( rtl ) {
					offset.left += $this.outerWidth();
				}

				// Let's not have numbers appear outside the editor over other content
				if ( offset.top > maxTop || offset.top < minTop ) {
					return;
				}

				$( '<div>' )
					.text( index + 1 )
					.addClass( 'shortcut-popup' )
					.appendTo( 'body' )
					.offset( { top: offset.top - 10, left: offset.left - 10 } );
			} );
		},

		hideShortcuts: function () {
			$( '.shortcut-popup' ).remove();
		}
	};

	mw.translate.editor = mw.translate.editor || {};
	$.extend( mw.translate.editor, translateEditorShortcuts );

}( jQuery, mediaWiki ) );