JavaScript
Bweretsani Bootstrap kukhala ndi moyo ndi mapulagini athu osankha a JavaScript omangidwa pa jQuery. Phunzirani za pulogalamu yowonjezera iliyonse, zosankha zathu zamapulogalamu a API, ndi zina zambiri.
Mapulagini amatha kuphatikizidwa payekhapayekha (pogwiritsa ntchito Bootstrap payekha js/dist/*.js
), kapena zonse nthawi imodzi pogwiritsa ntchito bootstrap.js
kapena minified bootstrap.min.js
(musaphatikizepo zonse ziwiri).
Ngati mugwiritsa ntchito bundler (Webpack, Rollup…), mutha kugwiritsa ntchito /js/dist/*.js
mafayilo omwe ali okonzeka ku UMD.
Mapulagini ena ndi zigawo za CSS zimadalira mapulagini ena. Ngati muphatikiza mapulagini payekhapayekha, onetsetsani kuti mwayang'ana zodalira izi mu ma docs. Onaninso kuti mapulagini onse amadalira jQuery (izi zikutanthauza kuti jQuery iyenera kuphatikizidwa pamaso pa mafayilo a pulogalamu yowonjezera). Funsani athupackage.json
kuti muwone mitundu ya jQuery yothandizidwa.
Kutsitsa kwathu, popovers ndi zida zothandizira zimadaliranso Popper.js .
Pafupifupi mapulagini onse a Bootstrap amatha kuyatsidwa ndikukonzedwa kudzera mu HTML yokha ndi ma data (njira yomwe timakonda yogwiritsira ntchito JavaScript). Onetsetsani kuti mungogwiritsa ntchito gulu limodzi la data pachinthu chimodzi (mwachitsanzo, simungathe kuyambitsa chida ndi modal kuchokera pa batani lomwelo.)
Komabe, nthawi zina zingakhale zofunika kuletsa izi. Kuti mulepheretse API ya data, masulani zochitika zonse pachikalatacho chokhala ndi dzina lotere data-api
:
Kapenanso, kuti mulondole pulogalamu yowonjezera, ingophatikizani dzina la plugin ngati malo okhala ndi dzina la data-api monga chonchi:
Zosankha zothawa
Ngati mugwiritsa ntchito osankhidwa apadera, mwachitsanzo: collapse:Example
, onetsetsani kuti mwawathawa, chifukwa adzadutsa mu jQuery.
Bootstrap imapereka zochitika zapadera pazochita zapadera za mapulagini ambiri. Nthawi zambiri, izi zimabwera mu mawonekedwe osamalizidwa komanso am'mbuyomu - pomwe mawu osamalitsa (mwachitsanzo. show
) amayambika kumayambiriro kwa chochitika, ndipo mawonekedwe ake apitalo (mwachitsanzo. shown
) amayambika akamaliza kuchitapo kanthu.
Zochitika zonse zopanda malire zimapereka preventDefault()
magwiridwe antchito. Izi zimapereka kuthekera koyimitsa kuchitapo kanthu kusanayambe. Kubweza zabodza kuchokera kwa woyang'anira zochitika kudzayimbanso preventDefault()
.
Tikukhulupiriranso kuti muyenera kugwiritsa ntchito mapulagini onse a Bootstrap kudzera mu JavaScript API. Ma API onse omwe ali pagulu ndi amodzi, njira zosinthira, ndikubweza zosonkhanitsa zomwe zachitika.
Njira zonse ziyenera kuvomereza chinthu chosankha, chingwe chomwe chimayang'ana njira inayake, kapena palibe (chomwe chimayambitsa pulogalamu yowonjezera yokhala ndi machitidwe osakhazikika):
Pulagi iliyonse imawululanso womanga wake panyumba Constructor
: $.fn.popover.Constructor
. Ngati mukufuna kupeza pulogalamu yowonjezera, itengereni mwachindunji ku chinthu: $('[rel="popover"]').data('popover')
.
Njira zonse zamapulogalamu a API ndizosasinthika ndipo zimabwerera kwa woyimbirayo pomwe kusintha kwayambika koma kusanathe .
Kuti muthe kuchitapo kanthu pakamaliza kusintha, mutha kumvera zomwe zikugwirizana.
Kuphatikiza apo, kuyitana kwa njira pagawo losinthira sikudzanyalanyazidwa .
Mutha kusintha makonda a pulogalamu yowonjezera posintha chinthu cha pulogalamu yowonjezera Constructor.Default
:
Nthawi zina pamafunika kugwiritsa ntchito mapulagini a Bootstrap okhala ndi ma UI ena. Pazifukwa izi, kugunda kwa mayina kumachitika nthawi zina. Izi zikachitika, mutha kuyitanitsa pulogalamu yowonjezera .noConflict
yomwe mukufuna kubwezeretsanso mtengo wake.
Mtundu wa mapulagini aliwonse a Bootstrap a jQuery atha kupezeka kudzera pamtundu VERSION
wa wopanga pulogalamu yowonjezera. Mwachitsanzo, pa tooltip plugin:
Mapulagini a Bootstrap samabwerera m'mbuyo mwachisomo pomwe JavaScript yazimitsidwa. Ngati mumasamala za ogwiritsa ntchito pankhaniyi, gwiritsani ntchito <noscript>
kufotokoza momwe zinthu ziliri (ndi momwe mungayambitsirenso JavaScript) kwa ogwiritsa ntchito anu, ndi/kapena onjezani zolakwika zanu.
malaibulale a chipani chachitatu
Bootstrap sichirikiza malaibulale a JavaScript a chipani chachitatu monga Prototype kapena jQuery UI. Ngakhale .noConflict
ndi zochitika zotchulidwa mayina, pakhoza kukhala zovuta zogwirizana zomwe muyenera kuzikonza nokha.
Mafayilo onse a JavaScript a Bootstrap amadalira util.js
ndipo amayenera kuphatikizidwa pamodzi ndi mafayilo ena a JavaScript. Ngati mukugwiritsa ntchito compiled (kapena minified) bootstrap.js
, palibe chifukwa chophatikizira izi - zili kale.
util.js
zikuphatikizapo ntchito zofunikira ndi zofunika mthandizi kwa transitionEnd
zochitika komanso CSS kusintha emulator. Amagwiritsidwa ntchito ndi mapulagini ena kuti ayang'ane thandizo la kusintha kwa CSS ndikugwira masinthidwe olendewera.