JavaScript
Hunza Bootstrap kuhupenyu neyedu sarudzo JavaScript plugins yakavakirwa pajQuery. Dzidza nezve plugin yega yega, data redu uye programmatic API sarudzo, nezvimwe.
Mapulagi anogona kuverengerwa ega (uchishandisa Bootstrap's munhu js/dist/*.js
), kana zvese kamwechete uchishandisa bootstrap.js
kana minified bootstrap.min.js
(usasanganise ese ari maviri).
Kana iwe ukashandisa bundler (Webpack, Rollup…), unogona kushandisa /js/dist/*.js
mafaera akagadzirira UMD.
Mamwe mapulagi neCSS zvinotsamira pane mamwe mapulagi. Kana iwe ukasanganisira plugins wega, ita shuwa yekutarisa kune izvi zvinotsamira mumagwaro. Ziva zvakare kuti ese maplugins anoenderana nejQuery (izvi zvinoreva kuti jQuery inofanira kuverengerwa pamberi pemafaira eplugin). Bvunza yedupackage.json
kuti uone kuti ndedzipi shanduro dzejQuery dzinotsigirwa.
Kudonhedza kwedu, popovers uye matipi ekushandisa zvakare zvinoenderana nePopper.js .
Anenge ese maBootstrap plugins anogona kugoneswa uye kugadziridzwa kuburikidza neHTML chete ane data hunhu (nzira yedu yatinoda yekushandisa JavaScript mashandiro). Ita shuwa kuti ungoshandisa seti imwe chete yedata hunhu pane chinhu chimwe chete (semuenzaniso, haugone kukonzeresa chetipi uye modal kubva kune rimwe bhatani.)
Zvisinei, mune mamwe mamiriro ezvinhu zvingava zvinodiwa kudzima basa iri. Kudzima iyo data API, sunungura zvese zviitiko pagwaro rakaiswa mazita data-api
saizvozvo:
Neimwe nzira, kunanga imwe plugin, ingo sanganisira zita replugin sezita rezita pamwe chete nedata-api namespace seizvi:
Kutiza vasarudzo
Kana iwe ukashandisa vakasarudzika vakasarudzika, semuenzaniso: collapse:Example
, iva nechokwadi chekuvatiza, nekuti ivo vanozopfuura kuburikidza nejQuery.
Bootstrap inopa zviitiko zvetsika kune akawanda plugins 'akasarudzika zviito. Kazhinji, izvi zvinouya muchimiro chechirevo chisingaperi uye chekare - apo chisingaperi (ex. show
) chinotangwa pakutanga kwechiitiko, uye chimiro chayo chechirevo chekare (ex. shown
) chinotangwa pakupedzwa kwechiito.
Zvose zvisingagumi zviitiko zvinopa preventDefault()
kushanda. Izvi zvinopa kugona kumisa kuitwa kwechiito chisati chatanga. Kudzorera nhema kubva kumubati wechiitiko kuchafonawo otomatiki preventDefault()
.
Isu tinotenda zvakare kuti unofanirwa kukwanisa kushandisa ese Bootstrap plugins kuburikidza neJavaScript API. MaAPI ese eruzhinji inzira imwechete, inobatika, uye inodzosa kuunganidzwa kwaitwa.
Nzira dzese dzinofanirwa kugamuchira chinhu chekusarudza sarudzo, tambo inonangana neimwe nzira, kana hapana (iyo inotanga plugin ine default maitiro):
Imwe neimwe plugin zvakare inofumura mugadziri wayo mbishi pachivakwa Constructor
: $.fn.popover.Constructor
. Kana iwe uchida kuwana imwe plugin muenzaniso, itore zvakananga kubva kune chinhu: $('[rel="popover"]').data('popover')
.
Yese programmatic API nzira dzine asynchronous uye dzinodzokera kune anofona kana shanduko yatanga asi isati yapera .
Kuti uite chiito kana shanduko yapera, unogona kuteerera kune chiitiko chinoenderana.
Pamusoro peiyo nzira yekufona pachikamu chekuchinja inozofuratirwa .
Unogona kushandura zvigadziriso zveplugin nekugadzirisa chinhu cheplugin Constructor.Default
:
Dzimwe nguva zvinodikanwa kushandisa Bootstrap plugins nemamwe maUI maficha. Mumamiriro ezvinhu aya, kudhumhana kwemazita kunogona kuitika dzimwe nguva. Kana izvi zvikaitika, unogona kufonera .noConflict
plugin yaunoda kudzorera kukosha kwayo.
Iyo vhezheni yeimwe neimwe yeBootstrap's jQuery plugins inogona kuwanikwa kuburikidza nemudziyo wemugadziri weplugin VERSION
. Semuenzaniso, kune tooltip plugin:
Bootstrap's plugins haidzoke kumashure zvakanyanya nenyasha kana JavaScript yakadzimwa. Kana iwe uine hanya neruzivo rwemushandisi mune iyi kesi, shandisa <noscript>
kutsanangura mamiriro acho (uye maitiro ekuitazve JavaScript) kune vashandisi vako, uye/kana wedzera yako wega yekudonha.
Mataibhurari ebato rechitatu
Bootstrap haitsigire zviri pamutemo-wechitatu-bato JavaScript raibhurari sePrototype kana jQuery UI. Kunyangwe .noConflict
uye zviitiko zvakapatsanurwa mazita, panogona kunge paine matambudziko ekuenderana aunoda kugadzirisa wega.
Mafaira ese eBootstrap eJavaScript anoenderana util.js
nazvo uye anofanirwa kuverengerwa padivi pemamwe mafaera eJavaScript. Kana uri kushandisa compiled (kana minified) bootstrap.js
, hapana chikonzero chekuisa izvi-zvatovepo.
util.js
inosanganisira mabasa ekushandisa uye mubatsiri wekutanga transitionEnd
wezviitiko pamwe neCSS shanduko emulator. Inoshandiswa nemamwe maplugins kutarisa CSS shanduko yerutsigiro uye kubata yakarembera shanduko.