Test Setup Failed
Pull Request — develop (#1764)
by Aristeides
02:01
created

modules/webfonts/kirki-webfonts.js   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 30
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 4
c 1
b 0
f 0
nc 1
mnd 0
bc 4
fnc 4
dl 0
loc 30
rs 10
bpm 1
cpm 1
noi 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A $(document).ready 0 19 1
1
/* global kirkiWebfonts, WebFont */
2
3
// Asyncronously add webfontloader.
4
( function( document ) {
5
	var wf      = document.createElement( 'script' ),
0 ignored issues
show
Coding Style introduced by
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
6
	    scripts = document.scripts[0];
7
8
	wf.src   = 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js';
9
	wf.id    = 'webfontloader',
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
	wf.async = true;
11
12
	scripts.parentNode.insertBefore( wf, scripts );
13
} )( document );
14
15
jQuery( document ).ready( function() {
16
	var script  = document.querySelector( '#webfontloader' ),
0 ignored issues
show
Coding Style introduced by
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
17
	    subsets = ['cyrillic', 'cyrillic-ext', 'devanagari', 'greek', 'greek-ext', 'khmer', 'latin', 'latin-ext', 'vietnamese', 'hebrew', 'arabic', 'bengali', 'gujarati', 'tamil', 'telugu', 'thai'];
18
19
	// Check when the webfontloader finishes loading.
20
	script.addEventListener( 'load', function() {
21
22
		// Loop fonts.
23
		_.each( kirkiWebfonts, function( weights, family ) {
24
25
			// Add font.
26
			WebFont.load( {
27
				google:{
28
					families: [ family + ':' + weights.join( ',' ) + subsets.join( ',' ) ]
29
				}
30
			} );
31
		} );
32
	} );
33
} );
34