Source

JavaScript

Tisa Bootstrap evuton’wini hi ti-plugin ta hina ta JavaScript leti nga hlawuriwa leti akiweke eka jQuery. Dyondza hi plugin yin’wana na yin’wana, data ya hina na swihlawulekisi swa API ya phurogireme, na swin’wana.

Hi munhu hi xiyexe kumbe leyi hlengeletiweke

Ti-plugin ti nga katsiwa hi toxe (hi ku tirhisa *.jstifayela ta Bootstrap ha yin’we-yin’we), kumbe hinkwato hi nkarhi wun’we hi ku tirhisa bootstrap.jskumbe leti hungutiweke bootstrap.min.js(u nga katsi havumbirhi bya tona).

Swilo leswi titshegeke hi swona

Ti-plugin tin’wana ni swiphemu swa CSS swi titshege hi ti-plugin tin’wana. Loko u katsa ti-plugin hi toxe, tiyisisa leswaku u kambela ku titshega loku eka ti-docs. Nakambe xiya leswaku ti-plugin hinkwato ti titshege hi jQuery (leswi swi vula leswaku jQuery yi fanele ku katsiwa emahlweni ka tifayela ta ti-plugin). Vulavula na hinapackage.json ku vona leswaku hi tihi tivhidiyo ta jQuery leti seketeriwaka.

Ti dropdowns ta hina, ti popovers na ti toltips na swona swi titshege hi Popper.js .

Swihlawulekisi swa datha

Kwalomu ka ti-plugin hinkwato ta Bootstrap ti nga tirhisiwa no lulamisiwa hi ku tirhisa HTML ntsena hi swihlawulekisi swa data (ndlela ya hina leyi hi yi tsakelaka yo tirhisa ntirho wa JavaScript). Tiyisisa leswaku u tirhisa ntsena sete yin’we ya swihlawulekisi swa datha eka elemente yin’we (xikombiso, a wu nge pfuli xitsundzuxo xa xitirhisiwa na modal ku suka eka buti yin’we.)

Hambiswiritano, eka swiyimo swin’wana swi nga ha tsakeriwa ku tshikisa ntirho lowu. Ku tshikisa API ya xihlawulekisi xa data, susa swiendlakalo hinkwaswo eka tsalwa ra namespaced hi data-apiku fana na sweswo:

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

Handle ka sweswo, ku kongomisa eka xiengetelo xo karhi, katsa ntsena vito ra xiengetelo tanihi ndhawu ya mavito swin’we ni ndhawu ya mavito ya data-api yo fana ni leyi:

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

Swiendlakalo

Bootstrap yi nyika swiendlakalo swa ntolovelo eka swiendlo swo hlawuleka swa ti-plugin to tala. Hi ntolovelo, leswi swi ta hi xivumbeko xa xiendliwa lexi nga heriki na xiendliwa lexi hundzeke - laha xiendliwa lexi nga heriki (ex. show) xi pfuriwaka eku sunguleni ka xiendlakalo, naswona xivumbeko xa xona xa xiendliwa lexi hundzeke (ex. shown) xi pfuriwa loko xiendlo xi hetisisiwa.

Swiendlakalo hinkwaswo leswi nga heriki swi nyika preventDefault()ntirho. Leswi swi nyika vuswikoti byo yimisa ku hetisisiwa ka xiendlo xi nga si sungula. Ku vuyisa mavunwa ku suka eka mufambisi wa xiendlakalo na swona swi ta vitana hi ku tisungulela preventDefault().

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

API ya minongonoko

Hi tlhela hi tshemba leswaku u fanele ku kota ku tirhisa ti-plugin hinkwato ta Bootstrap ntsena hi ku tirhisa JavaScript API. Ti-API hinkwato ta mani na mani i tindlela tin’we, leti nga ni tinketana, naswona ti vuyisa nhlengeleto lowu endliweke hi wona.

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

Maendlelo hinkwawo ya fanele ku amukela nchumu wa swihlawulekisi swa ku hlawula, ntambhu leyi kongomisaka eka ndlela yo karhi, kumbe ku nga ri na nchumu (leyi sungulaka xiengetelo hi mahanyelo ya xiviri):

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

Plugin yin’wana na yin’wana yi tlhela yi paluxa muaki wa yona wa raw eka Constructornhundzu: $.fn.popover.Constructor. Loko u lava ku kuma xikombiso xo karhi xa plugin, xi vuyise hi ku kongoma eka elemente: $('[rel="popover"]').data('popover').

Mintirho ya asynchronous na ku cinca

Maendlelo hinkwawo ya API ya phurogireme i ya asynchronous naswona ya tlhelela eka mufoyini loko ku cinca ku sungurile kambe ku nga si hela .

Leswaku u endla xiendlo loko ku cinca ku herile, u nga yingisela xiendlakalo lexi fambisanaka na xona.

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

Ku engetela kwalaho ku vitaniwa ka ndlela eka xiphemu lexi cincaka ku ta honisiwa .

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

Switirhisiwa swa ntolovelo

U nga cinca swiletelo swa xiviri swa xiengetelo hi ku cinca Constructor.Defaultnchumu wa xiengetelo:

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

Ku hava ku lwisana

Minkarhi yin’wana swa laveka ku tirhisa ti-plugin ta Bootstrap ni swivumbeko swin’wana swa UI. Eka swiyimo leswi, ku tlumbana ka ndhawu ya mavito ku nga humelela nkarhi wun’wana. Loko leswi swi humelela, u nga ha vitana .noConflicteka plugin leyi u lavaka ku tlherisela nkoka wa yona.

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

Tinomboro ta vuhundzuluxeri

Vuhundzuluxi bya yin’wana na yin’wana ya ti-plugin ta jQuery ta Bootstrap byi nga nghenisiwa hi ku tirhisa VERSIONnhundzu ya muaki wa xiengetelo. Xikombiso, eka xiengetelo xa xitsundzuxo xa switirhisiwa:

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

Ku hava ti fallback to hlawuleka loko JavaScript yi nga tirhi

Ti-plugin ta Bootstrap a ti tlheleli endzhaku hi ndlela yo hlawuleka loko JavaScript yi nga tirhi. Loko u khathala hi ntokoto wa mutirhisi eka mhaka leyi, tirhisa <noscript>ku hlamusela xiyimo (na ndlela yo tlhela u pfumelela JavaScript) eka vatirhisi va wena, na/kumbe ku engetela ti-fallback ta wena ta ntolovelo.

Tilayiburari ta vanhu va vunharhu

Bootstrap a yi seketeli ximfumo tilayiburari ta JavaScript ta vanhu van’wana to fana na Prototype kumbe jQuery UI. Ku nga khathariseki .noConflictswiendlakalo leswi nga ni swiphemu swa mavito, ku nga ha va ni swiphiqo swa ku fambisana leswi u faneleke u swi lulamisa hi wexe.

Util

Tifayili hinkwato ta JavaScript ta Bootstrap ti titshege hi util.jsnaswona ti fanele ku katsiwa etlhelo ka tifayela tin’wana ta JavaScript. Loko u tirhisa leyi hlengeletiweke (kumbe leyi hungutiweke) bootstrap.js, a ku na xilaveko xo katsa leswi—se swi kona.

util.jsku katsa mintirho ya vukorhokeri na mupfuni wa xisekelo wa transitionEndswiendlakalo xikan’we na xifaniso xa ku cinca ka CSS. Yi tirhisiwa hi ti-plugin tin’wana ku kambela nseketelo wa ku cinca ka CSS ni ku khoma ku cinca loku lenga-lengaka.