Skip to content

Commit 0bffe6c

Browse files
committed
TAG: Default options can be overridden on init
- Added init parameter for overriding default options
1 parent 4623a17 commit 0bffe6c

File tree

6 files changed

+46
-23
lines changed

6 files changed

+46
-23
lines changed

demo/demo.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/src/demo.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ $(async () => {
5757
// String.
5858
// See the full documentation for details.
5959
data: require("../data/test-odin.json"),
60-
format: "odin"
60+
format: "odin",
61+
62+
// Overrides for default options
63+
options: {
64+
showTopArgLabels: true
65+
}
6166
});
6267

6368
// -------------------

dist/tag/js/tag.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42408,8 +42408,10 @@ function () {
4240842408
* @param {String|Element|jQuery} container - Either a string containing the
4240942409
* ID of the container element, or the element itself (as a
4241042410
* native/jQuery object)
42411+
* @param {Object} options - Overrides for default library options
4241142412
*/
4241242413
function Main(container) {
42414+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4241342415
(0, _classCallCheck2.default)(this, Main);
4241442416
this.config = new _config.default(); // SVG.Doc expects either a string with the element's ID, or the element
4241542417
// itself (not a jQuery object).
@@ -42432,7 +42434,8 @@ function () {
4243242434
this.words = [];
4243342435
this.links = []; // Options
4243442436

42435-
this.options = {
42437+
this.options = _lodash.default.defaults(options, // Default options
42438+
{
4243642439
// Category of top Links to show
4243742440
topLinksCategory: "default",
4243842441
// Category of bottom Links to show
@@ -42445,7 +42448,7 @@ function () {
4244542448
showTopArgLabels: false,
4244642449
showBottomMainLabel: true,
4244742450
showBottomArgLabels: false
42448-
}; // Initialisation
42451+
}); // Initialisation
4244942452

4245042453
this.resize();
4245142454

dist/tag/js/tag.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/main.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ class Main {
2828
* @param {String|Element|jQuery} container - Either a string containing the
2929
* ID of the container element, or the element itself (as a
3030
* native/jQuery object)
31+
* @param {Object} options - Overrides for default library options
3132
*/
32-
constructor(container) {
33+
constructor(container, options = {}) {
3334
this.config = new Config();
3435

3536
// SVG.Doc expects either a string with the element's ID, or the element
@@ -56,22 +57,27 @@ class Main {
5657
this.links = [];
5758

5859
// Options
59-
this.options = {
60-
// Category of top Links to show
61-
topLinksCategory: "default",
62-
// Category of bottom Links to show
63-
bottomLinksCategory: "none",
64-
65-
// Continue to display top/bottom Links when moving Words?
66-
showTopLinksOnMove: true,
67-
showBottomLinksOnMove: false,
68-
69-
// Show main/argument labels on Links?
70-
showTopMainLabel: true,
71-
showTopArgLabels: false,
72-
showBottomMainLabel: true,
73-
showBottomArgLabels: false
74-
};
60+
this.options = _.defaults(
61+
options,
62+
63+
// Default options
64+
{
65+
// Category of top Links to show
66+
topLinksCategory: "default",
67+
// Category of bottom Links to show
68+
bottomLinksCategory: "none",
69+
70+
// Continue to display top/bottom Links when moving Words?
71+
showTopLinksOnMove: true,
72+
showBottomLinksOnMove: false,
73+
74+
// Show main/argument labels on Links?
75+
showTopMainLabel: true,
76+
showTopArgLabels: false,
77+
showBottomMainLabel: true,
78+
showBottomArgLabels: false
79+
}
80+
);
7581

7682
// Initialisation
7783
this.resize();

src/js/tag.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ import Main from "./main";
1212
* @param {Object} [params.data] - Initial data to load, if any
1313
* @param {String} [params.format] - One of the supported format identifiers for
1414
* the data
15+
* @param {Object} [params.options] - Overrides for various default
16+
* library options
1517
*/
1618
function tag(params) {
19+
// Core params
1720
if (!params.container) {
1821
throw "No TAG container element specified.";
1922
}
20-
const instance = new Main(params.container);
2123

24+
if (!params.options) {
25+
params.options = {};
26+
}
27+
28+
const instance = new Main(params.container, params.options);
29+
30+
// Initial data load
2231
if (params.data && params.format) {
2332
instance.loadData(params.data, params.format);
2433
}

0 commit comments

Comments
 (0)