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.
Munthu payekha kapena gulu
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.
Zodalira
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 .
Makhalidwe a data
Pafupifupi mapulagini onse a Bootstrap amatha kuyatsidwa ndikukonzedwa kudzera mu HTML yokha ndi mawonekedwe a 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:
Osankha
Panopa kuti tifufuze zinthu za DOM timagwiritsa ntchito njira zachibadwidwe querySelector
komanso querySelectorAll
pazifukwa zogwirira ntchito, kotero muyenera kugwiritsa ntchito zosankha zovomerezeka . Ngati mumagwiritsa ntchito osankhidwa apadera, mwachitsanzo: collapse:Example
onetsetsani kuti mwawathawa.
Zochitika
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 mwayi woyimitsa kuchita chinthu chisanayambe. Kubweza zabodza kuchokera kwa woyang'anira zochitika kudzayimbanso preventDefault()
.
Programmatic API
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')
.
Asynchronous ntchito ndi kusintha
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 .
Zokonda zofikira
Mutha kusintha makonda a pulogalamu yowonjezera posintha chinthu cha pulogalamu yowonjezera Constructor.Default
:
Palibe mkangano
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.
Nambala za mtundu
Mtundu wa mapulagini aliwonse a Bootstrap a jQuery atha kupezeka kudzera pamtundu VERSION
wa wopanga pulogalamu yowonjezera. Mwachitsanzo, pa tooltip plugin:
Palibe zolakwika zapadera pomwe JavaScript yayimitsidwa
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.
Util
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 chithandizo cha kusintha kwa CSS ndikugwira masinthidwe olendewera.
Sanitizer
Zida ndi Popovers amagwiritsa ntchito sanitizer yathu yopangira kuti ayeretse zosankha zomwe zimavomereza HTML.
Mtengo whiteList
wokhazikika ndi uwu:
Ngati mukufuna kuwonjezera ma values atsopano pazosintha izi whiteList
mutha kuchita izi:
Ngati mukufuna kulambalala sanitizer yathu chifukwa mumakonda kugwiritsa ntchito laibulale yodzipereka, mwachitsanzo DOMpurify , muyenera kuchita izi: