Skip to content

Commit 0b23811

Browse files
authored
Ensure screen readers announce text copying (#66)
1 parent 81687e7 commit 0b23811

17 files changed

+6025
-3306
lines changed

.eslintrc.js

+38-39
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
module.exports = {
2-
"env": {
3-
"browser" : true,
4-
"commonjs": true,
5-
"es6" : true,
6-
"node" : true
7-
},
8-
"extends": "eslint:recommended",
9-
"parserOptions": {
10-
"ecmaVersion": 6,
11-
"sourceType" : "module"
12-
},
13-
"plugins": [
14-
],
15-
"rules": {
16-
"array-bracket-spacing" : ["error", "never"],
17-
"array-callback-return" : ["error"],
18-
"block-scoped-var" : ["error"],
19-
"block-spacing" : ["error", "always"],
20-
"curly" : ["error"],
21-
"dot-notation" : ["error"],
22-
"eqeqeq" : ["error"],
23-
"indent" : ["error", 4],
24-
"linebreak-style" : ["error", "unix"],
25-
"no-console" : ["warn"],
26-
"no-floating-decimal" : ["error"],
27-
"no-implicit-coercion" : ["error"],
28-
"no-implicit-globals" : ["error"],
29-
"no-loop-func" : ["error"],
30-
"no-return-assign" : ["error"],
31-
"no-template-curly-in-string": ["error"],
32-
"no-unneeded-ternary" : ["error"],
33-
"no-unused-vars" : ["error", { "args": "none" }],
34-
"no-useless-computed-key" : ["error"],
35-
"no-useless-return" : ["error"],
36-
"no-var" : ["error"],
37-
"prefer-const" : ["error"],
38-
"quotes" : ["error", "single"],
39-
"semi" : ["error", "always"]
40-
}
2+
env: {
3+
browser: true,
4+
commonjs: true,
5+
es6: true,
6+
node: true,
7+
},
8+
extends: ['eslint:recommended', 'prettier'],
9+
parserOptions: {
10+
ecmaVersion: 6,
11+
sourceType: 'module',
12+
},
13+
plugins: [],
14+
rules: {
15+
'array-bracket-spacing': ['error', 'never'],
16+
'array-callback-return': ['error'],
17+
'block-scoped-var': ['error'],
18+
'block-spacing': ['error', 'always'],
19+
curly: ['error'],
20+
'dot-notation': ['error'],
21+
eqeqeq: ['error'],
22+
indent: ['error', 2],
23+
'linebreak-style': ['error', 'unix'],
24+
'no-console': ['warn'],
25+
'no-floating-decimal': ['error'],
26+
'no-implicit-coercion': ['error'],
27+
'no-implicit-globals': ['error'],
28+
'no-loop-func': ['error'],
29+
'no-return-assign': ['error'],
30+
'no-template-curly-in-string': ['error'],
31+
'no-unneeded-ternary': ['error'],
32+
'no-unused-vars': ['error', { args: 'none' }],
33+
'no-useless-computed-key': ['error'],
34+
'no-useless-return': ['error'],
35+
'no-var': ['error'],
36+
'prefer-const': ['error'],
37+
quotes: ['error', 'single'],
38+
semi: ['error', 'always'],
39+
},
4140
};

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ npm-debug.log*
88
yarn-debug.log*
99
yarn-error.log*
1010

11+
# OS files
12+
.DS_Store
13+
Thumbs.db
14+
1115
# Runtime data
1216
pids
1317
*.pid

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore artifacts
2+
dist
3+
node_modules

.prettierrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "es5"
5+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cSpell.words": ["docsify", "iife"]
3+
}

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 2.1.0
44

5-
*2019-01-23*
5+
_2019-01-23_
66

77
- Added localization (l10n) support via `copyCode` options
88
- Added error feedback (UI & console)
@@ -13,14 +13,14 @@
1313

1414
## 2.0.2
1515

16-
*2018-04-16*
16+
_2018-04-16_
1717

1818
- Updated plugin bundling configuration
1919
- Removed necessity for `init()` method
2020
- Removed external stylesheet
2121

2222
## 1.0.0
2323

24-
*2017-09-28*
24+
_2017-09-28_
2525

2626
- Initial release

README.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ If you prefer to load the latest version of the library, you may do so by omitti
2424
<!-- Latest (not recommended for production) -->
2525
<script src="https://unpkg.com/docsify-copy-code"></script>
2626
```
27+
2728
## Usage
2829

2930
Create a markdown code block with help of triple backticks at the beginning and end of your code. This block will have a copy button on the top right when hovering over it.
@@ -38,11 +39,11 @@ Button text can be customized as follows:
3839
window.$docsify = {
3940
// docsify-copy-code (defaults)
4041
copyCode: {
41-
buttonText : 'Copy to clipboard',
42-
errorText : 'Error',
43-
successText: 'Copied'
44-
}
45-
}
42+
buttonText: 'Copy to clipboard',
43+
errorText: 'Error',
44+
successText: 'Copied',
45+
},
46+
};
4647
```
4748

4849
### Localization (l10n)
@@ -54,25 +55,25 @@ window.$docsify = {
5455
copyCode: {
5556
buttonText: {
5657
'/zh-cn/': '点击复制',
57-
'/ru/' : 'Скопировать в буфер обмена',
58+
'/ru/': 'Скопировать в буфер обмена',
5859
'/de-de/': 'Klicken Sie zum Kopieren',
59-
'/es/' : 'Haga clic para copiar',
60-
'/' : 'Copy to clipboard'
60+
'/es/': 'Haga clic para copiar',
61+
'/': 'Copy to clipboard',
6162
},
6263
errorText: {
6364
'/zh-cn/': '错误',
64-
'/ru/' : 'ошибка',
65-
'/' : 'Error'
65+
'/ru/': 'ошибка',
66+
'/': 'Error',
6667
},
6768
successText: {
6869
'/zh-cn/': '复制',
69-
'/ru/' : 'Скопировано',
70+
'/ru/': 'Скопировано',
7071
'/de-de/': 'Kopiert',
71-
'/es/' : 'Copiado',
72-
'/' : 'Copied'
73-
}
74-
}
75-
}
72+
'/es/': 'Copiado',
73+
'/': 'Copied',
74+
},
75+
},
76+
};
7677
```
7778

7879
**Note:** Docsify's [alias](https://docsify.js.org/#/configuration?id=alias) option makes it easy to manage local content using separate directories. See the [`/demo/`](https://github.com/jperasmus/docsify-copy-code/tree/master/demo) content in this repo for an example.

demo/index.html

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<!DOCTYPE html>
22
<html>
3+
34
<head>
45
<meta charset="utf-8">
56
<meta http-equiv="X-UA-Compatible" content="IE=edge">
67
<meta name="viewport" content="width=device-width,initial-scale=1">
78
<link rel="stylesheet" href="https://unpkg.com/docsify/themes/vue.css">
89
<!-- <link rel="stylesheet" href="https://unpkg.com/docsify-themeable/dist/css/theme-simple.css"> -->
910
</head>
11+
1012
<body>
1113
<div id="app"></div>
1214
<script>
1315
window.$docsify = {
1416
// GENERAL
1517
// -----------------------------------------------------------------
16-
name : 'docsify-copy-code',
17-
repo : 'https://github.com/jperasmus/docsify-copy-code',
18+
name: 'docsify-copy-code',
19+
repo: 'https://github.com/jperasmus/docsify-copy-code',
1820
loadNavbar: 'navbar.md',
1921
// themeColor: 'purple',
2022

@@ -26,8 +28,8 @@
2628
// Locals
2729
'/zh-cn/(.*)': './zh-cn/$1',
2830
'/de-de/(.*)': './de-de/$1',
29-
'/ru/(.*)' : './ru/$1',
30-
'/es/(.*)' : './es/$1'
31+
'/ru/(.*)': './ru/$1',
32+
'/es/(.*)': './es/$1'
3133
},
3234

3335
// PLUGINS
@@ -39,27 +41,28 @@
3941

4042
buttonText: {
4143
'/zh-cn/': '点击复制',
42-
'/ru/' : 'Скопировать в буфер обмена',
44+
'/ru/': 'Скопировать в буфер обмена',
4345
'/de-de/': 'Klicken Sie zum Kopieren',
44-
'/es/' : 'Haga clic para copiar',
45-
'/' : 'Copy to clipboard'
46+
'/es/': 'Haga clic para copiar',
47+
'/': 'Copy to clipboard'
4648
},
4749
errorText: {
4850
'/zh-cn/': '错误',
49-
'/ru/' : 'ошибка',
50-
'/' : 'Error'
51+
'/ru/': 'ошибка',
52+
'/': 'Error'
5153
},
5254
successText: {
5355
'/zh-cn/': '复制',
54-
'/ru/' : 'Скопировано',
56+
'/ru/': 'Скопировано',
5557
'/de-de/': 'Kopiert',
56-
'/es/' : 'Copiado',
57-
'/' : 'Copied'
58+
'/es/': 'Copiado',
59+
'/': 'Copied'
5860
}
5961
}
6062
}
6163
</script>
6264
<script src="https://unpkg.com/docsify@4"></script>
6365
<script src="/dist/docsify-copy-code.js"></script>
6466
</body>
67+
6568
</html>

index.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// Fix for v1.x installations
2-
(function() {
3-
// Deprecation warning for v1.x: init()
4-
window.DocsifyCopyCodePlugin = {
5-
init: function() {
6-
return function(hook, vm) {
7-
hook.ready(function() {
8-
// eslint-disable-next-line
9-
console.warn('[Update] docsify-copy-code has been updated. Please see new installation instructions at https://github.com/jperasmus/docsify-copy-code.');
10-
});
11-
};
12-
}
13-
};
2+
(function () {
3+
// Deprecation warning for v1.x: init()
4+
window.DocsifyCopyCodePlugin = {
5+
init: function () {
6+
return function (hook, vm) {
7+
hook.ready(function () {
8+
// eslint-disable-next-line no-console
9+
console.warn(
10+
'[Update] docsify-copy-code has been updated. Please see new installation instructions at https://github.com/jperasmus/docsify-copy-code.'
11+
);
12+
});
13+
};
14+
},
15+
};
1416
})();

0 commit comments

Comments
 (0)