JavaScript
Zana Bootstrap mubuzima hamwe na JavaScript idahitamo yubatswe kuri jQuery. Wige kuri buri plugin, amakuru yacu hamwe na gahunda ya API ihitamo, nibindi byinshi.
Umuntu ku giti cye cyangwa yakusanyijwe
Amacomeka arashobora gushyirwamo kugiti cye (ukoresheje Bootstrap kugiti cye js/dist/*.js
), cyangwa byose icyarimwe ukoresheje bootstrap.js
cyangwa bigabanijwe bootstrap.min.js
(ntushyiremo byombi).
Niba ukoresheje bundler (Webpack, Rollup…), urashobora gukoresha /js/dist/*.js
dosiye UMD yiteguye.
Kwishingikiriza
Amacomeka hamwe nibice bya CSS biterwa nandi macomeka. Niba ushizemo amacomeka kugiti cye, menya neza niba ugenzura ibyo biterwa muri doc. Menya kandi ko amacomeka yose aterwa na jQuery (ibi bivuze ko jQuery igomba kubamo mbere ya dosiye ya plugin). Baza ibyacupackage.json
kugirango urebe verisiyo ya jQuery ishyigikiwe.
Ibitonyanga byacu, popovers hamwe nibikoresho byifashishwa na Popper.js .
Ibiranga amakuru
Amacomeka hafi ya yose ya Bootstrap arashobora gushobozwa no kugenwa binyuze muri HTML yonyine hamwe nibiranga amakuru (uburyo twahisemo bwo gukoresha imikorere ya JavaScript). Wemeze gukoresha gusa urutonde rwibintu biranga ikintu kimwe (urugero, ntushobora gukurura igikoresho na modal kuva kuri buto imwe.)
Ariko, mubihe bimwe na bimwe birashobora kuba byiza guhagarika iyi mikorere. Kugirango uhagarike amakuru yikiranga API, uhuza ibyabaye byose kumazina yinyandiko yashyizwe hamwe nkaya data-api
:
Ubundi, kugirango ugaragaze plugin yihariye, shyiramo gusa izina rya plugin nkumwanya wizina hamwe na data-api izina ryumwanya nkuyu:
Abatoranya
Kugeza ubu kubaza ibintu DOM dukoresha uburyo kavukire querySelector
kandi querySelectorAll
kubwimpamvu zikorwa, ugomba rero gukoresha abatoranya bemewe . Niba ukoresha abatoranya badasanzwe, kurugero: collapse:Example
menya neza ko uhunga.
Ibyabaye
Bootstrap itanga ibyabaye kubintu byinshi byacometse kubikorwa byihariye. Mubisanzwe, ibi biza muburyo butagira ingano kandi bwashize - aho infinitive (ex. show
) Itangizwa mugitangira ibirori, kandi ifishi yacyo ya kera (ex. shown
) Iterwa no kurangiza igikorwa.
Ibintu byose bitagira ingano bitanga preventDefault()
imikorere. Ibi bitanga ubushobozi bwo guhagarika ikorwa ryigikorwa mbere yuko gitangira. Garuka ibinyoma bivuye mubyabaye nabyo bizahita bihamagara preventDefault()
.
Gahunda ya API
Turizera kandi ko ugomba gushobora gukoresha amacomeka yose ya Bootstrap ukoresheje JavaScript API. API rusange rusange ni imwe, uburyo bukurikirana, kandi igasubiza icyegeranyo cyakozwe.
Uburyo bwose bugomba kwemera ibintu bidahitamo ikintu, umugozi ugamije uburyo runaka, cyangwa ntakintu (gitangiza plugin hamwe nimyitwarire idasanzwe):
Buri plugin irerekana kandi ibyubaka byayo ku Constructor
mutungo : $.fn.popover.Constructor
. Niba ushaka kubona plugin runaka urugero, iyikure muburyo butaziguye : $('[rel="popover"]').data('popover')
.
Imikorere ninzibacyuho
Uburyo bwose bwa programme API nuburyo budahwitse kandi bugaruka kumuhamagara iyo inzibacyuho itangiye ariko mbere yuko irangira .
Kugirango ukore igikorwa iyo inzibacyuho irangiye, urashobora kumva ibyabaye.
Mubyongeyeho uburyo bwo guhamagarira ibice byinzibacyuho bizirengagizwa .
Igenamiterere risanzwe
Urashobora guhindura igenamiterere risanzwe rya plugin uhindura Constructor.Default
ikintu cya plugin:
Nta makimbirane
Rimwe na rimwe, birakenewe gukoresha amacomeka ya Bootstrap hamwe nibindi UI. Muri ibi bihe, umwanya wizina urashobora guhura rimwe na rimwe. Niba ibi bibaye, urashobora guhamagara .noConflict
kuri plugin wifuza guhindura agaciro ka.
Inomero za verisiyo
Verisiyo ya buri pompe ya jQuery ya Bootstrap irashobora kugerwaho hifashishijwe VERSION
umutungo wububiko bwa plugin. Kurugero, kubikoresho bya plugin:
Nta gusubira inyuma bidasanzwe iyo JavaScript ihagaritswe
Amacomeka ya Bootstrap ntasubira inyuma cyane cyane mugihe JavaScript ihagaritswe. Niba witaye kuburambe bwabakoresha muriki kibazo, koresha <noscript>
kugirango usobanure uko ibintu bimeze (nuburyo bwo kongera gukora JavaScript) kubakoresha, kandi / cyangwa wongereho ibyo wiboneye.
Isomero ryabandi
Bootstrap ntabwo ishigikira kumugaragaro amasomero-yandi masomero ya JavaScript nka Prototype cyangwa jQuery UI. Nubwo .noConflict
hamwe n'amazina yibyabaye, hashobora kubaho ibibazo byo guhuza ukeneye kwikemurira wenyine.
Koresha
Amadosiye yose ya JavaScript ya Bootstrap biterwa util.js
kandi igomba gushyirwamo hamwe nandi ma dosiye ya JavaScript. Niba ukoresha icyegeranyo (cyangwa cyaciwe) bootstrap.js
, nta mpamvu yo gushyiramo ibi-birahari.
util.js
ikubiyemo ibikorwa byingirakamaro hamwe numufasha wibanze transitionEnd
kubyabaye kimwe na CSS yinzibacyuho. Ikoreshwa nandi macomeka kugirango agenzure inkunga ya CSS yinzibacyuho no gufata inzibacyuho.