1
|
|
|
/** |
2
|
|
|
* @summary Disable hook extension controller object. |
3
|
|
|
* |
4
|
|
|
* @since 2.3.0 |
5
|
|
|
* |
6
|
|
|
* @module |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
var Extension = wp.wordpoints.hooks.controller.Extension, |
|
|
|
|
10
|
|
|
template = wp.wordpoints.hooks.template, |
11
|
|
|
Disable; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* wp.wordpoints.hooks.extension.Disable |
15
|
|
|
* |
16
|
|
|
* @since 2.3.0 |
17
|
|
|
* |
18
|
|
|
* @class |
19
|
|
|
* @augments Backbone.Model |
20
|
|
|
* @augments wp.wordpoints.hooks.controller.Extension |
21
|
|
|
*/ |
22
|
|
|
Disable = Extension.extend({ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @since 2.3.0 |
26
|
|
|
*/ |
27
|
|
|
defaults: { |
28
|
|
|
slug: 'disable' |
29
|
|
|
}, |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @summary The template for the extension settings. |
33
|
|
|
* |
34
|
|
|
* @since 2.3.0 |
35
|
|
|
*/ |
36
|
|
|
template: template( 'hook-disable' ), |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @summary The template for the "disabled" text shown in the reaction title. |
40
|
|
|
* |
41
|
|
|
* @since 2.3.0 |
42
|
|
|
*/ |
43
|
|
|
titleTemplate: template( 'hook-disabled-text' ), |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @since 2.3.0 |
47
|
|
|
*/ |
48
|
|
|
initReaction: function ( reaction ) { |
49
|
|
|
|
50
|
|
|
this.listenTo( reaction, 'render:title', function () { |
51
|
|
|
|
52
|
|
|
if ( ! reaction.$title.find( '.wordpoints-hook-disabled-text' ).length ) { |
53
|
|
|
reaction.$title.prepend( this.titleTemplate() ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
this.setDisabled( reaction ); |
57
|
|
|
}); |
58
|
|
|
|
59
|
|
|
this.listenToOnce( reaction, 'render:settings', function () { |
60
|
|
|
|
61
|
|
|
// We hook this up late so the settings will be below other extensions. |
62
|
|
|
this.listenTo( reaction, 'render:fields', function () { |
63
|
|
|
|
64
|
|
|
if ( ! reaction.$fields.find( '.disable' ).length ) { |
65
|
|
|
reaction.$fields.append( this.template() ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
this.setDisabled( reaction ); |
69
|
|
|
}); |
70
|
|
|
} ); |
71
|
|
|
|
72
|
|
|
this.listenTo( reaction.model, 'change:disabled', function () { |
73
|
|
|
this.setDisabled( reaction ); |
74
|
|
|
} ); |
75
|
|
|
|
76
|
|
|
this.listenTo( reaction.model, 'sync', function () { |
77
|
|
|
this.setDisabled( reaction ); |
78
|
|
|
} ); |
79
|
|
|
}, |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @summary Set the disabled class if the reaction is disabled. |
83
|
|
|
* |
84
|
|
|
* @since 2.3.0 |
85
|
|
|
*/ |
86
|
|
|
setDisabled: function ( reaction ) { |
87
|
|
|
|
88
|
|
|
var isDisabled = !! reaction.model.get( this.get( 'slug' ) ); |
89
|
|
|
|
90
|
|
|
reaction.$el.toggleClass( 'disabled', isDisabled ); |
91
|
|
|
|
92
|
|
|
reaction.$fields |
93
|
|
|
.find( 'input[name=disable]' ) |
94
|
|
|
.prop( 'checked', isDisabled ); |
95
|
|
|
}, |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @since 2.3.0 |
99
|
|
|
*/ |
100
|
|
|
validateReaction: function () {} |
101
|
|
|
|
102
|
|
|
} ); |
103
|
|
|
|
104
|
|
|
module.exports = Disable; |
105
|
|
|
|
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.