Skip to content

Commit

Permalink
Bug #10, add a methods.trans() Javascript function [ci skip]
Browse files Browse the repository at this point in the history
* Plus, lots of small edits
  • Loading branch information
nfreear committed Mar 4, 2018
1 parent d22d2e1 commit 0522629
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# zh*
LICENSE*

*.css
*.html
!test/index.html
!test/static.html
Expand All @@ -10,6 +11,7 @@ LICENSE*
*.*gz
*copy*
*BAK*
/*.png

x_legacy/
package*
Expand Down
1 change: 1 addition & 0 deletions .pa11yci.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"//": "Automated accessibility testing ~ https://github.com/pa11y/pa11y-ci",

"defaults": {
"screenCapture": "pa11y-screen-capture.png",
"standard": "WCAG2AAA",
"timeout": 5000,
"wait": 2000,
Expand Down
11 changes: 10 additions & 1 deletion bin/_ver.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ 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);
console.warn('VERSION_TAG :', VERSION_TAG, CARET_VERSION);

replace({
paths: [ INDEX_JS ],
Expand All @@ -41,6 +42,14 @@ replace({
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);
}
Expand Down
2 changes: 1 addition & 1 deletion bin/gaad.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var gaadobj = {
timestamp: today.toString('u'),
url: PKG.repository,
// texts: texts,
locales: PKG[ 'x-locales' ],
// locales: PKG[ 'x-locales' ],
count_years: LIMIT_YEARS,
dates: {}
};
Expand Down
4 changes: 2 additions & 2 deletions locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"#__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>。",

"#__howto_orig": "Put {z} on your site",
"howto": "",
"#__put_orig": "Put {z} on your web site",
"#__put": "",

"#__calendar_orig": "Download an iCal calendar file",
"calendar": "下载 日历文件",
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "gaad-widget",
"version": "3.2.0",
"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.",
"license": "MIT",
"browser": "dist/gaad-widget.js",
Expand All @@ -9,7 +10,7 @@
"author": "Nick Freear {@nfreear}",
"repository": "https://github.com/nfreear/gaad-widget.git",
"bugs": "https://github.com/nfreear/gaad-widget/issues",
"homepage": "http://nick.freear.org.uk/2017/05/14/gaad-widget.html?utm_source=npm",
"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",
Expand All @@ -30,7 +31,7 @@
"node": ">= 4.0.0"
},
"bin": {
"gaad": "./bin/gaad.js"
"gaad": "bin/gaad.js"
},
"scripts": {
"build": "rm -f dist/* && bin/gaad.js && bin/_ver.js && npm run browserify && npm run uglify && npm run less",
Expand Down Expand Up @@ -75,7 +76,7 @@
"style/*.css"
],
"x-locales": [ "en", "es", "fr", "zh-cn" ],
"x-build-js-size": "8.47kB",
"x-build-js-size": "12.9 kB",
"//": {
"Datejs-legacy": "https://github.com/datejs/Datejs#8164739566",
"universal-ga": "^1.1.0"
Expand Down
9 changes: 9 additions & 0 deletions src/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

var W = window;
var D = W.document;
var CFG;

module.exports = {

Expand All @@ -18,6 +19,8 @@ module.exports = {

gaad.script_url = scriptEl.src;

CFG = gaad;

return gaad;
},

Expand All @@ -42,6 +45,12 @@ module.exports = {
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,
Expand Down
13 changes: 8 additions & 5 deletions src/widget-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports.run = function (defaults, methods) {

var gaad = methods.getConfig(defaults, methods);

var texts = gaad.texts;
var GAAD_DATE = gaad.date;
var GAAD_NEXT = gaad.date_next;

Expand All @@ -26,15 +27,17 @@ module.exports.run = function (defaults, methods) {
gaad.xreplace = GAAD_NEXT;
}

gaad.xreplace[ '{at}' ] = methods.replaceObj(' href="{u}" target="_top" title="{t}"', { '{u}': gaad.url, '{t}': gaad.texts.en.name });
gaad.xreplace[ '{at}' ] = methods.replaceObj(' href="{u}" target="_top" title="{t}"', { '{u}': gaad.url, '{t}': texts.en.name });
gaad.xreplace[ '{x}' ] = gaad.xth;
// Was: gaad.xreplace[ '{g}' ] = gaad.texts.en.name;

var lang = gaad.texts[ gaad.lang ] ? gaad.lang : 'en';
var template = gaad.is_before ? gaad.texts[ lang ].before : gaad.texts[ lang ].after;
var putWidget = methods.replaceObj(gaad.put_widget, { '{p}': gaad.texts[ lang ].put, '{c}': gaad.put_char });
var lang = texts[ gaad.lang ] ? gaad.lang : 'en';
gaad.lang = lang;

gaad.xreplace[ '{g}' ] = gaad.texts[ lang ].name;
var template = gaad.is_before ? texts[ lang ].before : texts[ lang ].after;
var putWidget = methods.replaceObj(gaad.put_widget, { '{p}': methods.trans('put'), '{c}': gaad.put_char });

gaad.xreplace[ '{g}' ] = texts[ lang ].name;
gaad.message = methods.replaceObj(template, gaad.xreplace) + putWidget;

if (!gaad.should_show && !gaad.force) {
Expand Down
2 changes: 1 addition & 1 deletion style/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
.p { // a[ href *= '/gaad-widget' ]
border: 1px solid transparent;
border-bottom-color: #bbb;
border-radius: 3px;
border-radius: 4px;
bottom: -8px;
color: #bbb;
display: block;
Expand Down
14 changes: 10 additions & 4 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<!doctype html><html lang="en"><meta charset="utf-8"><title> gaad-widget test </title>

<style> body { font: 1em sans-serif; color: #333; X-background: #ccc; margin: 1em auto; max-width: 42em; } </style>
<body>

<h1> gaad-widget test </h1>


<div id="id-gaad-widget"></div>


<p> If the widget is not visible, <a href="?gaadwidget=force">click to add <code>?gaadwidget=force</code></a> to the URL in the address-bar above. </p>
<p> If the widget is not visible, <a href="?gaadwidget=force">click to add
<code>?gaadwidget=force</code></a> to the URL in the address-bar above.
</p>

<p> See the widget in <a href="?gaadwidget=force&lang=zh-cn">Chinese, with <code>?lang=zh-cn</code></a> | <a href="?gaadwidget=force">Revert to English</a>. </p>
<p> See the widget in <a href="?gaadwidget=force&lang=zh-cn">Chinese, with
<code>?lang=zh-cn</code></a> | <a href="?gaadwidget=force">revert to English</a>.
</p>


<script data-CDN-src="https://unpkg.com/gaad-widget@3.2.0#._.js"></script>

<script src="../dist/gaad-widget.js" data-gaad-widget='{ "debug": true, "X-lang": "fr", "X-theme": "black", "X-analytics": false }'></script>

<script src="../dist/gaad-widget.js" data-gaad-widget=
'{ "debug": true, "X-lang": "fr", "X-theme": "black", "X-analytics": null }'></script>


<pre>
Expand All @@ -28,4 +33,5 @@ <h1> gaad-widget test </h1>
* http://www.globalaccessibilityawarenessday.org

</pre>
</body>
</html>

0 comments on commit 0522629

Please sign in to comment.