weui.min.js 180 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975
  1. /*!
  2. * weui.js v1.2.1 (https://weui.io)
  3. * Copyright 2019, wechat ui team
  4. * MIT license
  5. */
  6. (function webpackUniversalModuleDefinition(root, factory) {
  7. if(typeof exports === 'object' && typeof module === 'object')
  8. module.exports = factory();
  9. else if(typeof define === 'function' && define.amd)
  10. define([], factory);
  11. else if(typeof exports === 'object')
  12. exports["weui"] = factory();
  13. else
  14. root["weui"] = factory();
  15. })(this, function() {
  16. return /******/ (function(modules) { // webpackBootstrap
  17. /******/ // The module cache
  18. /******/ var installedModules = {};
  19. /******/ // The require function
  20. /******/ function __webpack_require__(moduleId) {
  21. /******/ // Check if module is in cache
  22. /******/ if(installedModules[moduleId])
  23. /******/ return installedModules[moduleId].exports;
  24. /******/ // Create a new module (and put it into the cache)
  25. /******/ var module = installedModules[moduleId] = {
  26. /******/ exports: {},
  27. /******/ id: moduleId,
  28. /******/ loaded: false
  29. /******/ };
  30. /******/ // Execute the module function
  31. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  32. /******/ // Flag the module as loaded
  33. /******/ module.loaded = true;
  34. /******/ // Return the exports of the module
  35. /******/ return module.exports;
  36. /******/ }
  37. /******/ // expose the modules object (__webpack_modules__)
  38. /******/ __webpack_require__.m = modules;
  39. /******/ // expose the module cache
  40. /******/ __webpack_require__.c = installedModules;
  41. /******/ // __webpack_public_path__
  42. /******/ __webpack_require__.p = "";
  43. /******/ // Load entry module and return exports
  44. /******/ return __webpack_require__(0);
  45. /******/ })
  46. /************************************************************************/
  47. /******/ ([
  48. /* 0 */
  49. /***/ (function(module, exports, __webpack_require__) {
  50. 'use strict';
  51. Object.defineProperty(exports, "__esModule", {
  52. value: true
  53. });
  54. var _dialog = __webpack_require__(1);
  55. var _dialog2 = _interopRequireDefault(_dialog);
  56. var _alert = __webpack_require__(7);
  57. var _alert2 = _interopRequireDefault(_alert);
  58. var _confirm = __webpack_require__(8);
  59. var _confirm2 = _interopRequireDefault(_confirm);
  60. var _toast = __webpack_require__(9);
  61. var _toast2 = _interopRequireDefault(_toast);
  62. var _loading = __webpack_require__(11);
  63. var _loading2 = _interopRequireDefault(_loading);
  64. var _actionSheet = __webpack_require__(13);
  65. var _actionSheet2 = _interopRequireDefault(_actionSheet);
  66. var _topTips = __webpack_require__(15);
  67. var _topTips2 = _interopRequireDefault(_topTips);
  68. var _searchBar = __webpack_require__(17);
  69. var _searchBar2 = _interopRequireDefault(_searchBar);
  70. var _tab = __webpack_require__(18);
  71. var _tab2 = _interopRequireDefault(_tab);
  72. var _form = __webpack_require__(19);
  73. var _form2 = _interopRequireDefault(_form);
  74. var _uploader = __webpack_require__(20);
  75. var _uploader2 = _interopRequireDefault(_uploader);
  76. var _picker = __webpack_require__(24);
  77. var _gallery = __webpack_require__(30);
  78. var _gallery2 = _interopRequireDefault(_gallery);
  79. var _slider = __webpack_require__(32);
  80. var _slider2 = _interopRequireDefault(_slider);
  81. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  82. /*
  83. * Tencent is pleased to support the open source community by making WeUI.js available.
  84. *
  85. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  86. *
  87. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  88. * with the License. You may obtain a copy of the License at
  89. *
  90. * http://opensource.org/licenses/MIT
  91. *
  92. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  93. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  94. * either express or implied. See the License for the specific language governing permissions and
  95. * limitations under the License.
  96. */
  97. exports.default = {
  98. dialog: _dialog2.default,
  99. alert: _alert2.default,
  100. confirm: _confirm2.default,
  101. toast: _toast2.default,
  102. loading: _loading2.default,
  103. actionSheet: _actionSheet2.default,
  104. topTips: _topTips2.default,
  105. searchBar: _searchBar2.default,
  106. tab: _tab2.default,
  107. form: _form2.default,
  108. uploader: _uploader2.default,
  109. picker: _picker.picker,
  110. datePicker: _picker.datePicker,
  111. gallery: _gallery2.default,
  112. slider: _slider2.default
  113. };
  114. module.exports = exports['default'];
  115. /***/ }),
  116. /* 1 */
  117. /***/ (function(module, exports, __webpack_require__) {
  118. 'use strict';
  119. Object.defineProperty(exports, "__esModule", {
  120. value: true
  121. });
  122. var _util = __webpack_require__(2);
  123. var _util2 = _interopRequireDefault(_util);
  124. var _dialog = __webpack_require__(6);
  125. var _dialog2 = _interopRequireDefault(_dialog);
  126. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  127. /*
  128. * Tencent is pleased to support the open source community by making WeUI.js available.
  129. *
  130. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  131. *
  132. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  133. * with the License. You may obtain a copy of the License at
  134. *
  135. * http://opensource.org/licenses/MIT
  136. *
  137. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  138. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  139. * either express or implied. See the License for the specific language governing permissions and
  140. * limitations under the License.
  141. */
  142. var _sington = void 0;
  143. /**
  144. * dialog,弹窗,alert和confirm的父类
  145. *
  146. * @param {object=} options 配置项
  147. * @param {string=} options.title 弹窗的标题
  148. * @param {string=} options.content 弹窗的内容
  149. * @param {string=} options.className 弹窗的自定义类名
  150. * @param {array=} options.buttons 按钮配置项
  151. *
  152. * @param {string} [options.buttons[].label=确定] 按钮的文字
  153. * @param {string} [options.buttons[].type=primary] 按钮的类型 [primary, default]
  154. * @param {function} [options.buttons[].onClick=$.noop] 按钮的回调
  155. *
  156. * @example
  157. * weui.dialog({
  158. * title: 'dialog标题',
  159. * content: 'dialog内容',
  160. * className: 'custom-classname',
  161. * buttons: [{
  162. * label: '取消',
  163. * type: 'default',
  164. * onClick: function () { alert('取消') }
  165. * }, {
  166. * label: '确定',
  167. * type: 'primary',
  168. * onClick: function () { alert('确定') }
  169. * }]
  170. * });
  171. *
  172. * // 主动关闭
  173. * var $dialog = weui.dialog({...});
  174. * $dialog.hide(function(){
  175. * console.log('`dialog` has been hidden');
  176. * });
  177. */
  178. function dialog() {
  179. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  180. if (_sington) return _sington;
  181. var isAndroid = _util2.default.os.android;
  182. options = _util2.default.extend({
  183. title: null,
  184. content: '',
  185. className: '',
  186. buttons: [{
  187. label: '确定',
  188. type: 'primary',
  189. onClick: _util2.default.noop
  190. }],
  191. isAndroid: isAndroid
  192. }, options);
  193. var $dialogWrap = (0, _util2.default)(_util2.default.render(_dialog2.default, options));
  194. var $dialog = $dialogWrap.find('.weui-dialog');
  195. var $mask = $dialogWrap.find('.weui-mask');
  196. function _hide(callback) {
  197. _hide = _util2.default.noop; // 防止二次调用导致报错
  198. $mask.addClass('weui-animate-fade-out');
  199. $dialog.addClass('weui-animate-fade-out').on('animationend webkitAnimationEnd', function () {
  200. $dialogWrap.remove();
  201. _sington = false;
  202. callback && callback();
  203. });
  204. }
  205. function hide(callback) {
  206. _hide(callback);
  207. }
  208. (0, _util2.default)('body').append($dialogWrap);
  209. // 不能直接把.weui-animate-fade-in加到$dialog,会导致mask的z-index有问题
  210. $mask.addClass('weui-animate-fade-in');
  211. $dialog.addClass('weui-animate-fade-in');
  212. $dialogWrap.on('click', '.weui-dialog__btn', function (evt) {
  213. var index = (0, _util2.default)(this).index();
  214. if (options.buttons[index].onClick) {
  215. if (options.buttons[index].onClick.call(this, evt) !== false) hide();
  216. } else {
  217. hide();
  218. }
  219. }).on('touchmove', function (evt) {
  220. evt.stopPropagation();
  221. evt.preventDefault();
  222. });
  223. _sington = $dialogWrap[0];
  224. _sington.hide = hide;
  225. return _sington;
  226. }
  227. exports.default = dialog;
  228. module.exports = exports['default'];
  229. /***/ }),
  230. /* 2 */
  231. /***/ (function(module, exports, __webpack_require__) {
  232. 'use strict';
  233. Object.defineProperty(exports, "__esModule", {
  234. value: true
  235. });
  236. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /*
  237. * Tencent is pleased to support the open source community by making WeUI.js available.
  238. *
  239. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  240. *
  241. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  242. * with the License. You may obtain a copy of the License at
  243. *
  244. * http://opensource.org/licenses/MIT
  245. *
  246. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  247. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  248. * either express or implied. See the License for the specific language governing permissions and
  249. * limitations under the License.
  250. */
  251. __webpack_require__(3);
  252. var _objectAssign = __webpack_require__(4);
  253. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  254. var _balajs = __webpack_require__(5);
  255. var _balajs2 = _interopRequireDefault(_balajs);
  256. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  257. // 其实,$ 的原型就是一个数组,拥有数组的各种方法
  258. // 这里只是库内部使用,所以通过文档约束,不做容错校验,达到代码最小化
  259. /* 判断系统 */
  260. function _detect(ua) {
  261. var os = this.os = {},
  262. android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  263. if (android) {
  264. os.android = true;
  265. os.version = android[2];
  266. }
  267. }
  268. _detect.call(_balajs2.default, navigator.userAgent);
  269. (0, _objectAssign2.default)(_balajs2.default.fn, {
  270. /**
  271. * 只能是一个 HTMLElement 元素或者 HTMLElement 数组,不支持字符串
  272. * @param {Element|Element[]} $child
  273. * @returns {append}
  274. */
  275. append: function append($child) {
  276. if (!($child instanceof HTMLElement)) {
  277. $child = $child[0];
  278. }
  279. this.forEach(function ($element) {
  280. $element.appendChild($child);
  281. });
  282. return this;
  283. },
  284. /**
  285. *
  286. * @returns {remove}
  287. */
  288. remove: function remove() {
  289. this.forEach(function ($element) {
  290. $element.parentNode.removeChild($element);
  291. });
  292. return this;
  293. },
  294. /**
  295. *
  296. * @param selector
  297. * @returns {HTMLElement}
  298. */
  299. find: function find(selector) {
  300. return (0, _balajs2.default)(selector, this);
  301. },
  302. /**
  303. *
  304. * @param {String} className
  305. * @returns {addClass}
  306. */
  307. addClass: function addClass(className) {
  308. this.forEach(function ($element) {
  309. // http://caniuse.com/#search=classList
  310. $element.classList.add(className);
  311. });
  312. return this;
  313. },
  314. /**
  315. *
  316. * @param {String} className
  317. * @returns {removeClass}
  318. */
  319. removeClass: function removeClass(className) {
  320. this.forEach(function ($element) {
  321. // http://caniuse.com/#search=classList
  322. $element.classList.remove(className);
  323. });
  324. return this;
  325. },
  326. /**
  327. *
  328. * @param index
  329. * @returns {*|jQuery|HTMLElement}
  330. */
  331. eq: function eq(index) {
  332. return (0, _balajs2.default)(this[index]);
  333. },
  334. /**
  335. *
  336. * @returns {show}
  337. */
  338. show: function show() {
  339. this.forEach(function ($element) {
  340. $element.style.display = 'block';
  341. });
  342. return this;
  343. },
  344. /**
  345. *
  346. * @returns {hide}
  347. */
  348. hide: function hide() {
  349. this.forEach(function ($element) {
  350. $element.style.display = 'none';
  351. });
  352. return this;
  353. },
  354. /**
  355. *
  356. * @param html 目前只能接受字符串
  357. * @returns {html}
  358. */
  359. html: function html(_html) {
  360. this.forEach(function ($element) {
  361. $element.innerHTML = _html;
  362. });
  363. return this;
  364. },
  365. /**
  366. *
  367. * @param {Object} obj 目前只能接受object
  368. * @returns {css}
  369. */
  370. css: function css(obj) {
  371. var _this = this;
  372. Object.keys(obj).forEach(function (key) {
  373. _this.forEach(function ($element) {
  374. $element.style[key] = obj[key];
  375. });
  376. });
  377. return this;
  378. },
  379. /**
  380. *
  381. * @param eventType
  382. * @param selector
  383. * @param handler
  384. */
  385. on: function on(eventType, selector, handler) {
  386. var isDelegate = typeof selector === 'string' && typeof handler === 'function';
  387. if (!isDelegate) {
  388. handler = selector;
  389. }
  390. this.forEach(function ($element) {
  391. eventType.split(' ').forEach(function (event) {
  392. $element.addEventListener(event, function (evt) {
  393. if (isDelegate) {
  394. // http://caniuse.com/#search=closest
  395. if (this.contains(evt.target.closest(selector))) {
  396. handler.call(evt.target, evt);
  397. }
  398. } else {
  399. handler.call(this, evt);
  400. }
  401. });
  402. });
  403. });
  404. return this;
  405. },
  406. /**
  407. *
  408. * @param {String} eventType
  409. * @param {String|Function} selector
  410. * @param {Function=} handler
  411. * @returns {off}
  412. */
  413. off: function off(eventType, selector, handler) {
  414. if (typeof selector === 'function') {
  415. handler = selector;
  416. selector = null;
  417. }
  418. this.forEach(function ($element) {
  419. eventType.split(' ').forEach(function (event) {
  420. if (typeof selector === 'string') {
  421. $element.querySelectorAll(selector).forEach(function ($element) {
  422. $element.removeEventListener(event, handler);
  423. });
  424. } else {
  425. $element.removeEventListener(event, handler);
  426. }
  427. });
  428. });
  429. return this;
  430. },
  431. /**
  432. *
  433. * @returns {Number}
  434. */
  435. index: function index() {
  436. var $element = this[0];
  437. var $parent = $element.parentNode;
  438. return Array.prototype.indexOf.call($parent.children, $element);
  439. },
  440. /**
  441. * @desc 因为off方法目前不可以移除绑定的匿名函数,现在直接暴力移除所有listener
  442. * @returns {offAll}
  443. */
  444. offAll: function offAll() {
  445. var _this2 = this;
  446. this.forEach(function ($element, index) {
  447. var clone = $element.cloneNode(true);
  448. $element.parentNode.replaceChild(clone, $element);
  449. _this2[index] = clone;
  450. });
  451. return this;
  452. },
  453. /**
  454. *
  455. * @returns {*}
  456. */
  457. val: function val() {
  458. var _arguments = arguments;
  459. if (arguments.length) {
  460. this.forEach(function ($element) {
  461. $element.value = _arguments[0];
  462. });
  463. return this;
  464. }
  465. return this[0].value;
  466. },
  467. /**
  468. *
  469. * @returns {*}
  470. */
  471. attr: function attr() {
  472. var _arguments2 = arguments;
  473. if (_typeof(arguments[0]) == 'object') {
  474. var attrsObj = arguments[0];
  475. var that = this;
  476. Object.keys(attrsObj).forEach(function (attr) {
  477. that.forEach(function ($element) {
  478. $element.setAttribute(attr, attrsObj[attr]);
  479. });
  480. });
  481. return this;
  482. }
  483. if (typeof arguments[0] == 'string' && arguments.length < 2) {
  484. return this[0].getAttribute(arguments[0]);
  485. }
  486. this.forEach(function ($element) {
  487. $element.setAttribute(_arguments2[0], _arguments2[1]);
  488. });
  489. return this;
  490. }
  491. });
  492. (0, _objectAssign2.default)(_balajs2.default, {
  493. extend: _objectAssign2.default,
  494. /**
  495. * noop
  496. */
  497. noop: function noop() {},
  498. /**
  499. * render
  500. * 取值:<%= variable %>
  501. * 表达式:<% if {} %>
  502. * 例子:
  503. * <div>
  504. * <div class="weui-mask"></div>
  505. * <div class="weui-dialog">
  506. * <% if(typeof title === 'string'){ %>
  507. * <div class="weui-dialog__hd"><strong class="weui-dialog__title"><%=title%></strong></div>
  508. * <% } %>
  509. * <div class="weui-dialog__bd"><%=content%></div>
  510. * <div class="weui-dialog__ft">
  511. * <% for(var i = 0; i < buttons.length; i++){ %>
  512. * <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_<%=buttons[i]['type']%>"><%=buttons[i]['label']%></a>
  513. * <% } %>
  514. * </div>
  515. * </div>
  516. * </div>
  517. * A very simple template engine
  518. * @param {String} tpl
  519. * @param {Object=} data
  520. * @returns {String}
  521. */
  522. render: function render(tpl, data) {
  523. var code = 'var p=[];with(this){p.push(\'' + tpl.replace(/[\r\t\n]/g, ' ').split('<%').join('\t').replace(/((^|%>)[^\t]*)'/g, '$1\r').replace(/\t=(.*?)%>/g, '\',$1,\'').split('\t').join('\');').split('%>').join('p.push(\'').split('\r').join('\\\'') + '\');}return p.join(\'\');';
  524. return new Function(code).apply(data);
  525. },
  526. /**
  527. * getStyle 获得元素计算后的样式值
  528. * (from http://stackoverflow.com/questions/2664045/how-to-get-an-html-elements-style-values-in-javascript)
  529. */
  530. getStyle: function getStyle(el, styleProp) {
  531. var value,
  532. defaultView = (el.ownerDocument || document).defaultView;
  533. // W3C standard way:
  534. if (defaultView && defaultView.getComputedStyle) {
  535. // sanitize property name to css notation
  536. // (hypen separated words eg. font-Size)
  537. styleProp = styleProp.replace(/([A-Z])/g, '-$1').toLowerCase();
  538. return defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
  539. } else if (el.currentStyle) {
  540. // IE
  541. // sanitize property name to camelCase
  542. styleProp = styleProp.replace(/\-(\w)/g, function (str, letter) {
  543. return letter.toUpperCase();
  544. });
  545. value = el.currentStyle[styleProp];
  546. // convert other units to pixels on IE
  547. if (/^\d+(em|pt|%|ex)?$/i.test(value)) {
  548. return function (value) {
  549. var oldLeft = el.style.left,
  550. oldRsLeft = el.runtimeStyle.left;
  551. el.runtimeStyle.left = el.currentStyle.left;
  552. el.style.left = value || 0;
  553. value = el.style.pixelLeft + 'px';
  554. el.style.left = oldLeft;
  555. el.runtimeStyle.left = oldRsLeft;
  556. return value;
  557. }(value);
  558. }
  559. return value;
  560. }
  561. }
  562. });
  563. exports.default = _balajs2.default;
  564. module.exports = exports['default'];
  565. /***/ }),
  566. /* 3 */
  567. /***/ (function(module, exports) {
  568. // element-closest | CC0-1.0 | github.com/jonathantneal/closest
  569. (function (ElementProto) {
  570. if (typeof ElementProto.matches !== 'function') {
  571. ElementProto.matches = ElementProto.msMatchesSelector || ElementProto.mozMatchesSelector || ElementProto.webkitMatchesSelector || function matches(selector) {
  572. var element = this;
  573. var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
  574. var index = 0;
  575. while (elements[index] && elements[index] !== element) {
  576. ++index;
  577. }
  578. return Boolean(elements[index]);
  579. };
  580. }
  581. if (typeof ElementProto.closest !== 'function') {
  582. ElementProto.closest = function closest(selector) {
  583. var element = this;
  584. while (element && element.nodeType === 1) {
  585. if (element.matches(selector)) {
  586. return element;
  587. }
  588. element = element.parentNode;
  589. }
  590. return null;
  591. };
  592. }
  593. })(window.Element.prototype);
  594. /***/ }),
  595. /* 4 */
  596. /***/ (function(module, exports) {
  597. /*
  598. object-assign
  599. (c) Sindre Sorhus
  600. @license MIT
  601. */
  602. 'use strict';
  603. /* eslint-disable no-unused-vars */
  604. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  605. var hasOwnProperty = Object.prototype.hasOwnProperty;
  606. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  607. function toObject(val) {
  608. if (val === null || val === undefined) {
  609. throw new TypeError('Object.assign cannot be called with null or undefined');
  610. }
  611. return Object(val);
  612. }
  613. function shouldUseNative() {
  614. try {
  615. if (!Object.assign) {
  616. return false;
  617. }
  618. // Detect buggy property enumeration order in older V8 versions.
  619. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  620. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  621. test1[5] = 'de';
  622. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  623. return false;
  624. }
  625. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  626. var test2 = {};
  627. for (var i = 0; i < 10; i++) {
  628. test2['_' + String.fromCharCode(i)] = i;
  629. }
  630. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  631. return test2[n];
  632. });
  633. if (order2.join('') !== '0123456789') {
  634. return false;
  635. }
  636. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  637. var test3 = {};
  638. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  639. test3[letter] = letter;
  640. });
  641. if (Object.keys(Object.assign({}, test3)).join('') !==
  642. 'abcdefghijklmnopqrst') {
  643. return false;
  644. }
  645. return true;
  646. } catch (err) {
  647. // We don't expect any of the above to throw, but better to be safe.
  648. return false;
  649. }
  650. }
  651. module.exports = shouldUseNative() ? Object.assign : function (target, source) {
  652. var from;
  653. var to = toObject(target);
  654. var symbols;
  655. for (var s = 1; s < arguments.length; s++) {
  656. from = Object(arguments[s]);
  657. for (var key in from) {
  658. if (hasOwnProperty.call(from, key)) {
  659. to[key] = from[key];
  660. }
  661. }
  662. if (getOwnPropertySymbols) {
  663. symbols = getOwnPropertySymbols(from);
  664. for (var i = 0; i < symbols.length; i++) {
  665. if (propIsEnumerable.call(from, symbols[i])) {
  666. to[symbols[i]] = from[symbols[i]];
  667. }
  668. }
  669. }
  670. }
  671. return to;
  672. };
  673. /***/ }),
  674. /* 5 */
  675. /***/ (function(module, exports, __webpack_require__) {
  676. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function(root, $) {
  677. $ = (function(document, s_addEventListener, s_querySelectorAll) {
  678. function $(s, context, bala) {
  679. bala = Object.create($.fn);
  680. s && bala.push.apply(bala, // if s is truly then push the following
  681. s[s_addEventListener] // if arg is node or window,
  682. ? [s] // then pass [s]
  683. : "" + s === s // else if arg is a string
  684. ? /</.test(s) // if the string contains "<" (if HTML code is passed)
  685. // then parse it and return node.children
  686. // use 'addEventListener' (HTMLUnknownElement) if content is not presented
  687. ? ((context = document.createElement(context || s_addEventListener)).innerHTML = s
  688. , context.children)
  689. : context // else if context is truly
  690. ? ((context = $(context)[0]) // if context element is found
  691. ? context[s_querySelectorAll](s) // then select element from context
  692. : bala) // else pass [] (context isn't found)
  693. : document[s_querySelectorAll](s) // else select elements globally
  694. : typeof s == 'function' // else if function is passed
  695. // if DOM is ready
  696. // readyState[7] means readyState value is "interactive" or "complete" (not "loading")
  697. ? document.readyState[7]
  698. ? s() // then run given function
  699. : document[s_addEventListener]('DOMContentLoaded', s) // else wait for DOM ready
  700. : s); // else guessing that s variable is array-like Object
  701. return bala;
  702. }
  703. $.fn = [];
  704. $.one = function(s, context) {
  705. return $(s, context)[0] || null;
  706. };
  707. return $;
  708. })(document, 'addEventListener', 'querySelectorAll');
  709. if (true) {
  710. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() {
  711. return $;
  712. }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  713. } else if (typeof module == 'object' && module.exports) {
  714. module.exports = $;
  715. } else {
  716. root.$ = $;
  717. }
  718. })(this);
  719. /***/ }),
  720. /* 6 */
  721. /***/ (function(module, exports) {
  722. module.exports = "<div class=\"<%=className%>\"> <div class=weui-mask></div> <div class=\"weui-dialog <% if(isAndroid){ %> weui-skin_android <% } %>\"> <% if(title){ %> <div class=weui-dialog__hd><strong class=weui-dialog__title><%=title%></strong></div> <% } %> <div class=weui-dialog__bd><%=content%></div> <div class=weui-dialog__ft> <% for(var i = 0; i < buttons.length; i++){ %> <a href=javascript:; class=\"weui-dialog__btn weui-dialog__btn_<%=buttons[i]['type']%>\"><%=buttons[i]['label']%></a> <% } %> </div> </div> </div> ";
  723. /***/ }),
  724. /* 7 */
  725. /***/ (function(module, exports, __webpack_require__) {
  726. 'use strict';
  727. Object.defineProperty(exports, "__esModule", {
  728. value: true
  729. });
  730. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /*
  731. * Tencent is pleased to support the open source community by making WeUI.js available.
  732. *
  733. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  734. *
  735. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  736. * with the License. You may obtain a copy of the License at
  737. *
  738. * http://opensource.org/licenses/MIT
  739. *
  740. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  741. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  742. * either express or implied. See the License for the specific language governing permissions and
  743. * limitations under the License.
  744. */
  745. var _util = __webpack_require__(2);
  746. var _util2 = _interopRequireDefault(_util);
  747. var _dialog = __webpack_require__(1);
  748. var _dialog2 = _interopRequireDefault(_dialog);
  749. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  750. /**
  751. * alert 警告弹框,功能类似于浏览器自带的 alert 弹框,用于提醒、警告用户简单扼要的信息,只有一个“确认”按钮,点击“确认”按钮后关闭弹框。
  752. * @param {string} content 弹窗内容
  753. * @param {function=} yes 点击确定按钮的回调
  754. * @param {object=} options 配置项
  755. * @param {string=} options.title 弹窗的标题
  756. * @param {string=} options.className 自定义类名
  757. * @param {array=} options.buttons 按钮配置项,详情参考dialog
  758. *
  759. * @example
  760. * weui.alert('普通的alert');
  761. * weui.alert('带回调的alert', function(){ console.log('ok') });
  762. * var alertDom = weui.alert('手动关闭的alert', function(){
  763. * return false; // 不关闭弹窗,可用alertDom.hide()来手动关闭
  764. * });
  765. * weui.alert('自定义标题的alert', { title: '自定义标题' });
  766. * weui.alert('带回调的自定义标题的alert', function(){
  767. * console.log('ok')
  768. * }, {
  769. * title: '自定义标题'
  770. * });
  771. * weui.alert('自定义按钮的alert', {
  772. * title: '自定义按钮的alert',
  773. * buttons: [{
  774. * label: 'OK',
  775. * type: 'primary',
  776. * onClick: function(){ console.log('ok') }
  777. * }]
  778. * });
  779. *
  780. * // 多次使用
  781. * var alert = weui.alert('hello');
  782. * alert.hide(function(){
  783. * weui.alert('world');
  784. * });
  785. */
  786. function alert() {
  787. var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  788. var yes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _util2.default.noop;
  789. var options = arguments[2];
  790. if ((typeof yes === 'undefined' ? 'undefined' : _typeof(yes)) === 'object') {
  791. options = yes;
  792. yes = _util2.default.noop;
  793. }
  794. options = _util2.default.extend({
  795. content: content,
  796. buttons: [{
  797. label: '确定',
  798. type: 'primary',
  799. onClick: yes
  800. }]
  801. }, options);
  802. return (0, _dialog2.default)(options);
  803. }
  804. exports.default = alert;
  805. module.exports = exports['default'];
  806. /***/ }),
  807. /* 8 */
  808. /***/ (function(module, exports, __webpack_require__) {
  809. 'use strict';
  810. Object.defineProperty(exports, "__esModule", {
  811. value: true
  812. });
  813. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /*
  814. * Tencent is pleased to support the open source community by making WeUI.js available.
  815. *
  816. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  817. *
  818. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  819. * with the License. You may obtain a copy of the License at
  820. *
  821. * http://opensource.org/licenses/MIT
  822. *
  823. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  824. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  825. * either express or implied. See the License for the specific language governing permissions and
  826. * limitations under the License.
  827. */
  828. var _util = __webpack_require__(2);
  829. var _util2 = _interopRequireDefault(_util);
  830. var _dialog = __webpack_require__(1);
  831. var _dialog2 = _interopRequireDefault(_dialog);
  832. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  833. /**
  834. * 确认弹窗
  835. * @param {string} content 弹窗内容
  836. * @param {function=} yes 点击确定按钮的回调
  837. * @param {function=} no 点击取消按钮的回调
  838. * @param {object=} options 配置项
  839. * @param {string=} options.title 弹窗的标题
  840. * @param {string=} options.className 自定义类名
  841. * @param {array=} options.buttons 按钮配置项,详情参考dialog
  842. *
  843. * @example
  844. * weui.confirm('普通的confirm');
  845. * weui.confirm('自定义标题的confirm', { title: '自定义标题' });
  846. * weui.confirm('带回调的confirm', function(){ console.log('yes') }, function(){ console.log('no') });
  847. * var confirmDom = weui.confirm('手动关闭的confirm', function(){
  848. * return false; // 不关闭弹窗,可用confirmDom.hide()来手动关闭
  849. * });
  850. * weui.confirm('带回调的自定义标题的confirm', function(){ console.log('yes') }, function(){ console.log('no') }, {
  851. * title: '自定义标题'
  852. * });
  853. * weui.confirm('自定义按钮的confirm', {
  854. * title: '自定义按钮的confirm',
  855. * buttons: [{
  856. * label: 'NO',
  857. * type: 'default',
  858. * onClick: function(){ console.log('no') }
  859. * }, {
  860. * label: 'YES',
  861. * type: 'primary',
  862. * onClick: function(){ console.log('yes') }
  863. * }]
  864. * });
  865. */
  866. function confirm() {
  867. var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  868. var yes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _util2.default.noop;
  869. var no = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _util2.default.noop;
  870. var options = arguments[3];
  871. if ((typeof yes === 'undefined' ? 'undefined' : _typeof(yes)) === 'object') {
  872. options = yes;
  873. yes = _util2.default.noop;
  874. } else if ((typeof no === 'undefined' ? 'undefined' : _typeof(no)) === 'object') {
  875. options = no;
  876. no = _util2.default.noop;
  877. }
  878. options = _util2.default.extend({
  879. content: content,
  880. buttons: [{
  881. label: '取消',
  882. type: 'default',
  883. onClick: no
  884. }, {
  885. label: '确定',
  886. type: 'primary',
  887. onClick: yes
  888. }]
  889. }, options);
  890. return (0, _dialog2.default)(options);
  891. }
  892. exports.default = confirm;
  893. module.exports = exports['default'];
  894. /***/ }),
  895. /* 9 */
  896. /***/ (function(module, exports, __webpack_require__) {
  897. 'use strict';
  898. Object.defineProperty(exports, "__esModule", {
  899. value: true
  900. });
  901. var _util = __webpack_require__(2);
  902. var _util2 = _interopRequireDefault(_util);
  903. var _toast = __webpack_require__(10);
  904. var _toast2 = _interopRequireDefault(_toast);
  905. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  906. /*
  907. * Tencent is pleased to support the open source community by making WeUI.js available.
  908. *
  909. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  910. *
  911. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  912. * with the License. You may obtain a copy of the License at
  913. *
  914. * http://opensource.org/licenses/MIT
  915. *
  916. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  917. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  918. * either express or implied. See the License for the specific language governing permissions and
  919. * limitations under the License.
  920. */
  921. var _sington = void 0;
  922. /**
  923. * toast 一般用于操作成功时的提示场景
  924. * @param {string} content toast的文字
  925. * @param {Object|function=} options 配置项或回调
  926. * @param {number=} [options.duration=3000] 多少毫秒后关闭toast
  927. * @param {function=} options.callback 关闭后的回调
  928. * @param {string=} options.className 自定义类名
  929. *
  930. * @example
  931. * weui.toast('操作成功', 3000);
  932. * weui.toast('操作成功', {
  933. * duration: 3000,
  934. * className: 'custom-classname',
  935. * callback: function(){ console.log('close') }
  936. * });
  937. */
  938. function toast() {
  939. var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  940. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  941. if (_sington) return _sington;
  942. if (typeof options === 'number') {
  943. options = {
  944. duration: options
  945. };
  946. }
  947. if (typeof options === 'function') {
  948. options = {
  949. callback: options
  950. };
  951. }
  952. options = _util2.default.extend({
  953. content: content,
  954. duration: 3000,
  955. callback: _util2.default.noop,
  956. className: ''
  957. }, options);
  958. var $toastWrap = (0, _util2.default)(_util2.default.render(_toast2.default, options));
  959. var $toast = $toastWrap.find('.weui-toast');
  960. var $mask = $toastWrap.find('.weui-mask');
  961. (0, _util2.default)('body').append($toastWrap);
  962. $toast.addClass('weui-animate-fade-in');
  963. $mask.addClass('weui-animate-fade-in');
  964. setTimeout(function () {
  965. $mask.addClass('weui-animate-fade-out');
  966. $toast.addClass('weui-animate-fade-out').on('animationend webkitAnimationEnd', function () {
  967. $toastWrap.remove();
  968. _sington = false;
  969. options.callback();
  970. });
  971. }, options.duration);
  972. _sington = $toastWrap[0];
  973. return $toastWrap[0];
  974. }
  975. exports.default = toast;
  976. module.exports = exports['default'];
  977. /***/ }),
  978. /* 10 */
  979. /***/ (function(module, exports) {
  980. module.exports = "<div class=\"<%= className %>\"> <div class=weui-mask_transparent></div> <div class=weui-toast> <i class=\"weui-icon_toast weui-icon-success-no-circle\"></i> <p class=weui-toast__content><%=content%></p> </div> </div> ";
  981. /***/ }),
  982. /* 11 */
  983. /***/ (function(module, exports, __webpack_require__) {
  984. 'use strict';
  985. Object.defineProperty(exports, "__esModule", {
  986. value: true
  987. });
  988. var _util = __webpack_require__(2);
  989. var _util2 = _interopRequireDefault(_util);
  990. var _loading = __webpack_require__(12);
  991. var _loading2 = _interopRequireDefault(_loading);
  992. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  993. /*
  994. * Tencent is pleased to support the open source community by making WeUI.js available.
  995. *
  996. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  997. *
  998. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  999. * with the License. You may obtain a copy of the License at
  1000. *
  1001. * http://opensource.org/licenses/MIT
  1002. *
  1003. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  1004. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  1005. * either express or implied. See the License for the specific language governing permissions and
  1006. * limitations under the License.
  1007. */
  1008. var _sington = void 0;
  1009. /**
  1010. * loading
  1011. * @param {string} content loading的文字
  1012. * @param {object=} options 配置项
  1013. * @param {string=} options.className 自定义类名
  1014. *
  1015. * @example
  1016. * var loading = weui.loading('loading', {
  1017. * className: 'custom-classname'
  1018. * });
  1019. * setTimeout(function () {
  1020. * loading.hide(function() {
  1021. * console.log('`loading` has been hidden');
  1022. * });
  1023. * }, 3000);
  1024. */
  1025. function loading() {
  1026. var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1027. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1028. if (_sington) return _sington;
  1029. options = _util2.default.extend({
  1030. content: content,
  1031. className: ''
  1032. }, options);
  1033. var $loadingWrap = (0, _util2.default)(_util2.default.render(_loading2.default, options));
  1034. var $loading = $loadingWrap.find('.weui-toast');
  1035. var $mask = $loadingWrap.find('.weui-mask');
  1036. function _hide(callback) {
  1037. _hide = _util2.default.noop; // 防止二次调用导致报错
  1038. $mask.addClass('weui-animate-fade-out');
  1039. $loading.addClass('weui-animate-fade-out').on('animationend webkitAnimationEnd', function () {
  1040. $loadingWrap.remove();
  1041. _sington = false;
  1042. callback && callback();
  1043. });
  1044. }
  1045. function hide(callback) {
  1046. _hide(callback);
  1047. }
  1048. (0, _util2.default)('body').append($loadingWrap);
  1049. $loading.addClass('weui-animate-fade-in');
  1050. $mask.addClass('weui-animate-fade-in');
  1051. _sington = $loadingWrap[0];
  1052. _sington.hide = hide;
  1053. return _sington;
  1054. }
  1055. exports.default = loading;
  1056. module.exports = exports['default'];
  1057. /***/ }),
  1058. /* 12 */
  1059. /***/ (function(module, exports) {
  1060. module.exports = "<div class=\"weui-loading_toast <%= className %>\"> <div class=weui-mask_transparent></div> <div class=weui-toast> <i class=\"weui-loading weui-icon_toast\"></i> <p class=weui-toast__content><%=content%></p> </div> </div> ";
  1061. /***/ }),
  1062. /* 13 */
  1063. /***/ (function(module, exports, __webpack_require__) {
  1064. 'use strict';
  1065. Object.defineProperty(exports, "__esModule", {
  1066. value: true
  1067. });
  1068. var _util = __webpack_require__(2);
  1069. var _util2 = _interopRequireDefault(_util);
  1070. var _actionSheet = __webpack_require__(14);
  1071. var _actionSheet2 = _interopRequireDefault(_actionSheet);
  1072. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1073. /*
  1074. * Tencent is pleased to support the open source community by making WeUI.js available.
  1075. *
  1076. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  1077. *
  1078. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  1079. * with the License. You may obtain a copy of the License at
  1080. *
  1081. * http://opensource.org/licenses/MIT
  1082. *
  1083. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  1084. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  1085. * either express or implied. See the License for the specific language governing permissions and
  1086. * limitations under the License.
  1087. */
  1088. var _sington = void 0;
  1089. /**
  1090. * actionsheet 弹出式菜单
  1091. * @param {array} menus 上层的选项
  1092. * @param {string} menus[].label 选项的文字
  1093. * @param {function} menus[].onClick 选项点击时的回调
  1094. *
  1095. * @param {array} actions 下层的选项
  1096. * @param {string} actions[].label 选项的文字
  1097. * @param {function} actions[].onClick 选项点击时的回调
  1098. *
  1099. * @param {object=} options 配置项
  1100. * @param {string=} options.title actionSheet的title,如果isAndroid=true,则不会显示
  1101. * @param {string=} options.className 自定义类名
  1102. * @param {function=} [options.onClose] actionSheet关闭后的回调
  1103. *
  1104. * @example
  1105. * weui.actionSheet([
  1106. * {
  1107. * label: '拍照',
  1108. * onClick: function () {
  1109. * console.log('拍照');
  1110. * }
  1111. * }, {
  1112. * label: '从相册选择',
  1113. * onClick: function () {
  1114. * console.log('从相册选择');
  1115. * }
  1116. * }, {
  1117. * label: '其他',
  1118. * onClick: function () {
  1119. * console.log('其他');
  1120. * }
  1121. * }
  1122. * ], [
  1123. * {
  1124. * label: '取消',
  1125. * onClick: function () {
  1126. * console.log('取消');
  1127. * }
  1128. * }
  1129. * ], {
  1130. * className: 'custom-classname',
  1131. * onClose: function(){
  1132. * console.log('关闭');
  1133. * }
  1134. * });
  1135. */
  1136. function actionSheet() {
  1137. var menus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  1138. var actions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  1139. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1140. if (_sington) return _sington;
  1141. var isAndroid = _util2.default.os.android;
  1142. options = _util2.default.extend({
  1143. menus: menus,
  1144. actions: actions,
  1145. title: '',
  1146. className: '',
  1147. isAndroid: isAndroid,
  1148. onClose: _util2.default.noop
  1149. }, options);
  1150. var $actionSheetWrap = (0, _util2.default)(_util2.default.render(_actionSheet2.default, options));
  1151. var $actionSheet = $actionSheetWrap.find('.weui-actionsheet');
  1152. var $actionSheetMask = $actionSheetWrap.find('.weui-mask');
  1153. function _hide(callback) {
  1154. _hide = _util2.default.noop; // 防止二次调用导致报错
  1155. $actionSheet.addClass(options.isAndroid ? 'weui-animate-fade-out' : 'weui-animate-slide-down');
  1156. $actionSheetMask.addClass('weui-animate-fade-out').on('animationend webkitAnimationEnd', function () {
  1157. $actionSheetWrap.remove();
  1158. _sington = false;
  1159. options.onClose();
  1160. callback && callback();
  1161. });
  1162. }
  1163. function hide(callback) {
  1164. _hide(callback);
  1165. }
  1166. (0, _util2.default)('body').append($actionSheetWrap);
  1167. // 这里获取一下计算后的样式,强制触发渲染. fix IOS10下闪现的问题
  1168. _util2.default.getStyle($actionSheet[0], 'transform');
  1169. $actionSheet.addClass(options.isAndroid ? 'weui-animate-fade-in' : 'weui-animate-slide-up');
  1170. $actionSheetMask.addClass('weui-animate-fade-in').on('click', function () {
  1171. hide();
  1172. });
  1173. $actionSheetWrap.find('.weui-actionsheet__menu').on('click', '.weui-actionsheet__cell', function (evt) {
  1174. var index = (0, _util2.default)(this).index();
  1175. menus[index].onClick.call(this, evt);
  1176. hide();
  1177. });
  1178. $actionSheetWrap.find('.weui-actionsheet__action').on('click', '.weui-actionsheet__cell', function (evt) {
  1179. var index = (0, _util2.default)(this).index();
  1180. actions[index].onClick.call(this, evt);
  1181. hide();
  1182. });
  1183. _sington = $actionSheetWrap[0];
  1184. _sington.hide = hide;
  1185. return _sington;
  1186. }
  1187. exports.default = actionSheet;
  1188. module.exports = exports['default'];
  1189. /***/ }),
  1190. /* 14 */
  1191. /***/ (function(module, exports) {
  1192. module.exports = "<div class=\"<% if(isAndroid){ %>weui-skin_android <% } %><%= className %>\"> <div class=weui-mask></div> <div class=weui-actionsheet> <% if(!isAndroid && title){ %> <div class=weui-actionsheet__title> <p class=weui-actionsheet__title-text><%= title %></p> </div> <% } %> <div class=weui-actionsheet__menu> <% for(var i = 0; i < menus.length; i++){ %> <div class=weui-actionsheet__cell><%= menus[i].label %></div> <% } %> </div> <div class=weui-actionsheet__action> <% for(var j = 0; j < actions.length; j++){ %> <div class=weui-actionsheet__cell><%= actions[j].label %></div> <% } %> </div> </div> </div> ";
  1193. /***/ }),
  1194. /* 15 */
  1195. /***/ (function(module, exports, __webpack_require__) {
  1196. 'use strict';
  1197. Object.defineProperty(exports, "__esModule", {
  1198. value: true
  1199. });
  1200. var _util = __webpack_require__(2);
  1201. var _util2 = _interopRequireDefault(_util);
  1202. var _topTips = __webpack_require__(16);
  1203. var _topTips2 = _interopRequireDefault(_topTips);
  1204. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1205. /*
  1206. * Tencent is pleased to support the open source community by making WeUI.js available.
  1207. *
  1208. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  1209. *
  1210. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  1211. * with the License. You may obtain a copy of the License at
  1212. *
  1213. * http://opensource.org/licenses/MIT
  1214. *
  1215. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  1216. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  1217. * either express or implied. See the License for the specific language governing permissions and
  1218. * limitations under the License.
  1219. */
  1220. var _toptips = null;
  1221. /**
  1222. * toptips 顶部报错提示
  1223. * @param {string} content 报错的文字
  1224. * @param {number|function|object=} options 多少毫秒后消失|消失后的回调|配置项
  1225. * @param {number=} [options.duration=3000] 多少毫秒后消失
  1226. * @param {string=} options.className 自定义类名
  1227. * @param {function=} options.callback 消失后的回调
  1228. *
  1229. * @example
  1230. * weui.topTips('请填写正确的字段');
  1231. * weui.topTips('请填写正确的字段', 3000);
  1232. * weui.topTips('请填写正确的字段', function(){ console.log('close') });
  1233. * weui.topTips('请填写正确的字段', {
  1234. * duration: 3000,
  1235. * className: 'custom-classname',
  1236. * callback: function(){ console.log('close') }
  1237. * });
  1238. *
  1239. * // 主动关闭
  1240. * var $topTips = weui.topTips('请填写正确的字段');
  1241. * $topTips.hide(function() {
  1242. * console.log('`topTips` has been hidden');
  1243. * });
  1244. */
  1245. function topTips(content) {
  1246. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1247. if (typeof options === 'number') {
  1248. options = {
  1249. duration: options
  1250. };
  1251. }
  1252. if (typeof options === 'function') {
  1253. options = {
  1254. callback: options
  1255. };
  1256. }
  1257. options = _util2.default.extend({
  1258. content: content,
  1259. duration: 3000,
  1260. callback: _util2.default.noop,
  1261. className: ''
  1262. }, options);
  1263. var $topTips = (0, _util2.default)(_util2.default.render(_topTips2.default, options));
  1264. function _hide(callback) {
  1265. _hide = _util2.default.noop; // 防止二次调用导致报错
  1266. $topTips.remove();
  1267. callback && callback();
  1268. options.callback();
  1269. _toptips = null;
  1270. }
  1271. function hide(callback) {
  1272. _hide(callback);
  1273. }
  1274. (0, _util2.default)('body').append($topTips);
  1275. if (_toptips) {
  1276. clearTimeout(_toptips.timeout);
  1277. _toptips.hide();
  1278. }
  1279. _toptips = {
  1280. hide: hide
  1281. };
  1282. _toptips.timeout = setTimeout(hide, options.duration);
  1283. $topTips[0].hide = hide;
  1284. return $topTips[0];
  1285. }
  1286. exports.default = topTips;
  1287. module.exports = exports['default'];
  1288. /***/ }),
  1289. /* 16 */
  1290. /***/ (function(module, exports) {
  1291. module.exports = "<div class=\"weui-toptips weui-toptips_warn <%= className %>\" style=display:block><%= content %></div> ";
  1292. /***/ }),
  1293. /* 17 */
  1294. /***/ (function(module, exports, __webpack_require__) {
  1295. 'use strict';
  1296. Object.defineProperty(exports, "__esModule", {
  1297. value: true
  1298. });
  1299. var _util = __webpack_require__(2);
  1300. var _util2 = _interopRequireDefault(_util);
  1301. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1302. /**
  1303. * searchbar 搜索框,主要实现搜索框组件一些显隐逻辑
  1304. * @param {string} selector searchbar的selector
  1305. *
  1306. * @example
  1307. * #### html
  1308. * ```html
  1309. * <div class="weui-search-bar" id="searchBar">
  1310. * <form class="weui-search-bar__form">
  1311. * <div class="weui-search-bar__box">
  1312. * <i class="weui-icon-search"></i>
  1313. * <input type="search" class="weui-search-bar__input" placeholder="搜索" required="">
  1314. * <a href="javascript:" class="weui-icon-clear"></a>
  1315. * </div>
  1316. * <label class="weui-search-bar__label">
  1317. * <i class="weui-icon-search"></i>
  1318. * <span>搜索</span>
  1319. * </label>
  1320. * </form>
  1321. * <a href="javascript:" class="weui-search-bar__cancel-btn">取消</a>
  1322. * </div>
  1323. * ```
  1324. *
  1325. * #### js
  1326. * ```javascript
  1327. * weui.searchBar('#searchBar');
  1328. * ```
  1329. */
  1330. function searchBar(selector) {
  1331. var $eles = (0, _util2.default)(selector);
  1332. $eles.forEach(function (ele) {
  1333. var $searchBar = (0, _util2.default)(ele);
  1334. var $searchLabel = $searchBar.find('.weui-search-bar__label');
  1335. var $searchInput = $searchBar.find('.weui-search-bar__input');
  1336. var $searchClear = $searchBar.find('.weui-icon-clear');
  1337. var $searchCancel = $searchBar.find('.weui-search-bar__cancel-btn');
  1338. function cancelSearch() {
  1339. $searchInput.val('');
  1340. $searchBar.removeClass('weui-search-bar_focusing');
  1341. }
  1342. $searchLabel.on('click', function () {
  1343. $searchBar.addClass('weui-search-bar_focusing');
  1344. $searchInput[0].focus();
  1345. });
  1346. $searchInput.on('blur', function () {
  1347. if (!this.value.length) cancelSearch();
  1348. });
  1349. $searchClear.on('click', function () {
  1350. $searchInput.val('');
  1351. $searchInput[0].focus();
  1352. });
  1353. $searchCancel.on('click', function () {
  1354. cancelSearch();
  1355. $searchInput[0].blur();
  1356. });
  1357. });
  1358. return $eles;
  1359. } /*
  1360. * Tencent is pleased to support the open source community by making WeUI.js available.
  1361. *
  1362. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  1363. *
  1364. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  1365. * with the License. You may obtain a copy of the License at
  1366. *
  1367. * http://opensource.org/licenses/MIT
  1368. *
  1369. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  1370. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  1371. * either express or implied. See the License for the specific language governing permissions and
  1372. * limitations under the License.
  1373. */
  1374. exports.default = searchBar;
  1375. module.exports = exports['default'];
  1376. /***/ }),
  1377. /* 18 */
  1378. /***/ (function(module, exports, __webpack_require__) {
  1379. 'use strict';
  1380. Object.defineProperty(exports, "__esModule", {
  1381. value: true
  1382. });
  1383. var _util = __webpack_require__(2);
  1384. var _util2 = _interopRequireDefault(_util);
  1385. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1386. /**
  1387. * tab tab导航栏
  1388. * @param {string} selector tab的selector
  1389. * @param {object=} options 配置项
  1390. * @param {number=} [options.defaultIndex=0] 初始展示的index
  1391. * @param {function=} options.onChange 点击tab时,返回对应的index
  1392. *
  1393. * @example
  1394. * #### html
  1395. * ```html
  1396. * <div class="weui-tab" id="tab">
  1397. * <div class="weui-navbar">
  1398. * <div class="weui-navbar__item">反馈</div>
  1399. * <div class="weui-navbar__item">表单</div>
  1400. * <div class="weui-navbar__item">上传</div>
  1401. * <div class="weui-navbar__item">其它</div>
  1402. * </div>
  1403. * <div class="weui-tab__panel">
  1404. * <div class="weui-tab__content">反馈页</div>
  1405. * <div class="weui-tab__content">表单页</div>
  1406. * <div class="weui-tab__content">上传页</div>
  1407. * <div class="weui-tab__content">其它页</div>
  1408. * </div>
  1409. * </div>
  1410. * ```
  1411. *
  1412. * #### js
  1413. * ```javascript
  1414. * weui.tab('#tab',{
  1415. * defaultIndex: 0,
  1416. * onChange: function(index){
  1417. * console.log(index);
  1418. * }
  1419. * });
  1420. * ```
  1421. */
  1422. function tab(selector) {
  1423. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1424. var $eles = (0, _util2.default)(selector);
  1425. options = _util2.default.extend({
  1426. defaultIndex: 0,
  1427. onChange: _util2.default.noop
  1428. }, options);
  1429. $eles.forEach(function (ele) {
  1430. var $tab = (0, _util2.default)(ele);
  1431. var $tabItems = $tab.find('.weui-navbar__item, .weui-tabbar__item');
  1432. var $tabContents = $tab.find('.weui-tab__content');
  1433. $tabItems.eq(options.defaultIndex).addClass('weui-bar__item_on');
  1434. $tabContents.eq(options.defaultIndex).show();
  1435. $tabItems.on('click', function () {
  1436. var $this = (0, _util2.default)(this),
  1437. index = $this.index();
  1438. $tabItems.removeClass('weui-bar__item_on');
  1439. $this.addClass('weui-bar__item_on');
  1440. $tabContents.hide();
  1441. $tabContents.eq(index).show();
  1442. options.onChange.call(this, index);
  1443. });
  1444. });
  1445. return this;
  1446. } /*
  1447. * Tencent is pleased to support the open source community by making WeUI.js available.
  1448. *
  1449. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  1450. *
  1451. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  1452. * with the License. You may obtain a copy of the License at
  1453. *
  1454. * http://opensource.org/licenses/MIT
  1455. *
  1456. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  1457. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  1458. * either express or implied. See the License for the specific language governing permissions and
  1459. * limitations under the License.
  1460. */
  1461. exports.default = tab;
  1462. module.exports = exports['default'];
  1463. /***/ }),
  1464. /* 19 */
  1465. /***/ (function(module, exports, __webpack_require__) {
  1466. 'use strict';
  1467. Object.defineProperty(exports, "__esModule", {
  1468. value: true
  1469. });
  1470. var _util = __webpack_require__(2);
  1471. var _util2 = _interopRequireDefault(_util);
  1472. var _topTips = __webpack_require__(15);
  1473. var _topTips2 = _interopRequireDefault(_topTips);
  1474. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1475. /*
  1476. * Tencent is pleased to support the open source community by making WeUI.js available.
  1477. *
  1478. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  1479. *
  1480. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  1481. * with the License. You may obtain a copy of the License at
  1482. *
  1483. * http://opensource.org/licenses/MIT
  1484. *
  1485. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  1486. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  1487. * either express or implied. See the License for the specific language governing permissions and
  1488. * limitations under the License.
  1489. */
  1490. function _findCellParent(ele) {
  1491. if (!ele || !ele.classList) return null;
  1492. if (ele.classList.contains('weui-cell')) return ele;
  1493. return _findCellParent(ele.parentNode);
  1494. }
  1495. function _validate($input, $form, regexp) {
  1496. var input = $input[0],
  1497. val = $input.val();
  1498. if (input.tagName == 'INPUT' || input.tagName == 'TEXTAREA') {
  1499. var reg = input.getAttribute('pattern') || '';
  1500. if (input.type == 'radio') {
  1501. var radioInputs = $form.find('input[type="radio"][name="' + input.name + '"]');
  1502. for (var i = 0, len = radioInputs.length; i < len; ++i) {
  1503. if (radioInputs[i].checked) return null;
  1504. }
  1505. return 'empty';
  1506. } else if (input.type == 'checkbox') {
  1507. if (reg) {
  1508. var checkboxInputs = $form.find('input[type="checkbox"][name="' + input.name + '"]');
  1509. var regs = reg.replace(/[{\s}]/g, '').split(',');
  1510. var count = 0;
  1511. if (regs.length != 2) {
  1512. throw input.outerHTML + ' regexp is wrong.';
  1513. }
  1514. checkboxInputs.forEach(function (checkboxInput) {
  1515. if (checkboxInput.checked) ++count;
  1516. });
  1517. if (regs[1] === '') {
  1518. // {0,}
  1519. if (count >= parseInt(regs[0])) {
  1520. return null;
  1521. } else {
  1522. return count == 0 ? 'empty' : 'notMatch';
  1523. }
  1524. } else {
  1525. // {0,2}
  1526. if (parseInt(regs[0]) <= count && count <= parseInt(regs[1])) {
  1527. return null;
  1528. } else {
  1529. return count == 0 ? 'empty' : 'notMatch';
  1530. }
  1531. }
  1532. } else {
  1533. return input.checked ? null : 'empty';
  1534. }
  1535. } else if (reg) {
  1536. if (/^REG_/.test(reg)) {
  1537. if (!regexp) throw 'RegExp ' + reg + ' is empty.';
  1538. reg = reg.replace(/^REG_/, '');
  1539. if (!regexp[reg]) throw 'RegExp ' + reg + ' has not found.';
  1540. reg = regexp[reg];
  1541. }
  1542. return new RegExp(reg).test(val) ? null : !$input.val().length ? 'empty' : 'notMatch';
  1543. } else if (!$input.val().length) {
  1544. return 'empty';
  1545. } else {
  1546. return null;
  1547. }
  1548. } else if (val.length) {
  1549. // 有输入值
  1550. return null;
  1551. }
  1552. return 'empty';
  1553. }
  1554. /**
  1555. * 表单校验
  1556. * @param {string} selector 表单的selector
  1557. * @param {function} callback 校验后的回调
  1558. * @param {Object=} options 配置项
  1559. * @param {object=} options.regexp 表单所需的正则表达式
  1560. *
  1561. * @example
  1562. * ##### 普通input的HTML
  1563. * ```html
  1564. * <input type="tel" required pattern="[0-9]{11}" placeholder="输入你现在的手机号" emptyTips="请输入手机号" notMatchTips="请输入正确的手机号">
  1565. * <input type="text" required pattern="REG_IDNUM" placeholder="输入你的身份证号码" emptyTips="请输入身份证号码" notMatchTips="请输入正确的身份证号码">
  1566. * ```
  1567. * - required 表示需要校验
  1568. * - pattern 表示校验的正则,不填则进行为空校验。当以REG_开头时,则获取校验时传入的正则。如`pattern="REG_IDNUM"`,则需要在调用相应方法时传入`{regexp:{IDNUM: /(?:^\d{15}$)|(?:^\d{18}$)|^\d{17}[\dXx]$/}}`,详情请看下面`checkIfBlur`和`validate`
  1569. * - 报错的wording会从 emptyTips | notMatchTips | tips | placeholder 里获得
  1570. * <br>
  1571. *
  1572. * ##### radio
  1573. * radio需要检验,只需把参数写在同一表单下,同name的第一个元素即可。
  1574. * ```html
  1575. * <input type="radio" value="male" name="sex" required tips="请选择性别" />
  1576. * <input type="radio" value="female" name="sex" />
  1577. * ```
  1578. * <br>
  1579. *
  1580. * ##### checkbox
  1581. * checkbox需要校验,只需把参数写在同一表单下,同name的第一个元素即可。
  1582. * pattern 规定选择个数,用法与正则一致,例如:
  1583. * ```html
  1584. * <input type="checkbox" name="assistance" value="黄药师" required pattern="{1,2}" tips="请勾选1-2个敲码助手" />
  1585. * <input type="checkbox" name="assistance" value="欧阳锋" />
  1586. * <input type="checkbox" name="assistance" value="段智兴" />
  1587. * <input type="checkbox" name="assistance" value="洪七公" />
  1588. * ```
  1589. * - {1,} 至少选择1个
  1590. * - {1,2} 选择1-2个
  1591. * - 这里不会出现{0,}这种情况,因为有required就表示必选。否则直接去掉required即可。
  1592. * <br>
  1593. *
  1594. * ``` js
  1595. * // weui.form.validate('#form', function(error){ console.log(error);}); // error: {dom:[Object], msg:[String]}
  1596. * weui.form.validate('#form', function (error) {
  1597. * if (!error) {
  1598. * var loading = weui.loading('提交中...');
  1599. * setTimeout(function () {
  1600. * loading.hide();
  1601. * weui.toast('提交成功', 3000);
  1602. * }, 1500);
  1603. * }
  1604. * // return true; // 当return true时,不会显示错误
  1605. * }, {
  1606. * regexp: {
  1607. * IDNUM: /(?:^\d{15}$)|(?:^\d{18}$)|^\d{17}[\dXx]$/,
  1608. * VCODE: /^.{4}$/
  1609. * }
  1610. * });
  1611. * ```
  1612. */
  1613. function validate(selector) {
  1614. var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _util2.default.noop;
  1615. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1616. var $eles = (0, _util2.default)(selector);
  1617. $eles.forEach(function (ele) {
  1618. var $form = (0, _util2.default)(ele);
  1619. var $requireds = $form.find('[required]');
  1620. if (typeof callback != 'function') callback = showErrorTips;
  1621. for (var i = 0, len = $requireds.length; i < len; ++i) {
  1622. var $required = $requireds.eq(i),
  1623. errorMsg = _validate($required, $form, options.regexp),
  1624. error = { ele: $required[0], msg: errorMsg };
  1625. if (errorMsg) {
  1626. if (!callback(error)) showErrorTips(error);
  1627. return;
  1628. }
  1629. }
  1630. callback(null);
  1631. });
  1632. return this;
  1633. }
  1634. /**
  1635. * checkIfBlur 当表单的input失去焦点时校验
  1636. * @param {string} selector 表单的selector
  1637. * @param {Object=} options 配置项
  1638. * @param {object=} options.regexp 表单所需的正则表达式
  1639. *
  1640. * @example
  1641. * weui.form.checkIfBlur('#form', {
  1642. * regexp: {
  1643. * IDNUM: /(?:^\d{15}$)|(?:^\d{18}$)|^\d{17}[\dXx]$/,
  1644. * VCODE: /^.{4}$/
  1645. * }
  1646. * });
  1647. */
  1648. function checkIfBlur(selector) {
  1649. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1650. var $eles = (0, _util2.default)(selector);
  1651. $eles.forEach(function (ele) {
  1652. var $form = (0, _util2.default)(ele);
  1653. $form.find('[required]').on('blur', function () {
  1654. // checkbox 和 radio 不做blur检测,以免误触发
  1655. if (this.type == 'checkbox' || this.type == 'radio') return;
  1656. var $this = (0, _util2.default)(this);
  1657. if ($this.val().length < 1) return; // 当空的时候不校验,以防不断弹出toptips
  1658. var errorMsg = _validate($this, $form, options.regexp);
  1659. if (errorMsg) {
  1660. showErrorTips({
  1661. ele: $this[0],
  1662. msg: errorMsg
  1663. });
  1664. }
  1665. }).on('focus', function () {
  1666. hideErrorTips(this);
  1667. });
  1668. });
  1669. return this;
  1670. }
  1671. /**
  1672. * showErrorTips 显示错误提示
  1673. * @param {Object} error 错误数据
  1674. * @param {string} error.ele 出错了的dom元素
  1675. * @param {string} error.msg 出错了的msg。会根据此`msg`找到对应的`Tips`(比如`msg`是`empty`),那么`ele`上的`emptyTips`就会以`topTips`显示
  1676. *
  1677. * @example
  1678. * weui.form.showErrorTips({
  1679. * ele: document.getElementById("xxxInput")
  1680. * msg: 'empty'
  1681. * });
  1682. */
  1683. function showErrorTips(error) {
  1684. if (error) {
  1685. var $ele = (0, _util2.default)(error.ele),
  1686. msg = error.msg,
  1687. tips = $ele.attr(msg + 'Tips') || $ele.attr('tips') || $ele.attr('placeholder');
  1688. if (tips) (0, _topTips2.default)(tips);
  1689. if (error.ele.type == 'checkbox' || error.ele.type == 'radio') return;
  1690. var cellParent = _findCellParent(error.ele);
  1691. if (cellParent) cellParent.classList.add('weui-cell_warn');
  1692. }
  1693. }
  1694. /**
  1695. * hideErrorTips 隐藏错误提示
  1696. * @param {Object} ele dom元素
  1697. *
  1698. * @example
  1699. * weui.form.hideErrorTips(document.getElementById("xxxInput"));
  1700. */
  1701. function hideErrorTips(ele) {
  1702. var cellParent = _findCellParent(ele);
  1703. if (cellParent) cellParent.classList.remove('weui-cell_warn');
  1704. }
  1705. exports.default = {
  1706. showErrorTips: showErrorTips,
  1707. hideErrorTips: hideErrorTips,
  1708. validate: validate,
  1709. checkIfBlur: checkIfBlur
  1710. };
  1711. module.exports = exports['default'];
  1712. /***/ }),
  1713. /* 20 */
  1714. /***/ (function(module, exports, __webpack_require__) {
  1715. 'use strict';
  1716. Object.defineProperty(exports, "__esModule", {
  1717. value: true
  1718. });
  1719. var _util = __webpack_require__(2);
  1720. var _util2 = _interopRequireDefault(_util);
  1721. var _item = __webpack_require__(21);
  1722. var _item2 = _interopRequireDefault(_item);
  1723. var _image = __webpack_require__(22);
  1724. var _upload = __webpack_require__(23);
  1725. var _upload2 = _interopRequireDefault(_upload);
  1726. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1727. /*
  1728. * Tencent is pleased to support the open source community by making WeUI.js available.
  1729. *
  1730. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  1731. *
  1732. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  1733. * with the License. You may obtain a copy of the License at
  1734. *
  1735. * http://opensource.org/licenses/MIT
  1736. *
  1737. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  1738. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  1739. * either express or implied. See the License for the specific language governing permissions and
  1740. * limitations under the License.
  1741. */
  1742. var _id = 0;
  1743. /**
  1744. * uploader 上传组件
  1745. * @param {string} selector 上传组件的selector
  1746. * @param {object} options 配置项
  1747. * @param {string} [options.url] 上传的url,返回值需要使用json格式
  1748. * @param {boolean} [options.auto=true] 设置为`true`后,不需要手动调用上传,有文件选择即开始上传。用this.upload()来上传,详情请看example
  1749. * @param {string} [options.type=file] 上传类型, `file`为文件上传; `base64`为以base64上传
  1750. * @param {string=} [options.fileVal=file] 文件上传域的name
  1751. * @param {object=} [options.compress] 压缩配置, `false`则不压缩
  1752. * @param {number=} [options.compress.width=1600] 图片的最大宽度
  1753. * @param {number=} [options.compress.height=1600] 图片的最大高度
  1754. * @param {number=} [options.compress.quality=.8] 压缩质量, 取值范围 0 ~ 1
  1755. * @param {function=} [options.onBeforeQueued] 文件添加前的回调,return false则不添加
  1756. * @param {function=} [options.onQueued] 文件添加成功的回调
  1757. * @param {function=} [options.onBeforeSend] 文件上传前调用,具体参数看example
  1758. * @param {function=} [options.onSuccess] 上传成功的回调
  1759. * @param {function=} [options.onProgress] 上传进度的回调
  1760. * @param {function=} [options.onError] 上传失败的回调
  1761. *
  1762. * @example
  1763. * #### html
  1764. * ```html
  1765. <div class="weui-cells weui-cells_form" id="uploader">
  1766. <div class="weui-cell">
  1767. <div class="weui-cell__bd">
  1768. <div class="weui-uploader">
  1769. <div class="weui-uploader__hd">
  1770. <p class="weui-uploader__title">图片上传</p>
  1771. <div class="weui-uploader__info"><span id="uploadCount">0</span>/5</div>
  1772. </div>
  1773. <div class="weui-uploader__bd">
  1774. <ul class="weui-uploader__files" id="uploaderFiles"></ul>
  1775. <div class="weui-uploader__input-box">
  1776. <input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" capture="camera" multiple="" />
  1777. </div>
  1778. </div>
  1779. </div>
  1780. </div>
  1781. </div>
  1782. </div>
  1783. * ```
  1784. *
  1785. * #### js
  1786. * ```javascript
  1787. * var uploadCount = 0;
  1788. * weui.uploader('#uploader', {
  1789. * url: 'http://localhost:8081',
  1790. * auto: true,
  1791. * type: 'file',
  1792. * fileVal: 'fileVal',
  1793. * compress: {
  1794. * width: 1600,
  1795. * height: 1600,
  1796. * quality: .8
  1797. * },
  1798. * onBeforeQueued: function(files) {
  1799. * // `this` 是轮询到的文件, `files` 是所有文件
  1800. *
  1801. * if(["image/jpg", "image/jpeg", "image/png", "image/gif"].indexOf(this.type) < 0){
  1802. * weui.alert('请上传图片');
  1803. * return false; // 阻止文件添加
  1804. * }
  1805. * if(this.size > 10 * 1024 * 1024){
  1806. * weui.alert('请上传不超过10M的图片');
  1807. * return false;
  1808. * }
  1809. * if (files.length > 5) { // 防止一下子选择过多文件
  1810. * weui.alert('最多只能上传5张图片,请重新选择');
  1811. * return false;
  1812. * }
  1813. * if (uploadCount + 1 > 5) {
  1814. * weui.alert('最多只能上传5张图片');
  1815. * return false;
  1816. * }
  1817. *
  1818. * ++uploadCount;
  1819. *
  1820. * // return true; // 阻止默认行为,不插入预览图的框架
  1821. * },
  1822. * onQueued: function(){
  1823. * console.log(this);
  1824. *
  1825. * // console.log(this.status); // 文件的状态:'ready', 'progress', 'success', 'fail'
  1826. * // console.log(this.base64); // 如果是base64上传,file.base64可以获得文件的base64
  1827. *
  1828. * // this.upload(); // 如果是手动上传,这里可以通过调用upload来实现;也可以用它来实现重传。
  1829. * // this.stop(); // 中断上传
  1830. *
  1831. * // return true; // 阻止默认行为,不显示预览图的图像
  1832. * },
  1833. * onBeforeSend: function(data, headers){
  1834. * console.log(this, data, headers);
  1835. * // $.extend(data, { test: 1 }); // 可以扩展此对象来控制上传参数
  1836. * // $.extend(headers, { Origin: 'http://127.0.0.1' }); // 可以扩展此对象来控制上传头部
  1837. *
  1838. * // return false; // 阻止文件上传
  1839. * },
  1840. * onProgress: function(percent){
  1841. * console.log(this, percent);
  1842. * // return true; // 阻止默认行为,不使用默认的进度显示
  1843. * },
  1844. * onSuccess: function (ret) {
  1845. * console.log(this, ret);
  1846. * // return true; // 阻止默认行为,不使用默认的成功态
  1847. * },
  1848. * onError: function(err){
  1849. * console.log(this, err);
  1850. * // return true; // 阻止默认行为,不使用默认的失败态
  1851. * }
  1852. * });
  1853. * ```
  1854. */
  1855. function uploader(selector, options) {
  1856. var $uploader = (0, _util2.default)(selector);
  1857. var URL = window.URL || window.webkitURL || window.mozURL;
  1858. // 找到DOM里file-content,若无,则插入一个。
  1859. function findFileCtn($uploader, id) {
  1860. var $file = $uploader.find('[data-id="' + id + '"]');
  1861. var $fileCtn = $file.find('.weui-uploader__file-content');
  1862. if (!$fileCtn.length) {
  1863. $fileCtn = (0, _util2.default)('<div class="weui-uploader__file-content"></div>');
  1864. $file.append($fileCtn);
  1865. }
  1866. $file.addClass('weui-uploader__file_status');
  1867. return $fileCtn;
  1868. }
  1869. // 清除DOM里的上传状态
  1870. function clearFileStatus($uploader, id) {
  1871. var $file = $uploader.find('[data-id="' + id + '"]').removeClass('weui-uploader__file_status');
  1872. $file.find('.weui-uploader__file-content').remove();
  1873. }
  1874. // 设置上传
  1875. function setUploadFile(file) {
  1876. file.url = URL.createObjectURL(file);
  1877. file.status = 'ready';
  1878. file.upload = function () {
  1879. (0, _upload2.default)(_util2.default.extend({
  1880. $uploader: $uploader,
  1881. file: file
  1882. }, options));
  1883. };
  1884. file.stop = function () {
  1885. this.xhr.abort();
  1886. };
  1887. options.onQueued(file);
  1888. if (options.auto) file.upload();
  1889. }
  1890. options = _util2.default.extend({
  1891. url: '',
  1892. auto: true,
  1893. type: 'file',
  1894. fileVal: 'file',
  1895. xhrFields: {},
  1896. onBeforeQueued: _util2.default.noop,
  1897. onQueued: _util2.default.noop,
  1898. onBeforeSend: _util2.default.noop,
  1899. onSuccess: _util2.default.noop,
  1900. onProgress: _util2.default.noop,
  1901. onError: _util2.default.noop
  1902. }, options);
  1903. if (options.compress !== false) {
  1904. options.compress = _util2.default.extend({
  1905. width: 1600,
  1906. height: 1600,
  1907. quality: .8
  1908. }, options.compress);
  1909. }
  1910. if (options.onBeforeQueued) {
  1911. var onBeforeQueued = options.onBeforeQueued;
  1912. options.onBeforeQueued = function (file, files) {
  1913. var ret = onBeforeQueued.call(file, files);
  1914. if (ret === false) {
  1915. return false;
  1916. }
  1917. if (ret === true) {
  1918. return;
  1919. }
  1920. var $item = (0, _util2.default)(_util2.default.render(_item2.default, {
  1921. id: file.id
  1922. }));
  1923. $uploader.find('.weui-uploader__files').append($item);
  1924. };
  1925. }
  1926. if (options.onQueued) {
  1927. var onQueued = options.onQueued;
  1928. options.onQueued = function (file) {
  1929. if (!onQueued.call(file)) {
  1930. var $file = $uploader.find('[data-id="' + file.id + '"]');
  1931. $file.css({
  1932. backgroundImage: 'url("' + (file.base64 || file.url) + '")'
  1933. });
  1934. if (!options.auto) {
  1935. clearFileStatus($uploader, file.id);
  1936. }
  1937. }
  1938. };
  1939. }
  1940. if (options.onBeforeSend) {
  1941. var onBeforeSend = options.onBeforeSend;
  1942. options.onBeforeSend = function (file, data, headers) {
  1943. var ret = onBeforeSend.call(file, data, headers);
  1944. if (ret === false) {
  1945. return false;
  1946. }
  1947. };
  1948. }
  1949. if (options.onSuccess) {
  1950. var onSuccess = options.onSuccess;
  1951. options.onSuccess = function (file, ret) {
  1952. file.status = 'success';
  1953. if (!onSuccess.call(file, ret)) {
  1954. clearFileStatus($uploader, file.id);
  1955. }
  1956. };
  1957. }
  1958. if (options.onProgress) {
  1959. var onProgress = options.onProgress;
  1960. options.onProgress = function (file, percent) {
  1961. if (!onProgress.call(file, percent)) {
  1962. findFileCtn($uploader, file.id).html(percent + '%');
  1963. }
  1964. };
  1965. }
  1966. if (options.onError) {
  1967. var onError = options.onError;
  1968. options.onError = function (file, err) {
  1969. file.status = 'fail';
  1970. if (!onError.call(file, err)) {
  1971. findFileCtn($uploader, file.id).html('<i class="weui-icon-warn"></i>');
  1972. }
  1973. };
  1974. }
  1975. $uploader.find('input[type="file"]').on('change', function (evt) {
  1976. var files = evt.target.files;
  1977. if (files.length === 0) {
  1978. return;
  1979. }
  1980. if (options.compress === false && options.type == 'file') {
  1981. // 以原文件方式上传
  1982. Array.prototype.forEach.call(files, function (file) {
  1983. file.id = ++_id;
  1984. if (options.onBeforeQueued(file, files) === false) return;
  1985. setUploadFile(file);
  1986. });
  1987. } else {
  1988. // base64上传 和 压缩上传
  1989. Array.prototype.forEach.call(files, function (file) {
  1990. file.id = ++_id;
  1991. if (options.onBeforeQueued(file, files) === false) return;
  1992. (0, _image.compress)(file, options, function (blob) {
  1993. if (blob) setUploadFile(blob);
  1994. });
  1995. });
  1996. }
  1997. this.value = '';
  1998. });
  1999. }
  2000. exports.default = uploader;
  2001. module.exports = exports['default'];
  2002. /***/ }),
  2003. /* 21 */
  2004. /***/ (function(module, exports) {
  2005. module.exports = "<li class=\"weui-uploader__file weui-uploader__file_status\" data-id=\"<%= id %>\"> <div class=weui-uploader__file-content> <i class=weui-loading style=width:30px;height:30px></i> </div> </li> ";
  2006. /***/ }),
  2007. /* 22 */
  2008. /***/ (function(module, exports) {
  2009. 'use strict';
  2010. Object.defineProperty(exports, "__esModule", {
  2011. value: true
  2012. });
  2013. /*
  2014. * Tencent is pleased to support the open source community by making WeUI.js available.
  2015. *
  2016. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  2017. *
  2018. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  2019. * with the License. You may obtain a copy of the License at
  2020. *
  2021. * http://opensource.org/licenses/MIT
  2022. *
  2023. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  2024. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  2025. * either express or implied. See the License for the specific language governing permissions and
  2026. * limitations under the License.
  2027. */
  2028. /**
  2029. * 检查图片是否有被压扁,如果有,返回比率
  2030. * ref to http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
  2031. */
  2032. function detectVerticalSquash(img) {
  2033. // 拍照在IOS7或以下的机型会出现照片被压扁的bug
  2034. var data;
  2035. var ih = img.naturalHeight;
  2036. var canvas = document.createElement('canvas');
  2037. canvas.width = 1;
  2038. canvas.height = ih;
  2039. var ctx = canvas.getContext('2d');
  2040. ctx.drawImage(img, 0, 0);
  2041. try {
  2042. data = ctx.getImageData(0, 0, 1, ih).data;
  2043. } catch (err) {
  2044. console.log('Cannot check verticalSquash: CORS?');
  2045. return 1;
  2046. }
  2047. var sy = 0;
  2048. var ey = ih;
  2049. var py = ih;
  2050. while (py > sy) {
  2051. var alpha = data[(py - 1) * 4 + 3];
  2052. if (alpha === 0) {
  2053. ey = py;
  2054. } else {
  2055. sy = py;
  2056. }
  2057. py = ey + sy >> 1; // py = parseInt((ey + sy) / 2)
  2058. }
  2059. var ratio = py / ih;
  2060. return ratio === 0 ? 1 : ratio;
  2061. }
  2062. /**
  2063. * dataURI to blob, ref to https://gist.github.com/fupslot/5015897
  2064. * @param dataURI
  2065. */
  2066. function dataURItoBuffer(dataURI) {
  2067. var byteString = atob(dataURI.split(',')[1]);
  2068. var buffer = new ArrayBuffer(byteString.length);
  2069. var view = new Uint8Array(buffer);
  2070. for (var i = 0; i < byteString.length; i++) {
  2071. view[i] = byteString.charCodeAt(i);
  2072. }
  2073. return buffer;
  2074. }
  2075. function dataURItoBlob(dataURI) {
  2076. var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
  2077. var buffer = dataURItoBuffer(dataURI);
  2078. return new Blob([buffer], { type: mimeString });
  2079. }
  2080. /**
  2081. * 获取图片的orientation
  2082. * ref to http://stackoverflow.com/questions/7584794/accessing-jpeg-exif-rotation-data-in-javascript-on-the-client-side
  2083. */
  2084. function getOrientation(buffer) {
  2085. var view = new DataView(buffer);
  2086. if (view.getUint16(0, false) != 0xFFD8) return -2;
  2087. var length = view.byteLength,
  2088. offset = 2;
  2089. while (offset < length) {
  2090. var marker = view.getUint16(offset, false);
  2091. offset += 2;
  2092. if (marker == 0xFFE1) {
  2093. if (view.getUint32(offset += 2, false) != 0x45786966) return -1;
  2094. var little = view.getUint16(offset += 6, false) == 0x4949;
  2095. offset += view.getUint32(offset + 4, little);
  2096. var tags = view.getUint16(offset, little);
  2097. offset += 2;
  2098. for (var i = 0; i < tags; i++) {
  2099. if (view.getUint16(offset + i * 12, little) == 0x0112) return view.getUint16(offset + i * 12 + 8, little);
  2100. }
  2101. } else if ((marker & 0xFF00) != 0xFF00) break;else offset += view.getUint16(offset, false);
  2102. }
  2103. return -1;
  2104. }
  2105. /**
  2106. * 修正拍照时图片的方向
  2107. * ref to http://stackoverflow.com/questions/19463126/how-to-draw-photo-with-correct-orientation-in-canvas-after-capture-photo-by-usin
  2108. */
  2109. function orientationHelper(canvas, ctx, orientation) {
  2110. var w = canvas.width,
  2111. h = canvas.height;
  2112. if (orientation > 4) {
  2113. canvas.width = h;
  2114. canvas.height = w;
  2115. }
  2116. switch (orientation) {
  2117. case 2:
  2118. ctx.translate(w, 0);
  2119. ctx.scale(-1, 1);
  2120. break;
  2121. case 3:
  2122. ctx.translate(w, h);
  2123. ctx.rotate(Math.PI);
  2124. break;
  2125. case 4:
  2126. ctx.translate(0, h);
  2127. ctx.scale(1, -1);
  2128. break;
  2129. case 5:
  2130. ctx.rotate(0.5 * Math.PI);
  2131. ctx.scale(1, -1);
  2132. break;
  2133. case 6:
  2134. ctx.rotate(0.5 * Math.PI);
  2135. ctx.translate(0, -h);
  2136. break;
  2137. case 7:
  2138. ctx.rotate(0.5 * Math.PI);
  2139. ctx.translate(w, -h);
  2140. ctx.scale(-1, 1);
  2141. break;
  2142. case 8:
  2143. ctx.rotate(-0.5 * Math.PI);
  2144. ctx.translate(-w, 0);
  2145. break;
  2146. }
  2147. }
  2148. /**
  2149. * 压缩图片
  2150. */
  2151. function compress(file, options, callback) {
  2152. var reader = new FileReader();
  2153. reader.onload = function (evt) {
  2154. if (options.compress === false) {
  2155. // 不启用压缩 & base64上传 的分支,不做任何处理,直接返回文件的base64编码
  2156. file.base64 = evt.target.result;
  2157. callback(file);
  2158. return;
  2159. }
  2160. // 启用压缩的分支
  2161. var img = new Image();
  2162. img.onload = function () {
  2163. var ratio = detectVerticalSquash(img);
  2164. var orientation = getOrientation(dataURItoBuffer(img.src));
  2165. var canvas = document.createElement('canvas');
  2166. var ctx = canvas.getContext('2d');
  2167. var maxW = options.compress.width;
  2168. var maxH = options.compress.height;
  2169. var w = img.width;
  2170. var h = img.height;
  2171. var dataURL = void 0;
  2172. if (w < h && h > maxH) {
  2173. w = parseInt(maxH * img.width / img.height);
  2174. h = maxH;
  2175. } else if (w >= h && w > maxW) {
  2176. h = parseInt(maxW * img.height / img.width);
  2177. w = maxW;
  2178. }
  2179. canvas.width = w;
  2180. canvas.height = h;
  2181. if (orientation > 0) {
  2182. orientationHelper(canvas, ctx, orientation);
  2183. }
  2184. ctx.drawImage(img, 0, 0, w, h / ratio);
  2185. if (/image\/jpeg/.test(file.type) || /image\/jpg/.test(file.type)) {
  2186. dataURL = canvas.toDataURL('image/jpeg', options.compress.quality);
  2187. } else {
  2188. dataURL = canvas.toDataURL(file.type);
  2189. }
  2190. if (options.type == 'file') {
  2191. if (/;base64,null/.test(dataURL) || /;base64,$/.test(dataURL)) {
  2192. // 压缩出错,以文件方式上传的,采用原文件上传
  2193. console.warn('Compress fail, dataURL is ' + dataURL + '. Next will use origin file to upload.');
  2194. callback(file);
  2195. } else {
  2196. var blob = dataURItoBlob(dataURL);
  2197. blob.id = file.id;
  2198. blob.name = file.name;
  2199. blob.lastModified = file.lastModified;
  2200. blob.lastModifiedDate = file.lastModifiedDate;
  2201. callback(blob);
  2202. }
  2203. } else {
  2204. if (/;base64,null/.test(dataURL) || /;base64,$/.test(dataURL)) {
  2205. // 压缩失败,以base64上传的,直接报错不上传
  2206. options.onError(file, new Error('Compress fail, dataURL is ' + dataURL + '.'));
  2207. callback();
  2208. } else {
  2209. file.base64 = dataURL;
  2210. callback(file);
  2211. }
  2212. }
  2213. };
  2214. img.src = evt.target.result;
  2215. };
  2216. reader.readAsDataURL(file);
  2217. }
  2218. exports.default = {
  2219. compress: compress
  2220. };
  2221. module.exports = exports['default'];
  2222. /***/ }),
  2223. /* 23 */
  2224. /***/ (function(module, exports) {
  2225. 'use strict';
  2226. Object.defineProperty(exports, "__esModule", {
  2227. value: true
  2228. });
  2229. exports.default = upload;
  2230. /*
  2231. * Tencent is pleased to support the open source community by making WeUI.js available.
  2232. *
  2233. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  2234. *
  2235. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  2236. * with the License. You may obtain a copy of the License at
  2237. *
  2238. * http://opensource.org/licenses/MIT
  2239. *
  2240. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  2241. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  2242. * either express or implied. See the License for the specific language governing permissions and
  2243. * limitations under the License.
  2244. */
  2245. function upload(options) {
  2246. var url = options.url,
  2247. file = options.file,
  2248. fileVal = options.fileVal,
  2249. onBeforeSend = options.onBeforeSend,
  2250. onProgress = options.onProgress,
  2251. onError = options.onError,
  2252. onSuccess = options.onSuccess,
  2253. xhrFields = options.xhrFields;
  2254. var name = file.name,
  2255. type = file.type,
  2256. lastModifiedDate = file.lastModifiedDate;
  2257. var data = {
  2258. name: name,
  2259. type: type,
  2260. size: options.type == 'file' ? file.size : file.base64.length,
  2261. lastModifiedDate: lastModifiedDate
  2262. };
  2263. var headers = {};
  2264. if (onBeforeSend(file, data, headers) === false) return;
  2265. file.status = 'progress';
  2266. onProgress(file, 0);
  2267. var formData = new FormData();
  2268. var xhr = new XMLHttpRequest();
  2269. file.xhr = xhr;
  2270. // 设置参数
  2271. Object.keys(data).forEach(function (key) {
  2272. formData.append(key, data[key]);
  2273. });
  2274. if (options.type == 'file') {
  2275. formData.append(fileVal, file, name);
  2276. } else {
  2277. formData.append(fileVal, file.base64);
  2278. }
  2279. xhr.onreadystatechange = function () {
  2280. if (xhr.readyState == 4) {
  2281. if (xhr.status == 200) {
  2282. try {
  2283. // 只支持json
  2284. var ret = JSON.parse(xhr.responseText);
  2285. onSuccess(file, ret);
  2286. } catch (err) {
  2287. onError(file, err);
  2288. }
  2289. } else {
  2290. onError(file, new Error('XMLHttpRequest response status is ' + xhr.status));
  2291. }
  2292. }
  2293. };
  2294. xhr.upload.addEventListener('progress', function (evt) {
  2295. if (evt.total == 0) return;
  2296. var percent = Math.ceil(evt.loaded / evt.total) * 100;
  2297. onProgress(file, percent);
  2298. }, false);
  2299. xhr.open('POST', url);
  2300. Object.keys(xhrFields).forEach(function (key) {
  2301. xhr[key] = xhrFields[key];
  2302. });
  2303. // 设置头部信息
  2304. Object.keys(headers).forEach(function (key) {
  2305. xhr.setRequestHeader(key, headers[key]);
  2306. });
  2307. xhr.send(formData);
  2308. }
  2309. module.exports = exports['default'];
  2310. /***/ }),
  2311. /* 24 */
  2312. /***/ (function(module, exports, __webpack_require__) {
  2313. 'use strict';
  2314. Object.defineProperty(exports, "__esModule", {
  2315. value: true
  2316. });
  2317. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /*
  2318. * Tencent is pleased to support the open source community by making WeUI.js available.
  2319. *
  2320. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  2321. *
  2322. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  2323. * with the License. You may obtain a copy of the License at
  2324. *
  2325. * http://opensource.org/licenses/MIT
  2326. *
  2327. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  2328. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  2329. * either express or implied. See the License for the specific language governing permissions and
  2330. * limitations under the License.
  2331. */
  2332. var _util = __webpack_require__(2);
  2333. var _util2 = _interopRequireDefault(_util);
  2334. var _cron = __webpack_require__(25);
  2335. var _cron2 = _interopRequireDefault(_cron);
  2336. __webpack_require__(26);
  2337. var _util3 = __webpack_require__(27);
  2338. var util = _interopRequireWildcard(_util3);
  2339. var _picker = __webpack_require__(28);
  2340. var _picker2 = _interopRequireDefault(_picker);
  2341. var _group = __webpack_require__(29);
  2342. var _group2 = _interopRequireDefault(_group);
  2343. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  2344. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  2345. function Result(item) {
  2346. if ((typeof item === 'undefined' ? 'undefined' : _typeof(item)) != 'object') {
  2347. item = {
  2348. label: item,
  2349. value: item
  2350. };
  2351. }
  2352. _util2.default.extend(this, item);
  2353. }
  2354. Result.prototype.toString = function () {
  2355. return this.value;
  2356. };
  2357. Result.prototype.valueOf = function () {
  2358. return this.value;
  2359. };
  2360. var _sington = void 0;
  2361. var temp = {}; // temp 存在上一次滑动的位置
  2362. /**
  2363. * picker 多列选择器。
  2364. * @param {array} items picker的数据,即用于生成picker的数据,picker的层级可以自己定义,但建议最多三层。数据格式参考example。
  2365. * @param {Object} options 配置项
  2366. * @param {number=} [options.depth] picker深度(也就是picker有多少列) 取值为1-3。如果为空,则取items第一项的深度。
  2367. * @param {string=} [options.id=default] 作为picker的唯一标识,作用是以id缓存当时的选择。(当你想每次传入的defaultValue都是不一样时,可以使用不同的id区分)
  2368. * @param {string=} [options.className] 自定义类名
  2369. * @param {string=} [options.container] 指定容器
  2370. * @param {array=} [options.defaultValue] 默认选项的value数组
  2371. * @param {function=} [options.onChange] 在picker选中的值发生变化的时候回调
  2372. * @param {function=} [options.onConfirm] 在点击"确定"之后的回调。回调返回选中的结果(Array),数组长度依赖于picker的层级。
  2373. * @param {function=} [options.onClose] picker关闭后的回调
  2374. *
  2375. * @example
  2376. * // 单列picker
  2377. * weui.picker([
  2378. * {
  2379. * label: '飞机票',
  2380. * value: 0,
  2381. * disabled: true // 不可用
  2382. * },
  2383. * {
  2384. * label: '火车票',
  2385. * value: 1
  2386. * },
  2387. * {
  2388. * label: '汽车票',
  2389. * value: 3
  2390. * },
  2391. * {
  2392. * label: '公车票',
  2393. * value: 4,
  2394. * }
  2395. * ], {
  2396. * className: 'custom-classname',
  2397. * container: 'body',
  2398. * defaultValue: [3],
  2399. * onChange: function (result) {
  2400. * console.log(result)
  2401. * },
  2402. * onConfirm: function (result) {
  2403. * console.log(result)
  2404. * },
  2405. * id: 'singleLinePicker'
  2406. * });
  2407. *
  2408. * @example
  2409. * // 多列picker
  2410. * weui.picker([
  2411. * {
  2412. * label: '1',
  2413. * value: '1'
  2414. * }, {
  2415. * label: '2',
  2416. * value: '2'
  2417. * }, {
  2418. * label: '3',
  2419. * value: '3'
  2420. * }
  2421. * ], [
  2422. * {
  2423. * label: 'A',
  2424. * value: 'A'
  2425. * }, {
  2426. * label: 'B',
  2427. * value: 'B'
  2428. * }, {
  2429. * label: 'C',
  2430. * value: 'C'
  2431. * }
  2432. * ], {
  2433. * defaultValue: ['3', 'A'],
  2434. * onChange: function (result) {
  2435. * console.log(result);
  2436. * },
  2437. * onConfirm: function (result) {
  2438. * console.log(result);
  2439. * },
  2440. * id: 'multiPickerBtn'
  2441. * });
  2442. *
  2443. * @example
  2444. * // 级联picker
  2445. * weui.picker([
  2446. * {
  2447. * label: '飞机票',
  2448. * value: 0,
  2449. * children: [
  2450. * {
  2451. * label: '经济舱',
  2452. * value: 1
  2453. * },
  2454. * {
  2455. * label: '商务舱',
  2456. * value: 2
  2457. * }
  2458. * ]
  2459. * },
  2460. * {
  2461. * label: '火车票',
  2462. * value: 1,
  2463. * children: [
  2464. * {
  2465. * label: '卧铺',
  2466. * value: 1,
  2467. * disabled: true // 不可用
  2468. * },
  2469. * {
  2470. * label: '坐票',
  2471. * value: 2
  2472. * },
  2473. * {
  2474. * label: '站票',
  2475. * value: 3
  2476. * }
  2477. * ]
  2478. * },
  2479. * {
  2480. * label: '汽车票',
  2481. * value: 3,
  2482. * children: [
  2483. * {
  2484. * label: '快班',
  2485. * value: 1
  2486. * },
  2487. * {
  2488. * label: '普通',
  2489. * value: 2
  2490. * }
  2491. * ]
  2492. * }
  2493. * ], {
  2494. * className: 'custom-classname',
  2495. * container: 'body',
  2496. * defaultValue: [1, 3],
  2497. * onChange: function (result) {
  2498. * console.log(result)
  2499. * },
  2500. * onConfirm: function (result) {
  2501. * console.log(result)
  2502. * },
  2503. * id: 'doubleLinePicker'
  2504. * });
  2505. */
  2506. function picker() {
  2507. if (_sington) return _sington;
  2508. // 配置项
  2509. var options = arguments[arguments.length - 1];
  2510. var defaults = _util2.default.extend({
  2511. id: 'default',
  2512. className: '',
  2513. container: 'body',
  2514. title: '',
  2515. onChange: _util2.default.noop,
  2516. onConfirm: _util2.default.noop,
  2517. onClose: _util2.default.noop
  2518. }, options);
  2519. // 数据处理
  2520. var items = void 0;
  2521. var isMulti = false; // 是否多列的类型
  2522. if (arguments.length > 2) {
  2523. var i = 0;
  2524. items = [];
  2525. while (i < arguments.length - 1) {
  2526. items.push(arguments[i++]);
  2527. }
  2528. isMulti = true;
  2529. } else {
  2530. items = arguments[0];
  2531. }
  2532. // 获取缓存
  2533. temp[defaults.id] = temp[defaults.id] || [];
  2534. var result = [];
  2535. var lineTemp = temp[defaults.id];
  2536. var $picker = (0, _util2.default)(_util2.default.render(_picker2.default, defaults));
  2537. var depth = options.depth || (isMulti ? items.length : util.depthOf(items[0])),
  2538. groups = '';
  2539. // 显示与隐藏的方法
  2540. function show() {
  2541. (0, _util2.default)(defaults.container).append($picker);
  2542. // 这里获取一下计算后的样式,强制触发渲染. fix IOS10下闪现的问题
  2543. _util2.default.getStyle($picker[0], 'transform');
  2544. //更改标题
  2545. $picker.find('.weui-half-screen-dialog__title').html(defaults.title);
  2546. $picker.find('.weui-mask').addClass('weui-animate-fade-in');
  2547. $picker.find('.weui-picker').addClass('weui-animate-slide-up');
  2548. }
  2549. function _hide(callback) {
  2550. _hide = _util2.default.noop; // 防止二次调用导致报错
  2551. $picker.find('.weui-mask').addClass('weui-animate-fade-out');
  2552. $picker.find('.weui-picker').addClass('weui-animate-slide-down').on('animationend webkitAnimationEnd', function () {
  2553. $picker.remove();
  2554. _sington = false;
  2555. defaults.onClose();
  2556. callback && callback();
  2557. });
  2558. }
  2559. function hide(callback) {
  2560. _hide(callback);
  2561. }
  2562. // 初始化滚动的方法
  2563. function scroll(items, level) {
  2564. if (lineTemp[level] === undefined && defaults.defaultValue && defaults.defaultValue[level] !== undefined) {
  2565. // 没有缓存选项,而且存在defaultValue
  2566. var defaultVal = defaults.defaultValue[level];
  2567. var index = 0,
  2568. len = items.length;
  2569. if (_typeof(items[index]) == 'object') {
  2570. for (; index < len; ++index) {
  2571. if (defaultVal == items[index].value) break;
  2572. }
  2573. } else {
  2574. for (; index < len; ++index) {
  2575. if (defaultVal == items[index]) break;
  2576. }
  2577. }
  2578. if (index < len) {
  2579. lineTemp[level] = index;
  2580. } else {
  2581. console.warn('Picker has not match defaultValue: ' + defaultVal);
  2582. }
  2583. }
  2584. $picker.find('.weui-picker__group').eq(level).scroll({
  2585. items: items,
  2586. temp: lineTemp[level],
  2587. onChange: function onChange(item, index) {
  2588. //为当前的result赋值。
  2589. if (item) {
  2590. result[level] = new Result(item);
  2591. } else {
  2592. result[level] = null;
  2593. }
  2594. lineTemp[level] = index;
  2595. if (isMulti) {
  2596. if (result.length == depth) {
  2597. defaults.onChange(result);
  2598. }
  2599. } else {
  2600. /**
  2601. * @子列表处理
  2602. * 1. 在没有子列表,或者值列表的数组长度为0时,隐藏掉子列表。
  2603. * 2. 滑动之后发现重新有子列表时,再次显示子列表。
  2604. *
  2605. * @回调处理
  2606. * 1. 因为滑动实际上是一层一层传递的:父列表滚动完成之后,会call子列表的onChange,从而带动子列表的滑动。
  2607. * 2. 所以,使用者的传进来onChange回调应该在最后一个子列表滑动时再call
  2608. */
  2609. if (item.children && item.children.length > 0) {
  2610. $picker.find('.weui-picker__group').eq(level + 1).show();
  2611. !isMulti && scroll(item.children, level + 1); // 不是多列的情况下才继续处理children
  2612. } else {
  2613. //如果子列表test不通过,子孙列表都隐藏。
  2614. var $items = $picker.find('.weui-picker__group');
  2615. $items.forEach(function (ele, index) {
  2616. if (index > level) {
  2617. (0, _util2.default)(ele).hide();
  2618. }
  2619. });
  2620. result.splice(level + 1);
  2621. defaults.onChange(result);
  2622. }
  2623. }
  2624. },
  2625. onConfirm: defaults.onConfirm
  2626. });
  2627. }
  2628. var _depth = depth;
  2629. while (_depth--) {
  2630. groups += _group2.default;
  2631. }
  2632. $picker.find('.weui-picker__bd').html(groups);
  2633. show();
  2634. if (isMulti) {
  2635. items.forEach(function (item, index) {
  2636. scroll(item, index);
  2637. });
  2638. } else {
  2639. scroll(items, 0);
  2640. }
  2641. $picker.on('click', '.weui-mask', function () {
  2642. hide();
  2643. }).on('click', '.weui-picker__btn', function () {
  2644. hide();
  2645. }).on('click', '#weui-picker-confirm', function () {
  2646. defaults.onConfirm(result);
  2647. });
  2648. _sington = $picker[0];
  2649. _sington.hide = hide;
  2650. return _sington;
  2651. }
  2652. /**
  2653. * datePicker 时间选择器,由picker拓展而来,提供年、月、日的选择。
  2654. * @param options 配置项
  2655. * @param {string=} [options.id=datePicker] 作为picker的唯一标识
  2656. * @param {number=|string|Date} [options.start=2000] 起始年份,如果是 `Number` 类型,表示起始年份;如果是 `String` 类型,格式为 'YYYY-MM-DD';如果是 `Date` 类型,就传一个 Date
  2657. * @param {number=|string|Date} [options.end=2030] 结束年份,同上
  2658. * @param {string=} [options.cron=* * *] cron 表达式,三位,分别是 dayOfMonth[1-31],month[1-12] 和 dayOfWeek[0-6](周日-周六)
  2659. * @param {string=} [options.className] 自定义类名
  2660. * @param {array=} [options.defaultValue] 默认选项的value数组, 如 [1991, 6, 9]
  2661. * @param {function=} [options.onChange] 在picker选中的值发生变化的时候回调
  2662. * @param {function=} [options.onConfirm] 在点击"确定"之后的回调。回调返回选中的结果(Array),数组长度依赖于picker的层级。
  2663. *
  2664. *@example
  2665. * // 示例1:
  2666. * weui.datePicker({
  2667. * start: 1990,
  2668. * end: 2000,
  2669. * defaultValue: [1991, 6, 9],
  2670. * onChange: function(result){
  2671. * console.log(result);
  2672. * },
  2673. * onConfirm: function(result){
  2674. * console.log(result);
  2675. * },
  2676. * id: 'datePicker'
  2677. * });
  2678. *
  2679. * // 示例2:
  2680. * weui.datePicker({
  2681. * start: new Date(), // 从今天开始
  2682. * end: 2030,
  2683. * defaultValue: [2020, 6, 9],
  2684. * onChange: function(result){
  2685. * console.log(result);
  2686. * },
  2687. * onConfirm: function(result){
  2688. * console.log(result);
  2689. * },
  2690. * id: 'datePicker'
  2691. * });
  2692. *
  2693. * // 示例3:
  2694. * weui.datePicker({
  2695. * start: new Date(), // 从今天开始
  2696. * end: 2030,
  2697. * cron: '* * 0,6', // 每逢周日、周六
  2698. * onChange: function(result){
  2699. * console.log(result);
  2700. * },
  2701. * onConfirm: function(result){
  2702. * console.log(result);
  2703. * },
  2704. * id: 'datePicker'
  2705. * });
  2706. *
  2707. * // 示例4:
  2708. * weui.datePicker({
  2709. * start: new Date(), // 从今天开始
  2710. * end: 2030,
  2711. * cron: '1-10 * *', // 每月1日-10日
  2712. * onChange: function(result){
  2713. * console.log(result);
  2714. * },
  2715. * onConfirm: function(result){
  2716. * console.log(result);
  2717. * },
  2718. * id: 'datePicker'
  2719. * });
  2720. */
  2721. function datePicker(options) {
  2722. var nowDate = new Date();
  2723. var defaults = _util2.default.extend({
  2724. id: 'datePicker',
  2725. onChange: _util2.default.noop,
  2726. onConfirm: _util2.default.noop,
  2727. start: nowDate.getFullYear() - 20,
  2728. end: nowDate.getFullYear() + 20,
  2729. defaultValue: [nowDate.getFullYear(), nowDate.getMonth() + 1, nowDate.getDate()],
  2730. cron: '* * *'
  2731. }, options);
  2732. // 兼容原来的 start、end 传 Number 的用法
  2733. if (typeof defaults.start === 'number') {
  2734. defaults.start = new Date(defaults.start + '/01/01');
  2735. } else if (typeof defaults.start === 'string') {
  2736. defaults.start = new Date(defaults.start.replace(/-/g, '/'));
  2737. }
  2738. if (typeof defaults.end === 'number') {
  2739. defaults.end = new Date(defaults.end + '/12/31');
  2740. } else if (typeof defaults.end === 'string') {
  2741. defaults.end = new Date(defaults.end.replace(/-/g, '/'));
  2742. }
  2743. var findBy = function findBy(array, key, value) {
  2744. for (var i = 0, len = array.length; i < len; i++) {
  2745. var _obj = array[i];
  2746. if (_obj[key] == value) {
  2747. return _obj;
  2748. }
  2749. }
  2750. };
  2751. var date = [];
  2752. var interval = _cron2.default.parse(defaults.cron, defaults.start, defaults.end);
  2753. var obj = void 0;
  2754. do {
  2755. obj = interval.next();
  2756. var year = obj.value.getFullYear();
  2757. var month = obj.value.getMonth() + 1;
  2758. var day = obj.value.getDate();
  2759. var Y = findBy(date, 'value', year);
  2760. if (!Y) {
  2761. Y = {
  2762. label: year + '年',
  2763. value: year,
  2764. children: []
  2765. };
  2766. date.push(Y);
  2767. }
  2768. var M = findBy(Y.children, 'value', month);
  2769. if (!M) {
  2770. M = {
  2771. label: month + '月',
  2772. value: month,
  2773. children: []
  2774. };
  2775. Y.children.push(M);
  2776. }
  2777. M.children.push({
  2778. label: day + '日',
  2779. value: day
  2780. });
  2781. } while (!obj.done);
  2782. return picker(date, defaults);
  2783. }
  2784. exports.default = {
  2785. picker: picker,
  2786. datePicker: datePicker
  2787. };
  2788. module.exports = exports['default'];
  2789. /***/ }),
  2790. /* 25 */
  2791. /***/ (function(module, exports) {
  2792. 'use strict';
  2793. Object.defineProperty(exports, "__esModule", {
  2794. value: true
  2795. });
  2796. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  2797. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2798. /*
  2799. * Tencent is pleased to support the open source community by making WeUI.js available.
  2800. *
  2801. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  2802. *
  2803. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  2804. * with the License. You may obtain a copy of the License at
  2805. *
  2806. * http://opensource.org/licenses/MIT
  2807. *
  2808. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  2809. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  2810. * either express or implied. See the License for the specific language governing permissions and
  2811. * limitations under the License.
  2812. */
  2813. var regex = /^(\d+)(?:-(\d+))?(?:\/(\d+))?$/g;
  2814. var constraints = [[1, 31], [1, 12], [0, 6]];
  2815. /**
  2816. * Schedule
  2817. */
  2818. var Schedule = function () {
  2819. function Schedule(fields, start, end) {
  2820. _classCallCheck(this, Schedule);
  2821. /**
  2822. * dayOfMonth
  2823. * @type {Array}
  2824. */
  2825. this._dates = fields[0];
  2826. /**
  2827. * month
  2828. * @type {Array}
  2829. */
  2830. this._months = fields[1];
  2831. /**
  2832. * dayOfWeek
  2833. * @type {Array}
  2834. */
  2835. this._days = fields[2];
  2836. /**
  2837. * start
  2838. * @type {Date}
  2839. */
  2840. this._start = start;
  2841. /**
  2842. * end
  2843. * @type {Date}
  2844. */
  2845. this._end = end;
  2846. /**
  2847. * cursor
  2848. * @type {Date}
  2849. * @private
  2850. */
  2851. this._pointer = start;
  2852. }
  2853. _createClass(Schedule, [{
  2854. key: '_findNext',
  2855. value: function _findNext() {
  2856. var next = void 0;
  2857. while (true) {
  2858. if (this._end.getTime() - this._pointer.getTime() < 0) {
  2859. throw new Error('out of range, end is ' + this._end + ', current is ' + this._pointer);
  2860. }
  2861. var month = this._pointer.getMonth();
  2862. var date = this._pointer.getDate();
  2863. var day = this._pointer.getDay();
  2864. if (this._months.indexOf(month + 1) === -1) {
  2865. this._pointer.setMonth(month + 1);
  2866. this._pointer.setDate(1);
  2867. continue;
  2868. }
  2869. if (this._dates.indexOf(date) === -1) {
  2870. this._pointer.setDate(date + 1);
  2871. continue;
  2872. }
  2873. if (this._days.indexOf(day) === -1) {
  2874. this._pointer.setDate(date + 1);
  2875. continue;
  2876. }
  2877. next = new Date(this._pointer);
  2878. break;
  2879. }
  2880. return next;
  2881. }
  2882. /**
  2883. * fetch next data
  2884. */
  2885. }, {
  2886. key: 'next',
  2887. value: function next() {
  2888. var value = this._findNext();
  2889. // move next date
  2890. this._pointer.setDate(this._pointer.getDate() + 1);
  2891. return {
  2892. value: value,
  2893. done: !this.hasNext()
  2894. };
  2895. }
  2896. /**
  2897. * has next
  2898. * @returns {boolean}
  2899. */
  2900. }, {
  2901. key: 'hasNext',
  2902. value: function hasNext() {
  2903. try {
  2904. this._findNext();
  2905. return true;
  2906. } catch (e) {
  2907. return false;
  2908. }
  2909. }
  2910. }]);
  2911. return Schedule;
  2912. }();
  2913. function parseField(field, constraints) {
  2914. var low = constraints[0];
  2915. var high = constraints[1];
  2916. var result = [];
  2917. var pointer = void 0;
  2918. // * 号等于最低到最高
  2919. field = field.replace(/\*/g, low + '-' + high);
  2920. // 处理 1,2,5-9 这种情况
  2921. var fields = field.split(',');
  2922. for (var i = 0, len = fields.length; i < len; i++) {
  2923. var f = fields[i];
  2924. if (f.match(regex)) {
  2925. f.replace(regex, function ($0, lower, upper, step) {
  2926. // ref to `cron-parser`
  2927. step = parseInt(step) || 1;
  2928. // Positive integer higher than constraints[0]
  2929. lower = Math.min(Math.max(low, ~~Math.abs(lower)), high);
  2930. // Positive integer lower than constraints[1]
  2931. upper = upper ? Math.min(high, ~~Math.abs(upper)) : lower;
  2932. // Count from the lower barrier to the upper
  2933. pointer = lower;
  2934. do {
  2935. result.push(pointer);
  2936. pointer += step;
  2937. } while (pointer <= upper);
  2938. });
  2939. }
  2940. }
  2941. return result;
  2942. }
  2943. /**
  2944. *
  2945. * @param expr
  2946. * @param start
  2947. * @param end
  2948. * @returns {*}
  2949. */
  2950. function parse(expr, start, end) {
  2951. var atoms = expr.replace(/^\s\s*|\s\s*$/g, '').split(/\s+/);
  2952. var fields = [];
  2953. atoms.forEach(function (atom, index) {
  2954. var constraint = constraints[index];
  2955. fields.push(parseField(atom, constraint));
  2956. });
  2957. return new Schedule(fields, start, end);
  2958. }
  2959. exports.default = {
  2960. parse: parse
  2961. };
  2962. module.exports = exports['default'];
  2963. /***/ }),
  2964. /* 26 */
  2965. /***/ (function(module, exports, __webpack_require__) {
  2966. 'use strict';
  2967. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /*
  2968. * Tencent is pleased to support the open source community by making WeUI.js available.
  2969. *
  2970. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  2971. *
  2972. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  2973. * with the License. You may obtain a copy of the License at
  2974. *
  2975. * http://opensource.org/licenses/MIT
  2976. *
  2977. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  2978. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  2979. * either express or implied. See the License for the specific language governing permissions and
  2980. * limitations under the License.
  2981. */
  2982. var _util = __webpack_require__(2);
  2983. var _util2 = _interopRequireDefault(_util);
  2984. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  2985. /**
  2986. * set transition
  2987. * @param $target
  2988. * @param time
  2989. */
  2990. var setTransition = function setTransition($target, time) {
  2991. return $target.css({
  2992. '-webkit-transition': 'all ' + time + 's',
  2993. 'transition': 'all ' + time + 's'
  2994. });
  2995. };
  2996. /**
  2997. * set translate
  2998. */
  2999. var setTranslate = function setTranslate($target, diff) {
  3000. return $target.css({
  3001. '-webkit-transform': 'translate3d(0, ' + diff + 'px, 0)',
  3002. 'transform': 'translate3d(0, ' + diff + 'px, 0)'
  3003. });
  3004. };
  3005. /**
  3006. * @desc get index of middle item
  3007. * @param items
  3008. * @returns {number}
  3009. */
  3010. var getDefaultIndex = function getDefaultIndex(items) {
  3011. var current = Math.floor(items.length / 2);
  3012. var count = 0;
  3013. while (!!items[current] && items[current].disabled) {
  3014. current = ++current % items.length;
  3015. count++;
  3016. if (count > items.length) {
  3017. throw new Error('No selectable item.');
  3018. }
  3019. }
  3020. return current;
  3021. };
  3022. var getDefaultTranslate = function getDefaultTranslate(offset, rowHeight, items) {
  3023. var currentIndex = getDefaultIndex(items);
  3024. return (offset - currentIndex) * rowHeight;
  3025. };
  3026. /**
  3027. * get max translate
  3028. * @param offset
  3029. * @param rowHeight
  3030. * @returns {number}
  3031. */
  3032. var getMax = function getMax(offset, rowHeight) {
  3033. return offset * rowHeight;
  3034. };
  3035. /**
  3036. * get min translate
  3037. * @param offset
  3038. * @param rowHeight
  3039. * @param length
  3040. * @returns {number}
  3041. */
  3042. var getMin = function getMin(offset, rowHeight, length) {
  3043. return -(rowHeight * (length - offset - 1));
  3044. };
  3045. _util2.default.fn.scroll = function (options) {
  3046. var _this = this;
  3047. var defaults = _util2.default.extend({
  3048. items: [], // 数据
  3049. scrollable: '.weui-picker__content', // 滚动的元素
  3050. offset: 2, // 列表初始化时的偏移量(列表初始化时,选项是聚焦在中间的,通过offset强制往上挪3项,以达到初始选项是为顶部的那项)
  3051. rowHeight: 48, // 列表每一行的高度
  3052. onChange: _util2.default.noop, // onChange回调
  3053. temp: null, // translate的缓存
  3054. bodyHeight: 5 * 48 // picker的高度,用于辅助点击滚动的计算
  3055. }, options);
  3056. var items = defaults.items.map(function (item) {
  3057. return '<div class="weui-picker__item' + (item.disabled ? ' weui-picker__item_disabled' : '') + '">' + ((typeof item === 'undefined' ? 'undefined' : _typeof(item)) == 'object' ? item.label : item) + '</div>';
  3058. }).join('');
  3059. var $this = (0, _util2.default)(this);
  3060. $this.find('.weui-picker__content').html(items);
  3061. var $scrollable = $this.find(defaults.scrollable); // 可滚动的元素
  3062. var start = void 0; // 保存开始按下的位置
  3063. var end = void 0; // 保存结束时的位置
  3064. var startTime = void 0; // 开始触摸的时间
  3065. var translate = void 0; // 缓存 translate
  3066. var points = []; // 记录移动点
  3067. // 首次触发选中事件
  3068. // 如果有缓存的选项,则用缓存的选项,否则使用中间值。
  3069. if (defaults.temp !== null && defaults.temp < defaults.items.length) {
  3070. var index = defaults.temp;
  3071. defaults.onChange.call(this, defaults.items[index], index);
  3072. translate = (defaults.offset - index) * defaults.rowHeight;
  3073. } else {
  3074. var _index = getDefaultIndex(defaults.items);
  3075. defaults.onChange.call(this, defaults.items[_index], _index);
  3076. translate = getDefaultTranslate(defaults.offset, defaults.rowHeight, defaults.items);
  3077. }
  3078. setTranslate($scrollable, translate);
  3079. var stop = function stop(diff) {
  3080. translate += diff;
  3081. // 移动到最接近的那一行
  3082. translate = Math.round(translate / defaults.rowHeight) * defaults.rowHeight;
  3083. var max = getMax(defaults.offset, defaults.rowHeight);
  3084. var min = getMin(defaults.offset, defaults.rowHeight, defaults.items.length);
  3085. // 不要超过最大值或者最小值
  3086. if (translate > max) {
  3087. translate = max;
  3088. }
  3089. if (translate < min) {
  3090. translate = min;
  3091. }
  3092. // 如果是 disabled 的就跳过
  3093. var index = defaults.offset - translate / defaults.rowHeight;
  3094. while (!!defaults.items[index] && defaults.items[index].disabled) {
  3095. diff > 0 ? ++index : --index;
  3096. }
  3097. translate = (defaults.offset - index) * defaults.rowHeight;
  3098. setTransition($scrollable, .3);
  3099. setTranslate($scrollable, translate);
  3100. // 触发选择事件
  3101. defaults.onChange.call(_this, defaults.items[index], index);
  3102. };
  3103. function _start(pageY) {
  3104. start = pageY;
  3105. startTime = +new Date();
  3106. }
  3107. function _move(pageY) {
  3108. end = pageY;
  3109. var diff = end - start;
  3110. setTransition($scrollable, 0);
  3111. setTranslate($scrollable, translate + diff);
  3112. startTime = +new Date();
  3113. points.push({ time: startTime, y: end });
  3114. if (points.length > 40) {
  3115. points.shift();
  3116. }
  3117. }
  3118. function _end(pageY) {
  3119. if (!start) return;
  3120. /**
  3121. * 思路:
  3122. * 0. touchstart 记录按下的点和时间
  3123. * 1. touchmove 移动时记录前 40个经过的点和时间
  3124. * 2. touchend 松开手时, 记录该点和时间. 如果松开手时的时间, 距离上一次 move时的时间超过 100ms, 那么认为停止了, 不执行惯性滑动
  3125. * 如果间隔时间在 100ms 内, 查找 100ms 内最近的那个点, 和松开手时的那个点, 计算距离和时间差, 算出速度
  3126. * 速度乘以惯性滑动的时间, 例如 300ms, 计算出应该滑动的距离
  3127. */
  3128. var endTime = new Date().getTime();
  3129. var relativeY = $this[0].getBoundingClientRect().top + defaults.bodyHeight / 2;
  3130. end = pageY;
  3131. // 如果上次时间距离松开手的时间超过 100ms, 则停止了, 没有惯性滑动
  3132. if (endTime - startTime > 100) {
  3133. //如果end和start相差小于10,则视为
  3134. if (Math.abs(end - start) > 10) {
  3135. stop(end - start);
  3136. } else {
  3137. stop(relativeY - end);
  3138. }
  3139. } else {
  3140. if (Math.abs(end - start) > 10) {
  3141. var endPos = points.length - 1;
  3142. var startPos = endPos;
  3143. for (var i = endPos; i > 0 && startTime - points[i].time < 100; i--) {
  3144. startPos = i;
  3145. }
  3146. if (startPos !== endPos) {
  3147. var ep = points[endPos];
  3148. var sp = points[startPos];
  3149. var t = ep.time - sp.time;
  3150. var s = ep.y - sp.y;
  3151. var v = s / t; // 出手时的速度
  3152. var diff = v * 150 + (end - start); // 滑行 150ms,这里直接影响“灵敏度”
  3153. stop(diff);
  3154. } else {
  3155. stop(0);
  3156. }
  3157. } else {
  3158. stop(relativeY - end);
  3159. }
  3160. }
  3161. start = null;
  3162. }
  3163. /**
  3164. * 因为现在没有移除匿名函数的方法,所以先暴力移除(offAll),并且改变$scrollable。
  3165. */
  3166. $scrollable = $this.offAll().on('touchstart', function (evt) {
  3167. _start(evt.changedTouches[0].pageY);
  3168. }).on('touchmove', function (evt) {
  3169. _move(evt.changedTouches[0].pageY);
  3170. evt.preventDefault();
  3171. }).on('touchend', function (evt) {
  3172. _end(evt.changedTouches[0].pageY);
  3173. }).find(defaults.scrollable);
  3174. // 判断是否支持touch事件 https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
  3175. var isSupportTouch = 'ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch;
  3176. if (!isSupportTouch) {
  3177. $this.on('mousedown', function (evt) {
  3178. _start(evt.pageY);
  3179. evt.stopPropagation();
  3180. evt.preventDefault();
  3181. }).on('mousemove', function (evt) {
  3182. if (!start) return;
  3183. _move(evt.pageY);
  3184. evt.stopPropagation();
  3185. evt.preventDefault();
  3186. }).on('mouseup mouseleave', function (evt) {
  3187. _end(evt.pageY);
  3188. evt.stopPropagation();
  3189. evt.preventDefault();
  3190. });
  3191. }
  3192. };
  3193. /***/ }),
  3194. /* 27 */
  3195. /***/ (function(module, exports) {
  3196. "use strict";
  3197. Object.defineProperty(exports, "__esModule", {
  3198. value: true
  3199. });
  3200. /*
  3201. * Tencent is pleased to support the open source community by making WeUI.js available.
  3202. *
  3203. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  3204. *
  3205. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  3206. * with the License. You may obtain a copy of the License at
  3207. *
  3208. * http://opensource.org/licenses/MIT
  3209. *
  3210. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  3211. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  3212. * either express or implied. See the License for the specific language governing permissions and
  3213. * limitations under the License.
  3214. */
  3215. var depthOf = exports.depthOf = function depthOf(object) {
  3216. var depth = 1;
  3217. if (object.children && object.children[0]) {
  3218. depth = depthOf(object.children[0]) + 1;
  3219. }
  3220. return depth;
  3221. };
  3222. /***/ }),
  3223. /* 28 */
  3224. /***/ (function(module, exports) {
  3225. module.exports = " <div class=\"<%= className %>\"> <div class=weui-mask></div> <div class=\"weui-half-screen-dialog weui-picker\"> <div class=weui-half-screen-dialog__hd> <div class=weui-half-screen-dialog__hd__side> <button class=\"weui-icon-btn weui-icon-btn_close weui-picker__btn\">关闭</button> </div> <div class=weui-half-screen-dialog__hd__main> <strong class=weui-half-screen-dialog__title>标题</strong> </div> </div> <div class=weui-half-screen-dialog__bd> <div class=weui-picker__bd></div> </div> <div class=weui-half-screen-dialog__ft> <a href=javascript:; class=\"weui-btn weui-btn_primary weui-picker__btn\" id=weui-picker-confirm data-action=select>确定</a> </div> </div> </div>";
  3226. /***/ }),
  3227. /* 29 */
  3228. /***/ (function(module, exports) {
  3229. module.exports = "<div class=weui-picker__group> <div class=weui-picker__mask></div> <div class=weui-picker__indicator></div> <div class=weui-picker__content></div> </div>";
  3230. /***/ }),
  3231. /* 30 */
  3232. /***/ (function(module, exports, __webpack_require__) {
  3233. 'use strict';
  3234. Object.defineProperty(exports, "__esModule", {
  3235. value: true
  3236. });
  3237. var _util = __webpack_require__(2);
  3238. var _util2 = _interopRequireDefault(_util);
  3239. var _gallery = __webpack_require__(31);
  3240. var _gallery2 = _interopRequireDefault(_gallery);
  3241. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  3242. /*
  3243. * Tencent is pleased to support the open source community by making WeUI.js available.
  3244. *
  3245. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  3246. *
  3247. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  3248. * with the License. You may obtain a copy of the License at
  3249. *
  3250. * http://opensource.org/licenses/MIT
  3251. *
  3252. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  3253. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  3254. * either express or implied. See the License for the specific language governing permissions and
  3255. * limitations under the License.
  3256. */
  3257. var _sington = void 0;
  3258. /**
  3259. * gallery 带删除按钮的图片预览,主要是配合图片上传使用
  3260. * @param {string} url gallery显示的图片的url
  3261. * @param {object=} options 配置项
  3262. * @param {string=} options.className 自定义类名
  3263. * @param {function=} options.onDelete 点击删除图片时的回调
  3264. *
  3265. * @example
  3266. * var gallery = weui.gallery(url, {
  3267. * className: 'custom-classname',
  3268. * onDelete: function(){
  3269. * if(confirm('确定删除该图片?')){ console.log('删除'); }
  3270. * gallery.hide(function() {
  3271. * console.log('`gallery` has been hidden');
  3272. * });
  3273. * }
  3274. * });
  3275. */
  3276. function gallery(url) {
  3277. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  3278. if (_sington) return _sington;
  3279. options = _util2.default.extend({
  3280. className: '',
  3281. onDelete: _util2.default.noop
  3282. }, options);
  3283. var $gallery = (0, _util2.default)(_util2.default.render(_gallery2.default, _util2.default.extend({
  3284. url: url
  3285. }, options)));
  3286. function _hide(callback) {
  3287. _hide = _util2.default.noop; // 防止二次调用导致报错
  3288. $gallery.addClass('weui-animate-fade-out').on('animationend webkitAnimationEnd', function () {
  3289. $gallery.remove();
  3290. _sington = false;
  3291. callback && callback();
  3292. });
  3293. }
  3294. function hide(callback) {
  3295. _hide(callback);
  3296. }
  3297. (0, _util2.default)('body').append($gallery);
  3298. $gallery.find('.weui-gallery__img').on('click', function () {
  3299. hide();
  3300. });
  3301. $gallery.find('.weui-gallery__del').on('click', function () {
  3302. options.onDelete.call(this, url);
  3303. });
  3304. $gallery.show().addClass('weui-animate-fade-in');
  3305. _sington = $gallery[0];
  3306. _sington.hide = hide;
  3307. return _sington;
  3308. }
  3309. exports.default = gallery;
  3310. module.exports = exports['default'];
  3311. /***/ }),
  3312. /* 31 */
  3313. /***/ (function(module, exports) {
  3314. module.exports = "<div class=\"weui-gallery <%= className %>\"> <span class=weui-gallery__img style=\"background-image:url(<%= url %>)\"></span> <div class=weui-gallery__opr> <a href=javascript: class=weui-gallery__del> <i class=\"weui-icon-delete weui-icon_gallery-delete\"></i> </a> </div> </div> ";
  3315. /***/ }),
  3316. /* 32 */
  3317. /***/ (function(module, exports, __webpack_require__) {
  3318. 'use strict';
  3319. Object.defineProperty(exports, "__esModule", {
  3320. value: true
  3321. });
  3322. var _util = __webpack_require__(2);
  3323. var _util2 = _interopRequireDefault(_util);
  3324. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  3325. /**
  3326. * slider slider滑块,单位是百分比。注意,因为需要获取slider的长度,所以必须要在slider可见的情况下来调用。
  3327. * @param {string} selector slider的selector
  3328. * @param {object=} options 配置项
  3329. * @param {number=} options.step slider的step,每次移动的百分比,取值范围 [0-100]
  3330. * @param {number=} [options.defaultValue=0] slider的默认百分比值,取值范围 [0-100]
  3331. * @param {function=} options.onChange slider发生改变时返回对应的百分比,取值范围 [0-100]
  3332. *
  3333. * @example
  3334. * #### html
  3335. * ```html
  3336. * <div class="weui-slider-box">
  3337. * <div id="slider" class="weui-slider">
  3338. * <div class="weui-slider__inner">
  3339. * <div class="weui-slider__track"></div>
  3340. * <div class="weui-slider__handler"></div>
  3341. * </div>
  3342. * </div>
  3343. * <div id="sliderValue" class="weui-slider-box__value"></div>
  3344. * </div>
  3345. * ```
  3346. *
  3347. * #### js
  3348. * ```javascript
  3349. * weui.slider('#slider', {
  3350. * step: 10,
  3351. * defaultValue: 40,
  3352. * onChange: function(percent){
  3353. * console.log(percent);
  3354. * }
  3355. * });
  3356. * ```
  3357. */
  3358. function slider(selector) {
  3359. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  3360. var $eles = (0, _util2.default)(selector);
  3361. options = _util2.default.extend({
  3362. step: undefined,
  3363. defaultValue: 0,
  3364. onChange: _util2.default.noop
  3365. }, options);
  3366. if (options.step !== undefined) {
  3367. options.step = parseFloat(options.step);
  3368. if (!options.step || options.step < 0) {
  3369. throw new Error('Slider step must be a positive number.');
  3370. }
  3371. }
  3372. if (options.defaultValue !== undefined && options.defaultValue < 0 || options.defaultValue > 100) {
  3373. throw new Error('Slider defaultValue must be >= 0 and <= 100.');
  3374. }
  3375. $eles.forEach(function (ele) {
  3376. var $slider = (0, _util2.default)(ele);
  3377. var $sliderInner = $slider.find('.weui-slider__inner');
  3378. var $sliderTrack = $slider.find('.weui-slider__track');
  3379. var $sliderHandler = $slider.find('.weui-slider__handler');
  3380. var sliderLength = parseInt(_util2.default.getStyle($sliderInner[0], 'width')); // slider的长度
  3381. var sliderLeft = $sliderInner[0].offsetLeft; // slider相对于页面的offset
  3382. var handlerStartPos = 0; // handler起始位置
  3383. var handlerStartX = 0; // handler touchstart的X
  3384. var stepWidth = void 0; // 每个step的宽度
  3385. function getHandlerPos() {
  3386. var pos = _util2.default.getStyle($sliderHandler[0], 'left');
  3387. if (/%/.test(pos)) {
  3388. pos = sliderLength * parseFloat(pos) / 100;
  3389. } else {
  3390. pos = parseFloat(pos);
  3391. }
  3392. return pos;
  3393. }
  3394. function setHandler(distance) {
  3395. var dist = void 0,
  3396. // handler的目标位置
  3397. percent = void 0; // 所在位置的百分比
  3398. if (options.step) {
  3399. distance = Math.round(distance / stepWidth) * stepWidth;
  3400. }
  3401. dist = handlerStartPos + distance;
  3402. dist = dist < 0 ? 0 : dist > sliderLength ? sliderLength : dist;
  3403. percent = 100 * dist / sliderLength;
  3404. $sliderTrack.css({ width: percent + '%' });
  3405. $sliderHandler.css({ left: percent + '%' });
  3406. options.onChange.call(ele, percent);
  3407. }
  3408. if (options.step) {
  3409. stepWidth = sliderLength * options.step / 100;
  3410. }
  3411. if (options.defaultValue) {
  3412. setHandler(sliderLength * options.defaultValue / 100);
  3413. }
  3414. $slider.on('click', function (evt) {
  3415. evt.preventDefault();
  3416. handlerStartPos = getHandlerPos();
  3417. setHandler(evt.pageX - sliderLeft - handlerStartPos);
  3418. });
  3419. $sliderHandler.on('touchstart', function (evt) {
  3420. handlerStartPos = getHandlerPos();
  3421. handlerStartX = evt.changedTouches[0].clientX;
  3422. }).on('touchmove', function (evt) {
  3423. evt.preventDefault();
  3424. setHandler(evt.changedTouches[0].clientX - handlerStartX);
  3425. });
  3426. });
  3427. return this;
  3428. } /*
  3429. * Tencent is pleased to support the open source community by making WeUI.js available.
  3430. *
  3431. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  3432. *
  3433. * Licensed under the MIT License (the "License"); you may not use this file except in compliance
  3434. * with the License. You may obtain a copy of the License at
  3435. *
  3436. * http://opensource.org/licenses/MIT
  3437. *
  3438. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  3439. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  3440. * either express or implied. See the License for the specific language governing permissions and
  3441. * limitations under the License.
  3442. */
  3443. exports.default = slider;
  3444. module.exports = exports['default'];
  3445. /***/ })
  3446. /******/ ])
  3447. });
  3448. ;