JavaScript hmangin a rawn lang ang
jQuery-a siam kan optional JavaScript plugins hmangin Bootstrap chu nunna pe rawh. Plugin tin chungchang te, kan data leh programmatic API option te leh thil dang tam tak zir rawh.
Mimal emaw, khawlkhawm emaw a ni thei
Plugins chu pakhat zel hmangin (Bootstrap’s individual hmangin js/dist/*.js
), a nih loh leh vawi khatah hmang vek bootstrap.js
emaw, minified emaw hmangin bootstrap.min.js
(a pahnih hian telh loh tur) te pawh a tel thei bawk.
Bundler (Webpack, Rollup...) i hman chuan /js/dist/*.js
UMD ready file i hmang thei bawk.
Innghahna te
Plugin leh CSS component thenkhat chu plugin dang a innghat a ni. Plugin te chu pakhat zel i dah tel a nih chuan docs ah hian heng dependencies te hi check ngei ngei tur a ni. Tin, plugin zawng zawng hi jQuery ah an innghat tih hre bawk ang che (hei hian plugin files hmain jQuery hi a tel tur a ni tihna a ni). jQuery version eng ber nge support tih hriat duh chuan our hi zawt rawh .package.json
Kan dropdowns, popovers leh tooltips te pawh Popper.js ah a innghat bawk .
Data attribute te hi a ni
Bootstrap plugin zawng zawng deuhthaw hi HTML hmang chauhvin data attribute (JavaScript functionality hman dan kan duh ber) hmangin enable leh configure theih a ni. Element pakhatah data attribute set khat chauh hmang ngei ang che (eg, button pakhat atang hian tooltip leh modal i trigger thei lo.)
Mahse, dinhmun thenkhatah chuan he functionality hi tihtawp hi duhthusam a ni thei. Data attribute API disable tur chuan document namespace-a event awm zawng zawng chu hetiang hian unbind vek data-api
ang che:
$(document).off('.data-api')
A dang pawhin, plugin bik target tur chuan plugin hming chu namespace atan data-api namespace nen hetiang hian dah mai rawh:
$(document).off('.alert.data-api')
Selector te pawh a awm
Tunah hian DOM elements zawhna tur chuan native methods kan hmang a querySelector
, querySelectorAll
performance vangin, chuvangin valid selectors hman a ngai a ni . Special selector i hman chuan, entirnan: collapse:Example
tlanbosan ngei ang che.
Thil thlengte
Bootstrap hian plugin tam zawkte thiltih danglam bik atan custom event a pe a. A tlangpuiin, hengte hi infinitive leh past participle form-ah an lo kal a - chutah chuan show
thilthleng pakhat tan tirh lamah infinitive (ex. ) chu a insiam a, a past participle form (ex. shown
) chu thiltih zawh hunah a insiam a ni.
Infinitive event zawng zawng hian preventDefault()
functionality an pe vek a. Hei hian action pakhat execution chu a tan hmaa tihtawp theihna a pe a ni. Event handler atanga false rawn thawn let pawhin automatic in a call ang preventDefault()
.
$('#myModal').on('show.bs.modal', function (event) {
if (!data) {
return event.preventDefault() // stops modal from being shown
}
})
Programmatic API hmanga siam a ni
Tin, Bootstrap plugin zawng zawng hi JavaScript API hmang chauhvin i hmang thei tur a ni tih kan ring bawk. Public API zawng zawng hi single, chainable method a ni a, collection acted on chu a rawn pe kir vek a ni.
$('.btn.danger').button('toggle').addClass('fat')
Method zawng zawng hian optional options object, method bik target tu string emaw, engmah (default behavior hmanga plugin initiate tu) emaw an pawm tur a ni:
$('#myModal').modal() // initialized with defaults
$('#myModal').modal({ keyboard: false }) // initialized with no keyboard
$('#myModal').modal('show') // initializes and invokes show immediately
Plugin tin hian an raw constructor chu Constructor
property pakhatah an expose bawk: $.fn.popover.Constructor
. Plugin instance bik i hmuh duh chuan element atanga direct-in la chhuak rawh: $('[rel="popover"]').data('popover')
.
Asynchronous function leh inthlak danglamna te
Programmatic API method zawng zawng hi asynchronous a ni a , transition tan a nih veleh a tawp hmain caller hnenah a kir leh thin .
Transition zawh veleh action execute tur chuan a inmil event chu i ngaithla thei ang.
$('#myCollapse').on('shown.bs.collapse', function (event) {
// Action to execute once the collapsible area is expanded
})
Chu bakah transitioning component a method call chu ngaihthah a ni ang .
$('#myCarousel').on('slid.bs.carousel', function (event) {
$('#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 hmasa ber a ni
Plugin pakhat tana default settings chu plugin Constructor.Default
object chu siam danglamin i thlak thei ang:
// changes default for the modal plugin's `keyboard` option to false
$.fn.modal.Constructor.Default.keyboard = false
Inhnialna a awm lo
A chang chuan Bootstrap plugins te hi UI framework dang nen hman a ngai thin. Hetiang dinhmunah hian namespace collision a awm fo thin. Chutiang a nih chuan i .noConflict
value revert duh plugin chu i call thei ang.
var bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value
$.fn.bootstrapBtn = bootstrapButton // give $().bootstrapBtn the Bootstrap functionality
Version number te pawh a awm
Bootstrap-a jQuery plugin pakhat zel version chu VERSION
plugin constructor property hmangin a lut thei a ni. Entirnan, tooltip plugin atan chuan:
$.fn.tooltip.Constructor.VERSION // => "4.6.2"
JavaScript tihtawp a nih chuan special fallback a awm lo
Bootstrap-a plugins te hi JavaScript tihtawp a nih chuan a bik takin grace takin an tla leh lo. Hetiang a nih avang hian user experience i ngaih pawimawh a nih chuan, i user-te <noscript>
hnena thil awmdan (leh JavaScript re-enable dan tur) hrilhfiah nan hmang la, leh/ emaw, nangmah ngeiin i custom fallback te pawh add rawh.
Third-party library te pawh a awm bawk
Bootstrap hian official takin third-party JavaScript library Prototype emaw jQuery UI ang chi a support lo. Despite .noConflict
leh namespaced events, compatibility problem a awm thei a, chu chu nangmah ngeiin i siam that a ngai a ni.
Util
Bootstrap-a JavaScript file zawng zawng hi a innghat a, util.js
JavaScript file dangte nen a dah tel a ngai bawk. Compiled (or minified) i hmang a nih chuan bootstrap.js
hei hi dah tel a ngai lo—a awm tawh.
util.js
utility function leh transitionEnd
event hrang hrang atana basic helper bakah CSS transition emulator a awm bawk. Plugin dangte chuan CSS transition support a awm leh awm loh enfiah nan leh hanging transition man nan an hmang thin.
Sanitizer hman a ni
Tooltips leh Popovers te hian kan built-in sanitizer hmangin HTML pawmtu option te chu sanitize turin an hmang thin.
Default whiteList
value chu a hnuaia mi ang hian a ni:
var ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i
var DefaultWhitelist = {
// Global attributes allowed on any supplied element below.
'*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN],
a: ['target', 'href', 'title', 'rel'],
area: [],
b: [],
br: [],
col: [],
code: [],
div: [],
em: [],
hr: [],
h1: [],
h2: [],
h3: [],
h4: [],
h5: [],
h6: [],
i: [],
img: ['src', 'srcset', 'alt', 'title', 'width', 'height'],
li: [],
ol: [],
p: [],
pre: [],
s: [],
small: [],
span: [],
sub: [],
sup: [],
strong: [],
u: [],
ul: []
}
He default ah hian value thar i dah duh chuan whiteList
a hnuaia mi ang hian i ti thei ang:
var myDefaultWhiteList = $.fn.tooltip.Constructor.Default.whiteList
// To allow table elements
myDefaultWhiteList.table = []
// To allow td elements and data-option attributes on td elements
myDefaultWhiteList.td = ['data-option']
// You can push your custom regex to validate your attributes.
// Be careful about your regular expressions being too lax
var myCustomRegex = /^data-my-app-[\w-]+/
myDefaultWhiteList['*'].push(myCustomRegex)
Library bik hman i duh avangin kan sanitizer hi bypass i duh a nih chuan, entirnan DOMPurify , a hnuaia mi ang hian i ti tur a ni:
$('#yourTooltip').tooltip({
sanitizeFn: function (content) {
return DOMPurify.sanitize(content)
}
})