Chris@0
|
1 /**
|
Chris@0
|
2 * DO NOT EDIT THIS FILE.
|
Chris@0
|
3 * See the following change record for more information,
|
Chris@0
|
4 * https://www.drupal.org/node/2815083
|
Chris@0
|
5 * @preserve
|
Chris@0
|
6 **/
|
Chris@0
|
7
|
Chris@0
|
8 (function ($, _, Drupal, document) {
|
Chris@0
|
9 Drupal.editorConfiguration = {
|
Chris@0
|
10 addedFeature: function addedFeature(feature) {
|
Chris@0
|
11 $(document).trigger('drupalEditorFeatureAdded', feature);
|
Chris@0
|
12 },
|
Chris@0
|
13 removedFeature: function removedFeature(feature) {
|
Chris@0
|
14 $(document).trigger('drupalEditorFeatureRemoved', feature);
|
Chris@0
|
15 },
|
Chris@0
|
16 modifiedFeature: function modifiedFeature(feature) {
|
Chris@0
|
17 $(document).trigger('drupalEditorFeatureModified', feature);
|
Chris@0
|
18 },
|
Chris@0
|
19 featureIsAllowedByFilters: function featureIsAllowedByFilters(feature) {
|
Chris@17
|
20 function emptyProperties(section) {
|
Chris@17
|
21 return section.attributes.length === 0 && section.classes.length === 0 && section.styles.length === 0;
|
Chris@17
|
22 }
|
Chris@17
|
23
|
Chris@0
|
24 function generateUniverseFromFeatureRequirements(feature) {
|
Chris@0
|
25 var properties = ['attributes', 'styles', 'classes'];
|
Chris@0
|
26 var universe = {};
|
Chris@0
|
27
|
Chris@0
|
28 for (var r = 0; r < feature.rules.length; r++) {
|
Chris@0
|
29 var featureRule = feature.rules[r];
|
Chris@0
|
30
|
Chris@0
|
31 var requiredTags = featureRule.required.tags;
|
Chris@0
|
32 for (var t = 0; t < requiredTags.length; t++) {
|
Chris@0
|
33 universe[requiredTags[t]] = {
|
Chris@0
|
34 tag: false,
|
Chris@0
|
35
|
Chris@0
|
36 touchedByAllowedPropertyRule: false,
|
Chris@0
|
37
|
Chris@0
|
38 touchedBytouchedByForbiddenPropertyRule: false
|
Chris@0
|
39 };
|
Chris@0
|
40 }
|
Chris@0
|
41
|
Chris@0
|
42 if (emptyProperties(featureRule.required)) {
|
Chris@0
|
43 continue;
|
Chris@0
|
44 }
|
Chris@0
|
45
|
Chris@0
|
46 for (var p = 0; p < properties.length; p++) {
|
Chris@0
|
47 var property = properties[p];
|
Chris@0
|
48 for (var pv = 0; pv < featureRule.required[property].length; pv++) {
|
Chris@0
|
49 var propertyValue = featureRule.required[property];
|
Chris@0
|
50 universe[requiredTags][property + ':' + propertyValue] = false;
|
Chris@0
|
51 }
|
Chris@0
|
52 }
|
Chris@0
|
53 }
|
Chris@0
|
54
|
Chris@0
|
55 return universe;
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 function findPropertyValueOnTag(universe, tag, property, propertyValue, allowing) {
|
Chris@0
|
59 if (!_.has(universe, tag)) {
|
Chris@0
|
60 return false;
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@0
|
63 var key = property + ':' + propertyValue;
|
Chris@0
|
64
|
Chris@0
|
65 if (allowing) {
|
Chris@0
|
66 universe[tag].touchedByAllowedPropertyRule = true;
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 if (_.indexOf(propertyValue, '*') === -1) {
|
Chris@0
|
70 if (_.has(universe, tag) && _.has(universe[tag], key)) {
|
Chris@0
|
71 if (allowing) {
|
Chris@0
|
72 universe[tag][key] = true;
|
Chris@0
|
73 }
|
Chris@0
|
74 return true;
|
Chris@0
|
75 }
|
Chris@0
|
76 return false;
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79
|
Chris@0
|
80 var atLeastOneFound = false;
|
Chris@0
|
81 var regex = key.replace(/\*/g, '[^ ]*');
|
Chris@0
|
82 _.each(_.keys(universe[tag]), function (key) {
|
Chris@0
|
83 if (key.match(regex)) {
|
Chris@0
|
84 atLeastOneFound = true;
|
Chris@0
|
85 if (allowing) {
|
Chris@0
|
86 universe[tag][key] = true;
|
Chris@0
|
87 }
|
Chris@0
|
88 }
|
Chris@0
|
89 });
|
Chris@0
|
90 return atLeastOneFound;
|
Chris@0
|
91 }
|
Chris@0
|
92
|
Chris@17
|
93 function findPropertyValuesOnAllTags(universe, property, propertyValues, allowing) {
|
Chris@17
|
94 var atLeastOneFound = false;
|
Chris@17
|
95 _.each(_.keys(universe), function (tag) {
|
Chris@17
|
96 if (findPropertyValuesOnTag(universe, tag, property, propertyValues, allowing)) {
|
Chris@17
|
97 atLeastOneFound = true;
|
Chris@17
|
98 }
|
Chris@17
|
99 });
|
Chris@17
|
100 return atLeastOneFound;
|
Chris@17
|
101 }
|
Chris@17
|
102
|
Chris@17
|
103 function findPropertyValuesOnTag(universe, tag, property, propertyValues, allowing) {
|
Chris@0
|
104 if (tag === '*') {
|
Chris@17
|
105 return findPropertyValuesOnAllTags(universe, property, propertyValues, allowing);
|
Chris@0
|
106 }
|
Chris@17
|
107
|
Chris@17
|
108 var atLeastOneFound = false;
|
Chris@17
|
109 _.each(propertyValues, function (propertyValue) {
|
Chris@17
|
110 if (findPropertyValueOnTag(universe, tag, property, propertyValue, allowing)) {
|
Chris@17
|
111 atLeastOneFound = true;
|
Chris@17
|
112 }
|
Chris@17
|
113 });
|
Chris@17
|
114 return atLeastOneFound;
|
Chris@0
|
115 }
|
Chris@0
|
116
|
Chris@0
|
117 function deleteAllTagsFromUniverseIfAllowed(universe) {
|
Chris@0
|
118 var atLeastOneDeleted = false;
|
Chris@0
|
119 _.each(_.keys(universe), function (tag) {
|
Chris@0
|
120 if (deleteFromUniverseIfAllowed(universe, tag)) {
|
Chris@0
|
121 atLeastOneDeleted = true;
|
Chris@0
|
122 }
|
Chris@0
|
123 });
|
Chris@0
|
124 return atLeastOneDeleted;
|
Chris@0
|
125 }
|
Chris@0
|
126
|
Chris@17
|
127 function deleteFromUniverseIfAllowed(universe, tag) {
|
Chris@17
|
128 if (tag === '*') {
|
Chris@17
|
129 return deleteAllTagsFromUniverseIfAllowed(universe);
|
Chris@17
|
130 }
|
Chris@17
|
131 if (_.has(universe, tag) && _.every(_.omit(universe[tag], 'touchedByAllowedPropertyRule'))) {
|
Chris@17
|
132 delete universe[tag];
|
Chris@17
|
133 return true;
|
Chris@17
|
134 }
|
Chris@17
|
135 return false;
|
Chris@17
|
136 }
|
Chris@17
|
137
|
Chris@0
|
138 function anyForbiddenFilterRuleMatches(universe, filterStatus) {
|
Chris@0
|
139 var properties = ['attributes', 'styles', 'classes'];
|
Chris@0
|
140
|
Chris@0
|
141 var allRequiredTags = _.keys(universe);
|
Chris@0
|
142 var filterRule = void 0;
|
Chris@0
|
143 for (var i = 0; i < filterStatus.rules.length; i++) {
|
Chris@0
|
144 filterRule = filterStatus.rules[i];
|
Chris@0
|
145 if (filterRule.allow === false) {
|
Chris@0
|
146 if (_.intersection(allRequiredTags, filterRule.tags).length > 0) {
|
Chris@0
|
147 return true;
|
Chris@0
|
148 }
|
Chris@0
|
149 }
|
Chris@0
|
150 }
|
Chris@0
|
151
|
Chris@0
|
152 for (var n = 0; n < filterStatus.rules.length; n++) {
|
Chris@0
|
153 filterRule = filterStatus.rules[n];
|
Chris@0
|
154
|
Chris@0
|
155 if (filterRule.restrictedTags.tags.length && !emptyProperties(filterRule.restrictedTags.forbidden)) {
|
Chris@0
|
156 for (var j = 0; j < filterRule.restrictedTags.tags.length; j++) {
|
Chris@0
|
157 var tag = filterRule.restrictedTags.tags[j];
|
Chris@0
|
158
|
Chris@0
|
159 for (var k = 0; k < properties.length; k++) {
|
Chris@0
|
160 var property = properties[k];
|
Chris@0
|
161
|
Chris@0
|
162 if (findPropertyValuesOnTag(universe, tag, property, filterRule.restrictedTags.forbidden[property], false)) {
|
Chris@0
|
163 return true;
|
Chris@0
|
164 }
|
Chris@0
|
165 }
|
Chris@0
|
166 }
|
Chris@0
|
167 }
|
Chris@0
|
168 }
|
Chris@0
|
169
|
Chris@0
|
170 return false;
|
Chris@0
|
171 }
|
Chris@0
|
172
|
Chris@0
|
173 function markAllowedTagsAndPropertyValues(universe, filterStatus) {
|
Chris@0
|
174 var properties = ['attributes', 'styles', 'classes'];
|
Chris@0
|
175
|
Chris@0
|
176 var filterRule = void 0;
|
Chris@0
|
177 var tag = void 0;
|
Chris@0
|
178 for (var l = 0; !_.isEmpty(universe) && l < filterStatus.rules.length; l++) {
|
Chris@0
|
179 filterRule = filterStatus.rules[l];
|
Chris@0
|
180 if (filterRule.allow === true) {
|
Chris@0
|
181 for (var m = 0; !_.isEmpty(universe) && m < filterRule.tags.length; m++) {
|
Chris@0
|
182 tag = filterRule.tags[m];
|
Chris@0
|
183 if (_.has(universe, tag)) {
|
Chris@0
|
184 universe[tag].tag = true;
|
Chris@0
|
185 deleteFromUniverseIfAllowed(universe, tag);
|
Chris@0
|
186 }
|
Chris@0
|
187 }
|
Chris@0
|
188 }
|
Chris@0
|
189 }
|
Chris@0
|
190
|
Chris@0
|
191 for (var i = 0; !_.isEmpty(universe) && i < filterStatus.rules.length; i++) {
|
Chris@0
|
192 filterRule = filterStatus.rules[i];
|
Chris@0
|
193
|
Chris@0
|
194 if (filterRule.restrictedTags.tags.length && !emptyProperties(filterRule.restrictedTags.allowed)) {
|
Chris@0
|
195 for (var j = 0; !_.isEmpty(universe) && j < filterRule.restrictedTags.tags.length; j++) {
|
Chris@0
|
196 tag = filterRule.restrictedTags.tags[j];
|
Chris@0
|
197
|
Chris@0
|
198 for (var k = 0; k < properties.length; k++) {
|
Chris@0
|
199 var property = properties[k];
|
Chris@0
|
200
|
Chris@0
|
201 if (findPropertyValuesOnTag(universe, tag, property, filterRule.restrictedTags.allowed[property], true)) {
|
Chris@0
|
202 deleteFromUniverseIfAllowed(universe, tag);
|
Chris@0
|
203 }
|
Chris@0
|
204 }
|
Chris@0
|
205 }
|
Chris@0
|
206 }
|
Chris@0
|
207 }
|
Chris@0
|
208 }
|
Chris@0
|
209
|
Chris@0
|
210 function filterStatusAllowsFeature(filterStatus, feature) {
|
Chris@0
|
211 if (!filterStatus.active) {
|
Chris@0
|
212 return true;
|
Chris@0
|
213 }
|
Chris@0
|
214
|
Chris@0
|
215 if (feature.rules.length === 0) {
|
Chris@0
|
216 return true;
|
Chris@0
|
217 }
|
Chris@0
|
218
|
Chris@0
|
219 if (filterStatus.rules.length === 0) {
|
Chris@0
|
220 return true;
|
Chris@0
|
221 }
|
Chris@0
|
222
|
Chris@0
|
223 var universe = generateUniverseFromFeatureRequirements(feature);
|
Chris@0
|
224
|
Chris@0
|
225 if (anyForbiddenFilterRuleMatches(universe, filterStatus)) {
|
Chris@0
|
226 return false;
|
Chris@0
|
227 }
|
Chris@0
|
228
|
Chris@0
|
229 markAllowedTagsAndPropertyValues(universe, filterStatus);
|
Chris@0
|
230
|
Chris@0
|
231 if (_.some(_.pluck(filterStatus.rules, 'allow'))) {
|
Chris@0
|
232 if (_.isEmpty(universe)) {
|
Chris@0
|
233 return true;
|
Chris@0
|
234 }
|
Chris@0
|
235
|
Chris@0
|
236 if (!_.every(_.pluck(universe, 'tag'))) {
|
Chris@0
|
237 return false;
|
Chris@0
|
238 }
|
Chris@0
|
239
|
Chris@0
|
240
|
Chris@0
|
241 var tags = _.keys(universe);
|
Chris@0
|
242
|
Chris@0
|
243 for (var i = 0; i < tags.length; i++) {
|
Chris@0
|
244 var tag = tags[i];
|
Chris@0
|
245 if (_.has(universe, tag)) {
|
Chris@0
|
246 if (universe[tag].touchedByAllowedPropertyRule === false) {
|
Chris@0
|
247 delete universe[tag];
|
Chris@0
|
248 }
|
Chris@0
|
249 }
|
Chris@0
|
250 }
|
Chris@0
|
251 return _.isEmpty(universe);
|
Chris@0
|
252 }
|
Chris@0
|
253
|
Chris@0
|
254
|
Chris@0
|
255 return true;
|
Chris@0
|
256 }
|
Chris@0
|
257
|
Chris@0
|
258 Drupal.filterConfiguration.update();
|
Chris@17
|
259 return Object.keys(Drupal.filterConfiguration.statuses).every(function (filterID) {
|
Chris@17
|
260 return filterStatusAllowsFeature(Drupal.filterConfiguration.statuses[filterID], feature);
|
Chris@17
|
261 });
|
Chris@0
|
262 }
|
Chris@0
|
263 };
|
Chris@0
|
264
|
Chris@0
|
265 Drupal.EditorFeatureHTMLRule = function () {
|
Chris@17
|
266 this.required = {
|
Chris@17
|
267 tags: [],
|
Chris@17
|
268 attributes: [],
|
Chris@17
|
269 styles: [],
|
Chris@17
|
270 classes: []
|
Chris@17
|
271 };
|
Chris@0
|
272
|
Chris@17
|
273 this.allowed = {
|
Chris@17
|
274 tags: [],
|
Chris@17
|
275 attributes: [],
|
Chris@17
|
276 styles: [],
|
Chris@17
|
277 classes: []
|
Chris@17
|
278 };
|
Chris@0
|
279
|
Chris@0
|
280 this.raw = null;
|
Chris@0
|
281 };
|
Chris@0
|
282
|
Chris@0
|
283 Drupal.EditorFeature = function (name) {
|
Chris@0
|
284 this.name = name;
|
Chris@0
|
285 this.rules = [];
|
Chris@0
|
286 };
|
Chris@0
|
287
|
Chris@0
|
288 Drupal.EditorFeature.prototype.addHTMLRule = function (rule) {
|
Chris@0
|
289 this.rules.push(rule);
|
Chris@0
|
290 };
|
Chris@0
|
291
|
Chris@0
|
292 Drupal.FilterStatus = function (name) {
|
Chris@0
|
293 this.name = name;
|
Chris@0
|
294
|
Chris@0
|
295 this.active = false;
|
Chris@0
|
296
|
Chris@0
|
297 this.rules = [];
|
Chris@0
|
298 };
|
Chris@0
|
299
|
Chris@0
|
300 Drupal.FilterStatus.prototype.addHTMLRule = function (rule) {
|
Chris@0
|
301 this.rules.push(rule);
|
Chris@0
|
302 };
|
Chris@0
|
303
|
Chris@0
|
304 Drupal.FilterHTMLRule = function () {
|
Chris@0
|
305 this.tags = [];
|
Chris@0
|
306 this.allow = null;
|
Chris@0
|
307
|
Chris@0
|
308 this.restrictedTags = {
|
Chris@0
|
309 tags: [],
|
Chris@0
|
310 allowed: { attributes: [], styles: [], classes: [] },
|
Chris@0
|
311 forbidden: { attributes: [], styles: [], classes: [] }
|
Chris@0
|
312 };
|
Chris@0
|
313
|
Chris@0
|
314 return this;
|
Chris@0
|
315 };
|
Chris@0
|
316
|
Chris@0
|
317 Drupal.FilterHTMLRule.prototype.clone = function () {
|
Chris@0
|
318 var clone = new Drupal.FilterHTMLRule();
|
Chris@0
|
319 clone.tags = this.tags.slice(0);
|
Chris@0
|
320 clone.allow = this.allow;
|
Chris@0
|
321 clone.restrictedTags.tags = this.restrictedTags.tags.slice(0);
|
Chris@0
|
322 clone.restrictedTags.allowed.attributes = this.restrictedTags.allowed.attributes.slice(0);
|
Chris@0
|
323 clone.restrictedTags.allowed.styles = this.restrictedTags.allowed.styles.slice(0);
|
Chris@0
|
324 clone.restrictedTags.allowed.classes = this.restrictedTags.allowed.classes.slice(0);
|
Chris@0
|
325 clone.restrictedTags.forbidden.attributes = this.restrictedTags.forbidden.attributes.slice(0);
|
Chris@0
|
326 clone.restrictedTags.forbidden.styles = this.restrictedTags.forbidden.styles.slice(0);
|
Chris@0
|
327 clone.restrictedTags.forbidden.classes = this.restrictedTags.forbidden.classes.slice(0);
|
Chris@0
|
328 return clone;
|
Chris@0
|
329 };
|
Chris@0
|
330
|
Chris@0
|
331 Drupal.filterConfiguration = {
|
Chris@0
|
332 statuses: {},
|
Chris@0
|
333
|
Chris@0
|
334 liveSettingParsers: {},
|
Chris@0
|
335
|
Chris@0
|
336 update: function update() {
|
Chris@14
|
337 Object.keys(Drupal.filterConfiguration.statuses || {}).forEach(function (filterID) {
|
Chris@14
|
338 Drupal.filterConfiguration.statuses[filterID].active = $('[name="filters[' + filterID + '][status]"]').is(':checked');
|
Chris@0
|
339
|
Chris@14
|
340 if (Drupal.filterConfiguration.liveSettingParsers[filterID]) {
|
Chris@14
|
341 Drupal.filterConfiguration.statuses[filterID].rules = Drupal.filterConfiguration.liveSettingParsers[filterID].getRules();
|
Chris@0
|
342 }
|
Chris@14
|
343 });
|
Chris@0
|
344 }
|
Chris@0
|
345 };
|
Chris@0
|
346
|
Chris@0
|
347 Drupal.behaviors.initializeFilterConfiguration = {
|
Chris@0
|
348 attach: function attach(context, settings) {
|
Chris@0
|
349 var $context = $(context);
|
Chris@0
|
350
|
Chris@0
|
351 $context.find('#filters-status-wrapper input.form-checkbox').once('filter-editor-status').each(function () {
|
Chris@0
|
352 var $checkbox = $(this);
|
Chris@0
|
353 var nameAttribute = $checkbox.attr('name');
|
Chris@0
|
354
|
Chris@0
|
355 var filterID = nameAttribute.substring(8, nameAttribute.indexOf(']'));
|
Chris@0
|
356
|
Chris@0
|
357 Drupal.filterConfiguration.statuses[filterID] = new Drupal.FilterStatus(filterID);
|
Chris@0
|
358 });
|
Chris@0
|
359 }
|
Chris@0
|
360 };
|
Chris@0
|
361 })(jQuery, _, Drupal, document); |