res/scite.text.selector.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 40
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 23
c 0
b 0
f 0
dl 0
loc 40
rs 10
mnd 2
bc 2
fnc 4
bpm 0.5
cpm 1.5
noi 1
1
/**
2
 * qTip Javascript handler for the scite extension
3
 */
4
5
/*global jQuery, mediaWiki */
6
/*global confirm */
7
8
( function ( $, mw ) {
0 ignored issues
show
Unused Code introduced by
The parameter mw is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
9
10
	'use strict';
11
12
	$( function ( $ ) {
13
14
		// http://jsfiddle.net/edelman/KcX6A/1506/
15
		var highlighter = {
16
			doSelectFor: function( selector ){
17
18
				var context = $( selector );
19
20
				var doc = document,
21
					element = context[0], range, selection;
22
23
				if (doc.body.createTextRange) {
24
					range = document.body.createTextRange();
25
					range.moveToElementText(element);
26
					range.select();
27
				} else if ( window.getSelection ) {
28
					selection = window.getSelection();
29
					range = document.createRange();
30
					range.selectNodeContents(element);
31
					selection.removeAllRanges();
32
					selection.addRange(range);
33
				}
34
			}
35
		};
36
37
		$( '.scite-highlight' ).on( 'click', function( event ) {
38
39
			highlighter.doSelectFor(
40
				$( this ).data( 'content-selector' )
41
			);
42
43
			event.preventDefault();
44
		} );
45
46
	} );
47
}( jQuery, mediaWiki ) );
48