Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New widget #150

Merged
merged 3 commits into from
Dec 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.env
env.docker
node_modules/
npm-debug.log
npm-debug.log.*
public/js/

.DS_Store
.idea
43 changes: 1 addition & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,7 @@ The PaperBadger widget enables *anyone*, from publishers to individual researche

![Badge Preview](./public/img/badge_preview.jpg)

1. To use the widget on your own site, include a `<div>` with your custom class in your view file, for example:
`<div class="my-container"></div>`

2. Above the closing `<body>` tag, add

```html
<script type="text/javascript">
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://badges.mozillascience.org/widgets/paper-badger-widget.js";
document.write(decodeURIComponent("%3Cscript src='https://badges.mozillascience.org/widgets/paper-badger-widget.js' type='text/javascript'%3E%3C/script%3E"));
</script>
```

3. In your scripts, include your custom values:
* the class name where your widget will appear for the `container-class` key and
* the doi for the paper you are interested in as the `article-doi` key

```html
<!DOCTYPE html>

<html>
<head>
<title>Paper view snippet example | Paper Badger</title>
</head>
<body>

<div class="my-container"></div>

<script type="text/javascript">
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://badges.mozillascience.org/widgets/paper-badger-widget.js";
document.write(decodeURIComponent("%3Cscript src='https://badges.mozillascience.org/widgets/paper-badger-widget.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
var conf={"article-doi": "10.1186/2047-217X-3-18", "container-class": "my-container"};
showBadges(conf);
</script>
</body>
</html>
```
You can either use paper-badger-widget.js ([documentation](docs/paper-badger-widget.md)), which supports old browsers or widget.js ([documentation](docs/widget.md)), which is in development and currently only supports evergreen browsers and IE9+.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how you handled this! Thanks.

We may want to start a wiki and move those docs there, but in the meantime this is great.


## Contributing

Expand Down
43 changes: 43 additions & 0 deletions docs/paper-badger-widget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# paper-badger-widget.js Documentation
1. To use the widget on your own site, include a `<div>` with your custom class in your view file, for example:
`<div class="my-container"></div>`

2. Above the closing `<body>` tag, add

```html
<script type="text/javascript">
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://badges.mozillascience.org/widgets/paper-badger-widget.js";
document.write(decodeURIComponent("%3Cscript src='https://badges.mozillascience.org/widgets/paper-badger-widget.js' type='text/javascript'%3E%3C/script%3E"));
</script>
```

3. In your scripts, include your custom values:
* the class name where your widget will appear for the `container-class` key and
* the doi for the paper you are interested in as the `article-doi` key

```html
<!DOCTYPE html>

<html>
<head>
<title>Paper view snippet example | Paper Badger</title>
</head>
<body>

<div class="my-container"></div>

<script type="text/javascript">
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://badges.mozillascience.org/widgets/paper-badger-widget.js";
document.write(decodeURIComponent("%3Cscript src='https://badges.mozillascience.org/widgets/paper-badger-widget.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
var conf={"article-doi": "10.1186/2047-217X-3-18", "container-class": "my-container"};
showBadges(conf);
</script>
</body>
</html>
```
48 changes: 48 additions & 0 deletions docs/widget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# widget.js Documentation
This shows what the Paper Badger Widget can do and how to use it.

## Demos
The demos can be found in [public/widgets/demos](../public/widgets/demos).

## Usage
1. To use the widget on your own site, include a `<div>` with your custom class in your view file, for example:
`<div class="my-container"></div>`

2. Above the closing `<body>` tag, add
```html
<script>
(function () {
var d=document,g=d.createElement("script");g.type="text/javascript";g.async=!0;g.defer=!0;
g.src="https://badges.mozillascience.org/widgets/widget.js";g.onload=load;d.body.appendChild(g);

function load() {
new PaperBadgerWidget({
DOI: "10.1186/2047-217X-3-18",
containerClass: "my-container"
});
}
})();
</script>
```

3. In the load method, include your custom values:
* the element class where your widget will appear for the `containerClass` key and
* either the doi for the paper you are interested in as the `DOI` key or the ORCID for the author you are interesed in as the `ORCID` key

## Required configuration options
* the `containerClass` key: contains the class of the element which will contain the Paper Badger widget
* either the `DOI` or the `ORCID` key: defines which information the widget will display

## Optional configuration options
* the `ORCIDWidgetType` key (only in combination with the `ORCID` key): set the key to the value `default` to show names below the badges, set it to `DOI` to show DOIs
* the `loaderText` key: changes the default text shown while the Paper Badger widget is loading
* the `removeClass` key: the widget will remove this class from all elements once it has loaded, if this is a non-empty string
* the `clickCallback` key: a method that gets called when a link under a badge gets clicked. The method is called with an object containing either the DOI or ORCID of the link and the badge taxonomy:

```
{
doi: '10.1186/2047-217X-3-18', // either DOI
orcid: '0000-0001-5207-5061', // or ORCID
taxonomy: 'data_curation'
}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link to the demos you made here somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a new commit and added a seperate heading for demos. Is it ok like that?

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"watch:js": "npm run build:js -- --watch",
"clean": "rm -r public/js/*",
"server": "node src/index.js",
"jscs": "jscs -c node_modules/mofo-style/linters/.jscsrc src test webpack.config.js",
"jshint": "jshint -c .jshintrc src webpack.config.js",
"jscs": "jscs -c node_modules/mofo-style/linters/.jscsrc src test webpack.config.js public/widgets/widget.js",
"jshint": "jshint -c .jshintrc src webpack.config.js public/widgets/widget.js",
"jshint:test": "jshint -c test/.jshintrc test",
"jsbeautify": "js-beautify --config node_modules/mofo-style/linters/.jsbeautifyrc src/*.js test/*.js webpack.config.js -r -n",
"jsbeautify": "js-beautify --config node_modules/mofo-style/linters/.jsbeautifyrc src/*.js test/*.js webpack.config.js public/widgets/widget.js -r -n",
"lint": "npm run jsbeautify && npm run jshint && npm run jshint:test && npm run jscs",
"build:production": "npm run build:js -- --optimize-minimize --optimize-dedupe",
"start:production": "npm-run-all build:production server",
Expand Down
28 changes: 28 additions & 0 deletions public/widgets/demos/doi-widget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>

<html>
<head>
<title>Paper view snippet example | Paper Badger</title>
<style>.my-remove-class { display: none; } .my-element { overflow: hidden; }</style>
</head>

<body>
<div class="my-element"></div>
<div class="my-remove-class">This text is only shown when the API returns badges.</div>

<script>
(function () {
var d=document,g=d.createElement("script");g.type="text/javascript";g.async=!0;g.defer=!0;
g.src="../widget.js";g.onload=load;d.body.appendChild(g);

function load() {
new PaperBadgerWidget({
DOI: "10.1186/2047-217X-3-18",
containerClass: "my-element",
removeClass: "my-remove-class"
});
}
})();
</script>
</body>
</html>
26 changes: 26 additions & 0 deletions public/widgets/demos/orcid-widget-with-doi-shown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>

<html>
<head>
<title>Paper view snippet example | Paper Badger</title>
</head>
<body>

<div class="my-element"></div>

<script>
(function () {
var d=document,g=d.createElement("script");g.type="text/javascript";g.async=!0;g.defer=!0;
g.src="../widget.js";g.onload=load;d.body.appendChild(g);

function load() {
new PaperBadgerWidget({
ORCID: "0000-0001-5207-5061",
ORCIDWidgetType: "DOI",
containerClass: "my-element"
});
}
})();
</script>
</body>
</html>
25 changes: 25 additions & 0 deletions public/widgets/demos/orcid-widget-with-name-shown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>

<html>
<head>
<title>Paper view snippet example | Paper Badger</title>
</head>
<body>

<div class="my-element"></div>

<script>
(function () {
var d=document,g=d.createElement("script");g.type="text/javascript";g.async=!0;g.defer=!0;
g.src="../widget.js";g.onload=load;d.body.appendChild(g);

function load() {
new PaperBadgerWidget({
ORCID: "0000-0001-5207-5061",
containerClass: "my-element"
});
}
})();
</script>
</body>
</html>
Loading