Source

Javascript

Weta Bootstrap ndụ site na ngwa mgbakwunye Javascript nke arụnyere na jQuery. Mụta maka ngwa mgbakwunye ọ bụla, data anyị na nhọrọ API mmemme, yana ndị ọzọ.

Onye ma ọ bụ chịkọtara

Enwere ike itinye ngwa mgbakwunye n'otu n'otu (iji Bootstrap's onye js/dist/*.js), ma ọ bụ ihe niile n'otu oge na-eji bootstrap.jsma ọ bụ nke pere mpe bootstrap.min.js(anaghị etinye ha abụọ).

Ọ bụrụ na ị na-eji ngwugwu (Webpack, Rollup…), ị nwere ike iji /js/dist/*.jsfaịlụ ndị dị njikere UMD.

Ndabere

Ụfọdụ plugins na akụkụ CSS na-adabere na plugins ndị ọzọ. Ọ bụrụ na ị gụnyere plugins n'otu n'otu, jide n'aka na ịlele maka ndabere ndị a na docs. Rịba ama na plugins niile dabere na jQuery (nke a pụtara jQuery ga-etinyerịrị tupu faịlụ ngwa mgbakwunye). Gaa na anyịpackage.json ka ịhụ ụdị jQuery akwadoro.

Ihe ndapụta anyị, popovers na ndụmọdụ ngwaọrụ dabere na Popper.js .

Njirimara data

Ihe fọrọ nke nta ka ọ bụrụ plugins Bootstrap niile nwere ike ịme ma hazie ya site na HTML naanị ya na njirimara data (ụzọ kachasị amasị anyị iji ọrụ Javascript). Jide n'aka na ị ga -eji naanị otu njirimara data na otu mmewere (dịka ọmụmaatụ, ị nweghị ike ịkpalite ngwa ọrụ na modal site na otu bọtịnụ ahụ.)

Agbanyeghị, n'ọnọdụ ụfọdụ ọ nwere ike ịdị mma iji gbanyụọ ọrụ a. Iji gbanyụọ njirimara data API, wepụ ihe omume niile dị na akwụkwọ aha ya data-apidị ka:

$(document).off('.data-api')

N'aka nke ọzọ, iji kwado ngwa mgbakwunye a kapịrị ọnụ, tinye naanị aha ngwa mgbakwunye dị ka oghere aha yana data-api namespace dị ka nke a:

$(document).off('.alert.data-api')
Na-agbanahụ ndị na-ahọpụta

Ọ bụrụ na ị na-eji ndị nhọpụta pụrụ iche, dịka ọmụmaatụ: collapse:Example, jide n'aka na ị ga-agbanarị ha, n'ihi na a ga-agafe ha na jQuery.

Ihe omume

Bootstrap na-enye mmemme omenala maka ọtụtụ omume pụrụ iche nke plugins. N'ozuzu, ndị a na-abịa n'ụdị njedebe na nke gara aga - ebe njedebe (dịka show) na-akpalite na mmalite nke mmemme, na ụdị nsonye ya gara aga (dịka shown) na-akpalite na mmecha nke omume.

Ihe omume enweghị ngwụcha na-enye preventDefault()ọrụ. Nke a na-enye ikike ịkwụsị mmezu nke ihe tupu ya amalite. Iweghachi ụgha site na onye njikwa mmemme ga-akpọkwa akpaghị aka preventDefault().

$('#myModal').on('show.bs.modal', function (e) {
  if (!data) return e.preventDefault() // stops modal from being shown
})

API mmemme

Anyị kwenyekwara na ị ga-enwe ike iji plugins Bootstrap naanị site na API Javascript. API ọhaneze niile bụ otu, ụzọ enwere ike ịgbanye, wee weghachi mkpokọta emere.

$('.btn.danger').button('toggle').addClass('fat')

Ụzọ niile kwesịrị ịnakwere ihe nhọrọ nhọrọ, eriri nke lekwasịrị anya otu usoro, ma ọ bụ ihe ọ bụla (nke na-amalite ngwa mgbakwunye nwere omume ndabara):

$('#myModal').modal()                      // initialized with defaults
$('#myModal').modal({ keyboard: false })   // initialized with no keyboard
$('#myModal').modal('show')                // initializes and invokes show immediately

Ngwa mgbakwunye ọ bụla na-ekpughekwa ihe nrụpụta akụrụngwa ya na akụrụngwa Constructor: $.fn.popover.Constructor. Ọ bụrụ na ị ga-achọ ịnweta otu ngwa mgbakwunye ihe atụ, weghachite ya ozugbo na mmewere: $('[rel="popover"]').data('popover').

Ọrụ asynchronous na ntụgharị

Ụzọ API mmemme niile enweghị atụ ma laghachikwuru onye na-akpọ oku ozugbo mgbanwe malitere mana tupu ọ akwụsị .

Iji mee ihe ozugbo mgbanwe ahụ gwụchara, ị nwere ike ige ntị na mmemme kwekọrọ.

$('#myCollapse').on('shown.bs.collapse', function (e) {
  // Action to execute once the collapsible area is expanded
})

Na mgbakwunye, a ga-eleghara oku usoro na mpaghara mgbanwe anya .

$('#myCarousel').on('slid.bs.carousel', function (e) {
  $('#myCarousel').carousel('2') // Will slide to the slide 2 as soon as the transition to slide 1 is finished
})

$('#myCarousel').carousel('1') // Will start sliding to the slide 1 and returns to the caller
$('#myCarousel').carousel('2') // !! Will be ignored, as the transition to the slide 1 is not finished !!

Ntọala mbụ

Ị nwere ike ịgbanwe ntọala ndabara maka ngwa mgbakwunye site n'ịgbanwe ihe ngwa mgbakwunye Constructor.Default:

$.fn.modal.Constructor.Default.keyboard = false // changes default for the modal plugin's `keyboard` option to false

Enweghị esemokwu

Mgbe ụfọdụ, ọ dị mkpa iji plugins Bootstrap nwere usoro UI ndị ọzọ. N'ọnọdụ ndị a, ndakọrịta oghere aha nwere ike ime mgbe ụfọdụ. Ọ bụrụ na nke a emee, ị nwere ike ịkpọ .noConflictna ngwa mgbakwunye ịchọrọ iweghachi uru nke.

var bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value
$.fn.bootstrapBtn = bootstrapButton            // give $().bootstrapBtn the Bootstrap functionality

Nọmba ụdị

Enwere ike ịnweta ụdị nke ọ bụla nke Bootstrap's jQuery plugins site na VERSIONakụrụngwa nke ihe nrụpụta ngwa mgbakwunye. Dịka ọmụmaatụ, maka ngwa mgbakwunye ngwa ngwa:

$.fn.tooltip.Constructor.VERSION // => "4.1.3"

Enweghị ndaghachi azụ pụrụ iche mgbe Javascript nwere nkwarụ

Ihe mgbakwunye Bootstrap anaghị ada azụ n'ọmarịcha mgbe Javascript nwere nkwarụ. Ọ bụrụ na ị na-eche banyere ahụmahụ onye ọrụ na nke a, jiri <noscript>kọwaa ọnọdụ ahụ (na otu esi eme ka Javascript dịghachi) nye ndị ọrụ gị, na / ma ọ bụ gbakwunye ọdịda omenala nke gị.

Ụlọ ọba akwụkwọ ndị ọzọ

Bootstrap anaghị akwado ọba akwụkwọ JavaScript nke ndị ọzọ dị ka Prototype ma ọ bụ jQuery UI. N'agbanyeghị .noConflictna ihe omume kpọpụtara aha, enwere ike ịnwe nsogbu ndakọrịta nke ịchọrọ idozi n'onwe gị.

Ul

Faịlụ JavaScript nke Bootstrap niile dabere na util.jsọ ga-etinye ya n'akụkụ faịlụ Javascript ndị ọzọ. Ọ bụrụ na ị na-eji nke achịkọtara (ma ọ bụ miniified) bootstrap.js, ọ dịghị mkpa itinye nke a-ọ dịlarị ebe ahụ.

util.jsgụnyere ọrụ ịba uru yana onye enyemaka bụ isi maka transitionEndmmemme yana emulator mgbanwe CSS. Ndị plugins ndị ọzọ na-eji ya iji lelee nkwado mgbanwe CSS yana ijide mgbanwe nkwudo.