JavaScript
Zisa iBootstrap ebomini ngeeplagi zethu ozikhethelayo zeJavaScript ezakhelwe kwijQuery. Funda malunga neplagin nganye, idatha yethu kunye nokhetho lweprogram ye-API, kunye nokunye.
Iiplagi zingabandakanywa ngabanye (usebenzisa iBootstrap's individual js/dist/*.js
), okanye zonke ngaxeshanye usebenzisa bootstrap.js
okanye iminified bootstrap.min.js
(ungaquki zombini).
Ukuba usebenzisa i-bundler (i-Webpack, i-Rollup…), unokusebenzisa /js/dist/*.js
iifayile ezisele zilungile i-UMD.
Ezinye iiplagi kunye namalungu eCSS axhomekeke kwezinye iiplagi. Ukuba ubandakanya ii-plugins nganye, qiniseka ukuba ukhangele ezi zixhomekeke kumaxwebhu. Kwakhona qaphela ukuba zonke iiplagi zixhomekeke kwijQuery (oku kuthetha ukuba i-jQuery kufuneka ifakwe phambi kweefayile zeplagin). Qhagamshelana nathipackage.json
ukuze ubone ukuba zeziphi iinguqulelo zejQuery ezixhaswayo.
Iidrophu zethu, iipopovers kunye netooltips nazo zixhomekeke kwiPopper.js .
Phantse zonke iiplagi ze-Bootstrap zinokwenziwa kwaye ziqwalaselwe nge-HTML yodwa ngeempawu zedatha (indlela yethu esiyithandayo yokusebenzisa ukusebenza kweJavaScript). Qiniseka ukuba usebenzisa kuphela iseti enye yeempawu zedatha kwinto enye (umzekelo, awukwazi ukuvusa ingcebiso yesixhobo kunye nemodali ukusuka kwiqhosha elifanayo.)
Nangona kunjalo, kwezinye iimeko kunokunqweneleka ukuvala lo msebenzi. Ukukhubaza uphawu loyelelwano lwedatha, khulula zonke iziganeko kuxwebhu olunezithuba data-api
ezilolo hlobo:
Kungenjalo, ukujolisa iplagin ethile, faka nje igama leplagi njengendawo yegama kunye ne-data-api namespace efana nale:
Ukubaleka abakhethi
Ukuba usebenzisa abakhethi abakhethekileyo, umzekelo: collapse:Example
, qiniseka ukuba uyabaleka, kuba baya kudluliselwa kwijQuery.
I-Bootstrap ibonelela ngeziganeko zesiko kwiintshukumo ezininzi ezizodwa zeeplagi. Ngokuqhelekileyo, ezi ziza ngendlela engapheliyo kunye neyexesha elidlulileyo - apho i-infinitive (umz. show
) iqaliswa ekuqaleni kwesiganeko, kwaye imo yaso yexesha elidlulileyo ye-participle (umz. shown
) ivuselelwe ekugqityweni kwesenzo.
Zonke iziganeko ezingapheliyo zibonelela preventDefault()
ngokusebenza. Oku kubonelela ukukwazi ukumisa ukuphunyezwa kwesenzo phambi kokuba siqale. Ukubuyisa okungeyonyani kumphathi wesiganeko nako kuyakufowunela ngokuzenzekelayo preventDefault()
.
Sikwakholelwa ukuba kufuneka ukwazi ukusebenzisa zonke iiplagi zeBootstrap ngeJavaScript API. Zonke ii-API zikawonke-wonke zinye, iindlela ezibolekwayo, kwaye zibuyisela ingqokelela eyenziwayo.
Zonke iindlela kufuneka zamkele into ekhethiweyo yeenketho, umtya ojolise kwindlela ethile, okanye akukho nto (eqalisa iplagin ngokuziphatha okungagqibekanga):
I-plugin nganye iphinda iveze umakhi wayo ekrwada Constructor
kwipropati: $.fn.popover.Constructor
. Ukuba ungathanda ukufumana umzekelo othile weplagi, yifumane ngokuthe ngqo kwinto: $('[rel="popover"]').data('popover')
.
Zonke iindlela zeprogram ye-API zi -asynchronous kwaye zibuyela kumnxeba xa utshintsho luqalisiwe kodwa ngaphambi kokuba luphele .
Ukuze wenze isenzo xa utshintsho lugqityiwe, ungamamela isiganeko esihambelanayo.
Ukongeza umnxeba wendlela kwicandelo lotshintsho awuyi kuhoywa .
Ungatshintsha useto olungagqibekanga lweplagi ngokulungisa Constructor.Default
into yeplagin:
Ngamanye amaxesha kuyimfuneko ukusebenzisa iiplagi ze-Bootstrap kunye nezinye izikhokelo ze-UI. Kwezi meko, ukungqubana kwesithuba segama kunokwenzeka ngamanye amaxesha. Ukuba oku kuyenzeka, .noConflict
ungafowunela iplagin onqwenela ukubuyisela ixabiso layo.
Uguqulelo lweplagi nganye yeBootstrap's jQuery inokufikelelwa VERSION
ngepropathi yomakhi weplagi. Umzekelo, kwi-plugin yengcebiso yesixhobo:
Iiplagi zeBootstrap azibuyeli ngasemva ngokukodwa xa iJavaScript ivaliwe. Ukuba unenkathalo ngamava omsebenzisi kule meko, sebenzisa <noscript>
ukuchaza imeko (kunye nendlela yokwenza kwakhona iJavaScript) kubasebenzisi bakho, kunye/okanye ukongeza okwakho ukusilela.
Amathala eencwadi eqela lesithathu
I-Bootstrap ayizixhasi ngokusemthethweni iilayibrari zeJavaScript zomntu wesithathu njengePrototype okanye i-jQuery UI. Ngaphandle .noConflict
kweziganeko ezinamagama, kusenokubakho iingxaki zokuhambelana ekufuneka uzilungise wedwa.
Zonke iifayile zeJavaScript zeBootstrap zixhomekeke util.js
kwaye kufuneka zibandakanywe ecaleni kwezinye iifayile zeJavaScript. Ukuba usebenzisa i compiled (okanye minified) bootstrap.js
, akukho mfuneko yokubandakanya oku-sele kukho.
util.js
ibandakanya imisebenzi eluncedo kunye nomncedisi osisiseko wemisitho transitionEnd
kunye ne-emulator yenguqu ye-CSS. Isetyenziswa zezinye iiplagi ukukhangela inkxaso yenguqu yeCSS nokubamba iinguqu ezijingayo.