JavaScript
Keen Bootstrap nolosha iyada oo la adeegsanayo furayaashayada JavaScript ee ikhtiyaarka ah ee lagu dhisay jQuery. Baro plugin kasta, xogtayada iyo barnaamijyada API ikhtiyaarka ah, iyo in ka badan.
Plugins si gaar ah ayaa loogu dari karaa (iyadoo la adeegsanayo shakhsi Bootstrap js/dist/*.js
), ama dhammaan hal mar la isticmaalayo bootstrap.js
ama la dhimay bootstrap.min.js
(ha ku darin labadaba).
Haddii aad isticmaasho xidhmo (Webpack, Rollup…), waxaad isticmaali kartaa /js/dist/*.js
faylasha UMD diyaar ah.
Qaybaha qaar iyo qaybaha CSS waxay ku xidhan yihiin plugins kale. Haddii aad si gaar ah ugu darto plugins, hubi inaad hubiso waxyaalahan ku-tiirsanaanta dukumentiyada. Sidoo kale ogow in dhammaan pluginsku ay ku xiran yihiin jQuery (taasi waxay ka dhigan tahay jQuery waa in lagu daraa ka hor faylasha plugin). Kala tashopackage.json
si aad u aragto noocyada jQuery ee la taageeray.
Hoos-u-dhacyadayada , popovers iyo qalabyada qalabku waxay sidoo kale ku xiran yihiin Popper.js .
Ku dhawaad dhammaan bootstrap plugins waa la awoodsiin karaa oo lagu habeyn karaa HTML oo keliya oo leh sifooyinka xogta (habka aan doorbideyno ee isticmaalka shaqeynta JavaScript). Hubi inaad isticmaasho hal sifo oo xogta ah oo keliya hal shay (tusaale, ma kicin kartid qalab iyo qaab isla badhanka.)
Si kastaba ha ahaatee, xaaladaha qaarkood waxa laga yaabaa in la jeclaysto in la joojiyo shaqadan. Si loo baabi'iyo sifada xogta API, ka saar dhammaan dhacdooyinka dukumeentiga u dhexeeyo data-api
sidan:
Haddii kale, si loo beegsado plugin gaar ah, kaliya ku dar magaca plugin-ka oo ah meel magac ah oo ay la socoto xogta-api namespace sidan oo kale:
Ka baxsanaya xulayaasha
Haddii aad isticmaasho doorayaal gaar ah, tusaale ahaan: collapse:Example
, hubi inaad ka baxsato, sababtoo ah waxaa lagu dhex mari doonaa jQuery.
Bootstrap waxay siisaa dhacdooyin caado u ah inta badan ficilada gaarka ah ee plugins. Guud ahaan, kuwani waxay ku yimaadaan qaab aan dhammaad lahayn oo hore uga qayb-qaatay-halkaas oo aan dhammaad lahayn (tusaale ahaan show
) uu kiciyo bilawga dhacdada, iyo qaabkeedii hore ee ka qaybqaadashada (tus. shown
) uu kiciyo marka ficilku dhammeeyo.
Dhammaan dhacdooyinka aan dhamaadka lahayn waxay bixiyaan preventDefault()
shaqeyn Tani waxay siinaysaa awoodda lagu joojinayo fulinta ficilka ka hor inta uusan bilaaban. Ka soo noqoshada beenta maamulaha dhacdada ayaa sidoo kale si toos ah u soo wici doona preventDefault()
.
Waxaan sidoo kale aaminsanahay inaad awood u leedahay inaad isticmaasho dhammaan Bootstrap plugins iyada oo keliya JavaScript API. Dhammaan API-yada dadwaynaha waa hal, habab la silsiladi karo, oo soo celi ururinta lagu dhaqmay.
Dhammaan hababka waa in ay aqbalaan shay ikhtiyaari ikhtiyaari ah, xadhig bartilmaameed u ah hab gaar ah, ama waxba (kaas oo bilaabaya plugin leh dabeecad aan caadi ahayn):
Plugin kasta waxa kale oo uu soo bandhigaa dhisaha ceeriin ee Constructor
guriga: $.fn.popover.Constructor
. Haddii aad jeclaan lahayd inaad hesho tusaale plugin gaar ah, si toos ah uga soo celi curiyaha: $('[rel="popover"]').data('popover')
.
Dhammaan hababka API-ga ee barnaamijku waa isku mid waxayna ku noqdaan soo wacaha marka kala guurka la bilaabo laakiin ka hor inta uusan dhammaan .
Si loo fuliyo ficil marka kala guurka la dhammeeyo, waxaad dhagaysan kartaa dhacdada u dhiganta.
Intaa waxa dheer hab ku baaqaya qayb ka-wareejineed waa la iska indhatiraa .
Waxaad ka beddeli kartaa habaynta caadiga ah ee plugin adiga oo wax ka beddelaya Constructor.Default
shayga plugin:
Mararka qaarkood waa lagama maarmaan in la isticmaalo bootstrap plugins oo leh qaabab kale oo UI ah. Duruufahaan, isku dhacyada meel magac ayaa marmar dhici kara. Haddii tani dhacdo, waxaad wici .noConflict
kartaa plugin-ka aad rabto inaad dib u soo celiso qiimaha.
Nooca mid kasta oo ka mid ah Bootstrap's jQuery plugins waxaa laga geli karaa VERSION
hantida dhisaha plugin. Tusaale ahaan, plugin tip-ka ah:
Bootstrap’s plugins don’t fall back particularly gracefully when JavaScript is disabled. If you care about the user experience in this case, use <noscript>
to explain the situation (and how to re-enable JavaScript) to your users, and/or add your own custom fallbacks.
Third-party libraries
Bootstrap does not officially support third-party JavaScript libraries like Prototype or jQuery UI. Despite .noConflict
and namespaced events, there may be compatibility problems that you need to fix on your own.
All Bootstrap’s JavaScript files depend on util.js
and it has to be included alongside the other JavaScript files. If you’re using the compiled (or minified) bootstrap.js
, there is no need to include this—it’s already there.
util.js
waxaa ka mid ah hawlaha utility iyo caawiyaha aasaasiga ah ee transitionEnd
dhacdooyinka iyo sidoo kale ku dayashada kala guurka CSS. Waxa isticmaala plugins-yada kale si ay u hubiyaan taageerada kala-guurka ee CSS iyo inay qabtaan kala-guurka ka laadlaadda.