Source

JavaScript ye

Aw ye Bootstrap lase ɲɛnamaya ma ni an ka JavaScript sɛgɛsɛgɛlikɛlanw ye minnu bɛ se ka sugandi minnu jɔlen bɛ jQuery kan. Aw ye kunnafoni sɔrɔ plugin kelen-kelen bɛɛ kan, an ka data ani porogaramu API suganditaw kan, ani fɛn wɛrɛw.

Mɔgɔ kelen-kelen walima a lajɛlen

Plugins bɛ se ka don u kelen-kelen na (ka baara kɛ ni Bootstrap ka kelen-kelen ye js/dist/*.js), walima u bɛɛ bɛ se ka don a kɔnɔ siɲɛ kelen ka baara kɛ ni bootstrap.jswalima ka dɔgɔya bootstrap.min.js(i kana u fila bɛɛ don a kɔnɔ).

N’i ​​bɛ baara Kɛ ni bundler (Webpack, Rollup...) ye, i bɛ Se ka baara Kɛ ni /js/dist/*.jsfilew ye minnu labɛnnen dòn UMD fɛ.

Dependencies (Jɛkuluw).

Plugin dɔw ni CSS yɔrɔ dɔw bɛ bɔ plugins wɛrɛw de la. N’i ​​ye plugins (dakunw) Dòn u kelen-kelen na, i k’a lajɛ k’o dependencies (daɲɛw) ninnu Lajɛ docs (dɔgɔkun) kɔnɔ. Aw k’a kɔlɔsi fana ko plugins bɛɛ bɛ tali kɛ jQuery de la (o kɔrɔ ye ko jQuery ka kan ka don a kɔnɔ ka kɔn plugin files ɲɛ). Aw ye anw lajɛpackage.json walasa k’a dɔn jQuery bɔko minnu bɛ dɛmɛ.

An ka dropdowns, popovers ani baarakɛminɛnw fana bɛ bɔ Popper.js de la.

Donanw ka fɛnw

Bootstrap 'kɔnɔfɛnw bɛɛ bɛ Se ka Dabɔ ani k'u Labɛn HTML dɔrɔn fɛ ni data attributes (an ka JavaScript baarakɛcogo ɲuman ye). Aw ye aw jija ka baara kɛ ni kunnafoni-falen-falen-yɔrɔ kelen dɔrɔn ye fɛn kelen kan (misali la, aw tɛ se ka baarakɛminɛnw ni modɛli dɔ daminɛ ka bɔ butɔni kelen na.)

Nka, ko dɔw la, a bɛ se ka kɛ ko a ka ɲi ka nin baarakɛcogo in bali. Walasa ka data attribut API bali, i ka ko kɛlenw bɛɛ bɔ sɛbɛn tɔgɔla yɔrɔ la ni data-apii n’a fɔ nin cogo la:

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

O cogo kelen na, walasa ka fɛn kɛrɛnkɛrɛnnen dɔ Laɲini, i ka fɛn in tɔgɔ Dòn dɔrɔn i n’a fɔ tɔgɔda-yɔrɔ ka Fàra data-api tɔgɔda-yɔrɔ kan i n’a fɔ nin:

$(document).off('.alert.data-api')
Sugandilikɛlaw minnu bɛ boli

N’i ​​bɛ baara Kɛ ni sugandili kɛrɛnkɛrɛnnenw ye, misali la: collapse:Example, i jija ka Bɔ u la, bawo u bɛna Tɛmɛ jQuery fɛ.

Ko minnu kɛra

Bootstrap bɛ ko kɛlenw di minnu bɛ kɛ ka kɛɲɛ ni mɔgɔw sago ye, ka ɲɛsin plugins fanba ka wale kɛrɛnkɛrɛnnenw ma. A ka c’a la, ninnu bɛ Nà daɲɛ-dafalen ni daɲɛ tɛmɛnen cogo la - daɲɛ-dafalen (ex. show) bɛ Daminɛ yɔrɔ min na ko dɔ daminɛ na, wa a daɲɛ tɛmɛnen cogoya (ex. shown) bɛ Daminɛ wale dɔ dafalen na.

Ko minnu tɛ dantigɛ, olu bɛɛ bɛ preventDefault()baarakɛcogo Di. O bɛ se di ka wale dɔ waleyali jɔ sani a ka daminɛ. nkalon seginni ka bɔ ko kɛlenw ɲɛnabɔbaga dɔ la , o fana bɛna wele a yɛrɛma preventDefault().

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

API porogaramulen

An dalen b’a la fana ko i ka kan ka se ka baara kɛ ni Bootstrap plugins bɛɛ ye JavaScript API dɔrɔn fɛ. Foroba APIw bɛɛ ye fɛɛrɛ kelenw ye, minnu bɛ se ka siri ni cakɛda ye, ani ka segin dalajɛlen kan min waleyara.

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

Fɛɛrɛ bɛɛ ka kan ka sɔn sugandili fɛn dɔ ma, sɛrɛ min bɛ fɛɛrɛ kɛrɛnkɛrɛnnen dɔ laɲini, walima foyi tɛ (min bɛ fɛn dɔ daminɛ ni kɛcogo kɔrɔ ye):

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

Plugin kelen-kelen bɛɛ fana b’a ka raw constructor jira Constructornafolo dɔ kan: $.fn.popover.Constructor. N’i ​​b’a fɛ ka plugin instance kɛrɛnkɛrɛnnen dɔ sɔrɔ, i k’a sɔrɔ k’a ɲɛsin element dɔ ma: $('[rel="popover"]').data('popover').

Baarakɛcogo minnu tɛ kelen ye ani fɛn caman tigɛli

porogaramu API fɛɛrɛw bɛɛ ye asynchrone ye wa u bɛ segin welebaga ma ni wuli daminɛna nka sanni a ka ban .

Walasa ka wale dɔ Kɛ ni 'tɛmɛsira Banna, i bɛ Se ka ko kɛlen min bɛ Bɛn o ma, i bɛ Se k'o Lamɛ.

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

ka fara o kan , fɛɛrɛ weleli dɔ bɛna kɛ fɛn ye min bɛ wuli ka bɔ a nɔ na .

$('#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 !!

Settings (Labɛnw) minnu bɛ daminɛ

Aw bɛ se ka fɛn dɔ labɛncogo kɔrɔw Changer ni aw ye fɛn dɔ sɛmɛntiya Constructor.Default:

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

Kɛlɛ si tɛ yen

Tuma dɔw la, a ka kan ka baara kɛ ni Bootstrap plugins ye ni UI framework wɛrɛw ye. O cogoyaw la, tɔgɔda-yɔrɔ-ko bɛ Se ka Kɛ tuma dɔw la. N'o Kɛra, i .noConflictb'a fɛ ka plugin min nafa Lasegin, i bɛ Se k'o Weele.

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

Version nimɔrɔw

Bootstrap ka jQuery 'kɔnɔfɛn kelen-kelen bɛɛ 'sèn bɛ Se ka Sɔrɔ 'sènfɛ-sɛbɛnni-minɛn in 'kɔnɔ 'fɛn fɛ VERSION. Misali la, baarakɛminɛnw ɲɛfɔli dakun na:

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

Fallback kɛrɛnkɛrɛnnen si tɛ yen ni JavaScript ma baara kɛ

Bootstrap ka plugins tɛ bin kɔfɛ kɛrɛnkɛrɛnnenya la gracefully ni JavaScript bɛ baara la. N’i ​​b’i janto baarakɛlaw ka ko kɛlenw na nin ko in na, i ka baara kɛ ni <noscript>u ye walasa ka ko in ɲɛfɔ (ani JavaScript daminɛcogo kura) i ka baarakɛlaw ye, ani/walima ka i yɛrɛ ka ladamu fallbacks fara a kan.

Mɔgɔ sabananw ka gafemarayɔrɔw

Bootstrap tɛ JavaScript gafemarayɔrɔ wɛrɛw dɛmɛ foroba la i n’a fɔ Prototype walima jQuery UI. Hali .noConflictni ni tɔgɔda-ko kɛlenw bɛ yen, bɛnkan gɛlɛyaw bɛ se ka sɔrɔ minnu ka kan ka ɲɛnabɔ i yɛrɛ ma.

Util

Bootstrap ka JavaScript filew bɛɛ bɛ Bɔ a la util.jswa a ka kan ka Dòn JavaScript file tɔw kɛrɛfɛ. N’i ​​bɛ baara Kɛ ni compiled (walima minified) bootstrap.jsye , kun t’a la k’o Dòn a la—a bɛ yen kaban.

util.jsnafalanw baarakɛcogo ani dɛmɛn jɔnjɔn dɔ bɛ sɔrɔ transitionEndko kɛlenw na ka fara CSS wulicogo misali kan. A bɛ Kɛ ni 'plugin tɔw ye walasa ka CSS 'tɛmɛsira dɛmɛni Lajɛ ani ka 'tɛmɛsira jɛgɛlenw Minɛ.