consul/ui-v2/config/environment.js
John Cowen e609defd70 ui: Allow text selection of clickable elements and their contents (#5770)
* ui: Allow text selection of clickable elements and their contents

This commit disables a click on mousedown be removing the `href`
attribute and moving it to a `data-href` attribute. On mouseup it will
only move it back if there is no selection. This means that an anchor
will only be followed on click _if_ there is no selection.

This fixes the fact that whenever you select some copy within a
clickable element it immediately throws you into the linked page when
you release your mouse.

Further notes:

We use the `isCollapsed` property here which 'seems' to be classed as
'experimental' in one place where I researched it:

https://developer.mozilla.org/en-US/docs/Web/API/Selection/isCollapsed

Although in others it makes no mention of this 'experimental' e.g:

- https://webplatform.github.io/docs/dom/Selection/isCollapsed/
- https://w3c.github.io/selection-api/#dom-selection-iscollapsed

I may have gone a little overboard in feature detection for this, but I
conscious of that fact that if `isCollapsed` doesn't exist at some point
in the future (something that seems unlikely). The code here will have
no effect on the UI. But I'd specifically like a second pair of eyes on
that.

* ui: Don't break right click, detects a secondary click on mousedown

* ui: Put anchor selection capability behind an ENV var
2019-09-04 08:34:58 +00:00

105 lines
2.9 KiB
JavaScript

'use strict';
const fs = require('fs');
const path = require('path');
module.exports = function(environment) {
let ENV = {
modulePrefix: 'consul-ui',
environment,
rootURL: '/ui/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
'ds-improved-ajax': true,
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false,
},
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
resizeServiceDefaults: {
injectionFactories: ['view', 'controller', 'component'],
},
};
// TODO: These should probably go onto APP
ENV = Object.assign({}, ENV, {
// TODO: Let people alter this, as with anchor selection
CONSUL_UI_DISABLE_REALTIME: false,
CONSUL_UI_DISABLE_ANCHOR_SELECTION:
typeof process.env.CONSUL_UI_DISABLE_ANCHOR_SELECTION !== 'undefined',
CONSUL_GIT_SHA: (function() {
if (process.env.CONSUL_GIT_SHA) {
return process.env.CONSUL_GIT_SHA;
}
return require('child_process')
.execSync('git rev-parse --short HEAD')
.toString()
.trim();
})(),
CONSUL_VERSION: (function() {
if (process.env.CONSUL_VERSION) {
return process.env.CONSUL_VERSION;
}
// see /scripts/dist.sh:8
const version_go = `${path.dirname(path.dirname(__dirname))}/version/version.go`;
const contents = fs.readFileSync(version_go).toString();
return contents
.split('\n')
.find(function(item, i, arr) {
return item.indexOf('Version =') !== -1;
})
.trim()
.split('"')[1];
})(),
CONSUL_BINARY_TYPE: (function() {
if (process.env.CONSUL_BINARY_TYPE) {
return process.env.CONSUL_BINARY_TYPE;
}
return 'oss';
})(),
CONSUL_DOCUMENTATION_URL: 'https://www.consul.io/docs',
CONSUL_COPYRIGHT_URL: 'https://www.hashicorp.com',
CONSUL_COPYRIGHT_YEAR: '2019',
});
if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
// ENV['ember-cli-mirage'] = {
// enabled: false,
// };
}
if (environment === 'test') {
// Testem prefers this...
ENV.locationType = 'none';
// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
ENV['ember-cli-api-double'] = {
reader: 'html',
endpoints: ['/node_modules/@hashicorp/consul-api-double/v1'],
};
}
if (environment === 'production') {
// here you can enable a production-specific feature
}
return ENV;
};