Skip to content

Commit 864ada7

Browse files
authored
Citation Plugin v1.0.0 (#2)
* Citation working in browser via console.log * Now outputs to results * Cleaned up the code and added some comments. * commented out some html, and changed pad to cite * Changed style on label and changed output to textarea * Changed manifest.json file to reflect the project and use a new icon * some changes * Allows for entering a url into the text box * Modified textarea to be disabled and not resizable * Modified textarea to be disabled and not resizable * Added Citation Format Dropdown * Moved citation style above citation text * Update citation core to 1.0.1 * Added eslinter and corrected the code formatting * Removed a line from the ignore that was copied and not used * Change comments to better describe what is going on. * Added Readme * Cleaned up the look of the plugin * "Changes for pr" * Updated stylesheet * Changes for the PR * Change to the description * Added EOF and fixed the issues with the readme
1 parent 7670f1b commit 864ada7

File tree

11 files changed

+270
-0
lines changed

11 files changed

+270
-0
lines changed

Plugin/.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules/*
2+
**/*.md
3+
**/*.json
4+
**/*.conf

Plugin/.eslintrc.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "airbnb-base",
3+
"plugins": [
4+
"import"
5+
],
6+
"rules": {
7+
"max-len": "off",
8+
"brace-style": ["error", "stroustrup"],
9+
"no-unused-vars": ["error", { "args": "none" }],
10+
"no-underscore-dangle": ["error", { "allowAfterThis": true }]
11+
},
12+
"env": {
13+
"browser": true,
14+
"node": true,
15+
"webextensions": true
16+
}
17+
}

Plugin/citation-plugin.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<link rel="stylesheet" href="style.css">
6+
</head>
7+
<body class="panel">
8+
<form id="citation-form">
9+
<table>
10+
<tr>
11+
<td><label for="citation-URL">Search URL</label></td>
12+
<td><input class="panel-formElements-item" type="text" id="citation-URL"></td>
13+
</tr>
14+
15+
<tr>
16+
<td><label for="citationFormats">Citation Format</label></td>
17+
<td><select class="panel-formElements-item" id="citationFormats"></select></td>
18+
</tr>
19+
20+
<tr>
21+
<td><label for="result">Result:</label></td>
22+
<td><textArea class="outputTextArea" id="result"></textArea></td>
23+
</tr>
24+
<table>
25+
26+
<footer class="panel-section panel-section-footer">
27+
<button type="submit" class="panel-section-footer-button default">Cite!</button>
28+
<div class="panel-section-footer-separator selectable"></div>
29+
</footer>
30+
</form>
31+
<script src="index.js"></script>
32+
</body>
33+
</html>

Plugin/citation-plugin.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const CitationCore = require('citation-core');
2+
3+
const resultNode = document.getElementById('result');
4+
const citationFormatsNode = document.getElementById('citationFormats');
5+
const textNode = document.getElementById('citation-URL');
6+
7+
/**
8+
* Generates the citation based on the link that is passed in from tab info.
9+
* @param {String} tabInfo - The url passed in as a string
10+
* @return {String} citationStr The citation is returned as a string
11+
*/
12+
function citationGeneration(tabInfo) {
13+
const formatOptions = new CitationCore.FormatOptions();
14+
const selectedStyleIndex = citationFormatsNode.selectedIndex;
15+
const selectedStyle = citationFormatsNode.options[selectedStyleIndex].value;
16+
17+
formatOptions.url = tabInfo;
18+
formatOptions.style = CitationCore.styles[selectedStyle];
19+
CitationCore.generate(formatOptions, (citationStr, errors) => {
20+
// Handle completion of citation generation
21+
resultNode.value = citationStr;
22+
});
23+
}
24+
25+
/**
26+
* A helper to get the url from the tab info if there is no user entered url.
27+
* @param {List} browserURL - Contains a list of objects that hold the tab information.
28+
*/
29+
function generationHelper(browserURL) {
30+
citationGeneration(browserURL[0].url);
31+
}
32+
33+
/**
34+
* Error handler
35+
* @param {Error[]} error - The error if there is one that occurs during operation.
36+
*/
37+
function onError(error) {
38+
throw new Error(`Error: ${error}`);
39+
}
40+
41+
/**
42+
* Get the current tabs url, then send it via a promise to citation generation.
43+
* @param {string} On click of the cite button return the correct citation.
44+
* @return {string} The string representation of the citation
45+
*/
46+
document.getElementById('citation-form').addEventListener('submit', (e) => {
47+
e.preventDefault();
48+
if (textNode.value === '') {
49+
const gettingCurrent = browser.tabs.query({ active: true });
50+
gettingCurrent.then(generationHelper).catch(onError);
51+
}
52+
else {
53+
citationGeneration(textNode.value);
54+
}
55+
}, false);
56+
57+
const styles = Object.keys(CitationCore.styles);
58+
styles.forEach((style) => {
59+
const newElement = document.createElement('option');
60+
newElement.innerHTML = style;
61+
newElement.value = style;
62+
citationFormatsNode.appendChild(newElement);
63+
});
457 Bytes
Loading

Plugin/icons/placeholder-32.png

530 Bytes
Loading

Plugin/manifest.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Software Citation Tools Plugin",
4+
"version": "1.0.0",
5+
"description": "A browser based tool for generating citations",
6+
"icons": {
7+
"32": "icons/cite-placeholder-32.png"
8+
},
9+
"browser_action": {
10+
"default_icon": "icons/cite-placeholder-32.png",
11+
"default_title": "Cite This",
12+
"default_popup": "citation-plugin.html",
13+
"browser_style": true
14+
},
15+
"permissions": [
16+
"*://developer.mozilla.org/*",
17+
"tabs"
18+
]
19+
}

Plugin/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "citation-plugin",
3+
"version": "1.0.0",
4+
"description": "A browser based tool for generating citations",
5+
"main": "citation-plugin.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"install": "./node_modules/browserify/bin/cmd.js citation-plugin.js -o index.js",
9+
"build": "./node_modules/browserify/bin/cmd.js citation-plugin.js -o index.js"
10+
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/mozillascience/citation-plugin.git"
15+
},
16+
"keywords": [
17+
"citation"
18+
],
19+
"author": ["Eric Lee <nokeeo@me.com>", "Robert Lowe <rdl8212@rit.edu>", "Colin O'Neill <cmo6720@rit.edu>", "Samuel Mosher <sam1360@rit.edu>", "mozillafoundation"],
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/mozillascience/citation-plugin/issues"
23+
},
24+
"homepage": "https://github.com/mozillascience/citation-plugin#readme",
25+
"dependencies": {
26+
"citation-core": "1.0.1"
27+
},
28+
"devDependencies": {
29+
"browserify": "^14.0.0",
30+
"eslint": "^3.13.1",
31+
"eslint-config-airbnb-base": "^11.0.1",
32+
"eslint-plugin-import": "^2.2.0"
33+
}
34+
}

Plugin/style.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* These styles extend the styles from browser_styles, see https://firefoxux.github.io/StyleGuide.
3+
*/
4+
5+
/* For some reason the footer creates a horizontal overflow */
6+
body {
7+
overflow-x: hidden;
8+
}
9+
10+
.panel-formElements-item output,
11+
.panel-formElements-item input[type="number"] {
12+
flex-grow: 1;
13+
}
14+
15+
.panel-formElements-item{
16+
width:100%;
17+
}
18+
19+
.outputTextArea {
20+
height:160px;
21+
width:350px;
22+
resize:none;
23+
}
24+
25+
input[type="number"] {
26+
background-color: #ffffff;
27+
border: 1px solid #b1b1b1;
28+
box-shadow: 0 0 0 0 #61b5ff;
29+
font: caption;
30+
padding: 0 6px 0;
31+
transition-duration: 250ms;
32+
transition-property: box-shadow;
33+
height: 24px;
34+
}
35+
36+
input[type="number"]:hover {
37+
border-color: #858585;
38+
}
39+
40+
input[type="number"]:focus {
41+
border-color: #0996f8;
42+
box-shadow: 0 0 0 2px rgba(97, 181, 255, 0.75);
43+
}
44+
.result{
45+
-moz-user-select: text;
46+
-khtml-user-select: text;
47+
-webkit-user-select: text;
48+
-o-user-select: text;
49+
}
50+
51+
/* Reset the default styles for buttons if it's a footer button */
52+
button.panel-section-footer-button {
53+
background-color: #28A75F;
54+
padding: 12px;
55+
}

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
11
# citation-plugin
2+
3+
citation-plugin is a firefox plugin which presents the [CitationCore](https://github.com/mozillascience/CitationCore) library in a user friendly way in browswer. It is part of a larger effort, lead by Mozilla Science Lab, to develop a suite of tools that aim to implement a standard for citing software and making it easier to cite software correctly. To learn more about this project you can visit the [Software Citation Tools repository](https://github.com/mozillascience/software-citation-tools).
4+
5+
## Install
6+
To install:
7+
```
8+
cd Plugin
9+
npm install
10+
```
11+
12+
Once the install script finishes, navigate to [about:debugging#addons](about:debugging#addons). Once there, select "Load Temporary Add-on", navigate to the Plugin directory and select the manifest.json and click load
13+
## Contributor Install
14+
If you are interested in contributing to citation-plugin please follow these install instructions. They will add a pre-commit hook that will run our linter and reject commits that do not meet the project's coding standards. We are adhereing to the [AirBnb style guide](https://github.com/airbnb/javascript).
15+
```
16+
git clone https://github.com/mozillascience/citation-plugin.git
17+
cd Plugin
18+
cp dev/pre-commit .git/hooks/
19+
```

0 commit comments

Comments
 (0)