Passed
Push — master ( f566f3...fdd3db )
by Paul
04:45
created

+/scripts/site-reviews-admin.js   A

Complexity

Total Complexity 13
Complexity/F 1.44

Size

Lines of Code 72
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 2
dl 0
loc 72
rs 10
c 1
b 0
f 0
wmc 13
mnd 1
bc 12
fnc 9
bpm 1.3333
cpm 1.4443
noi 0
1
/** global: GLSR, site_reviews, site_reviews_pointers, wp, x */
2
3
x( function()
4
{
5
	x('.glsr-button-reset').on( 'click', function() {
6
		return confirm( site_reviews.are_you_sure );
7
	});
8
9
	var GLSR_textarea = x( '#contentdiv > textarea' );
10
	if( GLSR_textarea.length ) {
11
		GLSR.textareaResize( GLSR_textarea );
12
		x( document ).on( 'wp-window-resized.editor-expand', function() {
13
			GLSR.textareaResize( GLSR_textarea );
14
		});
15
	}
16
17
	x( 'form' ).on( 'click', '#clear-log', GLSR.onClearLog );
18
19
	x.each( site_reviews_pointers.pointers, function( i, pointer ) {
20
		GLSR.pointers( pointer );
21
	});
22
23
	GLSR.colorControls();
24
25
	new GLSR.pinned();
26
	new GLSR.tabs();
27
	new GLSR.forms( 'form.glsr-form' );
28
	new GLSR.status( 'a.glsr-change-status' );
29
	new GLSR.search( '#glsr-search-posts', {
30
		action: 'search-posts',
31
		onInit: function() {
32
			this.el.on( 'click', '.glsr-remove-button', this.onUnassign.bind( this ));
33
		},
34
		onResultClick: function( ev ) {
35
			var result = x( ev.target );
36
			var template = wp.template( 'glsr-assigned-post' );
37
			var entry = {
38
				url: result.data( 'url' ),
39
				title: result.text(),
40
			};
41
			if( template ) {
42
				this.el.find( 'input#assigned_to' ).val( result.data( 'id' ));
43
				this.el.find( '.description' ).html( template( entry ));
44
				this.el.on( 'click', '.glsr-remove-button', this.onUnassign.bind( this ));
45
				this.reset();
46
			}
47
		},
48
	});
49
	new GLSR.search( '#glsr-search-translations', {
50
		action: 'search-translations',
51
		onInit: function() {
52
			this.makeSortable();
53
		},
54
		onResultClick: function( ev ) {
55
			var result = x( ev.target );
56
			var entry = result.data( 'entry' );
57
			var template = wp.template( 'glsr-string-' + ( entry.p1 ? 'plural' : 'single' ));
58
			entry.index = this.options.entriesEl.children().length;
59
			entry.prefix = this.options.resultsEl.data( 'prefix' );
60
			if( template ) {
61
				this.options.entriesEl.append( template( entry ));
62
				this.options.exclude.push({ id: entry.id });
63
				this.options.results = this.options.results.filter( function( i, el ) {
64
					return el !== result.get(0);
65
				});
66
			}
67
			this.setVisibility();
68
		},
69
	});
70
71
	GLSR.modules = {
72
		shortcode: new GLSR.shortcode( '.glsr-mce' ),
73
	};
74
});
75