JavaSkript fɔ di Baybul
Bring Bootstrap to layf wit wi opshɔnal JavaSkript plɔgin dɛn we dɛn bil pan jQuery. Lan bɔt ɛni plɔgin, wi data ɛn programmatik API opshɔn dɛn, ɛn ɔda tin dɛn.
Wan wan ɔ we dɛn dɔn kɔmpilayt
Plɔgin dɛn kin inklud wan wan (yuz Bootstrap in wan wan js/dist/*.js
), ɔ ɔl wan tɛm yuz bootstrap.js
ɔ di minified bootstrap.min.js
(nɔ inklud ɔl tu).
If yu yuz bundler (Webpack, Rollup...), yu kin yuz /js/dist/*.js
fayl dɛn we dɔn rɛdi fɔ UMD.
Dipɛnsin dɛn
Sɔm plɔgin dɛn ɛn CSS kɔmpɔnɛnt dɛn de dipen pan ɔda plɔgin dɛn. If yu put plɔgin dɛn wan bay wan, mek shɔ se yu chɛk fɔ dɛn dipɛnsin dɛn ya na di dɔkyumɛnt dɛn. Notis bak se ɔl di plɔgin dɛn dipen pan jQuery (dis min se jQuery fɔ de bifo di plɔgin fayl dɛn). Kɔnsul wipackage.json
fɔ si us vɛshɔn dɛn fɔ jQuery dɛn de sɔpɔt.
Wi dropdowns, popovers ɛn tultips dɛn bak de dipen pan Popper.js .
Data atribyut dɛn
Klose to ɔl di Bootstrap plɔgin dɛn kin ɛnabul ɛn kɔnfigyut tru HTML nɔmɔ wit data atribyut dɛn (wi we wi lɛk fɔ yuz JavaSkript funkshɔnaliti). Mek shɔ se yu jɔs yuz wan sɛt fɔ data atribyut dɛn pan wan ɛlimɛnt (ɛgz., yu nɔ go ebul fɔ trig wan tultip ɛn modal frɔm di sem bɔtin.)
Bɔt, insay sɔm tin dɛn, i kin fayn fɔ mek dɛn disable dis wok. Fɔ disable di data atribyut API, unbind ɔl di ivintɛns dɛn na di dɔkyumɛnt nemspɛs wit data-api
lɛk so:
Ɔda we de fɔ du dat, fɔ tɔch wan patikyula plɔgin, jɔs put di plɔgin in nem as nemspɛs wit di data-api nemspɛs lɛk dis:
Di wan dɛn we de pik di tin dɛn
Naw fɔ aks DOM ɛlimɛnt dɛn wi de yuz di nativ we dɛn querySelector
ɛn querySelectorAll
fɔ pefɔmɛns rizin dɛn, so yu fɔ yuz valid sɛlɛktɔ dɛn . If yu yuz spɛshal sɛlɛktɔ dɛn, fɔ ɛgzampul: collapse:Example
mek shɔ se yu rɔnawe pan dɛn.
Di tin dɛn we kin apin
Bootstrap de gi kɔstɔm ivin fɔ bɔku pan di plɔgin dɛn yunik akshɔn dɛn. Jɛnɛral wan, dɛn wan ya kin kam insay wan infinitiv ɛn past patisipul fɔm - usay di infinitiv (ɛks. show
) kin trig we wan ivin bigin, ɛn in past patisipul fɔm (ɛks. shown
) kin trig we wan akshɔn dɔn.
Ɔl di infinitiv ivin dɛn de gi preventDefault()
funkshɔnaliti. Dis de gi di abiliti fɔ stɔp di ɛgzikishɔn fɔ wan akshɔn bifo i bigin. Ritɔn false frɔm wan ivent handla go kɔl bak ɔtomɛtik wan preventDefault()
.
Programmetik API fɔ di wan dɛn we de wok
Wi biliv bak se yu fɔ ebul fɔ yuz ɔl di Bootstrap plɔgin dɛn jɔs tru di JavaSkript API. Ɔl di pɔblik API dɛn na wan, chenj we dɛn kin yuz fɔ du tin, ɛn dɛn kin gi bak di kɔleshiɔn we dɛn akt pan.
Ɔl di we dɛn fɔ aksept wan opshɔnal opshɔn ɔbjɛkt, wan string we de tɔch wan patikyula we, ɔ natin (we de bigin wan plɔgin wit difɔlt bihayvya):
Ɛni plɔgin de ɛksplɔz in raw kɔnstrɔkta bak pan wan Constructor
prɔpati: $.fn.popover.Constructor
. If yu want fɔ gɛt wan patikyula plɔgin instans, tek am dairekt frɔm wan ɛlimɛnt: $('[rel="popover"]').data('popover')
.
Asynchronous fכnshכn dεm εn transishכn dεm
Ɔl di programmatik API mɛtɔd dɛn na asynchronous ɛn dɛn kin kam bak to di pɔsin we kɔl wans di transishɔn dɔn stat bɔt bifo i dɔn .
Fɔ mek yu ebul fɔ du wan akshɔn wans di chenj dɔn, yu kin lisin to di kɔrɛspɔndɛns ivin.
Apat frɔm dat wan mɛtɔd kɔl pan wan transishɔn kɔmpɔnɛnt go ignore .
Difɔlt sɛtin dɛn
Yu kin chenj di difɔlt sɛtin fɔ wan plɔgin bay we yu chenj di tin we di plɔgin de Constructor.Default
yuz:
Nɔ kɔnflikt nɔ de
Sɔntɛnde i nid fɔ yuz Bootstrap plɔgin dɛn wit ɔda UI fremwɔk dɛn. Insay dɛn kayn tin ya, nemspɛs kɔlishin kin apin wan wan tɛm. If dis apin, yu kin kɔl .noConflict
di plɔgin we yu want fɔ gi bak di valyu fɔ.
Vɛshɔn nɔmba dɛn
Di vɛshɔn fɔ ɛni wan pan Bootstrap in jQuery plɔgin dɛn kin akses tru di VERSION
prɔpati fɔ di plɔgin in kɔnstrɔkta. Fɔ ɛgzampul, fɔ di tultip plɔgin:
Nɔ spɛshal fɔl bak we dɛn nɔ yuz JavaSkript
Bootstrap in plɔgin dɛn nɔ de fɔdɔm bak patikyula grasful wan we JavaSkript nɔ de wok. If yu bisin bɔt di yuza ɛkspiriɛns na dis kes, yuz <noscript>
fɔ ɛksplen di sityueshɔn (ɛn aw fɔ ri-ɛnabul JavaSkript) to yu yuza dɛn, ɛn/ɔ ad yu yon kɔstɔm fɔlbak dɛn.
Tɔd-pati laybri dɛn
Bootstrap nɔ ɔfishal wan sɔpɔt tɔd-pati JavaSkript laybri dɛn lɛk Prototype ɔ jQuery UI. Pan ɔl .noConflict
we tin dɛn kin apin ɛn we gɛt nem-spɛs, prɔblɛm dɛn kin de we gɛt fɔ du wit di kɔmpitishɔn we yu nid fɔ fiks fɔ yusɛf.
Yutil
Ɔl di Bootstrap in JavaSkript fayl dɛn dipen pan util.js
ɛn i gɛt fɔ de nia di ɔda JavaSkript fayl dɛn. If yu de yuz di kɔmpilayt (ɔ minified) bootstrap.js
, nid nɔ de fɔ put dis insay—i dɔn ɔlrɛdi de.
util.js
inklud yutiliti fɛnshɔn dɛn ɛn wan besik ɛp fɔ transitionEnd
ivintɛns dɛn ɛn bak wan CSS transishɔn ɛmulatɔ. Na di ɔda plɔgin dɛn de yuz am fɔ chɛk fɔ CSS transishɔn sɔpɔt ɛn fɔ kech transishɔn dɛn we de hang.