Skip to main content

buildfire.components.contentSlider

The contentSlider component provides a tool to display a navigational bar with simple left (previous) and right (next) controls anywhere inside your plugin.

Requirements

Widget

<head>
<!-- CSS -->
<link rel="stylesheet" href="../../../styles/components/contentSlider/contentSlider.css" />

<!-- JS -->
<script src="../../../scripts/buildfire.min.js"></script>
<script src="../../../scripts/buildfire/components/contentSlider/contentSlider.js"></script>
</head>

In your widget body, create an html container element for the content slider.

<body>
<div id="slider"></div>
</body>

Methods

const contentSlider = new buildfire.components.contentSlider(selector, options);

ContentSlider class constructor method which initializes the content slider component.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider()

Arguments

NameTypeRequiredDescriptionDefault
selectorstringyesCSS selector of element that will contain component
optionsobjectnooptions object

options

NameTypeRequiredDescriptionDefault
itemsarrayyesitem object
settingsobjectnosettings object

item

NameTypeRequiredDescriptionDefault
idnumberyesUnique idnull
titlestringyesTitle of the itemnull
subtitlestringnoSubtitle of the itemnull

settings

NameTypeRequiredDescriptionDefault
showSubtitlebooleannoHides or shows the subtitle of the contenttrue
startingIndexnumbernoSpecifies which item to start from0

insertAt()

contentSlider.insertAt(options, callback)

Appends one or more items to the specified position of the content slider component.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: "23", title: "23 November, 2022", subtitle: "Sunday" }
{ id: "24", title: "24 November, 2022", subtitle: "Monday" },
{ id: "25", title: "25 November, 2022", subtitle: "Tuesday" }
]
});

contentSlider.insertAt({
items: [{ id: "22", title: "22 November, 2022", subtitle: "Saturday" }],
index: 0,
position: 'before'
}, () => console.log('Inserted Data'));

Arguments

NameTypeRequiredDescriptionDefault
optionsobjectyesoptions object
callbackfunctionyesCompletion callback

options

NameTypeRequiredDescriptionDefault
itemsarray/objectyesArray of items, or single item to be appended to list view.
indexnumberyesindex to specify where to insert items
positionstringyesspecify how to insert items on the index, options are before/after

append()

contentSlider.append(items, callback)

Appends one or more items to the content slider.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.append(
[
{
id: '26',
title: '26 November, 2022',
subtitle: 'Wednesday',
},
],
() => console.log('Appended Data')
);

Arguments

NameTypeRequiredDescriptionDefault
items[object] or objectyesArray of items, or single item to be appended to list view.
callbackyesprovides a callback to do something when the items are appended

prepend()

contentSlider.prepend(items, callback)

Prepends one or more items to the content slider.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.prepend(
[
{
id: '22',
title: '22 November, 2022',
subtitle: 'Saturday',
},
],
() => console.log('Prepended Data')
);

Arguments

NameTypeRequiredDescriptionDefault
items[object] or objectyesArray of items, or single item to be prepended to list view.
callbackyesProvides callback to do something when the items are prepended

update()

contentSlider.update(id, data)

Updates an item. If the item is the current content, updates the slider accordingly.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.update('24', {
id: '24',
title: '24 November, 2022',
subtitle: 'I Hate Mondays',
});

Arguments

NameTypeRequiredDescriptionDefault
idstringyesObject id
dataobjectyesObject to be updated

remove()

contenSlider.remove(id)

Removes an item from the content slider

note

If the item is the current index component, it will render the next or previous item depending on the number of items and the current index. In the example below the component will render the item with the id "24" after removing the item with the id "23".

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.remove('23');

Arguments

NameTypeRequiredDescriptionDefault
idstringyesObject id

next()

contentSlider.next()

Sets the next item as the current content of the slider.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.next();

previous()

contentSlider.previous()

Sets the previous item as the current content of the slider.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.next();
setTimeout(() => {
contentSlider.previous();
}, 2000);

enable()

contentSlider.enable(direction)

Enables the corresponding arrow for the pointed direction of the slider.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.enable('previous');

Arguments

NameTypeRequiredDescriptionDefault
directionstringyesnext or previousnull

disable()

contentSlider.disable(direction)

Enables the corresponding arrow for the pointed direction of the slider.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.disable('next');

Arguments

NameTypeRequiredDescriptionDefault
directionstringyesnext or previousnull

getCurrent()

contentSlider.getCurrent(callback)

Retrieves the current item rendered in the component.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.getCurrent();

Arguments

NameTypeRequiredDescriptionDefault
callbackyesReturns the current item

setCurrent()

contentSlider.setCurrent(options)

Sets the current item of the component and replaces current content with the new one.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.setCurrent({
id: '24',
});

Arguments

NameTypeRequiredDescriptionDefault
optionsobjectyesoptions object

options

NameTypeRequiredDescriptionDefault
idstring/numberyesitem id
indexnumberyesitem index
note

At least one of the options object parameters must be specified.


refresh()

contentSlider.refresh()

Refreshes the component to apply new options provided and re-renders current content.

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
});

contentSlider.options.settings.showSubtitle = false;
contentSlider.refresh();

Handlers

The following event handlers can be assigned:

onNext(event)

Triggered when the user clicks on the next arrow.

contentSlider.onNext = (event) => {
console.log(`Navigated to item id ${event.item.id}`);
};

Arguments

NameTypeRequiredDescriptionDefault
eventobjectyesholds item clicked

Event

NameTypeRequiredDescriptionDefault
itemobjectyesclicked item objectnull

onPrevious(event)

Triggered when the user clicks on the previous arrow.

contentSlider.onPrevious = (event) => {
console.log(`Navigated to item id ${event.item.id}`);
};

Arguments

NameTypeRequiredDescriptionDefault
eventobjectyesholds item clicked

Event

NameTypeRequiredDescriptionDefault
itemobjectyesclicked item objectnull


Example

Code

const contentSlider = new buildfire.components.contentSlider('#slider', {
items: [
{ id: '23', title: '23 November, 2022', subtitle: 'Sunday' },
{ id: '24', title: '24 November, 2022', subtitle: 'Monday' },
{ id: '25', title: '25 November, 2022', subtitle: 'Tuesday' },
],
settings: {
startingIndex: 1,
},
});

//managing items in the component
contentSlider.append(
[
{ id: '26', title: '26 November, 2022', subtitle: 'Wednesday' },
{ id: '27', title: '27 November, 2022', subtitle: 'Thursday' },
{ id: '28', title: '28 November, 2022', subtitle: 'Friday' },
],
() => console.log('Appended Data')
);

contentSlider.insertAt(
{
items: [
{ id: '30', title: '30 November, 2022', subtitle: 'Sunday' },
{ id: '29', title: '29 November, 2022', subtitle: 'Saturday' },
],
index: 0,
position: 'after',
},
() => console.log('Inserted Data')
);

contentSlider.update('26', { id: '26', title: '26 November, 2022', subtitle: 'Happy Wednesday' });

contentSlider.remove('26');

//controlling component
contentSlider.setCurrent({ index: '2' });

contentSlider.disable('previous');
contentSlider.disable('next');

contentSlider.options.settings.showSubtitle = false;
contentSlider.refresh();

contentSlider.enable('previous');
contentSlider.enable('next');

contentSlider.previous();
setTimeout(() => {
contentSlider.next();
}, 2000);

//handling events from the component
contentSlider.onPrevious = (event) => {
console.log(event);
};

contentSlider.onNext = (event) => {
console.log(event);
};