Source

Javascript

Aumai Bootstrap i le ola ma a matou filifiliga JavaScript plugins fausia i luga o le jQuery. A'oa'o e uiga i mea fa'apipi'i ta'itasi, a matou fa'amaumauga ma polokalame API filifiliga, ma isi mea.

Ta'ito'atasi pe tuufaatasia

E mafai ona fa'apipi'i fa'apipi'i ta'ito'atasi (fa'aaogā le tagata ta'ito'atasi a Bootstrap js/dist/*.js), po'o fa'aaoga uma i le taimi e tasi bootstrap.jspo'o le fa'aitiitiga bootstrap.min.js(aua le aofia uma).

Afai e te faʻaogaina se fusi (Webpack, Rollup…), e mafai ona e faʻaogaina /js/dist/*.jsfaila ua saunia UMD.

Fa'alagolago

O nisi fa'apipi'i ma vaega CSS fa'alagolago i isi fa'apipi'i. Afai e te faʻapipiʻi faʻapipiʻi taʻitasi, ia mautinoa e siaki mo nei faʻalagolago i le docs. Ia maitauina foi o plugini uma e faalagolago i le jQuery (o lona uiga e tatau ona aofia ai le jQuery i luma o faila faila). Fa'afeso'ota'i matoupackage.json e va'ai po'o fea fa'aliliuga o le jQuery e lagolagoina.

E fa'alagolago fo'i a matou pa'u, popovers ma meafaigaluega i Popper.js .

Uiga fa'amaumauga

Toeitiiti lava o Bootstrap plugins e mafai ona faʻaogaina ma faʻapipiʻi e ala ile HTML naʻo faʻatasi ai ma faʻamatalaga uiga (o la tatou auala sili e faʻaogaina ai le JavaScript). Ia mautinoa e naʻo le tasi le seti o faʻamatalaga uiga i luga o se elemene e tasi (faʻataʻitaʻiga, e le mafai ona e faʻaosoina se meafaigaluega ma auala mai le ki lava e tasi.)

Ae ui i lea, i nisi tulaga atonu e manaʻomia le tapeina o lenei gaioiga. Ina ia fa'agata le API fa'amaumauga, tatala uma mea na tutupu i luga o le pepa fa'ailoga igoa data-apifa'apea:

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

I le isi itu, e faʻatatau i se mea faʻapipiʻi faʻapitoa, naʻo le faʻapipiʻiina o le igoa ole plugin o se igoa avanoa faʻatasi ai ma le data-api namespace pei o lenei:

$(document).off('.alert.data-api')
Sola ese tagata filifilia

Afai e te faʻaogaina tagata filifilia faʻapitoa, mo se faʻataʻitaʻiga: collapse:Example, ia mautinoa e sola ese mai i latou, aua o le a latou pasia i le jQuery.

Mea na tutupu

O le Bootstrap e tuʻuina atu mea faʻapitoa mo le tele o mea faʻapitoa a plugins. E masani lava, o nei mea e sau i se fa'ailoga fa'apitoa ma le taimi ua tuana'i - lea e fa'aosoina ai le infinitive (ex. show) i le amataga o se mea na tupu, ma lona fa'ailoga participle ua mavae (ex. shown) e fa'aosoina pe a mae'a se gaioiga.

O mea fa'apitoa uma e maua ai preventDefault()galuega fa'atino. O lenei mea e maua ai le malosi e taofi ai le faʻatinoina o se gaioiga aʻo leʻi amataina. O le toe fa'afo'i sese mai se tagata e fa'atino mea na tupu e otometi fo'i ona vala'au preventDefault().

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

API polokalame

Matou te talitonu foi e tatau ona e faʻaogaina uma Bootstrap plugins mama e ala i le JavaScript API. O API fa'alaua'itele uma e tasi, auala e mafai ona filifili, ma toe fa'afo'i le aoina na fa'atino.

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

O metotia uma e tatau ona talia se mea e filifili ai filifiliga, se manoa e faʻatatau i se metotia faʻapitoa, poʻo leai se mea (lea e amataina ai se faʻapipiʻi ma amioga le lelei):

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

E fa'aalia fo'i e fa'apipi'i ta'itasi lona faufale mata'utia i luga o se Constructormeatotino: $.fn.popover.Constructor. Afai e te manaʻo e maua se faʻataʻitaʻiga faʻapitoa faʻapipiʻi, aumai saʻo mai se elemene: $('[rel="popover"]').data('popover').

Gaioiga asynchronous ma suiga

O metotia API fa'apolokalame uma e le fa'atasi ma toe fo'i i le tagata vala'au pe a amata le suiga ae le'i uma .

Ina ia mafai ona faʻatino se gaioiga pe a maeʻa le suiga, e mafai ona e faʻalogo i le mea na tupu.

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

E le gata i lea, o le a le amana'ia se auala e valaau ai i se vaega o suiga .

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

Fa'atonuga

E mafai ona e suia tulaga fa'aletonu mo se fa'apipi'i e ala i le suia o le Constructor.Defaultmea fa'apipi'i:

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

Leai se feteenaiga

O nisi taimi e manaʻomia le faʻaogaina o Bootstrap plugins ma isi faʻavae UI. I ia tulaga, e mafai ona tupu i nisi taimi le fete'ena'iga o igoa. Afai e tupu lenei mea, e mafai ona e valaʻau .noConflicti le plugin e te manaʻo e toe faʻafoʻi le tau o.

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

Numera fa'aliliuga

E mafai ona maua le fa'asologa o mea ta'itasi a Bootstrap's jQuery plugins e ala i le VERSIONmeatotino a le faufale o le plugin. Mo se faʻataʻitaʻiga, mo le meafaigaluega faʻapipiʻi:

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

Leai ni fa'aletonu fa'apitoa pe a fa'aletonu le JavaScript

O plugini a Bootstrap e le toe fo'i fa'apitoa pe a fa'aletonu le JavaScript. Afai e te popole e uiga i le tagata faʻaoga i lenei tulaga, faʻaaoga <noscript>e faʻamatala ai le tulaga (ma pe faʻafefea ona toe faʻaogaina le JavaScript) i au tagata faʻaoga, ma / pe faʻaopoopo au lava faʻaleaga masani.

Faletusi a isi vaega

E le lagolagoina aloaia e Bootstrap faletusi JavaScript isi vaega e pei o le Prototype poʻo le jQuery UI. E ui lava .noConflictma fa'aigoa mea tutupu, e ono iai fa'afitauli feso'ota'iga e mana'omia ona e fa'aleleia e oe lava.

Util

O faila JavaScript uma a Bootstrap e faʻalagolago i util.jsai ma e tatau ona aofia ai faʻatasi ma isi faila JavaScript. Afai o loʻo e faʻaaogaina le tuʻufaʻatasia (poʻo le faʻaititia) bootstrap.js, e leai se manaʻoga e aofia ai lenei mea-ua uma ona iai.

util.jse aofia ai galuega aoga ma se fesoasoani autu mo transitionEndmea e tutupu faʻapea foʻi ma le CSS transition emulator. O lo'o fa'aogaina e isi fa'apipi'i e siaki ai le lagolago mo suiga o le CSS ma pu'e fa'aoga fa'atautau.