2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, _, Drupal, document) {
9 Drupal.editorConfiguration = {
10 addedFeature: function addedFeature(feature) {
11 $(document).trigger('drupalEditorFeatureAdded', feature);
13 removedFeature: function removedFeature(feature) {
14 $(document).trigger('drupalEditorFeatureRemoved', feature);
16 modifiedFeature: function modifiedFeature(feature) {
17 $(document).trigger('drupalEditorFeatureModified', feature);
19 featureIsAllowedByFilters: function featureIsAllowedByFilters(feature) {
20 function emptyProperties(section) {
21 return section.attributes.length === 0 && section.classes.length === 0 && section.styles.length === 0;
24 function generateUniverseFromFeatureRequirements(feature) {
25 var properties = ['attributes', 'styles', 'classes'];
28 for (var r = 0; r < feature.rules.length; r++) {
29 var featureRule = feature.rules[r];
31 var requiredTags = featureRule.required.tags;
32 for (var t = 0; t < requiredTags.length; t++) {
33 universe[requiredTags[t]] = {
36 touchedByAllowedPropertyRule: false,
38 touchedBytouchedByForbiddenPropertyRule: false
42 if (emptyProperties(featureRule.required)) {
46 for (var p = 0; p < properties.length; p++) {
47 var property = properties[p];
48 for (var pv = 0; pv < featureRule.required[property].length; pv++) {
49 var propertyValue = featureRule.required[property];
50 universe[requiredTags][property + ':' + propertyValue] = false;
58 function findPropertyValueOnTag(universe, tag, property, propertyValue, allowing) {
59 if (!_.has(universe, tag)) {
63 var key = property + ':' + propertyValue;
66 universe[tag].touchedByAllowedPropertyRule = true;
69 if (_.indexOf(propertyValue, '*') === -1) {
70 if (_.has(universe, tag) && _.has(universe[tag], key)) {
72 universe[tag][key] = true;
80 var atLeastOneFound = false;
81 var regex = key.replace(/\*/g, '[^ ]*');
82 _.each(_.keys(universe[tag]), function (key) {
83 if (key.match(regex)) {
84 atLeastOneFound = true;
86 universe[tag][key] = true;
90 return atLeastOneFound;
93 function findPropertyValuesOnAllTags(universe, property, propertyValues, allowing) {
94 var atLeastOneFound = false;
95 _.each(_.keys(universe), function (tag) {
96 if (findPropertyValuesOnTag(universe, tag, property, propertyValues, allowing)) {
97 atLeastOneFound = true;
100 return atLeastOneFound;
103 function findPropertyValuesOnTag(universe, tag, property, propertyValues, allowing) {
105 return findPropertyValuesOnAllTags(universe, property, propertyValues, allowing);
108 var atLeastOneFound = false;
109 _.each(propertyValues, function (propertyValue) {
110 if (findPropertyValueOnTag(universe, tag, property, propertyValue, allowing)) {
111 atLeastOneFound = true;
114 return atLeastOneFound;
117 function deleteAllTagsFromUniverseIfAllowed(universe) {
118 var atLeastOneDeleted = false;
119 _.each(_.keys(universe), function (tag) {
120 if (deleteFromUniverseIfAllowed(universe, tag)) {
121 atLeastOneDeleted = true;
124 return atLeastOneDeleted;
127 function deleteFromUniverseIfAllowed(universe, tag) {
129 return deleteAllTagsFromUniverseIfAllowed(universe);
131 if (_.has(universe, tag) && _.every(_.omit(universe[tag], 'touchedByAllowedPropertyRule'))) {
132 delete universe[tag];
138 function anyForbiddenFilterRuleMatches(universe, filterStatus) {
139 var properties = ['attributes', 'styles', 'classes'];
141 var allRequiredTags = _.keys(universe);
142 var filterRule = void 0;
143 for (var i = 0; i < filterStatus.rules.length; i++) {
144 filterRule = filterStatus.rules[i];
145 if (filterRule.allow === false) {
146 if (_.intersection(allRequiredTags, filterRule.tags).length > 0) {
152 for (var n = 0; n < filterStatus.rules.length; n++) {
153 filterRule = filterStatus.rules[n];
155 if (filterRule.restrictedTags.tags.length && !emptyProperties(filterRule.restrictedTags.forbidden)) {
156 for (var j = 0; j < filterRule.restrictedTags.tags.length; j++) {
157 var tag = filterRule.restrictedTags.tags[j];
159 for (var k = 0; k < properties.length; k++) {
160 var property = properties[k];
162 if (findPropertyValuesOnTag(universe, tag, property, filterRule.restrictedTags.forbidden[property], false)) {
173 function markAllowedTagsAndPropertyValues(universe, filterStatus) {
174 var properties = ['attributes', 'styles', 'classes'];
176 var filterRule = void 0;
178 for (var l = 0; !_.isEmpty(universe) && l < filterStatus.rules.length; l++) {
179 filterRule = filterStatus.rules[l];
180 if (filterRule.allow === true) {
181 for (var m = 0; !_.isEmpty(universe) && m < filterRule.tags.length; m++) {
182 tag = filterRule.tags[m];
183 if (_.has(universe, tag)) {
184 universe[tag].tag = true;
185 deleteFromUniverseIfAllowed(universe, tag);
191 for (var i = 0; !_.isEmpty(universe) && i < filterStatus.rules.length; i++) {
192 filterRule = filterStatus.rules[i];
194 if (filterRule.restrictedTags.tags.length && !emptyProperties(filterRule.restrictedTags.allowed)) {
195 for (var j = 0; !_.isEmpty(universe) && j < filterRule.restrictedTags.tags.length; j++) {
196 tag = filterRule.restrictedTags.tags[j];
198 for (var k = 0; k < properties.length; k++) {
199 var property = properties[k];
201 if (findPropertyValuesOnTag(universe, tag, property, filterRule.restrictedTags.allowed[property], true)) {
202 deleteFromUniverseIfAllowed(universe, tag);
210 function filterStatusAllowsFeature(filterStatus, feature) {
211 if (!filterStatus.active) {
215 if (feature.rules.length === 0) {
219 if (filterStatus.rules.length === 0) {
223 var universe = generateUniverseFromFeatureRequirements(feature);
225 if (anyForbiddenFilterRuleMatches(universe, filterStatus)) {
229 markAllowedTagsAndPropertyValues(universe, filterStatus);
231 if (_.some(_.pluck(filterStatus.rules, 'allow'))) {
232 if (_.isEmpty(universe)) {
236 if (!_.every(_.pluck(universe, 'tag'))) {
241 var tags = _.keys(universe);
243 for (var i = 0; i < tags.length; i++) {
245 if (_.has(universe, tag)) {
246 if (universe[tag].touchedByAllowedPropertyRule === false) {
247 delete universe[tag];
251 return _.isEmpty(universe);
258 Drupal.filterConfiguration.update();
259 return Object.keys(Drupal.filterConfiguration.statuses).every(function (filterID) {
260 return filterStatusAllowsFeature(Drupal.filterConfiguration.statuses[filterID], feature);
265 Drupal.EditorFeatureHTMLRule = function () {
283 Drupal.EditorFeature = function (name) {
288 Drupal.EditorFeature.prototype.addHTMLRule = function (rule) {
289 this.rules.push(rule);
292 Drupal.FilterStatus = function (name) {
300 Drupal.FilterStatus.prototype.addHTMLRule = function (rule) {
301 this.rules.push(rule);
304 Drupal.FilterHTMLRule = function () {
308 this.restrictedTags = {
310 allowed: { attributes: [], styles: [], classes: [] },
311 forbidden: { attributes: [], styles: [], classes: [] }
317 Drupal.FilterHTMLRule.prototype.clone = function () {
318 var clone = new Drupal.FilterHTMLRule();
319 clone.tags = this.tags.slice(0);
320 clone.allow = this.allow;
321 clone.restrictedTags.tags = this.restrictedTags.tags.slice(0);
322 clone.restrictedTags.allowed.attributes = this.restrictedTags.allowed.attributes.slice(0);
323 clone.restrictedTags.allowed.styles = this.restrictedTags.allowed.styles.slice(0);
324 clone.restrictedTags.allowed.classes = this.restrictedTags.allowed.classes.slice(0);
325 clone.restrictedTags.forbidden.attributes = this.restrictedTags.forbidden.attributes.slice(0);
326 clone.restrictedTags.forbidden.styles = this.restrictedTags.forbidden.styles.slice(0);
327 clone.restrictedTags.forbidden.classes = this.restrictedTags.forbidden.classes.slice(0);
331 Drupal.filterConfiguration = {
334 liveSettingParsers: {},
336 update: function update() {
337 Object.keys(Drupal.filterConfiguration.statuses || {}).forEach(function (filterID) {
338 Drupal.filterConfiguration.statuses[filterID].active = $('[name="filters[' + filterID + '][status]"]').is(':checked');
340 if (Drupal.filterConfiguration.liveSettingParsers[filterID]) {
341 Drupal.filterConfiguration.statuses[filterID].rules = Drupal.filterConfiguration.liveSettingParsers[filterID].getRules();
347 Drupal.behaviors.initializeFilterConfiguration = {
348 attach: function attach(context, settings) {
349 var $context = $(context);
351 $context.find('#filters-status-wrapper input.form-checkbox').once('filter-editor-status').each(function () {
352 var $checkbox = $(this);
353 var nameAttribute = $checkbox.attr('name');
355 var filterID = nameAttribute.substring(8, nameAttribute.indexOf(']'));
357 Drupal.filterConfiguration.statuses[filterID] = new Drupal.FilterStatus(filterID);
361 })(jQuery, _, Drupal, document);