js/admin.js   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 103
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 61
nc 1
nop 1
dl 0
loc 103
rs 8.2763
c 1
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B $(document).ready 0 88 2
A admin.js ➔ podlove_init_color_buttons 0 11 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
(function($) {
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
3
	function podlove_init_color_buttons() {
4
		$(".podlove_subscribe_button_color").spectrum({
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
5
			preferredFormat: 'hex',
6
			showInput: true,
7
			palette: [ '#599677' ],
8
			showPalette: true,
9
			showSelectionPalette: false,
10
			chooseText: i18n.select_color,
0 ignored issues
show
Bug introduced by
The variable i18n seems to be never declared. If this is a global, consider adding a /** global: i18n */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
11
			cancelText: i18n.cancel,
12
		});
13
	}
14
15
	$( document ).ready( function() {
16
17
		podlove_init_color_buttons();
18
19
		$("#Podlove_cover_image_select").on( 'click', function(event) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Unused Code introduced by
The parameter event 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...
20
			podlove_cover_image_selector = wp.media.frames.customHeader = wp.media( {
0 ignored issues
show
Bug introduced by
The variable podlove_cover_image_selector seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.podlove_cover_image_selector.
Loading history...
Bug introduced by
The variable wp seems to be never declared. If this is a global, consider adding a /** global: wp */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
21
					title: i18n.media_library,
0 ignored issues
show
Bug introduced by
The variable i18n seems to be never declared. If this is a global, consider adding a /** global: i18n */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
22
					library: {
23
						type: 'image'
24
					},
25
					button: {
26
						text: i18n.use_for
27
			   		},
28
			   		multiple: false
29
			    } );
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
30
			podlove_cover_image_selector.open();
31
32
			podlove_cover_image_selector.on('select', function() {
33
				var podcast_image_url = podlove_cover_image_selector.state().get('selection').first().toJSON().url;
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
34
				$("#podlove-button-cover").val(podcast_image_url);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
35
				$("#podlove-button-cover").trigger('change');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
36
			});
37
		} );
38
39
		$(document).ready(function () {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
40
		    podlove_init_color_buttons();
41
42
		    jQuery(document).on('widget-updated', podlove_init_color_buttons);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
43
		    jQuery(document).on('widget-added', podlove_init_color_buttons);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
44
45
		    // re-init after saving configs
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
46
		    jQuery(document).on('ajaxComplete', function(e){
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Unused Code introduced by
The parameter e 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...
47
		        podlove_init_color_buttons();
48
		    });
49
		})
50
51
		var feed_counter = 0;
52
		var source = $("#feed_line_template").html();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
53
54
		$(".add_feed").on( 'click', function () {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
55
			add_new_feed();
56
		} );
57
58
		if ( window.feeds !== undefined ) {
59
			$.each( feeds, function (index, feed) {
0 ignored issues
show
Bug introduced by
The variable feeds seems to be never declared. If this is a global, consider adding a /** global: feeds */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
60
				add_existing_feed(feed);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
61
			} );
62
		}
63
64
		function add_new_feed() {
65
			row = source.replace( /\{\{url\}\}/g, '' );
0 ignored issues
show
Bug introduced by
The variable row seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.row.
Loading history...
66
			row = row.replace( /\{\{itunesfeedid\}\}/g, '' );
67
			row = row.replace( /\{\{id\}\}/g, feed_counter );
68
69
			$("#feeds_table_body").append(row);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
70
71
			new_row = $("#feeds_table_body tr:last");
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Bug introduced by
The variable new_row seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.new_row.
Loading history...
72
			new_row.find("input:first").focus();
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
73
74
			$(".podlove-icon-remove").on( 'click', function () {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
75
				$(this).closest("tr").remove();
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
76
			} );
77
78
			feed_counter++;
79
		}
80
81
		function add_existing_feed( feed ) {
82
			row = source.replace( /\{\{url\}\}/g, feed.url );
0 ignored issues
show
Bug introduced by
The variable row seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.row.
Loading history...
83
			row = row.replace( /\{\{id\}\}/g, feed_counter );
84
			if ( feed.itunesfeedid == null ) {
0 ignored issues
show
Best Practice introduced by
Comparing feed.itunesfeedid to null using the == operator is not safe. Consider using === instead.
Loading history...
85
				row = row.replace( /\{\{itunesfeedid\}\}/g, '' );
86
			} else {
87
				row = row.replace( /\{\{itunesfeedid\}\}/g, feed.itunesfeedid );
88
			}
89
90
			$("#feeds_table_body").append(row);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
91
92
			new_row = $("#feeds_table_body tr:last");
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Bug introduced by
The variable new_row seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.new_row.
Loading history...
93
			new_row.find('select.podlove-media-format option[value="' + feed.format + '"]').attr('selected',true);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
94
95
			$(".podlove-icon-remove").on( 'click', function () {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
96
				$(this).closest("tr").remove();
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
97
			} );
98
99
			feed_counter++;
100
		}
101
102
	} );
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines before closing brace of nested function; 1 found
Loading history...
103
}(jQuery));