Skip to content

Commit

Permalink
Bug #2/#3, Test that console exists - Internet Explorer fix [iet:89…
Browse files Browse the repository at this point in the history
…94834]
  • Loading branch information
nfreear committed May 15, 2017
1 parent 54e79aa commit ea98f4b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
test*.html
*.min.js
*copy*
*.php

node_modules/
*.log
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Note ~ this is not an official widget!
* Basic automated testing in place (Travis-CI),
* Accessible ~ _let me know if you spot a problem!_
* Compatible with all modern browsers, and MSIE 10-11 ([MSIE 9 is in-progress][ie])
* CDN courtesy of [RawGit][] (thank you!) - with HTTPS/SSL.

[Wishlist][].

Expand All @@ -47,7 +48,7 @@ Via [RawGit][] - production / CDN:
```html
<div id="id-gaad"></div>

<script src="https://cdn.rawgit.com/nfreear/gaad-widget/1.0-beta/build/GAAD.widget.js"></script>
<script src="https://cdn.rawgit.com/nfreear/gaad-widget/1.0-rc.1/build/GAAD.widget.js"></script>
```

Local hosting:
Expand Down Expand Up @@ -109,10 +110,11 @@ Twitter: [@nfreear][].
[gist]: https://gist.github.com/nfreear/eef4be96147cb5c1182cbc9e595f2833
[Datejs]: https://github.com/datejs/Datejs
[RawGit]: https://rawgit.com/
"Serves Git files with the correct mime-type; content delivery network (CDN)"
[MIT]: https://nfreear.mit-license.org/ "MIT License"
[travis]: https://travis-ci.org/nfreear/gaad-widget
[travis-icon]: https://api.travis-ci.org/nfreear/gaad-widget.svg
"Build status – Travis-CI (PHP + NPM/eslint)"
"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'"
16 changes: 9 additions & 7 deletions build/GAAD.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -1520,15 +1520,15 @@ Date.CultureInfo = {
https://github.com/nfreear/gaad-widget
*/
(function(W, D, C, Date) {
(function(W, D, console, Date) {
"use strict";
if (typeof Date.today !== "function") {
return C.error('GAAD error: missing dependency, "Datejs"');
return console.error('GAAD error: missing dependency, "Datejs"');
}
var GAAD_DATE = Date.may().third().thursday();
var defaults = {
id: "id-gaad",
script: "GAAD.widget.js",
script: "GAAD.widget.",
lang: "en",
template: 'Join us on Thursday %D and mark the %xth <a href="%U">Global Accessibility Awareness Day (GAAD)</a>.',
url: "http://globalaccessibilityawarenessday.org/?utm_source=github&utm_campaign=gaad-widget",
Expand All @@ -1539,13 +1539,14 @@ Date.CultureInfo = {
date: GAAD_DATE,
datefmt: GAAD_DATE.toString("MMMM dS, yyyy"),
today: Date.today(),
xth: Date.today().toString("yyyy") - 2011
xth: Date.today().toString("yyyy") - 2011,
log: /debug=1/.test(W.location.search) && W.console ? console.warn : function() {}
};
var scriptEl = D.querySelector('script[ src *= "' + defaults.script + '" ]');
var data = scriptEl.getAttribute("data-gaad");
var options = data ? JSON.parse(data) : {};
C.warn(scriptEl, options);
var gaad = extend(defaults, options);
gaad.log(scriptEl, options);
gaad.script_url = scriptEl.src;
gaad.show_date = new Date(GAAD_DATE).addDays(-gaad.days_before);
gaad.hide_date = new Date(GAAD_DATE).addDays(gaad.days_after);
Expand All @@ -1554,15 +1555,16 @@ Date.CultureInfo = {
gaad.should_show = gaad.diff_show >= 0 && gaad.diff_hide < 0;
gaad.join = gaad.template.replace(/%D/, gaad.datefmt).replace(/%x/, gaad.xth).replace(/%U/, gaad.url);
if (!gaad.should_show) {
return C.warn("GAAD: no-show", gaad);
return gaad.log("GAAD: no-show", gaad);
}
C.warn("GAAD: show", gaad);
gaad.log("GAAD: show", gaad);
var elem = D.getElementById(gaad.id);
elem.lang = gaad.lang;
elem.setAttribute("role", "alert");
elem.className = "gaad-widget-js";
elem.innerHTML = gaad.join;
addStylesheet(gaad.script_url + gaad.style_url);
W.console && console.log("Happy GAAD! ~ http://globalaccessibilityawarenessday.org");
function extend() {
var extended = {};
var key;
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "gaad-widget",
"description": "Display a banner-link to promote Global Accessibility Awareness Day (GAAD). Display it for a period before and after the day.",
"author": "Nick Freear (@nfreear)",
"version": "1.0.0-rc.1",
"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}",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -16,7 +17,7 @@
},
"scripts": {
"build": "node_modules/.bin/uglifyjs src/c*.js node_modules/Datejs/build/date.js src/w*.js --comments=/^[!*]/ -bo build/GAAD.widget.js",
"build-min": "node_modules/.bin/uglifyjs build/*.widget.js --comments=/^[!*]/ -o build/GAAD.widget.min.js",
"build-min": "node_modules/.bin/uglifyjs build/*.widget.js --comments=/^[!*]/ -mo build/GAAD.widget.min.js",
"test": "node_modules/.bin/semistandard"
},
"semistandard": {
Expand Down
19 changes: 11 additions & 8 deletions src/widget-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
https://github.com/nfreear/gaad-widget
*/

(function (W, D, C, Date) {
(function (W, D, console, Date) {
'use strict';

if (typeof Date.today !== 'function') {
return C.error('GAAD error: missing dependency, "Datejs"');
return console.error('GAAD error: missing dependency, "Datejs"');
}

// "...we invite you to help us mark GAAD on the third Thursday of May."
Expand All @@ -17,7 +17,7 @@

var defaults = {
id: 'id-gaad',
script: 'GAAD.widget.js',
script: 'GAAD.widget.', // .js OR .min.js;
lang: 'en',
template: 'Join us on Thursday %D and mark the %xth <a href="%U">Global Accessibility Awareness Day (GAAD)</a>.',
url: 'http://globalaccessibilityawarenessday.org/?utm_source=github&utm_campaign=gaad-widget',
Expand All @@ -28,18 +28,19 @@
date: GAAD_DATE,
datefmt: GAAD_DATE.toString('MMMM dS, yyyy'),
today: Date.today(),
xth: Date.today().toString('yyyy') - 2011
xth: Date.today().toString('yyyy') - 2011,
log: /debug=1/.test(W.location.search) && W.console ? console.warn : function () {}
};

var scriptEl = D.querySelector('script[ src *= "' + defaults.script + '" ]');

var data = scriptEl.getAttribute('data-gaad');
var options = data ? JSON.parse(data) : {};

C.warn(scriptEl, options); // Not: scriptEl.dataset

var gaad = extend(defaults, options);

gaad.log(scriptEl, options); // Not: scriptEl.dataset

gaad.script_url = scriptEl.src;

gaad.show_date = new Date(GAAD_DATE).addDays(-gaad.days_before); // Clone.
Expand All @@ -54,10 +55,10 @@
gaad.join = gaad.template.replace(/%D/, gaad.datefmt).replace(/%x/, gaad.xth).replace(/%U/, gaad.url);

if (!gaad.should_show) {
return C.warn('GAAD: no-show', gaad);
return gaad.log('GAAD: no-show', gaad);
}

C.warn('GAAD: show', gaad);
gaad.log('GAAD: show', gaad);

var elem = D.getElementById(gaad.id);

Expand All @@ -68,6 +69,8 @@

addStylesheet(gaad.script_url + gaad.style_url);

W.console && console.log('Happy GAAD! ~ http://globalaccessibilityawarenessday.org');

// ---------------------------
// JuhQ: https://gist.github.com/pbojinov/8f3765b672efec122f66#gistcomment-1493930

Expand Down

0 comments on commit ea98f4b

Please sign in to comment.