APIs
The API is events used to call the specified SPZ elements in Javascript.
The value for the syntax is a simple form:
const spzElement = document.getElementById(targetId);
SPZ.whenApiDefined(spzElement).then(api => {
// doing something
});
spz-area
跳转到“spz-area”render
跳转到“render”Refetch data to render. It has a parameter:
countryCode
: Specifies a country code. It only takes effect when the element has theprovince
attribute.
spz-carousel
跳转到“spz-carousel”go
跳转到“go”Change the carousel to the next or previous slide. It has the following parameters:
dir
: it can take1
and-1
. If its value is1
, change the carousel to next slide, and vice versa.animate
: a Boolean attribute. If its value istrue
, the carousel changes with an animation.autoplay
: a Boolean attribute. If the carousel is currently automatically playing, it must be set totrue
.
<spz-carousel id="carousel" layout="fixed-height" height="500" initial-slide="0">
<spz-img layout="fixed-height" height="500" src="./images/1.jpg" object-fit="cover"></spz-img>
<spz-img layout="fixed-height" height="500" src="./images/2.jpg" object-fit="cover"></spz-img>
<spz-img layout="fixed-height" height="500" src="./images/3.jpg" object-fit="cover"></spz-img>
</spz-carousel>
<button id="button" type="button">Go Next Slide</button>
<script>
const button = document.getElementById('button');
const carousel = document.getElementById('carousel');
button.onclick = () => {
SPZ.whenApiDefined(carousel).then(api => {
api.go(1, true, false);
});
};
</script>
moveSlide
跳转到“moveSlide”Change the carousel to the next or previous slide. It has dir
and animate
parameters, same as go
API.
goToSlide
跳转到“goToSlide”Change the carousel to specify the slide, same as goToSlide
action. It has index
, animate
, and direct
parameters.
// api.goToSlide(index, animate, direct);
SPZ.whenApiDefined(carousel).then(api => {
api.goToSlide(2, true);
});
interactionNext
跳转到“interactionNext”Change the carousel to the next slide. It takes no parameters.
SPZ.whenApiDefined(carousel).then(api => {
api.interactionNext();
});
interactionPrev
跳转到“interactionPrev”Change the carousel to the previous slide. It takes no parameters.
SPZ.whenApiDefined(carousel).then(api => {
api.interactionPrev();
});
isLoopingEligible
跳转到“isLoopingEligible”Determine whether the carousel has the conditions of the loop. If the total number of slides is greater than one, its value is true
.
SPZ.whenApiDefined(carousel).then(api => {
const loop = api.isLoopingEligible();
if (loop) {
// ...
} else {
// ...
}
});
spz-cart
跳转到“spz-cart”getData
跳转到“getData”Return data of the cart.
render
跳转到“render”Same as the render
action.
spz-filter
跳转到“spz-filter”getData
跳转到“getData”Return filtered data.
SPZ.whenApiDefined(filter).then(api => {
const data = api.getData();
/*
data = {
"filter.p.vendor": "",
"filter.v.option.height": "2cm",
"filter.v.option.size": "",
"filter.v.availability": "",
"filter.v.price.gte": "",
"filter.v.price.lte": "",
"filter.v.option.color": ""
}
*/
});
spz-lightbox
跳转到“spz-lightbox”open
跳转到“open ”To open the lightbox.
close
跳转到“close”To close the lightbox.
<spz-lightbox id="lightbox" layout="nodisplay" has-mask>
<header>Header</header>
<main>
<h3>Content</h3>
</main>
<footer>Footer</footer>
<button id="close-btn" type="button">Close lightbox</button>
</spz-lightbox>
<button id="open-btn" type="button">Open lightbox</button>
<script>
const openButton = document.getElementById('open-btn');
const closeButton = document.getElementById('close-btn');
const lightbox = document.getElementById('lightbox');
openButton.onclick = () => {
SPZ.whenApiDefined(lightbox).then(api => {
api.open();
});
};
closeButton.onclick = () => {
SPZ.whenApiDefined(lightbox).then(api => {
api.close();
});
};
</script>
spz-list
跳转到“spz-list”getData
跳转到“getData”Return all data in the list of the current page.
const list = document.getElementById('collection-list');
SPZ.whenApiDefined(list).then(api => {
const items = api.getData();
});
refresh
跳转到“refresh”Same as the refresh
action.
spz-nested-menu
跳转到“spz-nested-menu”reset
跳转到“reset”To reset the menu to the first level.
SPZ.whenApiDefined(menu).then(api => {
api.reset();
});
spz-pagination
跳转到“spz-pagination”render
跳转到“render”spz-quantity
跳转到“spz-quantity”getData
跳转到“getData”Return the current value of the quantity.
SPZ.whenApiDefined(quantity).then(api => {
const value = api.getData();
// ...
});
render
跳转到“render”spz-recently-viewed
跳转到“spz-recently-viewed”getData
跳转到“getData”Return an object that contains the product ids and the value of the count
attribute.
const recentlyViewed = document.getElementById('recently-viewed');
SPZ.whenApiDefined(recentlyViewed).then(api => {
const data = api.getData(); // { limit: 18, ids: [ /* ...*/ ] }
});
spz-render
跳转到“spz-render”render
跳转到“render”Same as the render
action.
refresh
跳转到“refresh”Refresh the rendering of the element. It has a parameter:
option
: A Object attribute. It can contains some request parameters.
const render = document.getElementById('render');
SPZ.whenApiDefined(render).then(api => {
api.render({
page: 2,
per_page: 20
});
});
spz-selector
跳转到“spz-selector”getData
跳转到“getData”It must have a name
attribute. Returns the value
of the selected option.
const selector = document.getElementById('selector');
SPZ.whenApiDefined(selector).then(api => {
const data = api.getData(); // { selector: ['0', '1', /* ... */ ] }
});
render
跳转到“render”Same as the update
action.
spz-sidebar
跳转到“spz-sidebar”open
跳转到“open”To open the element.
SPZ.whenApiDefined(sidebar).then(api => {
api.open();
});
close
跳转到“close”To close the element.
SPZ.whenApiDefined(sidebar).then(api => {
api.close();
});
spz-toast
跳转到“spz-toast”showToast
跳转到“showToast”show the toast with a given text in javascript.
const toast = document.getElementById('toast');
SPZ.whenApiDefined(toast).then(api => {
api.showToast(text='This is a toast pop-up.')
});
spz-variants
跳转到“spz-variants”getData
跳转到“getData”Return the currently selected variant combination data.
SPZ.whenApiDefined(variantEle).then(api => {
const promise = api.getData();
promise.then(data => {
/*
// data object
data = {
product: {
// product info
},
productId: "66aac15b-33cc-485c-bd1c-f7905e4e48a1",
selectedValues: {
Color: ["Slategray"],
Size: ["M"]
// ...
},
variant: {
// the currently selected variant data
}
};
*/
})
});
spz-video
跳转到“spz-video”getData
跳转到“getData”Get the time that the video is played.
SPZ.whenApiDefined(video).then(api => {
console.log('The current time is ' + api.getData() + ' seconds.');
});
onEnterFullscreenCallback
跳转到“onEnterFullscreenCallback”Set full-screen play with the video. It has the following parameters:
isZoom
: if it istrue
, the video enters full-screen play and vice versa.
SPZ.whenApiDefined(video).then(api => {
api.onEnterFullscreenCallback(true);
});