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.
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.
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 kuba irimo mbere ya dosiye ya plugin). Menyesha ibyacupackage.json
kugirango urebe verisiyo ya jQuery ishyigikiwe.
Ibitonyanga byacu, popovers hamwe nibikoresho byifashishwa na Popper.js .
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:
Guhunga abatoranya
Niba ukoresha abatoranijwe badasanzwe, kurugero : collapse:Example
, menya neza ko ubahunga, kuko bizanyuzwa kuri jQuery.
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()
.
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')
.
Uburyo bwa porogaramu zose za 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 .
Urashobora guhindura igenamiterere risanzwe rya plugin uhindura Constructor.Default
ikintu cya plugin:
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.
Verisiyo ya buri pompe ya jQuery ya Bootstrap irashobora kugerwaho hifashishijwe VERSION
umutungo wububiko bwa plugin. Kurugero, kubikoresho bya plugin:
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.
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.