...
 
Commits (46)
zh*
# zh*
LICENSE*
*.css
*.html
!test/index.html
*.min.js
*.sa.js
#data/*.json
src/*.json
!test/static.html
*.min.js*
*.js.map
*.*gz
*copy*
*.php
*BAK*
/*.png
x_legacy/
package*
!package.json
node_modules/
*.log
*.php
composer.*
vendor/
*.js.map
*BAK*
*.js
!dist/gaad-widget.js
!bin/gaad.js
!bin/_ver.js
!src/*.js
!index.js
locales.json
*analytics*
ndf-*
*.yaml
# .gitlab-ci.yml
# SEE: https://gitlab.com/nfreear/gaad-widget/-/ci/lint
# https://gitlab.com/gitlab-examples/nodejs/blob/master/.gitlab-ci.yml
# https://gist.github.com/thornbill/b4f44ac81106fd539d5f493a269bf25b
# https://hub.docker.com/r/library/node/tags/
image: node:6
variables:
GIT_DEPTH: 8
cache:
paths:
- node_modules/
stages:
- test
before_script:
- node -v
- npm -v
- npm install
job 1:
stage: test
script:
- npm run build
- npm test
- npm run serve-ci & sleep 5; npm run pa11y-ci
artifacts:
# untracked: true
paths:
- dist/*
# - data/*
- gaad-*.tgz
- _*.png
expire_in: 1 week
after_script:
- npm run ps
- npm run kill-server
- npm pack
- nvm --version
# End.
{
"#": "Automated accessibility testing ~ https://github.com/pa11y/pa11y-ci",
"defaults": {
"screenCapture": "./_pa11y-screen-capture.png",
"standard": "WCAG2AAA",
"timeout": 5000,
"wait": 2000,
"verifyPage": "gaad-widget-js"
},
"urls": [
"http://127.0.0.1:9001/embed/?gaadwidget=force&_ua=pa11y-ci",
"http://127.0.0.1:9001/test/static.html?_ua=pa11y-ci"
],
"X-UNUSED--urls": [
"http://127.0.0.1:9001/test/index.html?gaadwidget=force&_ua=pa11y-ci",
"http://127.0.0.1:9001/test/fail.html?gaadwidget=force&_ua=pa11y-ci",
"https://nick.freear.org.uk/2017/05/14/gaad-widget.html?gaadwidget=force#id-gaad"
]
}
language: node_js
node_js:
- "4"
node_js: 6
git:
depth: 5
depth: 8
install: npm install
install:
- npm install
- npm run install-legacy-datejs
before_script: npm run build
script:
- node bin/gaad.js
- npm run build
- npm run build-min
- npm test
# http://cruft.io/posts/automated-accessibility-testing-node-travis-ci-pa11y/
- npm run serve-ci & sleep 5; npm run pa11y-ci;
after_script:
- ls -alh build
- npm run pa11y
- npm run ps
- npm run kill-server
- ls -alh dist
- ls -alh data
#- cat dist/gaad-widget.min.js
# End.
[![Build status — Travis-CI][travis-icon]][travis]
# gaad-widget changelog
[README][]
* Download on the [releases page][rel]. (Also, see the [wishlist][].)
## Version 3.2.2
* _Date: ~ May 2018_
* _Tag: 3.2.2_
* Fix `getConfig()` Javascript function, #11;
## Version 3.2.1
* _Date: ~ May 2018_
* _Tag: 3.2.1_
* Fix — Javascript selector for configuration — `script[ data-gaad-widget ]` (for WordPress etc.!), #11;
* Fix — switch `font-size` in the CSS stylesheet from `em` to `rem`;
* Fix — switch `url` field in locale JSON from `.html` to `.php`;
* Fix — adopt _proper_ release of `node-analytics-ga` package;
* Fix — make URL parameters like `?gaadwidget=force` more flexible (allow and `?..` and `#..`)
* Add [Gitlab CI][] test;
* Integration — [WordPress][wp] ([E-Access Bulletin][eab]);
* Integration — [CloudEngine][ce] ([Cloudworks][cw]);
## Version 3.2.0
* _Date: 30 April 2018_
* _Tag: 3.2.0_
* Incorrect message bug - logic bug (see screenshot) #10;
* Add a "_Put gaad-widget on your site_" link ([arrow][]);
* Display language-specific GAAD string, not English — bug/enhancement;
* Re-factor language/ locale/ translation/ i18n code, #4;
* Initial Chinese, Simplified translation, #4;
* Initial Spanish translation, #4;
* Automated accessibility testing, via [pa11y-ci][] and `live-server`, #9;
* Cast strings to integers in JSON — `parseInt()`;
* Adopt `lessc` to build a LESS stylesheet;
* Added [GitLab CI][] integration;
* Google Analytics via `node-analytics-ga`, can be disabled (see [README][]).
## Version 3.1.0 (Beta)
* _Date: 1 July 2017_
* _Tag: 3.1.0-beta_
* Adopted [Browserify][],
* Switch from `Datejs` include, to a lookup of JSON embedded in the Javascript,
* Reduces Javascript file size from 55 to ~8 kilobytes 💓
* Renamed Javascript, CSS etc. `build/GAAD.widget.js` → `build/gaad-widget.js`
* Renamed default HTML `id=".."` from `id-gaad``id-gaad-widget` (plus, `data-` attribute)
### v2.1
* Added `?gaadwidget=force` URL parameter, [#2][wishlist]
* Added iCal and JSON data files.
### v2.0
* Different after-event message - containing next year's date, [#5][b/a] - thanks [@srinivasu..][]
* Added translation into Français/French, [#4][i18n]
* Added neutral `black` theme, [#2][wishlist]
* Changed default `days_after` from 5 to 10.
### v1.x
* Zero configuration required by default,
* Paste and forget - the banner appears _10_ days before and disappears _10_ days after,
* Configurable,
* Basic internationalization,
* Basic automated testing in place (Travis-CI),
* Accessible ~ _let me know if you spot a problem!_
* Responsive design,
* Compatible with [all modern browsers, and MSIE 9-11][ie],
* CDN courtesy of [RawGit][] (thank you!) - with HTTPS/SSL.
## Version 1.0 (Alpha)
* _Date: 15 May 2017_
* _Tag: 1.0-alpha_
---
* Download on the [releases page][rel]. (Also, see the [wishlist][].)
[README][]
[readme]: https://github.com/nfreear/gaad-widget#readme
[rel]: https://github.com/nfreear/gaad-widget/releases
[wishlist]: https://github.com/nfreear/gaad-widget/issues/2#!-Wishlist
[i18n]: https://github.com/nfreear/gaad-widget/issues/4#!-i18n
[ie]: https://github.com/nfreear/gaad-widget/issues/3#!-MSIE-9-11
[pa11y-ci]: https://github.com/pa11y/pa11y-ci
[browserify]: http://browserify.org/
[@srinivasu..]: http://srinivasu.org/
[arrow]: http://xahlee.info/comp/unicode_arrows.html#!-U-2913
"U+2913: DOWNWARDS ARROW TO BAR — ⤓"
[gitlab ci]: https://gitlab.com/nfreear/gaad-widget/pipelines "GitLab CI"
[travis]: https://travis-ci.org/nfreear/gaad-widget
[travis-icon]: https://api.travis-ci.org/nfreear/gaad-widget.svg
"Build status – Travis-CI (NPM/eslint)"
[ce]: https://github.com/IET-OU/cloudengine/issues/376 "IET-OU/cloudengine # 376"
[wp]: https://github.com/nfreear/wp-eab-plugins/commit/7509d3612830f5b607982581d91290c52e648d97
"nfreear/wp-eab-plugins @ 7509d36"
[cw]: http://cloudworks.ac.uk/#!-gaadwidget=force "Cloudworks site"
[eab]: http://www.headstar.com/eablive/?gaadwidget=f "E-Access Bulletin site"
[End]: //.
[![Build status — Travis-CI][travis-icon]][travis]
[![GitLab pipeline status][gitlab-icon]][gitlab]
[![js-semistandard-style][semi-icon]][semi]
[![GAAD-widget on Npmjs][npm-icon]][npm]
[![License][license-icon]][mit]
[![Total downloads ~ NPMJS.com][downl-icon]][npm]
[![Size of Javascript][size-icon]][build]
[![vulnerabilities][snyk-icon]][snyk]
[![Accessibility testing - GAAD passes][pa11y-icon]][pa11y-ci]
<!--[![Browserify][built-icon]][gh]-->
# nfreear/gaad-widget
Display a banner-link to promote [Global Accessibility Awareness Day (GAAD)][gaad].
The banner displays for a configurable period before and after the day.
The banner displays for a configurable period before and after the day,
and the emphasis is on easy site-integration, via a [CDN][unpkg].
[![Global Accessibility Awareness Day][gaad-image]][gaad]
......@@ -13,73 +22,58 @@ The banner displays for a configurable period before and after the day.
> The purpose of GAAD is to get everyone talking, thinking and learning about digital
> (web, software, mobile, etc.) access/inclusion and people with different disabilities.
Built on [Datejs][].
Read the [blog post][blog]. Built on [Datejs][] ([API][datejs-api]).
Note ~ this is not an official widget!
_Note ~ this is not an official widget!_
[Original Gist][gist].
## Features
## Release notes
### Features
### v2.1
* Added `?gaadwidget=force` URL parameter, [#2][wishlist]
* Added iCal and JSON data files.
### v2.0
* Different after-event message - containing next year's date, [#5][b/a] - thanks [@srinivasu..][]
* Added translation into Français/French, [#4][i18n]
* Added neutral `black` theme, [#2][wishlist]
* Changed default `days_after` from 5 to 10.
### v1.x
* Zero configuration required by default,
* Paste and forget - the banner appears _10_ days before and disappears _10_ days after,
* Configurable,
* Basic internationalization,
* Basic automated testing in place (Travis-CI),
* Accessible ~ _let me know if you spot a problem!_
* Responsive design,
* Compatible with [all modern browsers, and MSIE 9-11][ie],
* CDN courtesy of [RawGit][] (thank you!) - with HTTPS/SSL.
[Wishlist][].
* See the [CHANGELOG][].
* Download on the [releases page][rel]. (Also, see the [wishlist][].)
## Install and test
```sh
npm install
npm i gaad-widget
npm run build
npm run build-min
npm test
```
## Usage
Via [RawGit][] - production / CDN:
Via [unpkg][][browse][] — production CDN:
```html
<div id="id-gaad-widget"></div>
<script src="https://unpkg.com/gaad-widget@^3#"></script>
```
Via [RawGit][] — production CDN:
```html
<div id="id-gaad"></div>
<div id="id-gaad-widget"></div>
<script src="https://cdn.rawgit.com/nfreear/gaad-widget/2.1-beta/build/GAAD.widget.js"></script>
<script src="https://cdn.rawgit.com/nfreear/gaad-widget/3.2.1/dist/gaad-widget.js"></script>
```
Local hosting:
```html
<div id="id-gaad"></div>
<div id="id-gaad-widget"></div>
<script src="build/GAAD.widget.js" ></script>
<script src="dist/gaad-widget.js" ></script>
```
Setting the `days_before` option:
```html
<div id="id-gaad"></div>
<div id="id-gaad-widget"></div>
<script src="build/GAAD.widget.js" data-gaad='{ "days_before": 20 }'></script>
<script src="dist/gaad-widget.js" data-gaad-widget='{ "days_before": 20 }'></script>
```
Setting several configuration options:
......@@ -88,49 +82,104 @@ Setting several configuration options:
<div id="custom_id"></div>
<script
src="build/GAAD.widget.js"
data-gaad='{ "id": "custom_id", "days_after": 10, "theme": "black", "debug": true }'
src="dist/gaad-widget.js"
data-gaad-widget='{ "id": "custom_id", "days_after": 10, "theme": "black", "debug": true }'
></script>
```
## Analytics
Anonymous usage statistics via Google Analytics is being added for version `3.2+` (`> 3.1.0`). It will be [enabled][analytics] by default, and can be disabled thus:
```html
<div id="id-gaad-widget"></div>
<script src="dist/gaad-widget.js" data-gaad-widget='{ "analytics": null }'></script>
```
## Translation
[Translations][i18n-code], [#4][i18n].
Please help with translating `gaad-widget` into your language!
* [Translation information ~ #4][i18n]
* [Current translations][i18n-code].
Français (French):
```html
<div id="id-gaad"></div>
<div id="id-gaad-widget"></div>
<script src="build/GAAD.widget.js" data-gaad='{ "lang": "fr" }' ></script>
<script src="dist/gaad-widget.js" data-gaad-widget='{ "lang": "fr" }' ></script>
```
## WordPress
A [plugin for WordPress][wp].
## License
License: [MIT][].
Twitter: [@nfreear][], [@gbla11yday][].
_See the related [isad-widget][]._
[blog]: http://nick.freear.org.uk/2017/05/14/gaad-widget.html?utm_source=readme
[GAAD]: http://globalaccessibilityawarenessday.org/?utm_source=github&utm_campaign=gaad-widget
[@gbla11yday]: https://twitter.com/gbla11yday
[@nfreear]: https://twitter.com/nfreear
[@srinivasu..]: http://srinivasu.org "Suggested by @srinivasuchakravarthula"
[gaad-widget]: https://github.com/nfreear/gaad-widget
[gaad-image]: https://github.com/nfreear/gaad-widget/raw/master/style/GAAD.widget.png
[gaad-image]: https://github.com/nfreear/gaad-widget/raw/3.x/style/gaad-widget-after.png
[gaad-img-00]: https://github.com/nfreear/gaad-widget/raw/3.x/style/gaad-widget.png
[changelog]: https://github.com/nfreear/gaad-widget/blob/3.x/CHANGELOG.md
[rel]: https://github.com/nfreear/gaad-widget/releases "Release notes / changelog"
[wishlist]: https://github.com/nfreear/gaad-widget/issues/2#!-Wishlist "Bug #2, Wishlist"
[i18n]: https://github.com/nfreear/gaad-widget/issues/4 "Bug #4, Translations (v 2.x)"
[i18n-code]: https://github.com/nfreear/gaad-widget/tree/master/locales "Translations, JSON format"
[i18n]: https://github.com/nfreear/gaad-widget/issues/4#!-i18n "Bug #4, Translations (v 2.x)"
[i18n-code]: https://github.com/nfreear/gaad-widget/tree/3.x/locales "Translations, JSON format"
[b/a]: https://github.com/nfreear/gaad-widget/issues/5 "Bug #5, Separate before and after messages (v 2.x)"
[ie]: https://github.com/nfreear/gaad-widget/issues/3#!-MSIE-9-11 "Bug #3, Browser compatibility"
[analytics]: https://github.com/nfreear/gaad-widget/blob/3.x/src/configure.js#L36-L40
"Analytics configuration, JS code"
[gist]: https://gist.github.com/nfreear/eef4be96147cb5c1182cbc9e595f2833
[Datejs]: https://github.com/datejs/Datejs
[wp]: https://gist.github.com/nfreear/e5520adbb930e537ef5fe2e0aab231d1 "WordPress plugin (PHP)"
[Datejs]: https://npmjs.com/package/datejs "Thanks: @abritinthebay"
[Datejs-api]: https://github.com/datejs/Datejs#example-usage "API only (legacy code-base)"
[RawGit]: https://rawgit.com/
"Serves Git files with the correct mime-type; content delivery network (CDN)"
[MIT]: https://nfreear.mit-license.org/2017#!-gaad-widget "MIT License"
"RawGit serves Git files with the correct mime-type; a content delivery network (CDN)"
[unpkg]: https://unpkg.com/ "unpkg is a fast content delivery network (CDN) for everything on npm"
[browse]: https://unpkg.com/gaad-widget@^3/ "Browse the most recent version on Unpkg.com"
[MIT]: https://nfreear.mit-license.org/2017-2018#!-gaad-widget "MIT License | © Nick Freear, 2017-04-27, 2018"
[mit-txt]: https://nfreear.mit-license.org/2017-2018/license.txt "MIT License | © Nick Freear"
[travis]: https://travis-ci.org/nfreear/gaad-widget
[travis-icon]: https://api.travis-ci.org/nfreear/gaad-widget.svg
"Build status – Travis-CI (NPM/eslint)"
[semi]: https://github.com/Flet/semistandard
[semi-icon]: https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square
"Javascript coding style — 'semistandard'"
[npm]: https://npmjs.com/package/gaad-widget
[npm-icon]: https://img.shields.io/npm/v/gaad-widget.svg
[license-icon]: https://img.shields.io/npm/l/gaad-widget.svg
[downl-icon]: https://img.shields.io/npm/dt/gaad-widget.svg "Count of total downloads ~NPM"
[size-icon]: https://img.shields.io/github/size/nfreear/gaad-widget/dist/gaad-widget.js.svg
"Size of built Javascript, kilo-bytes (kB) ~ on GitHub"
[built-icon]: https://img.shields.io/badge/built_with-browserify-blue.svg
"Built with Browserify"
[build]: https://github.com/nfreear/gaad-widget/tree/3.x/dist
[Browserify]: http://browserify.org/
"Browserify lets you require('modules') in the browser by bundling your dependencies."
[snyk]: https://snyk.io/test/npm/gaad-widget "Vulnerability count ~ via Snyk"
[snyk-icon]: https://snyk.io/test/npm/gaad-widget/badge.svg
[pa11y-ci]: https://github.com/pa11y/pa11y-ci
"Automated accessibility testing - via 'pa11y-ci'"
[pa11y-icon]: https://img.shields.io/badge/accessibility-pa11y--ci-blue.svg
[wcag-icon]: https://img.shields.io/badge/accessibility-WCAG_2.0_AAA-green.svg
[gitlab-icon]: https://gitlab.com/nfreear/gaad-widget/badges/3.x/pipeline.svg
[gitlab-co]: https://gitlab.com/nfreear/gaad-widget/commits/3.x
[gitlab]: https://gitlab.com/nfreear/gaad-widget/pipelines "GitLab pipeline status"
[isad-widget]: https://github.com/nfreear/isad-widget
"banner-link for International Stuttering Awareness Day (ISAD)"
[End]: //.
#!/usr/bin/env node
/**
* CLI. Implant `package.version` in index.js, README.md etc.
*
* @copyright © Nick Freear, 04-, 25-June-2017, 2018.
* @license MIT
* @see https://github.com/nfreear/gaad-widget
*/
const replace = require('replace');
const INDEX_JS = path('/../index.js');
const README = path('/../README.md');
const TEST_HTML = path('/../test/index.html');
const PKG = require('../package.json');
const VERSION_TAG = PKG.version; // Was: .replace(/\.0(-.+)?/, '$1');
const CARET_VERSION = PKG[ 'x-version-hat' ]; // Example, '^3'
console.warn('VERSION_TAG :', VERSION_TAG, CARET_VERSION);
replace({
paths: [ INDEX_JS ],
regex: /VERSION = '.+';(.+Auto.)?/,
replacement: version('VERSION = \'%s\'; // <Auto>'),
count: true,
recursive: false
});
replace({
paths: [ INDEX_JS ],
regex: /@version \d\.\d\.\d(-[.\w]+)?/,
replacement: version('@version %s'),
count: true,
recursive: false
});
replace({
paths: [ README, TEST_HTML ],
regex: /\/gaad-widget(\/|@)(\d\.\d\.\d(-[.\w]+)?)/g,
replacement: version('/gaad-widget$1%s'),
count: true,
recursive: false
});
replace({
paths: [ README ],
regex: /\/gaad-widget@[^\d]\d+(\.\d)?/g,
replacement: '/gaad-widget@' + CARET_VERSION,
count: true,
recursive: false
});
function path (file) {
return require('path').join(__dirname, file);
}
function version (str) {
return str.replace('%s', VERSION_TAG);
}
#!/usr/bin/env node
/**
* Node CLI. Build iCalendar and JSON data files.
* Node CLI. Build iCalendar, JSON data and lookup files.
*
* @copyright © Nick Freear, 19-May-2017.
* @copyright © Nick Freear, 19-May-2017, 2018.
* @license MIT.
* @link https://github.com/nfreear/gaad-widget
* @see https://github.com/nfreear/gaad-widget
*/
const NO_LIABILITY =
'License: MIT. The data is provided "as is". I accept no responsibility for the accuracy or otherwise of the data, or any losses arising.';
"License: MIT. The data is provided 'as is'. I accept no responsibility for the accuracy or otherwise of the data, or any losses arising.";
const path = require('path');
const ICS_FILE = path.join(__dirname, '/../data/gaad.en.ics');
const JSON_FILE = path.join(__dirname, '/../data/gaad.json');
const LOCALE_DIR = path.join(__dirname, '/../locales/');
// const LOCALE_FILE = path.join(__dirname, '/../src/locales.json');
// const JSON_TEXT = path.join(__dirname, '/../src/gaad-texts.json');
const PKG = require('../package.json');
const ICS_FILE = abspath('../data/gaad.en.ics');
const JSON_FILE = abspath('../data/gaad.json');
const MIN_FILE = abspath('../data/gaad-dates.min.json');
const LOCALE_DIR = abspath('../locales/');
const LOCALE_FILE = abspath('../data/locales.json');
// const JSON_TEXT = abspath('../src/gaad-texts.json');
const GAAD_START_YEAR = 2011;
const LIMIT_YEARS = 15;
// const A_DAY = 24 * 60 * 60;
const fs = require('fs');
const icalendar = require('icalendar');
const datejs = require('datejs');
const texts = readLocaleTexts(LOCALE_DIR);
const texts = readLocaleTexts(LOCALE_DIR, PKG[ 'x-locales' ]);
const GAAD_URL = texts.en.url;
const today = new Date();
var ical = new icalendar.iCalendar(); // eslint-disable-line
var gaadobj = {
'//': NO_LIABILITY,
'timestamp': today.toString('u'),
texts: texts,
'#': NO_LIABILITY,
name: PKG.name,
version: PKG.version,
timestamp: today.toString('u'),
url: PKG.repository,
// texts: texts,
// locales: PKG[ 'x-locales' ],
count_years: LIMIT_YEARS,
dates: {}
};
var idx;
......@@ -45,6 +50,8 @@ for (idx = 0; idx < LIMIT_YEARS; idx++) {
var event = ical.addComponent('VEVENT');
var year = (GAAD_START_YEAR + idx) + '';
// "...we invite you to help us mark GAAD on the third Thursday of May."
// ~~ http://globalaccessibilityawarenessday.org/background.html ~~
var GAAD_DATE = new Date(year).may().third().thursday();
console.log('> GAAD %d: %s', idx + 0, GAAD_DATE.toString());
......@@ -57,44 +64,71 @@ for (idx = 0; idx < LIMIT_YEARS; idx++) {
event.setProperty('DTEND;VALUE=DATE', GAAD_DATE.toString('yyyyMMdd'));
gaadobj.dates[ year ] = {
'{x}': idx + 0,
'{d}': GAAD_DATE.toString('dd'),
'{x}': parseInt(idx),
'{d}': parseInt(GAAD_DATE.toString('dd')),
'{th}': GAAD_DATE.toString('S'),
'{m}': GAAD_DATE.toString('MMMM'),
'{y}': GAAD_DATE.toString('yyyy')
'{y}': parseInt(GAAD_DATE.toString('yyyy')),
// iso: GAAD_DATE.toISOString(),
ts: GAAD_DATE.getTime() // Milli-seconds since epoch.
};
}
var json = JSON.stringify(gaadobj, null, 2);
// var locjson = JSON.stringify(texts, null, 2);
var ics = ical.toString();
fs.writeFile(JSON_FILE, json);
// fs.writeFile(LOCALE_FILE, locjson);
fs.writeFile(ICS_FILE, ics);
var gaaddates = {
dates: gaadobj.dates
};
setTimeout(function () {
var jsonstat = fs.statSync(JSON_FILE);
var icsstat = fs.statSync(ICS_FILE);
const json = JSON.stringify(gaadobj, null, 2);
const minjson = JSON.stringify(gaaddates);
const locjson = JSON.stringify(texts, null, 2);
const ics = ical.toString();
console.log('JSON, %d bytes: %s', jsonstat.size, JSON_FILE);
console.log('iCal, %d bytes: %s', icsstat.size, ICS_FILE);
}, 100);
writeStatFile(JSON_FILE, json, 'JSON');
writeStatFile(LOCALE_FILE, locjson, 'LANG');
writeStatFile(MIN_FILE, minjson, 'MIN');
writeStatFile(ICS_FILE, ics, 'iCal');
console.log(datejs);
// ------------------------------------
function readLocaleTexts (localedir) {
var texts = {};
fs.readdirSync(localedir).forEach(function (file) {
console.log('Locale: %s', file);
function abspath (path) {
return require('path').join(__dirname, path);
}
var locale = file.replace('.json', '');
var jsontext = fs.readFileSync(localedir + file, 'utf8');
texts[ locale ] = JSON.parse(jsontext);
function writeStatFile (file, data, label) {
const FS = require('fs');
FS.writeFile(file, data, 'utf8', function (err) {
if (err) throw err;
const stat = FS.statSync(file);
console.log('%s, %d bytes: %s', label, stat.size, file);
});
}
function readLocaleTexts (localedir, locales) {
var texts = {};
var locale;
for (var idx = 0; idx < locales.length; idx++) {
locale = locales[ idx ];
texts[ locale ] = removeJsonComments(require(localedir + locale));
}
return texts;
}
// https://github.com/i18next/i18next/issues/108#__A-comment
function removeJsonComments (locale) {
var texts = {};
var prop;
// console.log(locale);
for (prop in locale) {
if (!prop.match(/^#_+/)) {
texts[ prop ] = locale[ prop ];
}
}
return texts;
}
......
This diff is collapsed.
{
"//": "License: MIT. The data is provided \"as is\". I accept no responsibility for the accuracy or otherwise of the data, or any losses arising.",
"timestamp": "2017-05-21 10:29:48Z",
"texts": {
"en": {
"name": "Global Accessibility Awareness Day (GAAD)",
"before": "Join us on Thursday May {d}{th}, {y} and mark the {x}th <a {at}>{g}</a>{g}</a>.",
"after": "Put next year's <a {at}>{g}</a>{g}</a>, Thursday May {d}{th}, {y}, in your diary. See you then!",
"url": "http://globalaccessibilityawarenessday.org"
},
"fr": {
"before": "Rejoignez-nous le jeudi {d} mai {y} et marquez le {x}ème <a {at}>{g}</a>.",
"after": "Mettez le <a {at}>{g}</a> de l'année prochaine, le jeudi {d} mai {y} dans votre journal. À plus tard!",
"url": "/gaadfr.html"
}
},
"#": "License: MIT. The data is provided 'as is'. I accept no responsibility for the accuracy or otherwise of the data, or any losses arising.",
"name": "gaad-widget",
"version": "3.2.1",
"timestamp": "2018-05-11 13:27:05Z",
"url": "https://github.com/nfreear/gaad-widget.git",
"count_years": 15,
"dates": {
"2011": {
"{x}": 0,
"{d}": "19",
"{d}": 19,
"{th}": "th",
"{m}": "May",
"{y}": "2011"
"{y}": 2011,
"ts": 1305759600000
},
"2012": {
"{x}": 1,
"{d}": "17",
"{d}": 17,
"{th}": "th",
"{m}": "May",
"{y}": "2012"
"{y}": 2012,
"ts": 1337209200000
},
"2013": {
"{x}": 2,
"{d}": "16",
"{d}": 16,
"{th}": "th",
"{m}": "May",
"{y}": "2013"
"{y}": 2013,
"ts": 1368658800000
},
"2014": {
"{x}": 3,
"{d}": "15",
"{d}": 15,
"{th}": "th",
"{m}": "May",
"{y}": "2014"
"{y}": 2014,
"ts": 1400108400000
},
"2015": {
"{x}": 4,
"{d}": "21",
"{d}": 21,
"{th}": "st",
"{m}": "May",
"{y}": "2015"
"{y}": 2015,
"ts": 1432162800000
},
"2016": {
"{x}": 5,
"{d}": "19",
"{d}": 19,
"{th}": "th",
"{m}": "May",
"{y}": "2016"
"{y}": 2016,
"ts": 1463612400000
},
"2017": {
"{x}": 6,
"{d}": "18",
"{d}": 18,
"{th}": "th",
"{m}": "May",
"{y}": "2017"
"{y}": 2017,
"ts": 1495062000000
},
"2018": {
"{x}": 7,
"{d}": "17",
"{d}": 17,
"{th}": "th",
"{m}": "May",
"{y}": "2018"
"{y}": 2018,
"ts": 1526511600000
},
"2019": {
"{x}": 8,
"{d}": "16",
"{d}": 16,
"{th}": "th",
"{m}": "May",
"{y}": "2019"
"{y}": 2019,
"ts": 1557961200000
},
"2020": {
"{x}": 9,
"{d}": "21",
"{d}": 21,
"{th}": "st",
"{m}": "May",
"{y}": "2020"
"{y}": 2020,
"ts": 1590015600000
},
"2021": {
"{x}": 10,
"{d}": "20",
"{d}": 20,
"{th}": "th",
"{m}": "May",
"{y}": "2021"
"{y}": 2021,
"ts": 1621465200000
},
"2022": {
"{x}": 11,
"{d}": "19",
"{d}": 19,
"{th}": "th",
"{m}": "May",
"{y}": "2022"
"{y}": 2022,
"ts": 1652914800000
},
"2023": {
"{x}": 12,
"{d}": "18",
"{d}": 18,
"{th}": "th",
"{m}": "May",
"{y}": "2023"
"{y}": 2023,
"ts": 1684364400000
},
"2024": {
"{x}": 13,
"{d}": "16",
"{d}": 16,
"{th}": "th",
"{m}": "May",
"{y}": "2024"
"{y}": 2024,
"ts": 1715814000000
},
"2025": {
"{x}": 14,
"{d}": "15",
"{d}": 15,
"{th}": "th",
"{m}": "May",
"{y}": "2025"
"{y}": 2025,
"ts": 1747263600000
}
}
}
}
\ No newline at end of file
This diff is collapsed.
<!doctype html><html lang="en"><title>Global Accessibility Awareness Day (embedded banner)</title>
<style> body, body .gaad-widget-js { margin: 0; } </style>
<body>
<div id="id-gaad"></div>
<div id="id-gaad-widget"></div>
<script src="../build/GAAD.widget.js" data-gaad='{ "embed": true, "debug": true }'></script>
<script src="../dist/gaad-widget.js" data-gaad-widget='{ "embed": true, "debug": true }'></script>
</body>
</html>
<!--
Usage:
<style>
iframe.gaad-widget-ifr { width: 100%; height: 4.2em; border: none; }
.gaad-widget-ifr { width: 100%; height: 4.2em; border: none; }
</style>
<iframe src="https://cdn.rawgit.com/nfreear/gaad-widget/2.0-beta/embed/" class="gaad-widget-ifr"></iframe>
<iframe src="https://cdn.rawgit.com/nfreear/gaad-widget/3.2.2/embed/" class="gaad-widget-ifr"></iframe>
-->
/*!
gaad-widget.js | © 2018 Nick Freear | License: MIT | NOT an official widget!
https://github.com/nfreear/gaad-widget
http://globalaccessibilityawarenessday.org
*/
'use strict';
var VERSION = '3.2.2'; // <Auto>
var TRANSLATE_TEXTS = require('./data/locales'); // JSON.
var GAAD_DATE_LOOKUP = require('./data/gaad-dates.min'); // JSON.
// console.log(GAAD_DATE_LOOKUP);
var DEFAULTS = require('./src/configure').config(TRANSLATE_TEXTS, GAAD_DATE_LOOKUP, VERSION);
var METHODS = require('./src/methods');
METHODS.analytics = require('node-analytics-ga');
// METHODS.analytics = require('universal-ga');
// METHODS.analytics = require('./google-analytics/index');
require('./src/widget-src').run(DEFAULTS, METHODS);
{
"name": "Global Accessibility Awareness Day (GAAD)",
"before": "Join us on Thursday May {d}{th}, {y} and mark the {x}th <a {at}>{g}</a>{g}</a>.",
"after": "Put next year's <a {at}>{g}</a>{g}</a>, Thursday May {d}{th}, {y}, in your diary. See you then!",
"before": "Join us on Thursday May {d}{th}, {y} and mark the {x}th <a {at}>{g}</a>.",
"after": "Put next year's <a {at}>{g}</a>, Thursday May {d}{th}, {y}, in your diary. See you then!",
"put": "Put gaad-widget on your web site",
"url": "http://globalaccessibilityawarenessday.org"
}
{
"#__locale": "Español/Spanish (es)",
"#__translator": "Google Translate!",
"#__revision_date": "2018-02-24",
"name": "Día Mundial para Promover la Concienciación sobre la Accesibilidad Web (GAAD)",
"before": "El {d} de mayo de {y}, le invitamos a participar en el {x} ° <a {at}>{g}</a>.",
"#__known_as": "{k}, conocido en inglés como Global Accessibility Awareness Day (GAAD)",
"#__intro": "Cuando hablamos de la accesibilidad Web nos referimos a el contenido, la navegación y la interacción.",
"after": "Coloque el <a {at}>{g}<a> del próximo año, el jueves {d} de mayo de {y}, en su diario. ¡Hasta entonces!",
"url": "/gaadsp.php"
}
{
"#__locale": "français/French (fr)",
"#__translator": "(Google Translate!)",
"#__revision_date": "2017-05-22",
"name": "Journée Mondiale de Sensibilisation à l'Accessibilité (GAAD)",
"#__name_note": "World Day to Promote Awareness about Web Accessibility",
"before": "Rejoignez-nous le jeudi {d} mai {y} et marquez le {x}ème <a {at}>{g}</a>.",
"#__known_as": "{k}, connue en anglais sous le nom de Global Accessibility Awareness Day (GAAD)",
"#__intro": " L'objet de cette journée est d'amener des gens à parler, réfléchir et apprendre, sur l'accessibilité numérique (web, logicielle, mobile, etc.), et sur les utilisateurs en situation de handicap.",
"after": "Mettez le <a {at}>{g}</a> de l'année prochaine, le jeudi {d} mai {y} dans votre journal. À plus tard!",
"url": "/gaadfr.html"
"url": "/gaadfr.php"
}
{
"#__title": "TEMPLATE - English (en)",
"#__comment": "Thank you for contributing! (This is just a comment or note.)",
"#__name_orig": "Global Accessibility Awareness Day (GAAD)",
"name": "",
"#__translators": "Please leave {day}, {th} and other placeholders as they are, because they are needed by the software.",
"#__before_orig": "Join us on Thursday May {day}{th}, {year} and mark the {six}th <a {at}>{gaad}</a>.",
"before": "",
"#__after_orig": "Put next year's <a {at}>{gaad}</a>, Thursday May {day}{th}, {year}, in your diary. See you then!",
"after": "",
"#__url_orig": "http://globalaccessibilityawarenessday.org",
"url": "",
"#__put_orig": "Put {it} on your web site",
"put": "",
"#__calendar_orig": "Download an iCal calendar file",
"calendar": ""
}
{
"#__locale": "Chinese - Simplified (zh-cn)",
"#__translator": "YANG Guangyu / 杨光宇",
"#__revision_date": "2018-02-21",
"name": "国际残疾人网上科技使用活动日 (GAAD)",
"#__name_note": "International disabled online technology use activity day",
"#__before_orig": "Join us on Thursday May {d}{th}, {y} and mark the {x}th <a {at}>{g}</a>.",
"before": "欢迎在每年5月份的第三个星期四加入我们,— <a {at}>{g}</a>。",
"#__before_note": "welcome to join us at the third thursday of May every year",
"#__after_orig": "Put next year's <a {at}>{g}</a>, Thursday May {d}{th}, {y}, in your diary. See you then!",
"after": "请在您的日历上标注5月 日举行的活动日 — <a {at}>{g}</a>。",
"#__put_orig": "Put {z} on your web site",
"#__put": "",
"#__calendar_orig": "Download an iCal calendar file",
"calendar": "下载 日历文件",
"url": "/"
}
{
"name": "gaad-widget",
"version": "2.1.0-beta",
"description": "Display a banner-link to promote Global Accessibility Awareness Day (GAAD). Display the banner for a period before and after the day.",
"author": "Nick Freear {@nfreear}",
"version": "3.2.2",
"x-version-hat": "^3",
"description": "Display a banner-link to promote Global Accessibility Awareness Day (GAAD). Display the banner for a period before and after the day. Via unpkg CDN.",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/nfreear/gaad-widget"
},
"browser": "dist/gaad-widget.js",
"unpkg": "dist/gaad-widget.js",
"main": "index.js",
"author": "Nick Freear {@nfreear}",
"repository": "https://github.com/nfreear/gaad-widget.git",
"x-repository-alt": "https://gitlab.com/nfreear/gaad-widget.git",
"bugs": "https://github.com/nfreear/gaad-widget/issues",
"homepage": "https://nick.freear.org.uk/2017/05/14/gaad-widget.html?utm_source=npm",
"dependencies": {
"datejs": "^1.0.0-rc3",
"icalendar": "^0.7.1"
"icalendar": "^0.7.1",
"node-analytics-ga": "git+https://github.com/nfreear/node-analytics-ga.git#1.0.1"
},
"devDependencies": {
"browserify": "^14.5.0",
"csslint": "^1.0.5",
"exorcist": "^0.4.0",
"less": "^3.0.1",
"live-server": "^1.2.0",
"pa11y-ci": "^1.3.1",
"replace": "^0.3.0",
"semistandard": "^11.0.0",
"uglify-js": "^2.8.26"
"uglify-js": "^2.8.29"
},
"engines": {
"node": ">= 4.0.0"
},
"bin": {
"gaad": "./bin/gaad.js"
"gaad": "bin/gaad.js"
},
"scripts": {
"install-legacy-datejs": "mkdir x_legacy; npm i --prefix x_legacy https://github.com/datejs/Datejs#8164739566",
"build": "node_modules/.bin/uglifyjs src/c*.js x_legacy/node_modules/Datejs/build/date.js src/w*.js --comments=/^[!*]/ -bo build/GAAD.widget.js",
"x-build-sa": "node_modules/.bin/uglifyjs src/c*.js node_modules/superagent/superagent.js src/w*.js --comments=/^[!*]/ -bo build/GAAD.sa.js",
"build-min": "node_modules/.bin/uglifyjs build/*.widget.js --comments=/^[!*]/ -mco build/GAAD.widget.min.js",
"test": "node_modules/.bin/semistandard; node_modules/.bin/csslint style"
"build": "rm -f dist/* && bin/gaad.js && bin/_ver.js && npm run browserify && npm run uglify && npm run less",
"browserify": "browserify index.js --no-bf --debug | exorcist dist/gaad-widget.js.map > dist/gaad-widget.js",
"uglify": "uglifyjs dist/*-widget.js --comments=/^[!]/ -mco dist/gaad-widget.min.js",
"less": "lessc style/style.less style/gaad-widget.css",
"start": "live-server --port=9001 -V",
"serve-ci": "live-server --port=9001 -V --no-browser --watch=DUMMY",
"ps": "pgrep -lf live-server",
"kill-server": "pkill -f live-server",
"pa11y": "pa11y --standard WCAG2AAA http://127.0.0.1:9001/embed/?gaadwidget=force&_ua=pa11y",
"pa11y-ci": "pa11y-ci --config .pa11yci.json",
"pa11y-help": "pa11y --version && pa11y --help",
"test": "semistandard && csslint style"
},
"semistandard": {
"ignore": "build/"
"ignore": [
"dist/"
]
},
"//": {
"keywords": [
"accessibility",
"a11y",
"pa11y",
"campaign",
"browser-widget",
"date",
"datejs",
"icalendar",
"event",
"day",
"international",
"GAAD"
],
"files": [
"index.js",
"dist/",
"data/gaad.en.ics",
"data/gaad.json",
"data/locales.json",
"src/",
"style/*.css"
],
"x-locales": [
"en",
"es",
"fr",
"zh-cn"
],
"x-build-js-size": "12.7 kB",
"x-cdn": "https://unpkg.com/gaad-widget@^3/dist/gaad-widget.min.js",
"#": {
"Datejs-legacy": "https://github.com/datejs/Datejs#8164739566",
"superagent": "^3.5.2"
"universal-ga": "^1.1.0"
}
}
// Configure | ©Nick Freear.
var W = window;
var Date = W.Date;
var queryString = W.location.href; // Was: W.location.search;
module.exports.config = function (TRANSLATE_TEXTS, DATES, VERSION) {
'use strict';
var YEAR = new Date().getFullYear();
var GAAD_DATE = DATES.dates[ YEAR ];
var GAAD_NEXT = DATES.dates[ YEAR + 1 ];
var M_LANG = queryString.match(/[&?#!]lang=(\w{2}(-\w{2})?)/);
var defaults = {
id: 'id-gaad-widget',
script: '/gaad-widget', // Was: 'GAAD.widget.', // .js OR .min.js;
lang: M_LANG ? M_LANG[ 1 ] : 'en',
dir: 'ltr',
texts: TRANSLATE_TEXTS,
url: 'http://globalaccessibilityawarenessday.org/?utm_source=github&utm_campaign=gaad-widget',
days_before: 10,
days_after: 10,
embed: false,
style_url: '/../../style/gaad-widget.css', // Was: '/../../style/GAAD.widget.css'
theme: 'blue', // OR: 'black'
should_show: null,
is_before: null,
xreplace: GAAD_DATE,
date: GAAD_DATE,
date_next: GAAD_NEXT,
// Was: datefmt: GAAD_DATE.toString('MMMM dS, yyyy'),
today: new Date(),
xth: YEAR - 2011,
analytics: {
isWidget: true,
name: 'gaadWidget',
id: 'UA-102188521-1'
},
put_widget: '<a class=p href="https://github.com/nfreear/gaad-widget#usage" aria-label="{p}" title="{p} (v{v})" target=_top >{c}</a>',
put_char: '&#x2193;', // 'Downwards arrow to bar' - http://xahlee.info/comp/unicode_arrows.html; http://amp-what.com/
debug: /[&?#!]debug=1/.test(queryString),
force: /[&?#!]gaad.?widget=f(orce)?/i.test(queryString)
};
defaults.version = VERSION;
return defaults;
};
// Functions: extend, setHTML, addStylesheet.. | ©Nick Freear.
var W = window;
var D = W.document;
var CFG;
module.exports = {
getConfig: function (defaults, methods) {
var configEl = D.querySelector('script[ data-gaad-widget ]');
var data = configEl ? configEl.getAttribute('data-gaad-widget') : null;
var options = data ? JSON.parse(data) : {};
var gaad = methods.extend(defaults, options);
var scriptEl = D.querySelector('script[ src *= "' + gaad.script + '" ]');
gaad.log = gaad.debug && W.console ? console.warn : function () {};
gaad.script_url = scriptEl.src;
CFG = gaad;
return gaad;
},
addDays: function (dateObj, days) {
return dateObj.ts + (days * 24 * 60 * 60 * 1000); // Milliseconds.
},
// JuhQ (16 July 2015): https://gist.github.com/pbojinov/8f3765b672efec122f66#gistcomment-1493930
extend: function () {
var extended = {};
var key;
var prop;
for (key in arguments) {
var argument = arguments[ key ];
for (prop in argument) {
if (Object.prototype.hasOwnProperty.call(argument, prop)) {
extended[ prop ] = argument[ prop ];
}
}
}
return extended;
},
trans: function (msgid, vars) {
var texts = CFG.texts;
var msgstr = texts[ CFG.lang ][ msgid ] || texts[ 'en' ][ msgid ];
return msgstr; // replaceObj( msgstr, vars );
},
// Ben McCormick (24 March 2013), SirDerpington:
// http://stackoverflow.com/questions/15604140/replace-multiple-strings-with-multiple-other-strings
replaceObj: replaceObj,
setHTML: function (gaad) {
var elem = D.getElementById(gaad.id);
elem.lang = gaad.lang;
elem.dir = gaad.dir;
elem.setAttribute('role', 'alert');
elem.className = replaceObj('gaad-widget-js {t} {e}', { '{t}': gaad.theme, '{e}': gaad.embed ? 'embed' : 'no-embed' });
elem.innerHTML = gaad.message; // Was: 'gaad.join'
},
addStylesheet: function (gaad) {
var styleEl = D.createElement('link');
styleEl.rel = 'stylesheet';
styleEl.type = 'text/css';
styleEl.href = decideStyleUrl(gaad);
D.head.appendChild(styleEl);
}
};
function decideStyleUrl (CFG) {
// Support for 'unpkg' CDN short URL.
if (/@\d\.\d\.\d(-[\w.]+)(#|_.js|$)/.test(CFG.script_url)) {
CFG.log('GAAD: npm @version found');
CFG.style_url = CFG.style_url.replace('/../..', '');
CFG.script_url = CFG.script_url.replace(/(#.*|_\.js)/, '');
}
return CFG.script_url + CFG.style_url;
}
function replaceObj (str, mapObj) {
var re = new RegExp(Object.keys(mapObj).join('|'), 'g'); // Was: "gi".
return str.replace(re, function (matched) {
return mapObj[ matched ]; // Was: matched.toLowerCase().
});
}
/*!
GAAD.widget.js | ©Nick Freear 2017-04-27 | License: MIT.
https://github.com/nfreear/gaad-widget
*/
// Main widget 'run' function | ©Nick Freear.
(function (W, D, location, console, Date) {
var W = window;
module.exports.run = function (defaults, methods) {
'use strict';
if (typeof Date.today !== 'function') {
return console.error('GAAD error: missing dependency, "Datejs"');
}
var gaad = methods.getConfig(defaults, methods);
var texts = gaad.texts;
var GAAD_DATE = gaad.date;
var GAAD_NEXT = gaad.date_next;
// "...we invite you to help us mark GAAD on the third Thursday of May."
// ~~ http://globalaccessibilityawarenessday.org/background.html ~~
var GAAD_DATE = Date.may().third().thursday();
var GAAD_NEXT = Date.today('+1 year').may().third().thursday();
var defaults = {
id: 'id-gaad',
script: 'GAAD.widget.', // .js OR .min.js;
lang: 'en',
dir: 'ltr',
texts: {
en: {
name: 'Global Accessibility Awareness Day (GAAD)',
before: 'Join us on Thursday May {d}{th}, {y} and mark the {x}th <a {at}>{g}</a>.',
after: 'Put next year\'s <a {at}>{g}</a>, Thursday May {d}{th}, {y}, in your diary. See you then!'
},
fr: {
before: 'Rejoignez-nous le jeudi {d} mai {y} et marquez le {x}ème <a {at}>{g}</a>.',
after: 'Mettez le <a {at}>{g}</a> de l\'année prochaine, le jeudi {d} mai {y} dans votre journal. À plus tard!'
}
},
url: 'http://globalaccessibilityawarenessday.org/?utm_source=github&utm_campaign=gaad-widget',
days_before: 10,
days_after: 10,
embed: false,
style_url: '/../../style/GAAD.widget.css',
theme: 'blue', // OR: 'black'
should_show: null,
is_before: null,
xreplace: {
'{d}': GAAD_DATE.toString('dd'),
'{th}': GAAD_DATE.toString('S'),
'{m}': GAAD_DATE.toString('MMMM'),
'{y}': GAAD_DATE.toString('yyyy')
},
date: GAAD_DATE,
date_next: GAAD_NEXT,
// Was: datefmt: GAAD_DATE.toString('MMMM dS, yyyy'),
today: Date.today(),
xth: Date.today().toString('yyyy') - 2011,
debug: /[?&]debug=1/.test(location.search),
force: /[?&]gaadwidget=force/i.test(location.search)
};
var gaad = getConfig(defaults);
gaad.show_date = new Date(GAAD_DATE).addDays(-gaad.days_before); // Clone.
gaad.hide_date = new Date(GAAD_DATE).addDays(gaad.days_after);
gaad.show_date = methods.addDays(GAAD_DATE, -gaad.days_before); // new Date(GAAD_DATE).addDays(-gaad.days_before); // Clone.
gaad.hide_date = methods.addDays(GAAD_DATE, gaad.days_after); // new Date(GAAD_DATE).addDays(gaad.days_after);
// gaad.diff_days = gaad.today.toString('dd') - gaad.show_date.toString('dd');
gaad.diff_show = gaad.today - gaad.show_date;
......@@ -66,25 +21,24 @@
gaad.should_show = (gaad.diff_show >= 0 && gaad.diff_hide < 0);
gaad.is_before = (gaad.today - gaad.date) < 0;
gaad.is_before = (gaad.today - gaad.date.ts) < 0; // Use: 'JS Date - timestamp' (implicite cast), works!
if (!gaad.is_before) {
gaad.xreplace = {
'{d}': GAAD_NEXT.toString('dd'),
'{th}': GAAD_NEXT.toString('S'),
'{m}': GAAD_NEXT.toString('MMMM'),
'{y}': GAAD_NEXT.toString('yyyy')
};
gaad.xreplace = GAAD_NEXT;
}
gaad.xreplace[ '{at}' ] = replaceObj(' href="{u}" target="_top"', { '{u}': gaad.url });
gaad.xreplace[ '{at}' ] = methods.replaceObj(' href="{u}" target="_top" title="{t}"', { '{u}': gaad.url, '{t}': texts.en.name });
gaad.