1 | /** |
||
2 | * SEOmatic plugin for Craft CMS 3.x |
||
3 | * |
||
4 | * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful, |
||
5 | * and flexible |
||
6 | * |
||
7 | * @link https://nystudio107.com |
||
8 | * @copyright Copyright (c) 2017 nystudio107 |
||
9 | */ |
||
10 | |||
11 | import SchemaTypeList from "@/vue/SchemaTypeList.vue"; |
||
12 | |||
13 | /** |
||
14 | * @author nystudio107 |
||
15 | * @package SEOmatic |
||
16 | * @since 3.0.0 |
||
17 | */ |
||
18 | |||
19 | if (window.schemaSelectClass !== undefined) { |
||
20 | // Create our vue instance(s) |
||
21 | for (const el of document.querySelectorAll('.' + window.schemaSelectClass)) { |
||
22 | let elementId = 'vue-' + Math.round(Math.random() * 1000); |
||
23 | el.setAttribute('id', elementId); |
||
24 | |||
25 | new Vue({ |
||
0 ignored issues
–
show
|
|||
26 | el: '#' + elementId, |
||
27 | components: { |
||
28 | 'schema-type-list': SchemaTypeList, |
||
29 | }, |
||
30 | data: {}, |
||
31 | methods: {}, |
||
32 | mounted() { |
||
33 | }, |
||
34 | }); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | // Accept HMR as per: https://webpack.js.org/api/hot-module-replacement#accept |
||
39 | if (module.hot) { |
||
40 | module.hot.accept(); |
||
41 | } |
||
42 | |||
43 | function seomaticTabChangeHandler() { |
||
44 | // Tab handler |
||
45 | $('.seomatic-tab-links').on('click', function(e) { |
||
46 | e.preventDefault(); |
||
47 | $('.seomatic-tab-links').removeClass('sel'); |
||
48 | $(this).addClass('sel'); |
||
49 | $('.seomatic-tab-content').addClass('hidden'); |
||
50 | var selector = $(this).attr('href'); |
||
51 | $(selector).removeClass('hidden'); |
||
52 | }); |
||
53 | } |
||
54 | |||
55 | window.seomaticTabChangeHandler = seomaticTabChangeHandler; |
||
56 | window.seomaticTabChangeHandler(); |
||
57 | |||
58 | function initFieldSettings() { |
||
59 | |||
60 | const disableInputs = ($obj) => $obj.find('input, select, button').prop('disabled', true); |
||
61 | disableInputs($('.inheritable-field .inherited')); |
||
62 | |||
63 | $('.inheritable-field .override .lightswitch:not(.on) input').val(0); |
||
64 | $('.inheritable-field .override .lightswitch').on('change', function (ev) { |
||
65 | if ($(this).hasClass('on')) { |
||
66 | $(this).parents('.inheritable-field').addClass('defined-settings').removeClass('inherited-settings'); |
||
67 | } else { |
||
68 | $(this).parents('.inheritable-field').removeClass('defined-settings').addClass('inherited-settings'); |
||
69 | $(this).find('input').val(0); |
||
70 | } |
||
71 | }); |
||
72 | |||
73 | // Show/hide the script settings containers |
||
74 | var selector = $('.seomatic-script-lightswitch').find('.lightswitch'); |
||
75 | $(selector).each(function(index, value) { |
||
76 | var value = $(this).find('input').first().val(); |
||
77 | if (value) { |
||
78 | $(this).closest('.seomatic-script-wrapper').find('.seomatic-script-container').show(); |
||
79 | } else { |
||
80 | $(this).closest('.seomatic-script-wrapper').find('.seomatic-script-container').hide(); |
||
81 | } |
||
82 | }); |
||
83 | $(selector).on('click', function(e) { |
||
84 | var value = $(this).find('input').first().val(); |
||
85 | if (value) { |
||
86 | $(this).closest('.seomatic-script-wrapper').find('.seomatic-script-container').slideDown(); |
||
87 | } else { |
||
88 | $(this).closest('.seomatic-script-wrapper').find('.seomatic-script-container').slideUp(); |
||
89 | } |
||
90 | }); |
||
91 | |||
92 | // Show/hide the image source fields initially |
||
93 | $('.seomatic-imageSourceSelect > select').each(function(index, value) { |
||
94 | var popupValue = $(this).val(); |
||
95 | switch (popupValue) { |
||
96 | case 'sameAsSeo': |
||
97 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceNotFromUrl').show(); |
||
98 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromField').hide(); |
||
99 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromAsset').hide(); |
||
100 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromUrl').hide(); |
||
101 | break; |
||
102 | |||
103 | case 'fromField': |
||
104 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceNotFromUrl').show(); |
||
105 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromField').show(); |
||
106 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromAsset').hide(); |
||
107 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromUrl').hide(); |
||
108 | break; |
||
109 | |||
110 | case 'fromAsset': |
||
111 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceNotFromUrl').show(); |
||
112 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromField').hide(); |
||
113 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromAsset').show(); |
||
114 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromUrl').hide(); |
||
115 | break; |
||
116 | |||
117 | case 'fromUrl': |
||
118 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceNotFromUrl').hide(); |
||
119 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromField').hide(); |
||
120 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromAsset').hide(); |
||
121 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromUrl').show(); |
||
122 | break; |
||
123 | } |
||
124 | }); |
||
125 | // Handle hiding/showing the image source fields based on the selection |
||
126 | $('.seomatic-imageSourceSelect > select').on('change', function(e) { |
||
127 | switch (this.value) { |
||
128 | case 'sameAsSeo': |
||
129 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceNotFromUrl').slideDown(); |
||
130 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromField').slideUp(); |
||
131 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromAsset').slideUp(); |
||
132 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromUrl').slideUp(); |
||
133 | break; |
||
134 | |||
135 | case 'fromField': |
||
136 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceNotFromUrl').slideDown(); |
||
137 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromField').slideDown(); |
||
138 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromAsset').slideUp(); |
||
139 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromUrl').slideUp(); |
||
140 | break; |
||
141 | |||
142 | case 'fromAsset': |
||
143 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceNotFromUrl').slideDown(); |
||
144 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromField').slideUp(); |
||
145 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromAsset').slideDown(); |
||
146 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromUrl').slideUp(); |
||
147 | break; |
||
148 | |||
149 | case 'fromUrl': |
||
150 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceNotFromUrl').slideUp(); |
||
151 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromField').slideUp(); |
||
152 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromAsset').slideUp(); |
||
153 | $(this).parents('.seomatic-imageSourceWrapper').find('.seomatic-imageSourceFromUrl').slideDown(); |
||
154 | break; |
||
155 | } |
||
156 | }); |
||
157 | |||
158 | // Show/hide the text source fields initially |
||
159 | $('.seomatic-textSourceSelect select').each(function(index, value) { |
||
160 | var popupValue = $(this).val(); |
||
161 | switch (popupValue) { |
||
162 | case 'sameAsSeo': |
||
163 | case 'sameAsGlobal': |
||
164 | case 'sameAsSiteTwitter': |
||
165 | $(this).closest('.value-wrapper').children('.seomatic-textSourceFromField').hide(); |
||
166 | $(this).closest('.value-wrapper').children('.seomatic-textSourceFromUrl').hide(); |
||
167 | break; |
||
168 | |||
169 | case 'fromField': |
||
170 | case 'summaryFromField': |
||
171 | case 'keywordsFromField': |
||
172 | case 'fromUserField': |
||
173 | $(this).closest('.value-wrapper').children('.seomatic-textSourceFromField').show(); |
||
174 | $(this).closest('.value-wrapper').children('.seomatic-textSourceFromUrl').hide(); |
||
175 | break; |
||
176 | |||
177 | case 'fromCustom': |
||
178 | $(this).closest('.value-wrapper').children('.seomatic-textSourceFromField').hide(); |
||
179 | $(this).closest('.value-wrapper').children('.seomatic-textSourceFromUrl').show(); |
||
180 | break; |
||
181 | } |
||
182 | }); |
||
183 | // Handle hiding/showing the image source fields based on the selection |
||
184 | $('.field-settings .seomatic-textSourceSelect select').on('change', function(e) { |
||
185 | switch (this.value) { |
||
186 | case 'sameAsSeo': |
||
187 | case 'sameAsGlobal': |
||
188 | case 'sameAsSiteTwitter': |
||
189 | $(this).closest('.field-settings').children('.seomatic-textSourceFromField').hide(); |
||
190 | $(this).closest('.field-settings').children('.seomatic-textSourceFromUrl').hide(); |
||
191 | break; |
||
192 | |||
193 | case 'fromField': |
||
194 | case 'summaryFromField': |
||
195 | case 'keywordsFromField': |
||
196 | case 'fromUserField': |
||
197 | $(this).closest('.field-settings').children('.seomatic-textSourceFromField').show(); |
||
198 | $(this).closest('.field-settings').children('.seomatic-textSourceFromUrl').hide(); |
||
199 | break; |
||
200 | |||
201 | case 'fromCustom': |
||
202 | $(this).closest('.field-settings').children('.seomatic-textSourceFromField').hide(); |
||
203 | $(this).closest('.field-settings').children('.seomatic-textSourceFromUrl').show(); |
||
204 | break; |
||
205 | } |
||
206 | }); |
||
207 | } |
||
208 | |||
209 | if (typeof Craft.EntryTypeSwitcher !== 'undefined') { |
||
0 ignored issues
–
show
The variable
Craft seems to be never declared. If this is a global, consider adding a /** global: Craft */ 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. ![]() |
|||
210 | Garnish.on(Craft.EntryTypeSwitcher, 'typeChange', () => { |
||
0 ignored issues
–
show
The variable
Garnish seems to be never declared. If this is a global, consider adding a /** global: Garnish */ 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. ![]() |
|||
211 | initFieldSettings(); |
||
212 | }); |
||
213 | } |
||
214 | |||
215 | $(function() { |
||
216 | initFieldSettings(); |
||
217 | }); |
||
218 |
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.