1/** 2* DO NOT EDIT THIS FILE. 3* See the following change record for more information, 4* https://www.drupal.org/node/2815083 5* @preserve 6**/ 7 8(function ($, Drupal) { 9 var states = { 10 postponed: [] 11 }; 12 13 Drupal.states = states; 14 15 function invert(a, invertState) { 16 return invertState && typeof a !== 'undefined' ? !a : a; 17 } 18 19 function _compare2(a, b) { 20 if (a === b) { 21 return typeof a === 'undefined' ? a : true; 22 } 23 24 return typeof a === 'undefined' || typeof b === 'undefined'; 25 } 26 27 Drupal.behaviors.states = { 28 attach: function attach(context, settings) { 29 var $states = $(context).find('[data-drupal-states]'); 30 var il = $states.length; 31 32 var _loop = function _loop(i) { 33 var config = JSON.parse($states[i].getAttribute('data-drupal-states')); 34 Object.keys(config || {}).forEach(function (state) { 35 new states.Dependent({ 36 element: $($states[i]), 37 state: states.State.sanitize(state), 38 constraints: config[state] 39 }); 40 }); 41 }; 42 43 for (var i = 0; i < il; i++) { 44 _loop(i); 45 } 46 47 while (states.postponed.length) { 48 states.postponed.shift()(); 49 } 50 } 51 }; 52 53 states.Dependent = function (args) { 54 var _this = this; 55 56 $.extend(this, { values: {}, oldValue: null }, args); 57 58 this.dependees = this.getDependees(); 59 Object.keys(this.dependees || {}).forEach(function (selector) { 60 _this.initializeDependee(selector, _this.dependees[selector]); 61 }); 62 }; 63 64 states.Dependent.comparisons = { 65 RegExp: function RegExp(reference, value) { 66 return reference.test(value); 67 }, 68 Function: function Function(reference, value) { 69 return reference(value); 70 }, 71 Number: function Number(reference, value) { 72 return typeof value === 'string' ? _compare2(reference.toString(), value) : _compare2(reference, value); 73 } 74 }; 75 76 states.Dependent.prototype = { 77 initializeDependee: function initializeDependee(selector, dependeeStates) { 78 var _this2 = this; 79 80 this.values[selector] = {}; 81 82 Object.keys(dependeeStates).forEach(function (i) { 83 var state = dependeeStates[i]; 84 85 if ($.inArray(state, dependeeStates) === -1) { 86 return; 87 } 88 89 state = states.State.sanitize(state); 90 91 _this2.values[selector][state.name] = null; 92 93 $(selector).on('state:' + state, { selector: selector, state: state }, function (e) { 94 _this2.update(e.data.selector, e.data.state, e.value); 95 }); 96 97 new states.Trigger({ selector: selector, state: state }); 98 }); 99 }, 100 compare: function compare(reference, selector, state) { 101 var value = this.values[selector][state.name]; 102 if (reference.constructor.name in states.Dependent.comparisons) { 103 return states.Dependent.comparisons[reference.constructor.name](reference, value); 104 } 105 106 return _compare2(reference, value); 107 }, 108 update: function update(selector, state, value) { 109 if (value !== this.values[selector][state.name]) { 110 this.values[selector][state.name] = value; 111 this.reevaluate(); 112 } 113 }, 114 reevaluate: function reevaluate() { 115 var value = this.verifyConstraints(this.constraints); 116 117 if (value !== this.oldValue) { 118 this.oldValue = value; 119 120 value = invert(value, this.state.invert); 121 122 this.element.trigger({ 123 type: 'state:' + this.state, 124 value: value, 125 trigger: true 126 }); 127 } 128 }, 129 verifyConstraints: function verifyConstraints(constraints, selector) { 130 var _this3 = this; 131 132 var result = void 0; 133 if ($.isArray(constraints)) { 134 var hasXor = $.inArray('xor', constraints) === -1; 135 var len = constraints.length; 136 for (var i = 0; i < len; i++) { 137 if (constraints[i] !== 'xor') { 138 var constraint = this.checkConstraints(constraints[i], selector, i); 139 140 if (constraint && (hasXor || result)) { 141 return hasXor; 142 } 143 result = result || constraint; 144 } 145 } 146 } else if ($.isPlainObject(constraints)) { 147 result = Object.keys(constraints).every(function (constraint) { 148 var check = _this3.checkConstraints(constraints[constraint], selector, constraint); 149 150 return typeof check === 'undefined' ? true : check; 151 }); 152 } 153 return result; 154 }, 155 checkConstraints: function checkConstraints(value, selector, state) { 156 if (typeof state !== 'string' || /[0-9]/.test(state[0])) { 157 state = null; 158 } else if (typeof selector === 'undefined') { 159 selector = state; 160 state = null; 161 } 162 163 if (state !== null) { 164 state = states.State.sanitize(state); 165 return invert(this.compare(value, selector, state), state.invert); 166 } 167 168 return this.verifyConstraints(value, selector); 169 }, 170 getDependees: function getDependees() { 171 var cache = {}; 172 173 var _compare = this.compare; 174 this.compare = function (reference, selector, state) { 175 (cache[selector] || (cache[selector] = [])).push(state.name); 176 }; 177 178 this.verifyConstraints(this.constraints); 179 180 this.compare = _compare; 181 182 return cache; 183 } 184 }; 185 186 states.Trigger = function (args) { 187 $.extend(this, args); 188 189 if (this.state in states.Trigger.states) { 190 this.element = $(this.selector); 191 192 if (!this.element.data('trigger:' + this.state)) { 193 this.initialize(); 194 } 195 } 196 }; 197 198 states.Trigger.prototype = { 199 initialize: function initialize() { 200 var _this4 = this; 201 202 var trigger = states.Trigger.states[this.state]; 203 204 if (typeof trigger === 'function') { 205 trigger.call(window, this.element); 206 } else { 207 Object.keys(trigger || {}
207).forEach(function (event) { 208 _this4.defaultTrigger(event, trigger[event]); 209 }); 210 } 211 212 this.element.data('trigger:' + this.state, true); 213 }, 214 defaultTrigger: function defaultTrigger(event, valueFn) { 215 var oldValue = valueFn.call(this.element); 216 217 this.element.on(event, $.proxy(function (e) { 218 var value = valueFn.call(this.element, e); 219 220 if (oldValue !== value) { 221 this.element.trigger({ 222 type: 'state:' + this.state, 223 value: value, 224 oldValue: oldValue 225 }); 226 oldValue = value; 227 } 228 }, this)); 229 230 states.postponed.push($.proxy(function () { 231 this.element.trigger({ 232 type: 'state:' + this.state, 233 value: oldValue, 234 oldValue: null 235 }); 236 }, this)); 237 } 238 }; 239 240 states.Trigger.states = { 241 empty: { 242 keyup: function keyup() { 243 return this.val() === ''; 244 } 245 }, 246 247 checked: { 248 change: function change() { 249 var checked = false; 250 this.each(function () { 251 checked = $(this).prop('checked'); 252 253 return !checked; 254 }); 255 return checked; 256 } 257 }, 258 259 value: { 260 keyup: function keyup() { 261 if (this.length > 1) { 262 return this.filter(':checked').val() || false; 263 } 264 return this.val(); 265 }, 266 change: function change() { 267 if (this.length > 1) { 268 return this.filter(':checked').val() || false; 269 } 270 return this.val(); 271 } 272 }, 273 274 collapsed: { 275 collapsed: function collapsed(e) { 276 return typeof e !== 'undefined' && 'value' in e ? e.value : !this.is('[open]'); 277 } 278 } 279 }; 280 281 states.State = function (state) { 282 this.pristine = state; 283 this.name = state; 284 285 var process = true; 286 do { 287 while (this.name.charAt(0) === '!') { 288 this.name = this.name.substring(1); 289 this.invert = !this.invert; 290 } 291 292 if (this.name in states.State.aliases) { 293 this.name = states.State.aliases[this.name]; 294 } else { 295 process = false; 296 } 297 } while (process); 298 }; 299 300 states.State.sanitize = function (state) { 301 if (state instanceof states.State) { 302 return state; 303 } 304 305 return new states.State(state); 306 }; 307 308 states.State.aliases = { 309 enabled: '!disabled', 310 invisible: '!visible', 311 invalid: '!valid', 312 untouched: '!touched', 313 optional: '!required', 314 filled: '!empty', 315 unchecked: '!checked', 316 irrelevant: '!relevant', 317 expanded: '!collapsed', 318 open: '!collapsed', 319 closed: 'collapsed', 320 readwrite: '!readonly' 321 }; 322 323 states.State.prototype = { 324 invert: false, 325 326 toString: function toString() { 327 return this.name; 328 } 329 }; 330 331 var $document = $(document); 332 $document.on('state:disabled', function (e) { 333 if (e.trigger) { 334 $(e.target).prop('disabled', e.value).closest('.js-form-item, .js-form-submit, .js-form-wrapper').toggleClass('form-disabled', e.value).find('select, input, textarea').prop('disabled', e.value); 335 } 336 }); 337 338 $document.on('state:required', function (e) { 339 if (e.trigger) { 340 if (e.value) { 341 var label = 'label' + (e.target.id ? '[for=' + e.target.id + ']' : ''); 342 var $label = $(e.target).attr({ required: 'required', 'aria-required': 'aria-required' }).closest('.js-form-item, .js-form-wrapper').find(label); 343 344 if (!$label.hasClass('js-form-required').length) { 345 $label.addClass('js-form-required form-required'); 346 } 347 } else { 348 $(e.target).removeAttr('required aria-required').closest('.js-form-item, .js-form-wrapper').find('label.js-form-required').removeClass('js-form-required form-required'); 349 } 350 } 351 }); 352 353 $document.on('state:visible', function (e) { 354 if (e.trigger) { 355 $(e.target).closest('.js-form-item, .js-form-submit, .js-form-wrapper').toggle(e.value); 356 } 357 }); 358 359 $document.on('state:checked', function (e) { 360 if (e.trigger) { 361 $(e.target).prop('checked', e.value); 362 } 363 }); 364 365 $document.on('state:collapsed', function (e) { 366 if (e.trigger) { 367 if ($(e.target).is('[open]') === e.value) { 368 $(e.target).find('> summary').trigger('click'); 369 } 370 } 371 }); 372})(jQuery, Drupal);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.