I-JavaScript
Yenza i-Bootstrap iphile ngama-plugin wethu we-JavaScript ongawakhetha akhelwe ku-jQuery. Funda mayelana ne-plugin ngayinye, idatha yethu nezinketho zohlelo lwe-API, nokuningi.
Ama-plugin angafakwa ngawodwana (usebenzisa i-Bootstrap's individual js/dist/*.js
), noma wonke ngesikhathi esisodwa usebenzisa bootstrap.js
noma i-minified bootstrap.min.js
(ungafaki kokubili).
Uma usebenzisa i-bundler (Webpack, Rollup…), ungasebenzisa /js/dist/*.js
amafayela aselungile nge-UMD.
Amanye ama-plugin nezingxenye ze-CSS zincike kwamanye ama-plugin. Uma ufaka ama-plugin ngawodwana, qiniseka ukuthi uhlola lokhu kuncika kumadokhumenti. Futhi qaphela ukuthi wonke ama-plugin ancike ku-jQuery (lokhu kusho ukuthi i-jQuery kufanele ifakwe ngaphambi kwamafayela e-plugin). Xhumana nathipackage.json
ukuze ubone ukuthi yiziphi izinguqulo ze-jQuery ezisekelwayo.
Okwehliswayo kwethu, ama-popover kanye namathiphu amathuluzi nakho kuncike ku- Popper.js .
Cishe wonke ama-plugin e-Bootstrap angavulwa futhi amiswe nge-HTML iyodwa ngezibaluli zedatha (indlela yethu esiyikhethayo yokusebenzisa ukusebenza kwe-JavaScript). Qiniseka ukuthi usebenzisa isethi eyodwa yezibaluli zedatha entweni eyodwa (isb, awukwazi ukucupha ithiphu yamathuluzi nemodali enkinobho efanayo.)
Nokho, kwezinye izimo kungase kufiseleke ukukhubaza lokhu kusebenza. Ukuze ukhubaze i-API yesibaluli sedatha, khulula yonke imicimbi kudokhumenti enezikhala zamagama data-api
kanje:
Okunye, ukuze uqondise i-plugin ethile, vele ufake igama le-plugin njengendawo yegama kanye nendawo yegama yedatha-api kanje:
Abaqoki ababalekelayo
Uma usebenzisa izikhethi ezikhethekile, isibonelo: collapse:Example
, qiniseka ukuthi uyazibalekela, ngoba zizodlula ku-jQuery.
I-Bootstrap inikeza imicimbi yangokwezifiso yezenzo ezihlukile zama-plugin. Ngokuvamile, lezi ziza ngendlela engapheli kanye nenkathi edlule - lapho okungapheli (isib. show
) kuqalwa ekuqaleni komcimbi, futhi isimo saso sokuhlanganyela esidlule (isib. shown
) siqaliswa lapho kuqedwa isenzo.
Yonke imicimbi engapheli inikeza preventDefault()
ukusebenza. Lokhu kunikeza ikhono lokumisa ukwenziwa kwesenzo ngaphambi kokuthi siqale. Ukubuyisela amanga kusiphathi somcimbi nakho kuzoshaya ngokuzenzakalelayo preventDefault()
.
Sikholelwa futhi ukuthi kufanele ukwazi ukusebenzisa wonke ama-plugin e-Bootstrap nge-JavaScript API. Wonke ama-API asesidlangalaleni ayindlela eyodwa, esebenzisekayo, futhi abuyisela iqoqo osekwenziwe ngalo.
Zonke izindlela kufanele zamukele into ongakhetha kuyo, iyunithi yezinhlamvu eqondise indlela ethile, noma lutho (okuqalisa i-plugin ngokuziphatha okuzenzakalelayo):
I-plugin ngayinye iphinde iveze umakhi wayo ongahluziwe esakhiweni Constructor
: $.fn.popover.Constructor
. Uma ungathanda ukuthola isibonelo esithile se-plugin, sithole ngokuqondile entweni: $('[rel="popover"]').data('popover')
.
Zonke izindlela ze-API zohlelo azivumelanisi futhi zibuyela kofonayo uma inguquko isiqalile kodwa ngaphambi kokuthi iphele .
Ukuze wenze isenzo uma inguquko isiqedile, ungalalela umcimbi ohambisanayo.
Ngaphezu kwalokho ikholi yendlela engxenyeni eshintshayo izozitshwa .
Ungashintsha izilungiselelo ezizenzakalelayo ze-plugin ngokulungisa Constructor.Default
into ye-plugin:
Kwesinye isikhathi kuyadingeka ukusebenzisa ama-plugin e-Bootstrap nezinye izinhlaka ze-UI. Kulezi zimo, ukungqubuzana kwendawo yamagama kungenzeka ngezikhathi ezithile. Uma lokhu kwenzeka, ungashayela .noConflict
i-plugin ofisa ukubuyisela inani layo.
Inguqulo ye-plugin ngayinye ye-Bootstrap's jQuery ingafinyelelwa ngesakhiwo somakhi VERSION
we-plugin. Isibonelo, nge-plugin yethiphu yamathuluzi:
Ama-plugin e-Bootstrap awabuyeli kahle ikakhulukazi uma i-JavaScript ivaliwe. Uma unendaba nolwazi lomsebenzisi kulesi simo, sebenzisa <noscript>
ukuchaza isimo (nokuthi ungayenza kanjani i-JavaScript isebenze kabusha) kubasebenzisi bakho, kanye/noma wengeze okwakho okubuyela emuva ngokwezifiso.
Imitapo yolwazi yezinkampani zangaphandle
I-Bootstrap ayisekeli ngokusemthethweni amalabhulali e-JavaScript ezinkampani zangaphandle njenge-Prototype noma i-jQuery UI. Ngaphandle .noConflict
kwemicimbi enezikhala zamagama, kungase kube nezinkinga zokusebenzisana okudingeka uzilungise uwedwa.
Wonke amafayela e-JavaScript e-Bootstrap ancike kuwo util.js
futhi kufanele afakwe eceleni kwamanye amafayela e-JavaScript. Uma usebenzisa i-comiled (noma minified) bootstrap.js
, asikho isidingo sokufaka lokhu—sekuvele kukhona.
util.js
ihlanganisa imisebenzi ewusizo kanye nomsizi oyisisekelo transitionEnd
wemicimbi kanye nesifanisi soguquko se-CSS. Isetshenziswa amanye ama-plugin ukuhlola ukwesekwa koshintsho lwe-CSS nokubamba izinguquko ezilengayo.