Sha256: cf3592efc0ee2e5ccecce48fb27988e01e896a289bccd539221ad00d2dcd427a

Contents?: true

Size: 1.13 KB

Versions: 26

Compression:

Stored size: 1.13 KB

Contents

"use strict";

// This mixin doesn't have an IDL equivalent, but since MouseEvent and KeyboardEvent implement getModifierState() the
// same way, its implementation is shared here.

class EventModifierMixinImpl {
  // Event's constructor assumes all options correspond to IDL attributes with the same names, and sets them on `this`.
  // That is not the case for these modifier boolean options, but since the options are set on `this` anyway we'll
  // access them that way. The spec doesn't say much about the case where keyArg is not one of the valid ones
  // (https://w3c.github.io/uievents-key/#keys-modifier), but at least Chrome returns false for invalid modifiers. Since
  // these invalid modifiers will be undefined on `this` (thus `false` after casting it to boolean), we don't need to do
  // extra checking for validity.
  getModifierState(keyArg) {
    if (keyArg === "Control") {
      return Boolean(this.ctrlKey);
    }
    if (["Alt", "Meta", "Shift"].includes(keyArg)) {
      return Boolean(this[`${keyArg.toLowerCase()}Key`]);
    }
    return Boolean(this[`modifier${keyArg}`]);
  }
}

exports.implementation = EventModifierMixinImpl;

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/events/EventModifierMixin-impl.js