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

Toolbar: Minor improvements #1818

Merged
merged 3 commits into from
Mar 24, 2019
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
2 changes: 1 addition & 1 deletion plugins/toolbar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h1>How to use</h1>
<code>Prism.plugins.toolbar.registerButton</code>.</p>

<p>The function accepts a key for the button and an object with a <code>text</code> property string and an optional
<code>onClick</code> function or <code>url</code> string. The <code>onClick</code> function will be called when the button is clicked, while the
<code>onClick</code> function or a <code>url</code> string. The <code>onClick</code> function will be called when the button is clicked, while the
<code>url</code> property will be set to the anchor tag's <code>href</code>.</p>

<pre><code class="language-javascript">Prism.plugins.toolbar.registerButton('hello-world', {
Expand Down
14 changes: 13 additions & 1 deletion plugins/toolbar/prism-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@

Prism.plugins.toolbar = {};

/**
* @typedef ButtonOptions
* @property {string} text The text displayed.
* @property {string} [url] The URL of the link which will be created.
* @property {Function} [onClick] The event listener for the `click` event of the created button.
*/

/**
* Register a button callback with the toolbar.
*
* @param {string} key
* @param {Object|Function} opts
* @param {ButtonOptions|Function} opts
*/
var registerButton = Prism.plugins.toolbar.registerButton = function (key, opts) {
var callback;
Expand Down Expand Up @@ -43,6 +50,11 @@
};
}

if (key in map) {
console.warn('There is a button with the key "' + key + '" registered already.');
return;
}

callbacks.push(map[key] = callback);
};

Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbar/prism-toolbar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.