手机端官网

zepto.weui.js 141KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757
  1. ;(function($) {
  2. "use strict";
  3. $.fn.transitionEnd = function(callback) {
  4. var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
  5. i, dom = this;
  6. function fireCallBack(e) {
  7. /*jshint validthis:true */
  8. if (e.target !== this) return;
  9. callback.call(this, e);
  10. for (i = 0; i < events.length; i++) {
  11. dom.off(events[i], fireCallBack);
  12. }
  13. }
  14. if (callback) {
  15. for (i = 0; i < events.length; i++) {
  16. dom.on(events[i], fireCallBack);
  17. }
  18. }
  19. return this;
  20. };
  21. $.support = (function() {
  22. var support = {
  23. touch: !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch)
  24. };
  25. return support;
  26. })();
  27. $.touchEvents = {
  28. start: $.support.touch ? 'touchstart' : 'mousedown',
  29. move: $.support.touch ? 'touchmove' : 'mousemove',
  30. end: $.support.touch ? 'touchend' : 'mouseup'
  31. };
  32. $.getTouchPosition = function(e) {
  33. e = e.originalEvent || e; //jquery wrap the originevent
  34. if(e.type === 'touchstart' || e.type === 'touchmove' || e.type === 'touchend') {
  35. return {
  36. x: e.targetTouches[0].pageX,
  37. y: e.targetTouches[0].pageY
  38. };
  39. } else {
  40. return {
  41. x: e.pageX,
  42. y: e.pageY
  43. };
  44. }
  45. };
  46. $.fn.scrollHeight = function() {
  47. return this[0].scrollHeight;
  48. };
  49. $.fn.transform = function(transform) {
  50. for (var i = 0; i < this.length; i++) {
  51. var elStyle = this[i].style;
  52. elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
  53. }
  54. return this;
  55. };
  56. $.fn.transition = function(duration) {
  57. if (typeof duration !== 'string') {
  58. duration = duration + 'ms';
  59. }
  60. for (var i = 0; i < this.length; i++) {
  61. var elStyle = this[i].style;
  62. elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
  63. }
  64. return this;
  65. };
  66. $.getTranslate = function (el, axis) {
  67. var matrix, curTransform, curStyle, transformMatrix;
  68. // automatic axis detection
  69. if (typeof axis === 'undefined') {
  70. axis = 'x';
  71. }
  72. curStyle = window.getComputedStyle(el, null);
  73. if (window.WebKitCSSMatrix) {
  74. // Some old versions of Webkit choke when 'none' is passed; pass
  75. // empty string instead in this case
  76. transformMatrix = new WebKitCSSMatrix(curStyle.webkitTransform === 'none' ? '' : curStyle.webkitTransform);
  77. }
  78. else {
  79. transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
  80. matrix = transformMatrix.toString().split(',');
  81. }
  82. if (axis === 'x') {
  83. //Latest Chrome and webkits Fix
  84. if (window.WebKitCSSMatrix)
  85. curTransform = transformMatrix.m41;
  86. //Crazy IE10 Matrix
  87. else if (matrix.length === 16)
  88. curTransform = parseFloat(matrix[12]);
  89. //Normal Browsers
  90. else
  91. curTransform = parseFloat(matrix[4]);
  92. }
  93. if (axis === 'y') {
  94. //Latest Chrome and webkits Fix
  95. if (window.WebKitCSSMatrix)
  96. curTransform = transformMatrix.m42;
  97. //Crazy IE10 Matrix
  98. else if (matrix.length === 16)
  99. curTransform = parseFloat(matrix[13]);
  100. //Normal Browsers
  101. else
  102. curTransform = parseFloat(matrix[5]);
  103. }
  104. return curTransform || 0;
  105. };
  106. $.requestAnimationFrame = function (callback) {
  107. if (window.requestAnimationFrame) return window.requestAnimationFrame(callback);
  108. else if (window.webkitRequestAnimationFrame) return window.webkitRequestAnimationFrame(callback);
  109. else if (window.mozRequestAnimationFrame) return window.mozRequestAnimationFrame(callback);
  110. else {
  111. return window.setTimeout(callback, 1000 / 60);
  112. }
  113. };
  114. $.cancelAnimationFrame = function (id) {
  115. if (window.cancelAnimationFrame) return window.cancelAnimationFrame(id);
  116. else if (window.webkitCancelAnimationFrame) return window.webkitCancelAnimationFrame(id);
  117. else if (window.mozCancelAnimationFrame) return window.mozCancelAnimationFrame(id);
  118. else {
  119. return window.clearTimeout(id);
  120. }
  121. };
  122. $.fn.join = function(arg) {
  123. return this.toArray().join(arg);
  124. }
  125. })($);
  126. /*===========================
  127. Template7 Template engine
  128. ===========================*/
  129. /* global $:true */
  130. /* jshint unused:false */
  131. /* jshint forin:false */
  132. +function ($) {
  133. "use strict";
  134. $.Template7 = $.t7 = (function () {
  135. function isArray(arr) {
  136. return Object.prototype.toString.apply(arr) === '[object Array]';
  137. }
  138. function isObject(obj) {
  139. return obj instanceof Object;
  140. }
  141. function isFunction(func) {
  142. return typeof func === 'function';
  143. }
  144. var cache = {};
  145. function helperToSlices(string) {
  146. var helperParts = string.replace(/[{}#}]/g, '').split(' ');
  147. var slices = [];
  148. var shiftIndex, i, j;
  149. for (i = 0; i < helperParts.length; i++) {
  150. var part = helperParts[i];
  151. if (i === 0) slices.push(part);
  152. else {
  153. if (part.indexOf('"') === 0) {
  154. // Plain String
  155. if (part.match(/"/g).length === 2) {
  156. // One word string
  157. slices.push(part);
  158. }
  159. else {
  160. // Find closed Index
  161. shiftIndex = 0;
  162. for (j = i + 1; j < helperParts.length; j++) {
  163. part += ' ' + helperParts[j];
  164. if (helperParts[j].indexOf('"') >= 0) {
  165. shiftIndex = j;
  166. slices.push(part);
  167. break;
  168. }
  169. }
  170. if (shiftIndex) i = shiftIndex;
  171. }
  172. }
  173. else {
  174. if (part.indexOf('=') > 0) {
  175. // Hash
  176. var hashParts = part.split('=');
  177. var hashName = hashParts[0];
  178. var hashContent = hashParts[1];
  179. if (hashContent.match(/"/g).length !== 2) {
  180. shiftIndex = 0;
  181. for (j = i + 1; j < helperParts.length; j++) {
  182. hashContent += ' ' + helperParts[j];
  183. if (helperParts[j].indexOf('"') >= 0) {
  184. shiftIndex = j;
  185. break;
  186. }
  187. }
  188. if (shiftIndex) i = shiftIndex;
  189. }
  190. var hash = [hashName, hashContent.replace(/"/g,'')];
  191. slices.push(hash);
  192. }
  193. else {
  194. // Plain variable
  195. slices.push(part);
  196. }
  197. }
  198. }
  199. }
  200. return slices;
  201. }
  202. function stringToBlocks(string) {
  203. var blocks = [], i, j, k;
  204. if (!string) return [];
  205. var _blocks = string.split(/({{[^{^}]*}})/);
  206. for (i = 0; i < _blocks.length; i++) {
  207. var block = _blocks[i];
  208. if (block === '') continue;
  209. if (block.indexOf('{{') < 0) {
  210. blocks.push({
  211. type: 'plain',
  212. content: block
  213. });
  214. }
  215. else {
  216. if (block.indexOf('{/') >= 0) {
  217. continue;
  218. }
  219. if (block.indexOf('{#') < 0 && block.indexOf(' ') < 0 && block.indexOf('else') < 0) {
  220. // Simple variable
  221. blocks.push({
  222. type: 'variable',
  223. contextName: block.replace(/[{}]/g, '')
  224. });
  225. continue;
  226. }
  227. // Helpers
  228. var helperSlices = helperToSlices(block);
  229. var helperName = helperSlices[0];
  230. var helperContext = [];
  231. var helperHash = {};
  232. for (j = 1; j < helperSlices.length; j++) {
  233. var slice = helperSlices[j];
  234. if (isArray(slice)) {
  235. // Hash
  236. helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1];
  237. }
  238. else {
  239. helperContext.push(slice);
  240. }
  241. }
  242. if (block.indexOf('{#') >= 0) {
  243. // Condition/Helper
  244. var helperStartIndex = i;
  245. var helperContent = '';
  246. var elseContent = '';
  247. var toSkip = 0;
  248. var shiftIndex;
  249. var foundClosed = false, foundElse = false, foundClosedElse = false, depth = 0;
  250. for (j = i + 1; j < _blocks.length; j++) {
  251. if (_blocks[j].indexOf('{{#') >= 0) {
  252. depth ++;
  253. }
  254. if (_blocks[j].indexOf('{{/') >= 0) {
  255. depth --;
  256. }
  257. if (_blocks[j].indexOf('{{#' + helperName) >= 0) {
  258. helperContent += _blocks[j];
  259. if (foundElse) elseContent += _blocks[j];
  260. toSkip ++;
  261. }
  262. else if (_blocks[j].indexOf('{{/' + helperName) >= 0) {
  263. if (toSkip > 0) {
  264. toSkip--;
  265. helperContent += _blocks[j];
  266. if (foundElse) elseContent += _blocks[j];
  267. }
  268. else {
  269. shiftIndex = j;
  270. foundClosed = true;
  271. break;
  272. }
  273. }
  274. else if (_blocks[j].indexOf('else') >= 0 && depth === 0) {
  275. foundElse = true;
  276. }
  277. else {
  278. if (!foundElse) helperContent += _blocks[j];
  279. if (foundElse) elseContent += _blocks[j];
  280. }
  281. }
  282. if (foundClosed) {
  283. if (shiftIndex) i = shiftIndex;
  284. blocks.push({
  285. type: 'helper',
  286. helperName: helperName,
  287. contextName: helperContext,
  288. content: helperContent,
  289. inverseContent: elseContent,
  290. hash: helperHash
  291. });
  292. }
  293. }
  294. else if (block.indexOf(' ') > 0) {
  295. blocks.push({
  296. type: 'helper',
  297. helperName: helperName,
  298. contextName: helperContext,
  299. hash: helperHash
  300. });
  301. }
  302. }
  303. }
  304. return blocks;
  305. }
  306. var Template7 = function (template) {
  307. var t = this;
  308. t.template = template;
  309. function getCompileFn(block, depth) {
  310. if (block.content) return compile(block.content, depth);
  311. else return function () {return ''; };
  312. }
  313. function getCompileInverse(block, depth) {
  314. if (block.inverseContent) return compile(block.inverseContent, depth);
  315. else return function () {return ''; };
  316. }
  317. function getCompileVar(name, ctx) {
  318. var variable, parts, levelsUp = 0, initialCtx = ctx;
  319. if (name.indexOf('../') === 0) {
  320. levelsUp = name.split('../').length - 1;
  321. var newDepth = ctx.split('_')[1] - levelsUp;
  322. ctx = 'ctx_' + (newDepth >= 1 ? newDepth : 1);
  323. parts = name.split('../')[levelsUp].split('.');
  324. }
  325. else if (name.indexOf('@global') === 0) {
  326. ctx = '$.Template7.global';
  327. parts = name.split('@global.')[1].split('.');
  328. }
  329. else if (name.indexOf('@root') === 0) {
  330. ctx = 'ctx_1';
  331. parts = name.split('@root.')[1].split('.');
  332. }
  333. else {
  334. parts = name.split('.');
  335. }
  336. variable = ctx;
  337. for (var i = 0; i < parts.length; i++) {
  338. var part = parts[i];
  339. if (part.indexOf('@') === 0) {
  340. if (i > 0) {
  341. variable += '[(data && data.' + part.replace('@', '') + ')]';
  342. }
  343. else {
  344. variable = '(data && data.' + name.replace('@', '') + ')';
  345. }
  346. }
  347. else {
  348. if (isFinite(part)) {
  349. variable += '[' + part + ']';
  350. }
  351. else {
  352. if (part.indexOf('this') === 0) {
  353. variable = part.replace('this', ctx);
  354. }
  355. else {
  356. variable += '.' + part;
  357. }
  358. }
  359. }
  360. }
  361. return variable;
  362. }
  363. function getCompiledArguments(contextArray, ctx) {
  364. var arr = [];
  365. for (var i = 0; i < contextArray.length; i++) {
  366. if (contextArray[i].indexOf('"') === 0) arr.push(contextArray[i]);
  367. else {
  368. arr.push(getCompileVar(contextArray[i], ctx));
  369. }
  370. }
  371. return arr.join(', ');
  372. }
  373. function compile(template, depth) {
  374. depth = depth || 1;
  375. template = template || t.template;
  376. if (typeof template !== 'string') {
  377. throw new Error('Template7: Template must be a string');
  378. }
  379. var blocks = stringToBlocks(template);
  380. if (blocks.length === 0) {
  381. return function () { return ''; };
  382. }
  383. var ctx = 'ctx_' + depth;
  384. var resultString = '(function (' + ctx + ', data) {\n';
  385. if (depth === 1) {
  386. resultString += 'function isArray(arr){return Object.prototype.toString.apply(arr) === \'[object Array]\';}\n';
  387. resultString += 'function isFunction(func){return (typeof func === \'function\');}\n';
  388. resultString += 'function c(val, ctx) {if (typeof val !== "undefined") {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n';
  389. }
  390. resultString += 'var r = \'\';\n';
  391. var i, j, context;
  392. for (i = 0; i < blocks.length; i++) {
  393. var block = blocks[i];
  394. // Plain block
  395. if (block.type === 'plain') {
  396. resultString += 'r +=\'' + (block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'') + '\';';
  397. continue;
  398. }
  399. var variable, compiledArguments;
  400. // Variable block
  401. if (block.type === 'variable') {
  402. variable = getCompileVar(block.contextName, ctx);
  403. resultString += 'r += c(' + variable + ', ' + ctx + ');';
  404. }
  405. // Helpers block
  406. if (block.type === 'helper') {
  407. if (block.helperName in t.helpers) {
  408. compiledArguments = getCompiledArguments(block.contextName, ctx);
  409. resultString += 'r += ($.Template7.helpers.' + block.helperName + ').call(' + ctx + ', ' + (compiledArguments && (compiledArguments + ', ')) +'{hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: ctx_1});';
  410. }
  411. else {
  412. if (block.contextName.length > 0) {
  413. throw new Error('Template7: Missing helper: "' + block.helperName + '"');
  414. }
  415. else {
  416. variable = getCompileVar(block.helperName, ctx);
  417. resultString += 'if (' + variable + ') {';
  418. resultString += 'if (isArray(' + variable + ')) {';
  419. resultString += 'r += ($.Template7.helpers.each).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: ctx_1});';
  420. resultString += '}else {';
  421. resultString += 'r += ($.Template7.helpers.with).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: ctx_1});';
  422. resultString += '}}';
  423. }
  424. }
  425. }
  426. }
  427. resultString += '\nreturn r;})';
  428. return eval.call(window, resultString);
  429. }
  430. t.compile = function (template) {
  431. if (!t.compiled) {
  432. t.compiled = compile(template);
  433. }
  434. return t.compiled;
  435. };
  436. };
  437. Template7.prototype = {
  438. options: {},
  439. helpers: {
  440. 'if': function (context, options) {
  441. if (isFunction(context)) { context = context.call(this); }
  442. if (context) {
  443. return options.fn(this, options.data);
  444. }
  445. else {
  446. return options.inverse(this, options.data);
  447. }
  448. },
  449. 'unless': function (context, options) {
  450. if (isFunction(context)) { context = context.call(this); }
  451. if (!context) {
  452. return options.fn(this, options.data);
  453. }
  454. else {
  455. return options.inverse(this, options.data);
  456. }
  457. },
  458. 'each': function (context, options) {
  459. var ret = '', i = 0;
  460. if (isFunction(context)) { context = context.call(this); }
  461. if (isArray(context)) {
  462. if (options.hash.reverse) {
  463. context = context.reverse();
  464. }
  465. for (i = 0; i < context.length; i++) {
  466. ret += options.fn(context[i], {first: i === 0, last: i === context.length - 1, index: i});
  467. }
  468. if (options.hash.reverse) {
  469. context = context.reverse();
  470. }
  471. }
  472. else {
  473. for (var key in context) {
  474. i++;
  475. ret += options.fn(context[key], {key: key});
  476. }
  477. }
  478. if (i > 0) return ret;
  479. else return options.inverse(this);
  480. },
  481. 'with': function (context, options) {
  482. if (isFunction(context)) { context = context.call(this); }
  483. return options.fn(context);
  484. },
  485. 'join': function (context, options) {
  486. if (isFunction(context)) { context = context.call(this); }
  487. return context.join(options.hash.delimiter || options.hash.delimeter);
  488. },
  489. 'js': function (expression, options) {
  490. var func;
  491. if (expression.indexOf('return')>=0) {
  492. func = '(function(){'+expression+'})';
  493. }
  494. else {
  495. func = '(function(){return ('+expression+')})';
  496. }
  497. return eval.call(this, func).call(this);
  498. },
  499. 'js_compare': function (expression, options) {
  500. var func;
  501. if (expression.indexOf('return')>=0) {
  502. func = '(function(){'+expression+'})';
  503. }
  504. else {
  505. func = '(function(){return ('+expression+')})';
  506. }
  507. var condition = eval.call(this, func).call(this);
  508. if (condition) {
  509. return options.fn(this, options.data);
  510. }
  511. else {
  512. return options.inverse(this, options.data);
  513. }
  514. }
  515. }
  516. };
  517. var t7 = function (template, data) {
  518. if (arguments.length === 2) {
  519. var instance = new Template7(template);
  520. var rendered = instance.compile()(data);
  521. instance = null;
  522. return (rendered);
  523. }
  524. else return new Template7(template);
  525. };
  526. t7.registerHelper = function (name, fn) {
  527. Template7.prototype.helpers[name] = fn;
  528. };
  529. t7.unregisterHelper = function (name) {
  530. Template7.prototype.helpers[name] = undefined;
  531. delete Template7.prototype.helpers[name];
  532. };
  533. t7.compile = function (template, options) {
  534. var instance = new Template7(template, options);
  535. return instance.compile();
  536. };
  537. t7.options = Template7.prototype.options;
  538. t7.helpers = Template7.prototype.helpers;
  539. return t7;
  540. })();
  541. }($);
  542. + function($) {
  543. "use strict";
  544. var defaults;
  545. $.modal = function(params, onOpen) {
  546. params = $.extend({}, defaults, params);
  547. var buttons = params.buttons;
  548. var buttonsHtml = buttons.map(function(d, i) {
  549. return '<a href="javascript:;" class="weui-dialog__btn ' + (d.className || "") + '">' + d.text + '</a>';
  550. }).join("");
  551. var tpl = '<div class="weui-dialog">' +
  552. '<div class="weui-dialog__hd"><strong class="weui-dialog__title">' + params.title + '</strong></div>' +
  553. ( params.text ? '<div class="weui-dialog__bd">'+params.text+'</div>' : '')+
  554. '<div class="weui-dialog__ft">' + buttonsHtml + '</div>' +
  555. '</div>';
  556. var dialog = $.openModal(tpl, onOpen);
  557. dialog.find(".weui-dialog__btn").each(function(i, e) {
  558. var el = $(e);
  559. el.click(function() {
  560. //先关闭对话框,再调用回调函数
  561. if(params.autoClose) $.closeModal();
  562. if(buttons[i].onClick) {
  563. buttons[i].onClick.call(dialog);
  564. }
  565. });
  566. });
  567. return dialog;
  568. };
  569. $.openModal = function(tpl, onOpen) {
  570. var mask = $("<div class='weui-mask'></div>").appendTo(document.body);
  571. mask.show();
  572. var dialog = $(tpl).appendTo(document.body);
  573. if (onOpen) {
  574. dialog.transitionEnd(function () {
  575. onOpen.call(dialog);
  576. });
  577. }
  578. dialog.show();
  579. mask.addClass("weui-mask--visible");
  580. dialog.addClass("weui-dialog--visible");
  581. return dialog;
  582. }
  583. $.closeModal = function() {
  584. $(".weui-mask--visible").removeClass("weui-mask--visible").transitionEnd(function() {
  585. $(this).remove();
  586. });
  587. $(".weui-dialog--visible").removeClass("weui-dialog--visible").transitionEnd(function() {
  588. $(this).remove();
  589. });
  590. };
  591. $.alert = function(text, title, onOK) {
  592. var config;
  593. if (typeof text === 'object') {
  594. config = text;
  595. } else {
  596. if (typeof title === 'function') {
  597. onOK = arguments[1];
  598. title = undefined;
  599. }
  600. config = {
  601. text: text,
  602. title: title,
  603. onOK: onOK
  604. }
  605. }
  606. return $.modal({
  607. text: config.text,
  608. title: config.title,
  609. buttons: [{
  610. text: defaults.buttonOK,
  611. className: "primary",
  612. onClick: config.onOK
  613. }]
  614. });
  615. }
  616. $.confirm = function(text, title, onOK, onCancel) {
  617. var config;
  618. if (typeof text === 'object') {
  619. config = text
  620. } else {
  621. if (typeof title === 'function') {
  622. onCancel = arguments[2];
  623. onOK = arguments[1];
  624. title = undefined;
  625. }
  626. config = {
  627. text: text,
  628. title: title,
  629. onOK: onOK,
  630. onCancel: onCancel
  631. }
  632. }
  633. return $.modal({
  634. text: config.text,
  635. title: config.title,
  636. buttons: [
  637. {
  638. text: defaults.buttonCancel,
  639. className: "default",
  640. onClick: config.onCancel
  641. },
  642. {
  643. text: defaults.buttonOK,
  644. className: "primary",
  645. onClick: config.onOK
  646. }]
  647. });
  648. };
  649. //如果参数过多,建议通过 config 对象进行配置,而不是传入多个参数。
  650. $.prompt = function(text, title, onOK, onCancel, input) {
  651. var config;
  652. if (typeof text === 'object') {
  653. config = text;
  654. } else {
  655. if (typeof title === 'function') {
  656. input = arguments[3];
  657. onCancel = arguments[2];
  658. onOK = arguments[1];
  659. title = undefined;
  660. }
  661. config = {
  662. text: text,
  663. title: title,
  664. input: input,
  665. onOK: onOK,
  666. onCancel: onCancel,
  667. empty: false //allow empty
  668. }
  669. }
  670. var modal = $.modal({
  671. text: '<p class="weui-prompt-text">'+(config.text || '')+'</p><input type="text" class="weui-input weui-prompt-input" id="weui-prompt-input" value="' + (config.input || '') + '" />',
  672. title: config.title,
  673. autoClose: false,
  674. buttons: [
  675. {
  676. text: defaults.buttonCancel,
  677. className: "default",
  678. onClick: function () {
  679. $.closeModal();
  680. config.onCancel && config.onCancel.call(modal);
  681. }
  682. },
  683. {
  684. text: defaults.buttonOK,
  685. className: "primary",
  686. onClick: function() {
  687. var input = $("#weui-prompt-input").val();
  688. if (!config.empty && (input === "" || input === null)) {
  689. modal.find('.weui-prompt-input').focus()[0].select();
  690. return false;
  691. }
  692. $.closeModal();
  693. config.onOK && config.onOK.call(modal, input);
  694. }
  695. }]
  696. }, function () {
  697. this.find('.weui-prompt-input').focus()[0].select();
  698. });
  699. return modal;
  700. };
  701. //如果参数过多,建议通过 config 对象进行配置,而不是传入多个参数。
  702. $.login = function(text, title, onOK, onCancel, username, password) {
  703. var config;
  704. if (typeof text === 'object') {
  705. config = text;
  706. } else {
  707. if (typeof title === 'function') {
  708. password = arguments[4];
  709. username = arguments[3];
  710. onCancel = arguments[2];
  711. onOK = arguments[1];
  712. title = undefined;
  713. }
  714. config = {
  715. text: text,
  716. title: title,
  717. username: username,
  718. password: password,
  719. onOK: onOK,
  720. onCancel: onCancel
  721. }
  722. }
  723. var modal = $.modal({
  724. text: '<p class="weui-prompt-text">'+(config.text || '')+'</p>' +
  725. '<input type="text" class="weui-input weui-prompt-input" id="weui-prompt-username" value="' + (config.username || '') + '" placeholder="输入用户名" />' +
  726. '<input type="password" class="weui-input weui-prompt-input" id="weui-prompt-password" value="' + (config.password || '') + '" placeholder="输入密码" />',
  727. title: config.title,
  728. autoClose: false,
  729. buttons: [
  730. {
  731. text: defaults.buttonCancel,
  732. className: "default",
  733. onClick: function () {
  734. $.closeModal();
  735. config.onCancel && config.onCancel.call(modal);
  736. }
  737. }, {
  738. text: defaults.buttonOK,
  739. className: "primary",
  740. onClick: function() {
  741. var username = $("#weui-prompt-username").val();
  742. var password = $("#weui-prompt-password").val();
  743. if (!config.empty && (username === "" || username === null)) {
  744. modal.find('#weui-prompt-username').focus()[0].select();
  745. return false;
  746. }
  747. if (!config.empty && (password === "" || password === null)) {
  748. modal.find('#weui-prompt-password').focus()[0].select();
  749. return false;
  750. }
  751. $.closeModal();
  752. config.onOK && config.onOK.call(modal, username, password);
  753. }
  754. }]
  755. }, function () {
  756. this.find('#weui-prompt-username').focus()[0].select();
  757. });
  758. return modal;
  759. };
  760. defaults = $.modal.prototype.defaults = {
  761. title: "提示",
  762. text: undefined,
  763. buttonOK: "确定",
  764. buttonCancel: "取消",
  765. buttons: [{
  766. text: "确定",
  767. className: "primary"
  768. }],
  769. autoClose: true //点击按钮自动关闭对话框,如果你不希望点击按钮就关闭对话框,可以把这个设置为false
  770. };
  771. }($);
  772. + function($) {
  773. "use strict";
  774. var defaults;
  775. var show = function(html, className) {
  776. className = className || "";
  777. var mask = $("<div class='weui-mask_transparent'></div>").appendTo(document.body);
  778. var tpl = '<div class="weui-toast ' + className + '">' + html + '</div>';
  779. var dialog = $(tpl).appendTo(document.body);
  780. dialog.addClass("weui-toast--visible");
  781. dialog.show();
  782. };
  783. var hide = function(callback) {
  784. $(".weui-mask_transparent").remove();
  785. $(".weui-toast--visible").removeClass("weui-toast--visible").transitionEnd(function() {
  786. var $this = $(this);
  787. $this.remove();
  788. callback && callback($this);
  789. });
  790. }
  791. $.toast = function(text, style, callback) {
  792. if(typeof style === "function") {
  793. callback = style;
  794. }
  795. var className, iconClassName = 'weui-icon-success-no-circle';
  796. var duration = toastDefaults.duration;
  797. if(style == "cancel") {
  798. className = "weui-toast_cancel";
  799. iconClassName = 'weui-icon-cancel'
  800. } else if(style == "forbidden") {
  801. className = "weui-toast--forbidden";
  802. iconClassName = 'weui-icon-warn'
  803. } else if(style == "text") {
  804. className = "weui-toast--text";
  805. } else if(typeof style === typeof 1) {
  806. duration = style
  807. }
  808. show('<i class="' + iconClassName + ' weui-icon_toast"></i><p class="weui-toast_content">' + (text || "已经完成") + '</p>', className);
  809. setTimeout(function() {
  810. hide(callback);
  811. }, duration);
  812. }
  813. $.showLoading = function(text) {
  814. var html = '<div class="weui_loading">';
  815. html += '<i class="weui-loading weui-icon_toast"></i>';
  816. html += '</div>';
  817. html += '<p class="weui-toast_content">' + (text || "数据加载中") + '</p>';
  818. show(html, 'weui_loading_toast');
  819. }
  820. $.hideLoading = function() {
  821. hide();
  822. }
  823. var toastDefaults = $.toast.prototype.defaults = {
  824. duration: 2500
  825. }
  826. }($);
  827. + function($) {
  828. "use strict";
  829. var defaults;
  830. var show = function(params) {
  831. var mask = $("<div class='weui-mask weui-actions_mask'></div>").appendTo(document.body);
  832. var actions = params.actions || [];
  833. var actionsHtml = actions.map(function(d, i) {
  834. return '<div class="weui-actionsheet__cell ' + (d.className || "") + '">' + d.text + '</div>';
  835. }).join("");
  836. var titleHtml = "";
  837. if (params.title) {
  838. titleHtml = '<div class="weui-actionsheet__title"><p class="weui-actionsheet__title-text">' + params.title + '</p></div>';
  839. }
  840. var tpl = '<div class="weui-actionsheet " id="weui-actionsheet">'+
  841. titleHtml +
  842. '<div class="weui-actionsheet__menu">'+
  843. actionsHtml +
  844. '</div>'+
  845. '<div class="weui-actionsheet__action">'+
  846. '<div class="weui-actionsheet__cell weui-actionsheet_cancel">取消</div>'+
  847. '</div>'+
  848. '</div>';
  849. var dialog = $(tpl).appendTo(document.body);
  850. dialog.find(".weui-actionsheet__menu .weui-actionsheet__cell, .weui-actionsheet__action .weui-actionsheet__cell").each(function(i, e) {
  851. $(e).click(function() {
  852. $.closeActions();
  853. params.onClose && params.onClose();
  854. if(actions[i] && actions[i].onClick) {
  855. actions[i].onClick();
  856. }
  857. })
  858. });
  859. mask.show();
  860. dialog.show();
  861. mask.addClass("weui-mask--visible");
  862. dialog.addClass("weui-actionsheet_toggle");
  863. };
  864. var hide = function() {
  865. $(".weui-mask").removeClass("weui-mask--visible").transitionEnd(function() {
  866. $(this).remove();
  867. });
  868. $(".weui-actionsheet").removeClass("weui-actionsheet_toggle").transitionEnd(function() {
  869. $(this).remove();
  870. });
  871. }
  872. $.actions = function(params) {
  873. params = $.extend({}, defaults, params);
  874. show(params);
  875. }
  876. $.closeActions = function() {
  877. hide();
  878. }
  879. $(document).on("click", ".weui-actions_mask", function() {
  880. $.closeActions();
  881. });
  882. var defaults = $.actions.prototype.defaults = {
  883. title: undefined,
  884. onClose: undefined,
  885. /*actions: [{
  886. text: "菜单",
  887. className: "color-danger",
  888. onClick: function() {
  889. console.log(1);
  890. }
  891. },{
  892. text: "菜单2",
  893. className: "color-success",
  894. onClick: function() {
  895. console.log(2);
  896. }
  897. }]*/
  898. }
  899. }($);
  900. /* ===============================================================================
  901. ************ Pull to refreh ************
  902. =============================================================================== */
  903. /* global $:true */
  904. +function ($) {
  905. "use strict";
  906. var PTR = function(el, opt) {
  907. if (typeof opt === typeof function () {}) {
  908. opt = {
  909. onRefresh: opt
  910. }
  911. }
  912. if (typeof opt === typeof 'a') {
  913. opt = undefined
  914. }
  915. this.opt = $.extend(PTR.defaults, opt || {});
  916. this.container = $(el);
  917. this.attachEvents();
  918. }
  919. PTR.defaults = {
  920. distance: 50,
  921. onRefresh: undefined,
  922. onPull: undefined
  923. }
  924. PTR.prototype.touchStart = function(e) {
  925. if(this.container.hasClass("refreshing")) return;
  926. var p = $.getTouchPosition(e);
  927. this.start = p;
  928. this.diffX = this.diffY = 0;
  929. };
  930. PTR.prototype.touchMove= function(e) {
  931. if(this.container.hasClass("refreshing")) return;
  932. if(!this.start) return false;
  933. if(this.container.scrollTop() > 0) return;
  934. var p = $.getTouchPosition(e);
  935. this.diffX = p.x - this.start.x;
  936. this.diffY = p.y - this.start.y;
  937. if (Math.abs(this.diffX) > Math.abs(this.diffY)) return true; // 说明是左右方向的拖动
  938. if(this.diffY < 0) return;
  939. this.container.addClass("touching");
  940. e.preventDefault();
  941. e.stopPropagation();
  942. this.diffY = Math.pow(this.diffY, 0.75);
  943. this.container.css("transform", "translate3d(0, "+this.diffY+"px, 0)");
  944. this.triggerPull(this.diffY)
  945. };
  946. PTR.prototype.touchEnd = function() {
  947. this.start = false;
  948. if(this.diffY <= 0 || this.container.hasClass("refreshing")) return;
  949. this.container.removeClass("touching");
  950. this.container.removeClass("pull-down pull-up");
  951. this.container.css("transform", "");
  952. if(Math.abs(this.diffY) <= this.opt.distance) {
  953. } else {
  954. this.triggerPullToRefresh();
  955. }
  956. };
  957. PTR.prototype.triggerPullToRefresh = function() {
  958. this.triggerPull(this.opt.distance)
  959. this.container.removeClass('pull-up').addClass("refreshing");
  960. if (this.opt.onRefresh) {
  961. this.opt.onRefresh.call(this)
  962. }
  963. this.container.trigger("pull-to-refresh");
  964. }
  965. PTR.prototype.triggerPull = function(diffY) {
  966. if(diffY < this.opt.distance) {
  967. this.container.removeClass("pull-up").addClass("pull-down");
  968. } else {
  969. this.container.removeClass("pull-down").addClass("pull-up");
  970. }
  971. if (this.opt.onPull) {
  972. this.opt.onPull.call(this, Math.floor(diffY / this.opt.distance * 100))
  973. }
  974. this.container.trigger("pull");
  975. }
  976. PTR.prototype.pullToRefreshDone = function() {
  977. this.container.removeClass("refreshing");
  978. }
  979. PTR.prototype.attachEvents = function() {
  980. var el = this.container;
  981. el.addClass("weui-pull-to-refresh");
  982. el.on($.touchEvents.start, $.proxy(this.touchStart, this));
  983. el.on($.touchEvents.move, $.proxy(this.touchMove, this));
  984. el.on($.touchEvents.end, $.proxy(this.touchEnd, this));
  985. };
  986. var pullToRefreshDone = function(el) {
  987. $(el).removeClass("refreshing");
  988. }
  989. $.fn.pullToRefresh = function(opt) {
  990. return this.each(function() {
  991. var $this = $(this)
  992. var ptr = $this.data('ptr')
  993. if (!ptr) $this.data('ptr', ptr = new PTR(this, opt))
  994. if (typeof opt === typeof 'a') {
  995. ptr[opt].call(ptr)
  996. }
  997. });
  998. }
  999. $.fn.pullToRefreshDone = function() {
  1000. return this.each(function() {
  1001. pullToRefreshDone(this);
  1002. });
  1003. }
  1004. }($);
  1005. /* ===============================================================================
  1006. ************ Infinite ************
  1007. =============================================================================== */
  1008. /* global $:true */
  1009. +function ($) {
  1010. "use strict";
  1011. // fix https://github.com/lihongxun945/jquery-weui/issues/442
  1012. // chrome will always return 0, when use document.body.scrollTop
  1013. // https://stackoverflow.com/questions/43717316/google-chrome-document-body-scrolltop-always-returns-0
  1014. var getOffset = function (container) {
  1015. var tagName = container[0].tagName.toUpperCase()
  1016. var scrollTop
  1017. if (tagName === 'BODY' || tagName === 'HTML') {
  1018. scrollTop = container.scrollTop() || $(window).scrollTop()
  1019. } else {
  1020. scrollTop = container.scrollTop()
  1021. }
  1022. var offset = container.scrollHeight() - ($(window).height() + scrollTop)
  1023. console.log(offset)
  1024. return offset
  1025. }
  1026. var Infinite = function(el, distance) {
  1027. this.container = $(el);
  1028. this.container.data("infinite", this);
  1029. this.distance = distance || 50;
  1030. this.attachEvents();
  1031. }
  1032. Infinite.prototype.scroll = function() {
  1033. var container = this.container;
  1034. this._check();
  1035. }
  1036. Infinite.prototype.attachEvents = function(off) {
  1037. var el = this.container;
  1038. var scrollContainer = (el[0].tagName.toUpperCase() === "BODY" ? $(document) : el);
  1039. scrollContainer[off ? "off" : "on"]("scroll", $.proxy(this.scroll, this));
  1040. };
  1041. Infinite.prototype.detachEvents = function(off) {
  1042. this.attachEvents(true);
  1043. }
  1044. Infinite.prototype._check = function() {
  1045. var offset = getOffset(this.container);
  1046. if(Math.abs(offset) <= this.distance) {
  1047. this.container.trigger("infinite");
  1048. }
  1049. }
  1050. var infinite = function(el) {
  1051. attachEvents(el);
  1052. }
  1053. $.fn.infinite = function(distance) {
  1054. return this.each(function() {
  1055. new Infinite(this, distance);
  1056. });
  1057. }
  1058. $.fn.destroyInfinite = function() {
  1059. return this.each(function() {
  1060. var infinite = $(this).data("infinite");
  1061. if(infinite && infinite.detachEvents) infinite.detachEvents();
  1062. });
  1063. }
  1064. }($);
  1065. /* global $:true */
  1066. +function ($) {
  1067. "use strict";
  1068. var ITEM_ON = "weui-bar__item--on";
  1069. var showTab = function(a) {
  1070. var $a = $(a);
  1071. if($a.hasClass(ITEM_ON)) return;
  1072. var href = $a.attr("href");
  1073. if(!/^#/.test(href)) return ;
  1074. $a.parent().find("."+ITEM_ON).removeClass(ITEM_ON);
  1075. $a.addClass(ITEM_ON);
  1076. var bd = $a.parents(".weui-tab").find(".weui-tab__bd");
  1077. bd.find(".weui-tab__bd-item--active").removeClass("weui-tab__bd-item--active");
  1078. $(href).addClass("weui-tab__bd-item--active");
  1079. }
  1080. $.showTab = showTab;
  1081. $(document).on("click", ".weui-navbar__item, .weui-tabbar__item", function(e) {
  1082. var $a = $(e.currentTarget);
  1083. var href = $a.attr("href");
  1084. if($a.hasClass(ITEM_ON)) return;
  1085. if(!/^#/.test(href)) return;
  1086. e.preventDefault();
  1087. showTab($a);
  1088. });
  1089. }($);
  1090. /* global $:true */
  1091. + function($) {
  1092. "use strict";
  1093. $(document).on("click touchstart", ".weui-search-bar__label", function(e) {
  1094. $(e.target).parents(".weui-search-bar").addClass("weui-search-bar_focusing").find('input').focus();
  1095. })
  1096. .on("click", ".weui-search-bar__cancel-btn", function(e) {
  1097. var $input = $(e.target).parents(".weui-search-bar").removeClass("weui-search-bar_focusing").find(".weui-search-bar__input").val("").blur();
  1098. })
  1099. .on("click", ".weui-icon-clear", function(e) {
  1100. var $input = $(e.target).parents(".weui-search-bar").find(".weui-search-bar__input").val("").focus();
  1101. });
  1102. }($);
  1103. /*===========================
  1104. Device/OS Detection
  1105. ===========================*/
  1106. /* global $:true */
  1107. ;(function ($) {
  1108. "use strict";
  1109. var device = {};
  1110. var ua = navigator.userAgent;
  1111. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  1112. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  1113. var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  1114. var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  1115. device.ios = device.android = device.iphone = device.ipad = device.androidChrome = false;
  1116. // Android
  1117. if (android) {
  1118. device.os = 'android';
  1119. device.osVersion = android[2];
  1120. device.android = true;
  1121. device.androidChrome = ua.toLowerCase().indexOf('chrome') >= 0;
  1122. }
  1123. if (ipad || iphone || ipod) {
  1124. device.os = 'ios';
  1125. device.ios = true;
  1126. }
  1127. // iOS
  1128. if (iphone && !ipod) {
  1129. device.osVersion = iphone[2].replace(/_/g, '.');
  1130. device.iphone = true;
  1131. }
  1132. if (ipad) {
  1133. device.osVersion = ipad[2].replace(/_/g, '.');
  1134. device.ipad = true;
  1135. }
  1136. if (ipod) {
  1137. device.osVersion = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  1138. device.iphone = true;
  1139. }
  1140. // iOS 8+ changed UA
  1141. if (device.ios && device.osVersion && ua.indexOf('Version/') >= 0) {
  1142. if (device.osVersion.split('.')[0] === '10') {
  1143. device.osVersion = ua.toLowerCase().split('version/')[1].split(' ')[0];
  1144. }
  1145. }
  1146. // Webview
  1147. device.webView = (iphone || ipad || ipod) && ua.match(/.*AppleWebKit(?!.*Safari)/i);
  1148. // Minimal UI
  1149. if (device.os && device.os === 'ios') {
  1150. var osVersionArr = device.osVersion.split('.');
  1151. device.minimalUi = !device.webView &&
  1152. (ipod || iphone) &&
  1153. (osVersionArr[0] * 1 === 7 ? osVersionArr[1] * 1 >= 1 : osVersionArr[0] * 1 > 7) &&
  1154. $('meta[name="viewport"]').length > 0 && $('meta[name="viewport"]').attr('content').indexOf('minimal-ui') >= 0;
  1155. }
  1156. // Check for status bar and fullscreen app mode
  1157. var windowWidth = $(window).width();
  1158. var windowHeight = $(window).height();
  1159. device.statusBar = false;
  1160. if (device.webView && (windowWidth * windowHeight === screen.width * screen.height)) {
  1161. device.statusBar = true;
  1162. }
  1163. else {
  1164. device.statusBar = false;
  1165. }
  1166. // Classes
  1167. var classNames = [];
  1168. // Pixel Ratio
  1169. device.pixelRatio = window.devicePixelRatio || 1;
  1170. classNames.push('pixel-ratio-' + Math.floor(device.pixelRatio));
  1171. if (device.pixelRatio >= 2) {
  1172. classNames.push('retina');
  1173. }
  1174. // OS classes
  1175. if (device.os) {
  1176. classNames.push(device.os, device.os + '-' + device.osVersion.split('.')[0], device.os + '-' + device.osVersion.replace(/\./g, '-'));
  1177. if (device.os === 'ios') {
  1178. var major = parseInt(device.osVersion.split('.')[0], 10);
  1179. for (var i = major - 1; i >= 6; i--) {
  1180. classNames.push('ios-gt-' + i);
  1181. }
  1182. }
  1183. }
  1184. // Status bar classes
  1185. if (device.statusBar) {
  1186. classNames.push('with-statusbar-overlay');
  1187. }
  1188. else {
  1189. $('html').removeClass('with-statusbar-overlay');
  1190. }
  1191. // Add html classes
  1192. if (classNames.length > 0) $('html').addClass(classNames.join(' '));
  1193. $.device = device;
  1194. })($);
  1195. /*======================================================
  1196. ************ Picker ************
  1197. ======================================================*/
  1198. /* global $:true */
  1199. /* jshint unused:false */
  1200. /* jshint multistr:true */
  1201. + function($) {
  1202. "use strict";
  1203. var Picker = function (params) {
  1204. var p = this;
  1205. var defaults = {
  1206. updateValuesOnMomentum: false,
  1207. updateValuesOnTouchmove: true,
  1208. rotateEffect: false,
  1209. momentumRatio: 7,
  1210. freeMode: false,
  1211. // Common settings
  1212. scrollToInput: true,
  1213. inputReadOnly: true,
  1214. toolbar: true,
  1215. toolbarCloseText: '完成',
  1216. title: '请选择',
  1217. toolbarTemplate: '<div class="toolbar">\
  1218. <div class="toolbar-inner">\
  1219. <a href="javascript:;" class="picker-button close-picker">{{closeText}}</a>\
  1220. <h1 class="title">{{title}}</h1>\
  1221. </div>\
  1222. </div>',
  1223. };
  1224. params = params || {};
  1225. for (var def in defaults) {
  1226. if (typeof params[def] === 'undefined') {
  1227. params[def] = defaults[def];
  1228. }
  1229. }
  1230. p.params = params;
  1231. p.cols = [];
  1232. p.initialized = false;
  1233. // Inline flag
  1234. p.inline = p.params.container ? true : false;
  1235. // 3D Transforms origin bug, only on safari
  1236. var originBug = $.device.ios || (navigator.userAgent.toLowerCase().indexOf('safari') >= 0 && navigator.userAgent.toLowerCase().indexOf('chrome') < 0) && !$.device.android;
  1237. // Should be converted to popover
  1238. function isPopover() {
  1239. var toPopover = false;
  1240. if (!p.params.convertToPopover && !p.params.onlyInPopover) return toPopover;
  1241. if (!p.inline && p.params.input) {
  1242. if (p.params.onlyInPopover) toPopover = true;
  1243. else {
  1244. if ($.device.ios) {
  1245. toPopover = $.device.ipad ? true : false;
  1246. }
  1247. else {
  1248. if ($(window).width() >= 768) toPopover = true;
  1249. }
  1250. }
  1251. }
  1252. return toPopover;
  1253. }
  1254. function inPopover() {
  1255. if (p.opened && p.container && p.container.length > 0 && p.container.parents('.popover').length > 0) return true;
  1256. else return false;
  1257. }
  1258. // Value
  1259. p.setValue = function (arrValues, transition) {
  1260. var valueIndex = 0;
  1261. for (var i = 0; i < p.cols.length; i++) {
  1262. if (p.cols[i] && !p.cols[i].divider) {
  1263. p.cols[i].setValue(arrValues[valueIndex], transition);
  1264. valueIndex++;
  1265. }
  1266. }
  1267. };
  1268. p.updateValue = function () {
  1269. var newValue = [];
  1270. var newDisplayValue = [];
  1271. for (var i = 0; i < p.cols.length; i++) {
  1272. if (!p.cols[i].divider) {
  1273. newValue.push(p.cols[i].value);
  1274. newDisplayValue.push(p.cols[i].displayValue);
  1275. }
  1276. }
  1277. if (newValue.indexOf(undefined) >= 0) {
  1278. return;
  1279. }
  1280. p.value = newValue;
  1281. p.displayValue = newDisplayValue;
  1282. if (p.params.onChange) {
  1283. p.params.onChange(p, p.value, p.displayValue);
  1284. }
  1285. if (p.input && p.input.length > 0) {
  1286. $(p.input).val(p.params.formatValue ? p.params.formatValue(p, p.value, p.displayValue) : p.value.join(' '));
  1287. $(p.input).trigger('change');
  1288. }
  1289. };
  1290. // Columns Handlers
  1291. p.initPickerCol = function (colElement, updateItems) {
  1292. var colContainer = $(colElement);
  1293. var colIndex = colContainer.index();
  1294. var col = p.cols[colIndex];
  1295. if (col.divider) return;
  1296. col.container = colContainer;
  1297. col.wrapper = col.container.find('.picker-items-col-wrapper');
  1298. col.items = col.wrapper.find('.picker-item');
  1299. var i, j;
  1300. var wrapperHeight, itemHeight, itemsHeight, minTranslate, maxTranslate;
  1301. col.replaceValues = function (values, displayValues) {
  1302. col.destroyEvents();
  1303. col.values = values;
  1304. col.displayValues = displayValues;
  1305. var newItemsHTML = p.columnHTML(col, true);
  1306. col.wrapper.html(newItemsHTML);
  1307. col.items = col.wrapper.find('.picker-item');
  1308. col.calcSize();
  1309. col.setValue(col.values[0] || '', 0, true);
  1310. col.initEvents();
  1311. };
  1312. col.calcSize = function () {
  1313. if (!col.values.length) return;
  1314. if (p.params.rotateEffect) {
  1315. col.container.removeClass('picker-items-col-absolute');
  1316. if (!col.width) col.container.css({width:''});
  1317. }
  1318. var colWidth, colHeight;
  1319. colWidth = 0;
  1320. colHeight = col.container[0].offsetHeight;
  1321. wrapperHeight = col.wrapper[0].offsetHeight;
  1322. itemHeight = col.items[0].offsetHeight;
  1323. itemsHeight = itemHeight * col.items.length;
  1324. minTranslate = colHeight / 2 - itemsHeight + itemHeight / 2;
  1325. maxTranslate = colHeight / 2 - itemHeight / 2;
  1326. if (col.width) {
  1327. colWidth = col.width;
  1328. if (parseInt(colWidth, 10) === colWidth) colWidth = colWidth + 'px';
  1329. col.container.css({width: colWidth});
  1330. }
  1331. if (p.params.rotateEffect) {
  1332. if (!col.width) {
  1333. col.items.each(function () {
  1334. var item = $(this);
  1335. item.css({width:'auto'});
  1336. colWidth = Math.max(colWidth, item[0].offsetWidth);
  1337. item.css({width:''});
  1338. });
  1339. col.container.css({width: (colWidth + 2) + 'px'});
  1340. }
  1341. col.container.addClass('picker-items-col-absolute');
  1342. }
  1343. };
  1344. col.calcSize();
  1345. col.wrapper.transform('translate3d(0,' + maxTranslate + 'px,0)').transition(0);
  1346. var activeIndex = 0;
  1347. var animationFrameId;
  1348. // Set Value Function
  1349. col.setValue = function (newValue, transition, valueCallbacks) {
  1350. if (typeof transition === 'undefined') transition = '';
  1351. var newActiveIndex = col.wrapper.find('.picker-item[data-picker-value="' + newValue + '"]').index();
  1352. if(typeof newActiveIndex === 'undefined' || newActiveIndex === -1) {
  1353. col.value = col.displayValue = newValue;
  1354. return;
  1355. }
  1356. var newTranslate = -newActiveIndex * itemHeight + maxTranslate;
  1357. // Update wrapper
  1358. col.wrapper.transition(transition);
  1359. col.wrapper.transform('translate3d(0,' + (newTranslate) + 'px,0)');
  1360. // Watch items
  1361. if (p.params.updateValuesOnMomentum && col.activeIndex && col.activeIndex !== newActiveIndex ) {
  1362. $.cancelAnimationFrame(animationFrameId);
  1363. col.wrapper.transitionEnd(function(){
  1364. $.cancelAnimationFrame(animationFrameId);
  1365. });
  1366. updateDuringScroll();
  1367. }
  1368. // Update items
  1369. col.updateItems(newActiveIndex, newTranslate, transition, valueCallbacks);
  1370. };
  1371. col.updateItems = function (activeIndex, translate, transition, valueCallbacks) {
  1372. if (typeof translate === 'undefined') {
  1373. translate = $.getTranslate(col.wrapper[0], 'y');
  1374. }
  1375. if(typeof activeIndex === 'undefined') activeIndex = -Math.round((translate - maxTranslate)/itemHeight);
  1376. if (activeIndex < 0) activeIndex = 0;
  1377. if (activeIndex >= col.items.length) activeIndex = col.items.length - 1;
  1378. var previousActiveIndex = col.activeIndex;
  1379. col.activeIndex = activeIndex;
  1380. //去掉 .picker-after-selected, .picker-before-selected 以提高性能
  1381. col.wrapper.find('.picker-selected').removeClass('picker-selected');
  1382. if (p.params.rotateEffect) {
  1383. col.items.transition(transition);
  1384. }
  1385. var selectedItem = col.items.eq(activeIndex).addClass('picker-selected').transform('');
  1386. if (valueCallbacks || typeof valueCallbacks === 'undefined') {
  1387. // Update values
  1388. col.value = selectedItem.attr('data-picker-value');
  1389. col.displayValue = col.displayValues ? col.displayValues[activeIndex] : col.value;
  1390. // On change callback
  1391. if (previousActiveIndex !== activeIndex) {
  1392. if (col.onChange) {
  1393. col.onChange(p, col.value, col.displayValue);
  1394. }
  1395. p.updateValue();
  1396. }
  1397. }
  1398. // Set 3D rotate effect
  1399. if (!p.params.rotateEffect) {
  1400. return;
  1401. }
  1402. var percentage = (translate - (Math.floor((translate - maxTranslate)/itemHeight) * itemHeight + maxTranslate)) / itemHeight;
  1403. col.items.each(function () {
  1404. var item = $(this);
  1405. var itemOffsetTop = item.index() * itemHeight;
  1406. var translateOffset = maxTranslate - translate;
  1407. var itemOffset = itemOffsetTop - translateOffset;
  1408. var percentage = itemOffset / itemHeight;
  1409. var itemsFit = Math.ceil(col.height / itemHeight / 2) + 1;
  1410. var angle = (-18*percentage);
  1411. if (angle > 180) angle = 180;
  1412. if (angle < -180) angle = -180;
  1413. // Far class
  1414. if (Math.abs(percentage) > itemsFit) item.addClass('picker-item-far');
  1415. else item.removeClass('picker-item-far');
  1416. // Set transform
  1417. item.transform('translate3d(0, ' + (-translate + maxTranslate) + 'px, ' + (originBug ? -110 : 0) + 'px) rotateX(' + angle + 'deg)');
  1418. });
  1419. };
  1420. function updateDuringScroll() {
  1421. animationFrameId = $.requestAnimationFrame(function () {
  1422. col.updateItems(undefined, undefined, 0);
  1423. updateDuringScroll();
  1424. });
  1425. }
  1426. // Update items on init
  1427. if (updateItems) col.updateItems(0, maxTranslate, 0);
  1428. var allowItemClick = true;
  1429. var isTouched, isMoved, touchStartY, touchCurrentY, touchStartTime, touchEndTime, startTranslate, returnTo, currentTranslate, prevTranslate, velocityTranslate, velocityTime;
  1430. function handleTouchStart (e) {
  1431. if (isMoved || isTouched) return;
  1432. e.preventDefault();
  1433. isTouched = true;
  1434. var position = $.getTouchPosition(e);
  1435. touchStartY = touchCurrentY = position.y;
  1436. touchStartTime = (new Date()).getTime();
  1437. allowItemClick = true;
  1438. startTranslate = currentTranslate = $.getTranslate(col.wrapper[0], 'y');
  1439. }
  1440. function handleTouchMove (e) {
  1441. if (!isTouched) return;
  1442. e.preventDefault();
  1443. allowItemClick = false;
  1444. var position = $.getTouchPosition(e);
  1445. touchCurrentY = position.y;
  1446. if (!isMoved) {
  1447. // First move
  1448. $.cancelAnimationFrame(animationFrameId);
  1449. isMoved = true;
  1450. startTranslate = currentTranslate = $.getTranslate(col.wrapper[0], 'y');
  1451. col.wrapper.transition(0);
  1452. }
  1453. e.preventDefault();
  1454. var diff = touchCurrentY - touchStartY;
  1455. currentTranslate = startTranslate + diff;
  1456. returnTo = undefined;
  1457. // Normalize translate
  1458. if (currentTranslate < minTranslate) {
  1459. currentTranslate = minTranslate - Math.pow(minTranslate - currentTranslate, 0.8);
  1460. returnTo = 'min';
  1461. }
  1462. if (currentTranslate > maxTranslate) {
  1463. currentTranslate = maxTranslate + Math.pow(currentTranslate - maxTranslate, 0.8);
  1464. returnTo = 'max';
  1465. }
  1466. // Transform wrapper
  1467. col.wrapper.transform('translate3d(0,' + currentTranslate + 'px,0)');
  1468. // Update items
  1469. col.updateItems(undefined, currentTranslate, 0, p.params.updateValuesOnTouchmove);
  1470. // Calc velocity
  1471. velocityTranslate = currentTranslate - prevTranslate || currentTranslate;
  1472. velocityTime = (new Date()).getTime();
  1473. prevTranslate = currentTranslate;
  1474. }
  1475. function handleTouchEnd (e) {
  1476. if (!isTouched || !isMoved) {
  1477. isTouched = isMoved = false;
  1478. return;
  1479. }
  1480. isTouched = isMoved = false;
  1481. col.wrapper.transition('');
  1482. if (returnTo) {
  1483. if (returnTo === 'min') {
  1484. col.wrapper.transform('translate3d(0,' + minTranslate + 'px,0)');
  1485. }
  1486. else col.wrapper.transform('translate3d(0,' + maxTranslate + 'px,0)');
  1487. }
  1488. touchEndTime = new Date().getTime();
  1489. var velocity, newTranslate;
  1490. if (touchEndTime - touchStartTime > 300) {
  1491. newTranslate = currentTranslate;
  1492. }
  1493. else {
  1494. velocity = Math.abs(velocityTranslate / (touchEndTime - velocityTime));
  1495. newTranslate = currentTranslate + velocityTranslate * p.params.momentumRatio;
  1496. }
  1497. newTranslate = Math.max(Math.min(newTranslate, maxTranslate), minTranslate);
  1498. // Active Index
  1499. var activeIndex = -Math.floor((newTranslate - maxTranslate)/itemHeight);
  1500. // Normalize translate
  1501. if (!p.params.freeMode) newTranslate = -activeIndex * itemHeight + maxTranslate;
  1502. // Transform wrapper
  1503. col.wrapper.transform('translate3d(0,' + (parseInt(newTranslate,10)) + 'px,0)');
  1504. // Update items
  1505. col.updateItems(activeIndex, newTranslate, '', true);
  1506. // Watch items
  1507. if (p.params.updateValuesOnMomentum) {
  1508. updateDuringScroll();
  1509. col.wrapper.transitionEnd(function(){
  1510. $.cancelAnimationFrame(animationFrameId);
  1511. });
  1512. }
  1513. // Allow click
  1514. setTimeout(function () {
  1515. allowItemClick = true;
  1516. }, 100);
  1517. }
  1518. function handleClick(e) {
  1519. if (!allowItemClick) return;
  1520. $.cancelAnimationFrame(animationFrameId);
  1521. /*jshint validthis:true */
  1522. var value = $(this).attr('data-picker-value');
  1523. col.setValue(value);
  1524. }
  1525. col.initEvents = function (detach) {
  1526. var method = detach ? 'off' : 'on';
  1527. col.container[method]($.touchEvents.start, handleTouchStart);
  1528. col.container[method]($.touchEvents.move, handleTouchMove);
  1529. col.container[method]($.touchEvents.end, handleTouchEnd);
  1530. col.items[method]('click', handleClick);
  1531. };
  1532. col.destroyEvents = function () {
  1533. col.initEvents(true);
  1534. };
  1535. col.container[0].f7DestroyPickerCol = function () {
  1536. col.destroyEvents();
  1537. };
  1538. col.initEvents();
  1539. };
  1540. p.destroyPickerCol = function (colContainer) {
  1541. colContainer = $(colContainer);
  1542. if ('f7DestroyPickerCol' in colContainer[0]) colContainer[0].f7DestroyPickerCol();
  1543. };
  1544. // Resize cols
  1545. function resizeCols() {
  1546. if (!p.opened) return;
  1547. for (var i = 0; i < p.cols.length; i++) {
  1548. if (!p.cols[i].divider) {
  1549. p.cols[i].calcSize();
  1550. p.cols[i].setValue(p.cols[i].value, 0, false);
  1551. }
  1552. }
  1553. }
  1554. $(window).on('resize', resizeCols);
  1555. // HTML Layout
  1556. p.columnHTML = function (col, onlyItems) {
  1557. var columnItemsHTML = '';
  1558. var columnHTML = '';
  1559. if (col.divider) {
  1560. columnHTML += '<div class="picker-items-col picker-items-col-divider ' + (col.textAlign ? 'picker-items-col-' + col.textAlign : '') + ' ' + (col.cssClass || '') + '">' + col.content + '</div>';
  1561. }
  1562. else {
  1563. for (var j = 0; j < col.values.length; j++) {
  1564. columnItemsHTML += '<div class="picker-item" data-picker-value="' + col.values[j] + '">' + (col.displayValues ? col.displayValues[j] : col.values[j]) + '</div>';
  1565. }
  1566. columnHTML += '<div class="picker-items-col ' + (col.textAlign ? 'picker-items-col-' + col.textAlign : '') + ' ' + (col.cssClass || '') + '"><div class="picker-items-col-wrapper">' + columnItemsHTML + '</div></div>';
  1567. }
  1568. return onlyItems ? columnItemsHTML : columnHTML;
  1569. };
  1570. p.layout = function () {
  1571. var pickerHTML = '';
  1572. var pickerClass = '';
  1573. var i;
  1574. p.cols = [];
  1575. var colsHTML = '';
  1576. for (i = 0; i < p.params.cols.length; i++) {
  1577. var col = p.params.cols[i];
  1578. colsHTML += p.columnHTML(p.params.cols[i]);
  1579. p.cols.push(col);
  1580. }
  1581. pickerClass = 'weui-picker-modal picker-columns ' + (p.params.cssClass || '') + (p.params.rotateEffect ? ' picker-3d' : '') + (p.params.cols.length === 1 ? ' picker-columns-single' : '');
  1582. pickerHTML =
  1583. '<div class="' + (pickerClass) + '">' +
  1584. (p.params.toolbar ? p.params.toolbarTemplate.replace(/{{closeText}}/g, p.params.toolbarCloseText).replace(/{{title}}/g, p.params.title) : '') +
  1585. '<div class="picker-modal-inner picker-items">' +
  1586. colsHTML +
  1587. '<div class="picker-center-highlight"></div>' +
  1588. '</div>' +
  1589. '</div>';
  1590. p.pickerHTML = pickerHTML;
  1591. };
  1592. // Input Events
  1593. function openOnInput(e) {
  1594. e.preventDefault();
  1595. if (p.opened) return;
  1596. p.open();
  1597. if (p.params.scrollToInput && !isPopover()) {
  1598. var pageContent = p.input.parents('.content');
  1599. if (pageContent.length === 0) return;
  1600. var paddingTop = parseInt(pageContent.css('padding-top'), 10),
  1601. paddingBottom = parseInt(pageContent.css('padding-bottom'), 10),
  1602. pageHeight = pageContent[0].offsetHeight - paddingTop - p.container.height(),
  1603. pageScrollHeight = pageContent[0].scrollHeight - paddingTop - p.container.height(),
  1604. newPaddingBottom;
  1605. var inputTop = p.input.offset().top - paddingTop + p.input[0].offsetHeight;
  1606. if (inputTop > pageHeight) {
  1607. var scrollTop = pageContent.scrollTop() + inputTop - pageHeight;
  1608. if (scrollTop + pageHeight > pageScrollHeight) {
  1609. newPaddingBottom = scrollTop + pageHeight - pageScrollHeight + paddingBottom;
  1610. if (pageHeight === pageScrollHeight) {
  1611. newPaddingBottom = p.container.height();
  1612. }
  1613. pageContent.css({'padding-bottom': (newPaddingBottom) + 'px'});
  1614. }
  1615. pageContent.scrollTop(scrollTop, 300);
  1616. }
  1617. }
  1618. }
  1619. function closeOnHTMLClick(e) {
  1620. if (inPopover()) return;
  1621. if (p.input && p.input.length > 0) {
  1622. if (e.target !== p.input[0] && $(e.target).parents('.weui-picker-modal').length === 0) p.close();
  1623. }
  1624. else {
  1625. if ($(e.target).parents('.weui-picker-modal').length === 0) p.close();
  1626. }
  1627. }
  1628. if (p.params.input) {
  1629. p.input = $(p.params.input);
  1630. if (p.input.length > 0) {
  1631. if (p.params.inputReadOnly) p.input.prop('readOnly', true);
  1632. if (!p.inline) {
  1633. p.input.on('click', openOnInput);
  1634. }
  1635. if (p.params.inputReadOnly) {
  1636. p.input.on('focus mousedown', function (e) {
  1637. e.preventDefault();
  1638. });
  1639. }
  1640. }
  1641. }
  1642. if (!p.inline) $('html').on('click', closeOnHTMLClick);
  1643. // Open
  1644. function onPickerClose() {
  1645. p.opened = false;
  1646. if (p.input && p.input.length > 0) p.input.parents('.page-content').css({'padding-bottom': ''});
  1647. if (p.params.onClose) p.params.onClose(p);
  1648. // Destroy events
  1649. p.container.find('.picker-items-col').each(function () {
  1650. p.destroyPickerCol(this);
  1651. });
  1652. }
  1653. p.opened = false;
  1654. p.open = function () {
  1655. var toPopover = isPopover();
  1656. if (!p.opened) {
  1657. // Layout
  1658. p.layout();
  1659. // Append
  1660. if (toPopover) {
  1661. p.pickerHTML = '<div class="popover popover-picker-columns"><div class="popover-inner">' + p.pickerHTML + '</div></div>';
  1662. p.popover = $.popover(p.pickerHTML, p.params.input, true);
  1663. p.container = $(p.popover).find('.weui-picker-modal');
  1664. $(p.popover).on('close', function () {
  1665. onPickerClose();
  1666. });
  1667. }
  1668. else if (p.inline) {
  1669. p.container = $(p.pickerHTML);
  1670. p.container.addClass('picker-modal-inline');
  1671. $(p.params.container).append(p.container);
  1672. }
  1673. else {
  1674. p.container = $($.openPicker(p.pickerHTML));
  1675. $(p.container)
  1676. .on('close', function () {
  1677. onPickerClose();
  1678. });
  1679. }
  1680. // Store picker instance
  1681. p.container[0].f7Picker = p;
  1682. // Init Events
  1683. p.container.find('.picker-items-col').each(function () {
  1684. var updateItems = true;
  1685. if ((!p.initialized && p.params.value) || (p.initialized && p.value)) updateItems = false;
  1686. p.initPickerCol(this, updateItems);
  1687. });
  1688. // Set value
  1689. if (!p.initialized) {
  1690. if (p.params.value) {
  1691. p.setValue(p.params.value, 0);
  1692. }
  1693. }
  1694. else {
  1695. if (p.value) p.setValue(p.value, 0);
  1696. }
  1697. }
  1698. // Set flag
  1699. p.opened = true;
  1700. p.initialized = true;
  1701. if (p.params.onOpen) p.params.onOpen(p);
  1702. };
  1703. // Close
  1704. p.close = function (force) {
  1705. if (!p.opened || p.inline) return;
  1706. if (inPopover()) {
  1707. $.closePicker(p.popover);
  1708. return;
  1709. }
  1710. else {
  1711. $.closePicker(p.container);
  1712. return;
  1713. }
  1714. };
  1715. // Destroy
  1716. p.destroy = function () {
  1717. p.close();
  1718. if (p.params.input && p.input.length > 0) {
  1719. p.input.off('click focus', openOnInput);
  1720. $(p.input).data('picker', null);
  1721. }
  1722. $('html').off('click', closeOnHTMLClick);
  1723. $(window).off('resize', resizeCols);
  1724. };
  1725. if (p.inline) {
  1726. p.open();
  1727. }
  1728. return p;
  1729. };
  1730. $(document).on("click", ".close-picker", function() {
  1731. var pickerToClose = $('.weui-picker-modal.weui-picker-modal-visible');
  1732. if (pickerToClose.length > 0) {
  1733. $.closePicker(pickerToClose);
  1734. }
  1735. });
  1736. //修复picker会滚动页面的bug
  1737. $(document).on($.touchEvents.move, ".picker-modal-inner", function(e) {
  1738. e.preventDefault();
  1739. });
  1740. $.openPicker = function(tpl, className, callback) {
  1741. if(typeof className === "function") {
  1742. callback = className;
  1743. className = undefined;
  1744. }
  1745. $.closePicker();
  1746. var container = $("<div class='weui-picker-container "+ (className || "") + "'></div>").appendTo(document.body);
  1747. container.show();
  1748. container.addClass("weui-picker-container-visible");
  1749. //关于布局的问题,如果直接放在body上,则做动画的时候会撑开body高度而导致滚动条变化。
  1750. var dialog = $(tpl).appendTo(container);
  1751. dialog.width(); //通过取一次CSS值,强制浏览器不能把上下两行代码合并执行,因为合并之后会导致无法出现动画。
  1752. dialog.addClass("weui-picker-modal-visible");
  1753. callback && container.on("close", callback);
  1754. return dialog;
  1755. }
  1756. $.updatePicker = function(tpl) {
  1757. var container = $(".weui-picker-container-visible");
  1758. if(!container[0]) return false;
  1759. container.html("");
  1760. var dialog = $(tpl).appendTo(container);
  1761. dialog.addClass("weui-picker-modal-visible");
  1762. return dialog;
  1763. }
  1764. $.closePicker = function(container, callback) {
  1765. if(typeof container === "function") callback = container;
  1766. $(".weui-picker-modal-visible").removeClass("weui-picker-modal-visible").transitionEnd(function() {
  1767. $(this).parent().remove();
  1768. callback && callback();
  1769. }).trigger("close");
  1770. };
  1771. $.fn.picker = function(params) {
  1772. var args = arguments;
  1773. return this.each(function() {
  1774. if(!this) return;
  1775. var $this = $(this);
  1776. var picker = $this.data("picker");
  1777. if(!picker) {
  1778. params = $.extend({ input: this }, params || {}) // https://github.com/lihongxun945/jquery-weui/issues/432
  1779. var inputValue = $this.val();
  1780. if(params.value === undefined && inputValue !== "") {
  1781. params.value = (params.cols && params.cols.length > 1) ? inputValue.split(" ") : [inputValue];
  1782. }
  1783. var p = $.extend({input: this}, params);
  1784. picker = new Picker(p);
  1785. $this.data("picker", picker);
  1786. }
  1787. if(typeof params === typeof "a") {
  1788. picker[params].apply(picker, Array.prototype.slice.call(args, 1));
  1789. }
  1790. });
  1791. };
  1792. }($);
  1793. /* global $:true */
  1794. + function($) {
  1795. "use strict";
  1796. var defaults;
  1797. var selects = [];
  1798. var Select = function(input, config) {
  1799. var self = this;
  1800. this.config = config;
  1801. //init empty data
  1802. this.data = {
  1803. values: '',
  1804. titles: '',
  1805. origins: [],
  1806. length: 0
  1807. };
  1808. this.$input = $(input);
  1809. this.$input.prop("readOnly", true);
  1810. this.initConfig();
  1811. config = this.config;
  1812. this.$input.click($.proxy(this.open, this));
  1813. selects.push(this)
  1814. }
  1815. Select.prototype.initConfig = function() {
  1816. this.config = $.extend({}, defaults, this.config);
  1817. var config = this.config;
  1818. if(!config.items || !config.items.length) return;
  1819. config.items = config.items.map(function(d, i) {
  1820. if(typeof d == typeof "a") {
  1821. return {
  1822. title: d,
  1823. value: d
  1824. };
  1825. }
  1826. return d;
  1827. });
  1828. this.tpl = $.t7.compile("<div class='weui-picker-modal weui-select-modal'>" + config.toolbarTemplate + (config.multi ? config.checkboxTemplate : config.radioTemplate) + "</div>");
  1829. if(config.input !== undefined) this.$input.val(config.input);
  1830. this.parseInitValue();
  1831. this._init = true;
  1832. }
  1833. Select.prototype.updateInputValue = function(values, titles) {
  1834. var v, t;
  1835. if(this.config.multi) {
  1836. v = values.join(this.config.split);
  1837. t = titles.join(this.config.split);
  1838. } else {
  1839. v = values[0];
  1840. t = titles[0];
  1841. }
  1842. //caculate origin data
  1843. var origins = [];
  1844. this.config.items.forEach(function(d) {
  1845. values.each(function(i, dd) {
  1846. if(d.value == dd) origins.push(d);
  1847. });
  1848. });
  1849. this.$input.val(t).data("values", v);
  1850. this.$input.attr("value", t).attr("data-values", v);
  1851. var data = {
  1852. values: v,
  1853. titles: t,
  1854. valuesArray: values,
  1855. titlesArray: titles,
  1856. origins: origins,
  1857. length: origins.length
  1858. };
  1859. this.data = data;
  1860. this.$input.trigger("change", data);
  1861. this.config.onChange && this.config.onChange.call(this, data);
  1862. }
  1863. Select.prototype.parseInitValue = function() {
  1864. var value = this.$input.val();
  1865. var items = this.config.items;
  1866. //如果input为空,只有在第一次初始化的时候才保留默认选择。因为后来就是用户自己取消了全部选择,不能再为他选中默认值。
  1867. if( !this._init && (value === undefined || value == null || value === "")) return;
  1868. var titles = this.config.multi ? value.split(this.config.split) : [value];
  1869. for(var i=0;i<items.length;i++) {
  1870. items[i].checked = false;
  1871. for(var j=0;j<titles.length;j++) {
  1872. if(items[i].title === titles[j]) {
  1873. items[i].checked = true;
  1874. }
  1875. }
  1876. }
  1877. }
  1878. Select.prototype._bind = function(dialog) {
  1879. var self = this,
  1880. config = this.config;
  1881. dialog.on("change", function(e) {
  1882. var checked = dialog.find("input:checked");
  1883. var values = checked.map(function() {
  1884. return $(this).val();
  1885. });
  1886. var titles = checked.map(function() {
  1887. return $(this).data("title");
  1888. });
  1889. self.updateInputValue(values, titles);
  1890. if(config.autoClose && !config.multi) self.close();
  1891. })
  1892. .on("click", ".close-select", function() {
  1893. self.close();
  1894. });
  1895. }
  1896. //更新数据
  1897. Select.prototype.update = function(config) {
  1898. this.config = $.extend({}, this.config, config);
  1899. this.initConfig();
  1900. if(this._open) {
  1901. this._bind($.updatePicker(this.getHTML()));
  1902. }
  1903. }
  1904. Select.prototype.open = function(values, titles) {
  1905. if(this._open) return;
  1906. // open picker 会默认关掉其他的,但是 onClose 不会被调用,所以这里先关掉其他select
  1907. for (var i = 0; i < selects.length; i++ ) {
  1908. var s = selects[i];
  1909. if (s === this) continue;
  1910. if (s._open) {
  1911. if(!s.close()) return false; // 其他的select由于某些条件限制关闭失败。
  1912. }
  1913. }
  1914. this.parseInitValue();
  1915. var config = this.config;
  1916. var dialog = this.dialog = $.openPicker(this.getHTML());
  1917. this._bind(dialog);
  1918. this._open = true;
  1919. if(config.onOpen) config.onOpen(this);
  1920. }
  1921. Select.prototype.close = function(callback, force) {
  1922. if (!this._open) return false;
  1923. var self = this,
  1924. beforeClose = this.config.beforeClose;
  1925. if(typeof callback === typeof true) {
  1926. force === callback;
  1927. }
  1928. if(!force) {
  1929. if(beforeClose && typeof beforeClose === 'function' && beforeClose.call(this, this.data.values, this.data.titles) === false) {
  1930. return false
  1931. }
  1932. if(this.config.multi) {
  1933. if(this.config.min !== undefined && this.data.length < this.config.min) {
  1934. $.toast("请至少选择"+this.config.min+"个", "text");
  1935. return false
  1936. }
  1937. if(this.config.max !== undefined && this.data.length > this.config.max) {
  1938. $.toast("最多只能选择"+this.config.max+"个", "text");
  1939. return false
  1940. }
  1941. }
  1942. }
  1943. $.closePicker(function() {
  1944. self.onClose();
  1945. callback && callback();
  1946. });
  1947. return true
  1948. }
  1949. Select.prototype.onClose = function() {
  1950. this._open = false;
  1951. if(this.config.onClose) this.config.onClose(this);
  1952. }
  1953. Select.prototype.getHTML = function(callback) {
  1954. var config = this.config;
  1955. return this.tpl({
  1956. items: config.items,
  1957. title: config.title,
  1958. closeText: config.closeText
  1959. })
  1960. }
  1961. $.fn.select = function(params, args) {
  1962. return this.each(function() {
  1963. var $this = $(this);
  1964. if(!$this.data("weui-select")) $this.data("weui-select", new Select(this, params));
  1965. var select = $this.data("weui-select");
  1966. if(typeof params === typeof "a") select[params].call(select, args);
  1967. return select;
  1968. });
  1969. }
  1970. defaults = $.fn.select.prototype.defaults = {
  1971. items: [],
  1972. input: undefined, //输入框的初始值
  1973. title: "请选择",
  1974. multi: false,
  1975. closeText: "确定",
  1976. autoClose: true, //是否选择完成后自动关闭,只有单选模式下才有效
  1977. onChange: undefined, //function
  1978. beforeClose: undefined, // function 关闭之前,如果返回false则阻止关闭
  1979. onClose: undefined, //function
  1980. onOpen: undefined, //function
  1981. split: ",", //多选模式下的分隔符
  1982. min: undefined, //多选模式下可用,最少选择数
  1983. max: undefined, //单选模式下可用,最多选择数
  1984. toolbarTemplate: '<div class="toolbar">\
  1985. <div class="toolbar-inner">\
  1986. <a href="javascript:;" class="picker-button close-select">{{closeText}}</a>\
  1987. <h1 class="title">{{title}}</h1>\
  1988. </div>\
  1989. </div>',
  1990. radioTemplate:
  1991. '<div class="weui-cells weui-cells_radio">\
  1992. {{#items}}\
  1993. <label class="weui-cell weui-check_label" for="weui-select-id-{{this.title}}">\
  1994. <div class="weui-cell__bd weui-cell_primary">\
  1995. <p>{{this.title}}</p>\
  1996. </div>\
  1997. <div class="weui-cell__ft">\
  1998. <input type="radio" class="weui-check" name="weui-select" id="weui-select-id-{{this.title}}" value="{{this.value}}" {{#if this.checked}}checked="checked"{{/if}} data-title="{{this.title}}">\
  1999. <span class="weui-icon-checked"></span>\
  2000. </div>\
  2001. </label>\
  2002. {{/items}}\
  2003. </div>',
  2004. checkboxTemplate:
  2005. '<div class="weui-cells weui-cells_checkbox">\
  2006. {{#items}}\
  2007. <label class="weui-cell weui-check_label" for="weui-select-id-{{this.title}}">\
  2008. <div class="weui-cell__bd weui-cell_primary">\
  2009. <p>{{this.title}}</p>\
  2010. </div>\
  2011. <div class="weui-cell__ft">\
  2012. <input type="checkbox" class="weui-check" name="weui-select" id="weui-select-id-{{this.title}}" value="{{this.value}}" {{#if this.checked}}checked="checked"{{/if}} data-title="{{this.title}}" >\
  2013. <span class="weui-icon-checked"></span>\
  2014. </div>\
  2015. </label>\
  2016. {{/items}}\
  2017. </div>',
  2018. }
  2019. }($);
  2020. /*======================================================
  2021. ************ Calendar ************
  2022. ======================================================*/
  2023. /* global $:true */
  2024. /*jshint unused: false*/
  2025. +function ($) {
  2026. "use strict";
  2027. var rtl = false;
  2028. var defaults;
  2029. var isSameDate = function (a, b) {
  2030. var a = new Date(a),
  2031. b = new Date(b);
  2032. return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate()
  2033. }
  2034. var Calendar = function (params) {
  2035. var p = this;
  2036. params = params || {};
  2037. for (var def in defaults) {
  2038. if (typeof params[def] === 'undefined') {
  2039. params[def] = defaults[def];
  2040. }
  2041. }
  2042. p.params = params;
  2043. p.initialized = false;
  2044. // Inline flag
  2045. p.inline = p.params.container ? true : false;
  2046. // Is horizontal
  2047. p.isH = p.params.direction === 'horizontal';
  2048. // RTL inverter
  2049. var inverter = p.isH ? (rtl ? -1 : 1) : 1;
  2050. // Animating flag
  2051. p.animating = false;
  2052. // Should be converted to popover
  2053. function isPopover() {
  2054. var toPopover = false;
  2055. if (!p.params.convertToPopover && !p.params.onlyInPopover) return toPopover;
  2056. if (!p.inline && p.params.input) {
  2057. if (p.params.onlyInPopover) toPopover = true;
  2058. else {
  2059. if ($.device.ios) {
  2060. toPopover = $.device.ipad ? true : false;
  2061. }
  2062. else {
  2063. if ($(window).width() >= 768) toPopover = true;
  2064. }
  2065. }
  2066. }
  2067. return toPopover;
  2068. }
  2069. function inPopover() {
  2070. if (p.opened && p.container && p.container.length > 0 && p.container.parents('.popover').length > 0) return true;
  2071. else return false;
  2072. }
  2073. // Format date
  2074. function formatDate(date) {
  2075. date = new Date(date);
  2076. var year = date.getFullYear();
  2077. var month = date.getMonth();
  2078. var month1 = month + 1;
  2079. var day = date.getDate();
  2080. var weekDay = date.getDay();
  2081. return p.params.dateFormat
  2082. .replace(/yyyy/g, year)
  2083. .replace(/yy/g, (year + '').substring(2))
  2084. .replace(/mm/g, month1 < 10 ? '0' + month1 : month1)
  2085. .replace(/m/g, month1)
  2086. .replace(/MM/g, p.params.monthNames[month])
  2087. .replace(/M/g, p.params.monthNamesShort[month])
  2088. .replace(/dd/g, day < 10 ? '0' + day : day)
  2089. .replace(/d/g, day)
  2090. .replace(/DD/g, p.params.dayNames[weekDay])
  2091. .replace(/D/g, p.params.dayNamesShort[weekDay]);
  2092. }
  2093. // Value
  2094. p.addValue = function (value) {
  2095. if (p.params.multiple) {
  2096. if (!p.value) p.value = [];
  2097. var inValuesIndex;
  2098. for (var i = 0; i < p.value.length; i++) {
  2099. if (isSameDate(value, p.value[i])) {
  2100. inValuesIndex = i;
  2101. }
  2102. }
  2103. if (typeof inValuesIndex === 'undefined') {
  2104. p.value.push(value);
  2105. }
  2106. else {
  2107. p.value.splice(inValuesIndex, 1);
  2108. }
  2109. p.updateValue();
  2110. }
  2111. else {
  2112. p.value = [value];
  2113. p.updateValue();
  2114. }
  2115. };
  2116. p.setValue = function (arrValues) {
  2117. var date = new Date(arrValues[0]);
  2118. p.setYearMonth(date.getFullYear(), date.getMonth());
  2119. p.addValue(+ date);
  2120. };
  2121. p.updateValue = function () {
  2122. p.wrapper.find('.picker-calendar-day-selected').removeClass('picker-calendar-day-selected');
  2123. var i, inputValue;
  2124. for (i = 0; i < p.value.length; i++) {
  2125. var valueDate = new Date(p.value[i]);
  2126. p.wrapper.find('.picker-calendar-day[data-date="' + valueDate.getFullYear() + '-' + valueDate.getMonth() + '-' + valueDate.getDate() + '"]').addClass('picker-calendar-day-selected');
  2127. }
  2128. if (p.params.onChange) {
  2129. p.params.onChange(p, p.value.map(formatDate), p.value.map(function (d) {
  2130. return + new Date(typeof d === typeof 'a' ? d.split(/\D/).filter(function (a) { return !!a; }).join("-") : d);
  2131. }));
  2132. }
  2133. if (p.input && p.input.length > 0) {
  2134. if (p.params.formatValue) inputValue = p.params.formatValue(p, p.value);
  2135. else {
  2136. inputValue = [];
  2137. for (i = 0; i < p.value.length; i++) {
  2138. inputValue.push(formatDate(p.value[i]));
  2139. }
  2140. inputValue = inputValue.join(', ');
  2141. }
  2142. $(p.input).val(inputValue);
  2143. $(p.input).trigger('change');
  2144. }
  2145. };
  2146. // Columns Handlers
  2147. p.initCalendarEvents = function () {
  2148. var col;
  2149. var allowItemClick = true;
  2150. var isTouched, isMoved, touchStartX, touchStartY, touchCurrentX, touchCurrentY, touchStartTime, touchEndTime, startTranslate, currentTranslate, wrapperWidth, wrapperHeight, percentage, touchesDiff, isScrolling;
  2151. function handleTouchStart (e) {
  2152. if (isMoved || isTouched) return;
  2153. // e.preventDefault();
  2154. isTouched = true;
  2155. var position = $.getTouchPosition(e);
  2156. touchStartX = touchCurrentY = position.x;
  2157. touchStartY = touchCurrentY = position.y;
  2158. touchStartTime = (new Date()).getTime();
  2159. percentage = 0;
  2160. allowItemClick = true;
  2161. isScrolling = undefined;
  2162. startTranslate = currentTranslate = p.monthsTranslate;
  2163. }
  2164. function handleTouchMove (e) {
  2165. if (!isTouched) return;
  2166. var position = $.getTouchPosition(e);
  2167. touchCurrentX = position.x;
  2168. touchCurrentY = position.y;
  2169. if (typeof isScrolling === 'undefined') {
  2170. isScrolling = !!(isScrolling || Math.abs(touchCurrentY - touchStartY) > Math.abs(touchCurrentX - touchStartX));
  2171. }
  2172. if (p.isH && isScrolling) {
  2173. isTouched = false;
  2174. return;
  2175. }
  2176. e.preventDefault();
  2177. if (p.animating) {
  2178. isTouched = false;
  2179. return;
  2180. }
  2181. allowItemClick = false;
  2182. if (!isMoved) {
  2183. // First move
  2184. isMoved = true;
  2185. wrapperWidth = p.wrapper[0].offsetWidth;
  2186. wrapperHeight = p.wrapper[0].offsetHeight;
  2187. p.wrapper.transition(0);
  2188. }
  2189. e.preventDefault();
  2190. touchesDiff = p.isH ? touchCurrentX - touchStartX : touchCurrentY - touchStartY;
  2191. percentage = touchesDiff/(p.isH ? wrapperWidth : wrapperHeight);
  2192. currentTranslate = (p.monthsTranslate * inverter + percentage) * 100;
  2193. // Transform wrapper
  2194. p.wrapper.transform('translate3d(' + (p.isH ? currentTranslate : 0) + '%, ' + (p.isH ? 0 : currentTranslate) + '%, 0)');
  2195. }
  2196. function handleTouchEnd (e) {
  2197. if (!isTouched || !isMoved) {
  2198. isTouched = isMoved = false;
  2199. return;
  2200. }
  2201. isTouched = isMoved = false;
  2202. touchEndTime = new Date().getTime();
  2203. if (touchEndTime - touchStartTime < 300) {
  2204. if (Math.abs(touchesDiff) < 10) {
  2205. p.resetMonth();
  2206. }
  2207. else if (touchesDiff >= 10) {
  2208. if (rtl) p.nextMonth();
  2209. else p.prevMonth();
  2210. }
  2211. else {
  2212. if (rtl) p.prevMonth();
  2213. else p.nextMonth();
  2214. }
  2215. }
  2216. else {
  2217. if (percentage <= -0.5) {
  2218. if (rtl) p.prevMonth();
  2219. else p.nextMonth();
  2220. }
  2221. else if (percentage >= 0.5) {
  2222. if (rtl) p.nextMonth();
  2223. else p.prevMonth();
  2224. }
  2225. else {
  2226. p.resetMonth();
  2227. }
  2228. }
  2229. // Allow click
  2230. setTimeout(function () {
  2231. allowItemClick = true;
  2232. }, 100);
  2233. }
  2234. function handleDayClick(e) {
  2235. if (!allowItemClick) return;
  2236. var day = $(e.target).parents('.picker-calendar-day');
  2237. if (day.length === 0 && $(e.target).hasClass('picker-calendar-day')) {
  2238. day = $(e.target);
  2239. }
  2240. if (day.length === 0) return;
  2241. // if (day.hasClass('picker-calendar-day-selected') && !p.params.multiple) return;
  2242. if (day.hasClass('picker-calendar-day-disabled')) return;
  2243. if (day.hasClass('picker-calendar-day-next')) p.nextMonth();
  2244. if (day.hasClass('picker-calendar-day-prev')) p.prevMonth();
  2245. var dateYear = day.attr('data-year');
  2246. var dateMonth = day.attr('data-month');
  2247. var dateDay = day.attr('data-day');
  2248. if (p.params.onDayClick) {
  2249. p.params.onDayClick(p, day[0], dateYear, dateMonth, dateDay);
  2250. }
  2251. p.addValue(new Date(dateYear, dateMonth, dateDay).getTime());
  2252. if (p.params.closeOnSelect && !p.params.multiple) p.close();
  2253. }
  2254. p.container.find('.picker-calendar-prev-month').on('click', p.prevMonth);
  2255. p.container.find('.picker-calendar-next-month').on('click', p.nextMonth);
  2256. p.container.find('.picker-calendar-prev-year').on('click', p.prevYear);
  2257. p.container.find('.picker-calendar-next-year').on('click', p.nextYear);
  2258. p.wrapper.on('click', handleDayClick);
  2259. if (p.params.touchMove) {
  2260. p.wrapper.on($.touchEvents.start, handleTouchStart);
  2261. p.wrapper.on($.touchEvents.move, handleTouchMove);
  2262. p.wrapper.on($.touchEvents.end, handleTouchEnd);
  2263. }
  2264. p.container[0].f7DestroyCalendarEvents = function () {
  2265. p.container.find('.picker-calendar-prev-month').off('click', p.prevMonth);
  2266. p.container.find('.picker-calendar-next-month').off('click', p.nextMonth);
  2267. p.container.find('.picker-calendar-prev-year').off('click', p.prevYear);
  2268. p.container.find('.picker-calendar-next-year').off('click', p.nextYear);
  2269. p.wrapper.off('click', handleDayClick);
  2270. if (p.params.touchMove) {
  2271. p.wrapper.off($.touchEvents.start, handleTouchStart);
  2272. p.wrapper.off($.touchEvents.move, handleTouchMove);
  2273. p.wrapper.off($.touchEvents.end, handleTouchEnd);
  2274. }
  2275. };
  2276. };
  2277. p.destroyCalendarEvents = function (colContainer) {
  2278. if ('f7DestroyCalendarEvents' in p.container[0]) p.container[0].f7DestroyCalendarEvents();
  2279. };
  2280. // Calendar Methods
  2281. p.daysInMonth = function (date) {
  2282. var d = new Date(date);
  2283. return new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
  2284. };
  2285. p.monthHTML = function (date, offset) {
  2286. date = new Date(date);
  2287. var year = date.getFullYear(),
  2288. month = date.getMonth(),
  2289. day = date.getDate();
  2290. if (offset === 'next') {
  2291. if (month === 11) date = new Date(year + 1, 0);
  2292. else date = new Date(year, month + 1, 1);
  2293. }
  2294. if (offset === 'prev') {
  2295. if (month === 0) date = new Date(year - 1, 11);
  2296. else date = new Date(year, month - 1, 1);
  2297. }
  2298. if (offset === 'next' || offset === 'prev') {
  2299. month = date.getMonth();
  2300. year = date.getFullYear();
  2301. }
  2302. var daysInPrevMonth = p.daysInMonth(new Date(date.getFullYear(), date.getMonth()).getTime() - 10 * 24 * 60 * 60 * 1000),
  2303. daysInMonth = p.daysInMonth(date),
  2304. firstDayOfMonthIndex = new Date(date.getFullYear(), date.getMonth()).getDay();
  2305. if (firstDayOfMonthIndex === 0) firstDayOfMonthIndex = 7;
  2306. var dayDate, currentValues = [], i, j,
  2307. rows = 6, cols = 7,
  2308. monthHTML = '',
  2309. dayIndex = 0 + (p.params.firstDay - 1),
  2310. today = new Date().setHours(0,0,0,0),
  2311. minDate = p.params.minDate ? new Date(p.params.minDate).getTime() : null,
  2312. maxDate = p.params.maxDate ? new Date(p.params.maxDate).getTime() : null;
  2313. if (p.value && p.value.length) {
  2314. for (i = 0; i < p.value.length; i++) {
  2315. currentValues.push(new Date(p.value[i]).setHours(0,0,0,0));
  2316. }
  2317. }
  2318. for (i = 1; i <= rows; i++) {
  2319. var rowHTML = '';
  2320. var row = i;
  2321. for (j = 1; j <= cols; j++) {
  2322. var col = j;
  2323. dayIndex ++;
  2324. var dayNumber = dayIndex - firstDayOfMonthIndex;
  2325. var addClass = '';
  2326. if (dayNumber < 0) {
  2327. dayNumber = daysInPrevMonth + dayNumber + 1;
  2328. addClass += ' picker-calendar-day-prev';
  2329. dayDate = new Date(month - 1 < 0 ? year - 1 : year, month - 1 < 0 ? 11 : month - 1, dayNumber).getTime();
  2330. }
  2331. else {
  2332. dayNumber = dayNumber + 1;
  2333. if (dayNumber > daysInMonth) {
  2334. dayNumber = dayNumber - daysInMonth;
  2335. addClass += ' picker-calendar-day-next';
  2336. dayDate = new Date(month + 1 > 11 ? year + 1 : year, month + 1 > 11 ? 0 : month + 1, dayNumber).getTime();
  2337. }
  2338. else {
  2339. dayDate = new Date(year, month, dayNumber).getTime();
  2340. }
  2341. }
  2342. // Today
  2343. if (dayDate === today) addClass += ' picker-calendar-day-today';
  2344. // Selected
  2345. if (currentValues.indexOf(dayDate) >= 0) addClass += ' picker-calendar-day-selected';
  2346. // Weekend
  2347. if (p.params.weekendDays.indexOf(col - 1) >= 0) {
  2348. addClass += ' picker-calendar-day-weekend';
  2349. }
  2350. // Disabled
  2351. if ((minDate && dayDate < minDate) || (maxDate && dayDate > maxDate)) {
  2352. addClass += ' picker-calendar-day-disabled';
  2353. }
  2354. dayDate = new Date(dayDate);
  2355. var dayYear = dayDate.getFullYear();
  2356. var dayMonth = dayDate.getMonth();
  2357. rowHTML += '<div data-year="' + dayYear + '" data-month="' + dayMonth + '" data-day="' + dayNumber + '" class="picker-calendar-day' + (addClass) + '" data-date="' + (dayYear + '-' + dayMonth + '-' + dayNumber) + '"><span>'+dayNumber+'</span></div>';
  2358. }
  2359. monthHTML += '<div class="picker-calendar-row">' + rowHTML + '</div>';
  2360. }
  2361. monthHTML = '<div class="picker-calendar-month" data-year="' + year + '" data-month="' + month + '">' + monthHTML + '</div>';
  2362. return monthHTML;
  2363. };
  2364. p.animating = false;
  2365. p.updateCurrentMonthYear = function (dir) {
  2366. if (typeof dir === 'undefined') {
  2367. p.currentMonth = parseInt(p.months.eq(1).attr('data-month'), 10);
  2368. p.currentYear = parseInt(p.months.eq(1).attr('data-year'), 10);
  2369. }
  2370. else {
  2371. p.currentMonth = parseInt(p.months.eq(dir === 'next' ? (p.months.length - 1) : 0).attr('data-month'), 10);
  2372. p.currentYear = parseInt(p.months.eq(dir === 'next' ? (p.months.length - 1) : 0).attr('data-year'), 10);
  2373. }
  2374. p.container.find('.current-month-value').text(p.params.monthNames[p.currentMonth]);
  2375. p.container.find('.current-year-value').text(p.currentYear);
  2376. };
  2377. p.onMonthChangeStart = function (dir) {
  2378. p.updateCurrentMonthYear(dir);
  2379. p.months.removeClass('picker-calendar-month-current picker-calendar-month-prev picker-calendar-month-next');
  2380. var currentIndex = dir === 'next' ? p.months.length - 1 : 0;
  2381. p.months.eq(currentIndex).addClass('picker-calendar-month-current');
  2382. p.months.eq(dir === 'next' ? currentIndex - 1 : currentIndex + 1).addClass(dir === 'next' ? 'picker-calendar-month-prev' : 'picker-calendar-month-next');
  2383. if (p.params.onMonthYearChangeStart) {
  2384. p.params.onMonthYearChangeStart(p, p.currentYear, p.currentMonth);
  2385. }
  2386. };
  2387. p.onMonthChangeEnd = function (dir, rebuildBoth) {
  2388. p.animating = false;
  2389. var nextMonthHTML, prevMonthHTML, newMonthHTML;
  2390. p.wrapper.find('.picker-calendar-month:not(.picker-calendar-month-prev):not(.picker-calendar-month-current):not(.picker-calendar-month-next)').remove();
  2391. if (typeof dir === 'undefined') {
  2392. dir = 'next';
  2393. rebuildBoth = true;
  2394. }
  2395. if (!rebuildBoth) {
  2396. newMonthHTML = p.monthHTML(new Date(p.currentYear, p.currentMonth), dir);
  2397. }
  2398. else {
  2399. p.wrapper.find('.picker-calendar-month-next, .picker-calendar-month-prev').remove();
  2400. prevMonthHTML = p.monthHTML(new Date(p.currentYear, p.currentMonth), 'prev');
  2401. nextMonthHTML = p.monthHTML(new Date(p.currentYear, p.currentMonth), 'next');
  2402. }
  2403. if (dir === 'next' || rebuildBoth) {
  2404. p.wrapper.append(newMonthHTML || nextMonthHTML);
  2405. }
  2406. if (dir === 'prev' || rebuildBoth) {
  2407. p.wrapper.prepend(newMonthHTML || prevMonthHTML);
  2408. }
  2409. p.months = p.wrapper.find('.picker-calendar-month');
  2410. p.setMonthsTranslate(p.monthsTranslate);
  2411. if (p.params.onMonthAdd) {
  2412. p.params.onMonthAdd(p, dir === 'next' ? p.months.eq(p.months.length - 1)[0] : p.months.eq(0)[0]);
  2413. }
  2414. if (p.params.onMonthYearChangeEnd) {
  2415. p.params.onMonthYearChangeEnd(p, p.currentYear, p.currentMonth);
  2416. }
  2417. };
  2418. p.setMonthsTranslate = function (translate) {
  2419. translate = translate || p.monthsTranslate || 0;
  2420. if (typeof p.monthsTranslate === 'undefined') p.monthsTranslate = translate;
  2421. p.months.removeClass('picker-calendar-month-current picker-calendar-month-prev picker-calendar-month-next');
  2422. var prevMonthTranslate = -(translate + 1) * 100 * inverter;
  2423. var currentMonthTranslate = -translate * 100 * inverter;
  2424. var nextMonthTranslate = -(translate - 1) * 100 * inverter;
  2425. p.months.eq(0).transform('translate3d(' + (p.isH ? prevMonthTranslate : 0) + '%, ' + (p.isH ? 0 : prevMonthTranslate) + '%, 0)').addClass('picker-calendar-month-prev');
  2426. p.months.eq(1).transform('translate3d(' + (p.isH ? currentMonthTranslate : 0) + '%, ' + (p.isH ? 0 : currentMonthTranslate) + '%, 0)').addClass('picker-calendar-month-current');
  2427. p.months.eq(2).transform('translate3d(' + (p.isH ? nextMonthTranslate : 0) + '%, ' + (p.isH ? 0 : nextMonthTranslate) + '%, 0)').addClass('picker-calendar-month-next');
  2428. };
  2429. p.nextMonth = function (transition) {
  2430. if (typeof transition === 'undefined' || typeof transition === 'object') {
  2431. transition = '';
  2432. if (!p.params.animate) transition = 0;
  2433. }
  2434. var nextMonth = parseInt(p.months.eq(p.months.length - 1).attr('data-month'), 10);
  2435. var nextYear = parseInt(p.months.eq(p.months.length - 1).attr('data-year'), 10);
  2436. var nextDate = new Date(nextYear, nextMonth);
  2437. var nextDateTime = nextDate.getTime();
  2438. var transitionEndCallback = p.animating ? false : true;
  2439. if (p.params.maxDate) {
  2440. if (nextDateTime > new Date(p.params.maxDate).getTime()) {
  2441. return p.resetMonth();
  2442. }
  2443. }
  2444. p.monthsTranslate --;
  2445. if (nextMonth === p.currentMonth) {
  2446. var nextMonthTranslate = -(p.monthsTranslate) * 100 * inverter;
  2447. var nextMonthHTML = $(p.monthHTML(nextDateTime, 'next')).transform('translate3d(' + (p.isH ? nextMonthTranslate : 0) + '%, ' + (p.isH ? 0 : nextMonthTranslate) + '%, 0)').addClass('picker-calendar-month-next');
  2448. p.wrapper.append(nextMonthHTML[0]);
  2449. p.months = p.wrapper.find('.picker-calendar-month');
  2450. if (p.params.onMonthAdd) {
  2451. p.params.onMonthAdd(p, p.months.eq(p.months.length - 1)[0]);
  2452. }
  2453. }
  2454. p.animating = true;
  2455. p.onMonthChangeStart('next');
  2456. var translate = (p.monthsTranslate * 100) * inverter;
  2457. p.wrapper.transition(transition).transform('translate3d(' + (p.isH ? translate : 0) + '%, ' + (p.isH ? 0 : translate) + '%, 0)');
  2458. if (transitionEndCallback) {
  2459. p.wrapper.transitionEnd(function () {
  2460. p.onMonthChangeEnd('next');
  2461. });
  2462. }
  2463. if (!p.params.animate) {
  2464. p.onMonthChangeEnd('next');
  2465. }
  2466. };
  2467. p.prevMonth = function (transition) {
  2468. if (typeof transition === 'undefined' || typeof transition === 'object') {
  2469. transition = '';
  2470. if (!p.params.animate) transition = 0;
  2471. }
  2472. var prevMonth = parseInt(p.months.eq(0).attr('data-month'), 10);
  2473. var prevYear = parseInt(p.months.eq(0).attr('data-year'), 10);
  2474. var prevDate = new Date(prevYear, prevMonth + 1, -1);
  2475. var prevDateTime = prevDate.getTime();
  2476. var transitionEndCallback = p.animating ? false : true;
  2477. if (p.params.minDate) {
  2478. if (prevDateTime < new Date(p.params.minDate).getTime()) {
  2479. return p.resetMonth();
  2480. }
  2481. }
  2482. p.monthsTranslate ++;
  2483. if (prevMonth === p.currentMonth) {
  2484. var prevMonthTranslate = -(p.monthsTranslate) * 100 * inverter;
  2485. var prevMonthHTML = $(p.monthHTML(prevDateTime, 'prev')).transform('translate3d(' + (p.isH ? prevMonthTranslate : 0) + '%, ' + (p.isH ? 0 : prevMonthTranslate) + '%, 0)').addClass('picker-calendar-month-prev');
  2486. p.wrapper.prepend(prevMonthHTML[0]);
  2487. p.months = p.wrapper.find('.picker-calendar-month');
  2488. if (p.params.onMonthAdd) {
  2489. p.params.onMonthAdd(p, p.months.eq(0)[0]);
  2490. }
  2491. }
  2492. p.animating = true;
  2493. p.onMonthChangeStart('prev');
  2494. var translate = (p.monthsTranslate * 100) * inverter;
  2495. p.wrapper.transition(transition).transform('translate3d(' + (p.isH ? translate : 0) + '%, ' + (p.isH ? 0 : translate) + '%, 0)');
  2496. if (transitionEndCallback) {
  2497. p.wrapper.transitionEnd(function () {
  2498. p.onMonthChangeEnd('prev');
  2499. });
  2500. }
  2501. if (!p.params.animate) {
  2502. p.onMonthChangeEnd('prev');
  2503. }
  2504. };
  2505. p.resetMonth = function (transition) {
  2506. if (typeof transition === 'undefined') transition = '';
  2507. var translate = (p.monthsTranslate * 100) * inverter;
  2508. p.wrapper.transition(transition).transform('translate3d(' + (p.isH ? translate : 0) + '%, ' + (p.isH ? 0 : translate) + '%, 0)');
  2509. };
  2510. p.setYearMonth = function (year, month, transition) {
  2511. if (typeof year === 'undefined') year = p.currentYear;
  2512. if (typeof month === 'undefined') month = p.currentMonth;
  2513. if (typeof transition === 'undefined' || typeof transition === 'object') {
  2514. transition = '';
  2515. if (!p.params.animate) transition = 0;
  2516. }
  2517. var targetDate;
  2518. if (year < p.currentYear) {
  2519. targetDate = new Date(year, month + 1, -1).getTime();
  2520. }
  2521. else {
  2522. targetDate = new Date(year, month).getTime();
  2523. }
  2524. if (p.params.maxDate && targetDate > new Date(p.params.maxDate).getTime()) {
  2525. return false;
  2526. }
  2527. if (p.params.minDate && targetDate < new Date(p.params.minDate).getTime()) {
  2528. return false;
  2529. }
  2530. var currentDate = new Date(p.currentYear, p.currentMonth).getTime();
  2531. var dir = targetDate > currentDate ? 'next' : 'prev';
  2532. var newMonthHTML = p.monthHTML(new Date(year, month));
  2533. p.monthsTranslate = p.monthsTranslate || 0;
  2534. var prevTranslate = p.monthsTranslate;
  2535. var monthTranslate, wrapperTranslate;
  2536. var transitionEndCallback = p.animating ? false : true;
  2537. if (targetDate > currentDate) {
  2538. // To next
  2539. p.monthsTranslate --;
  2540. if (!p.animating) p.months.eq(p.months.length - 1).remove();
  2541. p.wrapper.append(newMonthHTML);
  2542. p.months = p.wrapper.find('.picker-calendar-month');
  2543. monthTranslate = -(prevTranslate - 1) * 100 * inverter;
  2544. p.months.eq(p.months.length - 1).transform('translate3d(' + (p.isH ? monthTranslate : 0) + '%, ' + (p.isH ? 0 : monthTranslate) + '%, 0)').addClass('picker-calendar-month-next');
  2545. }
  2546. else {
  2547. // To prev
  2548. p.monthsTranslate ++;
  2549. if (!p.animating) p.months.eq(0).remove();
  2550. p.wrapper.prepend(newMonthHTML);
  2551. p.months = p.wrapper.find('.picker-calendar-month');
  2552. monthTranslate = -(prevTranslate + 1) * 100 * inverter;
  2553. p.months.eq(0).transform('translate3d(' + (p.isH ? monthTranslate : 0) + '%, ' + (p.isH ? 0 : monthTranslate) + '%, 0)').addClass('picker-calendar-month-prev');
  2554. }
  2555. if (p.params.onMonthAdd) {
  2556. p.params.onMonthAdd(p, dir === 'next' ? p.months.eq(p.months.length - 1)[0] : p.months.eq(0)[0]);
  2557. }
  2558. p.animating = true;
  2559. p.onMonthChangeStart(dir);
  2560. wrapperTranslate = (p.monthsTranslate * 100) * inverter;
  2561. p.wrapper.transition(transition).transform('translate3d(' + (p.isH ? wrapperTranslate : 0) + '%, ' + (p.isH ? 0 : wrapperTranslate) + '%, 0)');
  2562. if (transitionEndCallback) {
  2563. p.wrapper.transitionEnd(function () {
  2564. p.onMonthChangeEnd(dir, true);
  2565. });
  2566. }
  2567. if (!p.params.animate) {
  2568. p.onMonthChangeEnd(dir);
  2569. }
  2570. };
  2571. p.nextYear = function () {
  2572. p.setYearMonth(p.currentYear + 1);
  2573. };
  2574. p.prevYear = function () {
  2575. p.setYearMonth(p.currentYear - 1);
  2576. };
  2577. // HTML Layout
  2578. p.layout = function () {
  2579. var pickerHTML = '';
  2580. var pickerClass = '';
  2581. var i;
  2582. var layoutDate = p.value && p.value.length ? p.value[0] : new Date().setHours(0,0,0,0);
  2583. var prevMonthHTML = p.monthHTML(layoutDate, 'prev');
  2584. var currentMonthHTML = p.monthHTML(layoutDate);
  2585. var nextMonthHTML = p.monthHTML(layoutDate, 'next');
  2586. var monthsHTML = '<div class="picker-calendar-months"><div class="picker-calendar-months-wrapper">' + (prevMonthHTML + currentMonthHTML + nextMonthHTML) + '</div></div>';
  2587. // Week days header
  2588. var weekHeaderHTML = '';
  2589. if (p.params.weekHeader) {
  2590. for (i = 0; i < 7; i++) {
  2591. var weekDayIndex = (i + p.params.firstDay > 6) ? (i - 7 + p.params.firstDay) : (i + p.params.firstDay);
  2592. var dayName = p.params.dayNamesShort[weekDayIndex];
  2593. weekHeaderHTML += '<div class="picker-calendar-week-day ' + ((p.params.weekendDays.indexOf(weekDayIndex) >= 0) ? 'picker-calendar-week-day-weekend' : '') + '"> ' + dayName + '</div>';
  2594. }
  2595. weekHeaderHTML = '<div class="picker-calendar-week-days">' + weekHeaderHTML + '</div>';
  2596. }
  2597. pickerClass = 'weui-picker-calendar ' + (p.params.cssClass || '');
  2598. if(!p.inline) pickerClass = 'weui-picker-modal ' + pickerClass;
  2599. var toolbarHTML = p.params.toolbar ? p.params.toolbarTemplate.replace(/{{closeText}}/g, p.params.toolbarCloseText) : '';
  2600. if (p.params.toolbar) {
  2601. toolbarHTML = p.params.toolbarTemplate
  2602. .replace(/{{closeText}}/g, p.params.toolbarCloseText)
  2603. .replace(/{{monthPicker}}/g, (p.params.monthPicker ? p.params.monthPickerTemplate : ''))
  2604. .replace(/{{yearPicker}}/g, (p.params.yearPicker ? p.params.yearPickerTemplate : ''));
  2605. }
  2606. pickerHTML =
  2607. '<div class="' + (pickerClass) + '">' +
  2608. toolbarHTML +
  2609. '<div class="picker-modal-inner">' +
  2610. weekHeaderHTML +
  2611. monthsHTML +
  2612. '</div>' +
  2613. '</div>';
  2614. p.pickerHTML = pickerHTML;
  2615. };
  2616. // Input Events
  2617. function openOnInput(e) {
  2618. e.preventDefault();
  2619. if (p.opened) return;
  2620. p.open();
  2621. if (p.params.scrollToInput && !isPopover()) {
  2622. var pageContent = p.input.parents('.page-content');
  2623. if (pageContent.length === 0) return;
  2624. var paddingTop = parseInt(pageContent.css('padding-top'), 10),
  2625. paddingBottom = parseInt(pageContent.css('padding-bottom'), 10),
  2626. pageHeight = pageContent[0].offsetHeight - paddingTop - p.container.height(),
  2627. pageScrollHeight = pageContent[0].scrollHeight - paddingTop - p.container.height(),
  2628. newPaddingBottom;
  2629. var inputTop = p.input.offset().top - paddingTop + p.input[0].offsetHeight;
  2630. if (inputTop > pageHeight) {
  2631. var scrollTop = pageContent.scrollTop() + inputTop - pageHeight;
  2632. if (scrollTop + pageHeight > pageScrollHeight) {
  2633. newPaddingBottom = scrollTop + pageHeight - pageScrollHeight + paddingBottom;
  2634. if (pageHeight === pageScrollHeight) {
  2635. newPaddingBottom = p.container.height();
  2636. }
  2637. pageContent.css({'padding-bottom': (newPaddingBottom) + 'px'});
  2638. }
  2639. pageContent.scrollTop(scrollTop, 300);
  2640. }
  2641. }
  2642. }
  2643. function closeOnHTMLClick(e) {
  2644. if (inPopover()) return;
  2645. if (p.input && p.input.length > 0) {
  2646. if (e.target !== p.input[0] && $(e.target).parents('.weui-picker-modal').length === 0) p.close();
  2647. }
  2648. else {
  2649. if ($(e.target).parents('.weui-picker-modal').length === 0) p.close();
  2650. }
  2651. }
  2652. if (p.params.input) {
  2653. p.input = $(p.params.input);
  2654. if (p.input.length > 0) {
  2655. if (p.params.inputReadOnly) p.input.prop('readOnly', true);
  2656. if (!p.inline) {
  2657. p.input.on('click', openOnInput);
  2658. }
  2659. if (p.params.inputReadOnly) {
  2660. p.input.on('focus mousedown', function (e) {
  2661. e.preventDefault();
  2662. });
  2663. }
  2664. }
  2665. }
  2666. //iphone 上无法正确触发 click,会导致点击外面无法关闭
  2667. if (!p.inline) $(document).on('click touchend', closeOnHTMLClick);
  2668. // Open
  2669. function onPickerClose() {
  2670. p.opened = false;
  2671. if (p.input && p.input.length > 0) p.input.parents('.page-content').css({'padding-bottom': ''});
  2672. if (p.params.onClose) p.params.onClose(p);
  2673. // Destroy events
  2674. p.destroyCalendarEvents();
  2675. }
  2676. p.opened = false;
  2677. p.open = function () {
  2678. var toPopover = isPopover() && false;
  2679. var updateValue = false;
  2680. if (!p.opened) {
  2681. // Set date value
  2682. if (!p.value) {
  2683. if (p.params.value) {
  2684. p.value = p.params.value;
  2685. updateValue = true;
  2686. }
  2687. }
  2688. // Layout
  2689. p.layout();
  2690. // Append
  2691. if (toPopover) {
  2692. p.pickerHTML = '<div class="popover popover-picker-calendar"><div class="popover-inner">' + p.pickerHTML + '</div></div>';
  2693. p.popover = $.popover(p.pickerHTML, p.params.input, true);
  2694. p.container = $(p.popover).find('.weui-picker-modal');
  2695. $(p.popover).on('close', function () {
  2696. onPickerClose();
  2697. });
  2698. }
  2699. else if (p.inline) {
  2700. p.container = $(p.pickerHTML);
  2701. p.container.addClass('picker-modal-inline');
  2702. $(p.params.container).append(p.container);
  2703. }
  2704. else {
  2705. p.container = $($.openPicker(p.pickerHTML));
  2706. $(p.container)
  2707. .on('close', function () {
  2708. onPickerClose();
  2709. });
  2710. }
  2711. // Store calendar instance
  2712. p.container[0].f7Calendar = p;
  2713. p.wrapper = p.container.find('.picker-calendar-months-wrapper');
  2714. // Months
  2715. p.months = p.wrapper.find('.picker-calendar-month');
  2716. // Update current month and year
  2717. p.updateCurrentMonthYear();
  2718. // Set initial translate
  2719. p.monthsTranslate = 0;
  2720. p.setMonthsTranslate();
  2721. // Init events
  2722. p.initCalendarEvents();
  2723. // Update input value
  2724. if (updateValue) p.updateValue();
  2725. }
  2726. // Set flag
  2727. p.opened = true;
  2728. p.initialized = true;
  2729. if (p.params.onMonthAdd) {
  2730. p.months.each(function () {
  2731. p.params.onMonthAdd(p, this);
  2732. });
  2733. }
  2734. if (p.params.onOpen) p.params.onOpen(p);
  2735. };
  2736. // Close
  2737. p.close = function () {
  2738. if (!p.opened || p.inline) return;
  2739. p.animating = false; //有可能还有动画没做完,因此animating设置还没改。
  2740. if (inPopover()) {
  2741. $.closePicker(p.popover);
  2742. return;
  2743. }
  2744. else {
  2745. $.closePicker(p.container);
  2746. return;
  2747. }
  2748. };
  2749. // Destroy
  2750. p.destroy = function () {
  2751. p.close();
  2752. if (p.params.input && p.input.length > 0) {
  2753. p.input.off('click focus', openOnInput);
  2754. p.input.data("calendar", null);
  2755. }
  2756. $('html').off('click', closeOnHTMLClick);
  2757. };
  2758. if (p.inline) {
  2759. p.open();
  2760. }
  2761. return p;
  2762. };
  2763. var format = function(d) {
  2764. return d < 10 ? "0"+d : d;
  2765. }
  2766. $.fn.calendar = function (params, args) {
  2767. params = params || {};
  2768. return this.each(function() {
  2769. var $this = $(this);
  2770. if(!$this[0]) return;
  2771. var p = {};
  2772. if($this[0].tagName.toUpperCase() === "INPUT") {
  2773. p.input = $this;
  2774. } else {
  2775. p.container = $this;
  2776. }
  2777. var calendar = $this.data("calendar");
  2778. if(!calendar) {
  2779. if(typeof params === typeof "a") {
  2780. } else {
  2781. if(!params.value && $this.val()) params.value = [$this.val()];
  2782. //默认显示今天
  2783. if(!params.value) {
  2784. var today = new Date();
  2785. params.value = [today.getFullYear() + "/" + format(today.getMonth() + 1) + "/" + format(today.getDate())];
  2786. }
  2787. calendar = $this.data("calendar", new Calendar($.extend(p, params)));
  2788. }
  2789. }
  2790. if(typeof params === typeof "a") {
  2791. calendar[params].call(calendar, args);
  2792. }
  2793. });
  2794. };
  2795. defaults = $.fn.calendar.prototype.defaults = {
  2796. value: undefined, // 通过JS赋值,注意是数组
  2797. monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  2798. monthNamesShort: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  2799. dayNames: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
  2800. dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
  2801. firstDay: 1, // First day of the week, Monday
  2802. weekendDays: [0, 6], // Sunday and Saturday
  2803. multiple: false,
  2804. dateFormat: 'yyyy/mm/dd',
  2805. direction: 'horizontal', // or 'vertical'
  2806. minDate: null,
  2807. maxDate: null,
  2808. touchMove: true,
  2809. animate: true,
  2810. closeOnSelect: true,
  2811. monthPicker: true,
  2812. monthPickerTemplate:
  2813. '<div class="picker-calendar-month-picker">' +
  2814. '<a href="javascript:;" class="link icon-only picker-calendar-prev-month"><i class="icon icon-prev"></i></a>' +
  2815. '<div class="current-month-value"></div>' +
  2816. '<a href="javascript:;" class="link icon-only picker-calendar-next-month"><i class="icon icon-next"></i></a>' +
  2817. '</div>',
  2818. yearPicker: true,
  2819. yearPickerTemplate:
  2820. '<div class="picker-calendar-year-picker">' +
  2821. '<a href="javascript:;" class="link icon-only picker-calendar-prev-year"><i class="icon icon-prev"></i></a>' +
  2822. '<span class="current-year-value"></span>' +
  2823. '<a href="javascript:;" class="link icon-only picker-calendar-next-year"><i class="icon icon-next"></i></a>' +
  2824. '</div>',
  2825. weekHeader: true,
  2826. // Common settings
  2827. scrollToInput: true,
  2828. inputReadOnly: true,
  2829. convertToPopover: true,
  2830. onlyInPopover: false,
  2831. toolbar: true,
  2832. toolbarCloseText: 'Done',
  2833. toolbarTemplate:
  2834. '<div class="toolbar">' +
  2835. '<div class="toolbar-inner">' +
  2836. '{{yearPicker}}' +
  2837. '{{monthPicker}}' +
  2838. // '<a href="#" class="link close-picker">{{closeText}}</a>' +
  2839. '</div>' +
  2840. '</div>',
  2841. /* Callbacks
  2842. onMonthAdd
  2843. onChange
  2844. onOpen
  2845. onClose
  2846. onDayClick
  2847. onMonthYearChangeStart
  2848. onMonthYearChangeEnd
  2849. */
  2850. };
  2851. }($);
  2852. /* global $:true */
  2853. /* jshint unused:false*/
  2854. + function($) {
  2855. "use strict";
  2856. var defaults;
  2857. var formatNumber = function (n) {
  2858. return n < 10 ? "0" + n : n;
  2859. }
  2860. var Datetime = function(input, params) {
  2861. this.input = $(input);
  2862. this.params = params || {};
  2863. this.initMonthes = params.monthes
  2864. this.initYears = params.years
  2865. var p = $.extend({}, params, this.getConfig());
  2866. $(this.input).picker(p);
  2867. }
  2868. Datetime.prototype = {
  2869. getDays : function(max) {
  2870. var days = [];
  2871. for(var i=1; i<= (max||31);i++) {
  2872. days.push(i < 10 ? "0"+i : i);
  2873. }
  2874. return days;
  2875. },
  2876. getDaysByMonthAndYear : function(month, year) {
  2877. var int_d = new Date(year, parseInt(month)+1-1, 1);
  2878. var d = new Date(int_d - 1);
  2879. return this.getDays(d.getDate());
  2880. },
  2881. getConfig: function() {
  2882. var today = new Date(),
  2883. params = this.params,
  2884. self = this,
  2885. lastValidValues;
  2886. var config = {
  2887. rotateEffect: false, //为了性能
  2888. cssClass: 'datetime-picker',
  2889. value: [today.getFullYear(), formatNumber(today.getMonth()+1), formatNumber(today.getDate()), formatNumber(today.getHours()), (formatNumber(today.getMinutes()))],
  2890. onChange: function (picker, values, displayValues) {
  2891. var cols = picker.cols;
  2892. var days = self.getDaysByMonthAndYear(values[1], values[0]);
  2893. var currentValue = values[2];
  2894. if(currentValue > days.length) currentValue = days.length;
  2895. picker.cols[4].setValue(currentValue);
  2896. //check min and max
  2897. var current = new Date(values[0]+'-'+values[1]+'-'+values[2]);
  2898. var valid = true;
  2899. if(params.min) {
  2900. var min = new Date(typeof params.min === "function" ? params.min() : params.min);
  2901. if(current < +min) {
  2902. picker.setValue(lastValidValues);
  2903. valid = false;
  2904. }
  2905. }
  2906. if(params.max) {
  2907. var max = new Date(typeof params.max === "function" ? params.max() : params.max);
  2908. if(current > +max) {
  2909. picker.setValue(lastValidValues);
  2910. valid = false;
  2911. }
  2912. }
  2913. valid && (lastValidValues = values);
  2914. if (self.params.onChange) {
  2915. self.params.onChange.apply(this, arguments);
  2916. }
  2917. },
  2918. formatValue: function (p, values, displayValues) {
  2919. return self.params.format(p, values, displayValues);
  2920. },
  2921. cols: [
  2922. {
  2923. values: this.initYears
  2924. },
  2925. {
  2926. divider: true, // 这是一个分隔符
  2927. content: params.yearSplit
  2928. },
  2929. {
  2930. values: this.initMonthes
  2931. },
  2932. {
  2933. divider: true, // 这是一个分隔符
  2934. content: params.monthSplit
  2935. },
  2936. {
  2937. values: (function () {
  2938. var dates = [];
  2939. for (var i=1; i<=31; i++) dates.push(formatNumber(i));
  2940. return dates;
  2941. })()
  2942. },
  2943. ]
  2944. }
  2945. if (params.dateSplit) {
  2946. config.cols.push({
  2947. divider: true,
  2948. content: params.dateSplit
  2949. })
  2950. }
  2951. config.cols.push({
  2952. divider: true,
  2953. content: params.datetimeSplit
  2954. })
  2955. var times = self.params.times();
  2956. if (times && times.length) {
  2957. config.cols = config.cols.concat(times);
  2958. }
  2959. var inputValue = this.input.val();
  2960. if(inputValue) config.value = params.parse(inputValue);
  2961. if(this.params.value) {
  2962. this.input.val(this.params.value);
  2963. config.value = params.parse(this.params.value);
  2964. }
  2965. return config;
  2966. }
  2967. }
  2968. $.fn.datetimePicker = function(params) {
  2969. params = $.extend({}, defaults, params);
  2970. return this.each(function() {
  2971. if(!this) return;
  2972. var $this = $(this);
  2973. var datetime = $this.data("datetime");
  2974. if(!datetime) $this.data("datetime", new Datetime(this, params));
  2975. return datetime;
  2976. });
  2977. };
  2978. defaults = $.fn.datetimePicker.prototype.defaults = {
  2979. input: undefined, // 默认值
  2980. min: undefined, // YYYY-MM-DD 最大最小值只比较年月日,不比较时分秒
  2981. max: undefined, // YYYY-MM-DD
  2982. yearSplit: '-',
  2983. monthSplit: '-',
  2984. dateSplit: '', // 默认为空
  2985. datetimeSplit: ' ', // 日期和时间之间的分隔符,不可为空
  2986. monthes: ('01 02 03 04 05 06 07 08 09 10 11 12').split(' '),
  2987. years: (function () {
  2988. var arr = [];
  2989. for (var i = 1950; i <= 2030; i++) { arr.push(i); }
  2990. return arr;
  2991. })(),
  2992. times: function () {
  2993. return [ // 自定义的时间
  2994. {
  2995. values: (function () {
  2996. var hours = [];
  2997. for (var i=0; i<24; i++) hours.push(formatNumber(i));
  2998. return hours;
  2999. })()
  3000. },
  3001. {
  3002. divider: true, // 这是一个分隔符
  3003. content: ':'
  3004. },
  3005. {
  3006. values: (function () {
  3007. var minutes = [];
  3008. for (var i=0; i<60; i++) minutes.push(formatNumber(i));
  3009. return minutes;
  3010. })()
  3011. }
  3012. ];
  3013. },
  3014. format: function (p, values) { // 数组转换成字符串
  3015. return p.cols.map(function (col) {
  3016. return col.value || col.content;
  3017. }).join('');
  3018. },
  3019. parse: function (str) {
  3020. // 把字符串转换成数组,用来解析初始值
  3021. // 如果你的定制的初始值格式无法被这个默认函数解析,请自定义这个函数。比如你的时间是 '子时' 那么默认情况这个'时'会被当做分隔符而导致错误,所以你需要自己定义parse函数
  3022. // 默认兼容的分隔符
  3023. var t = str.split(this.datetimeSplit);
  3024. return t[0].split(/\D/).concat(t[1].split(/:|时|分|秒/)).filter(function (d) {
  3025. return !!d;
  3026. })
  3027. }
  3028. }
  3029. }($);
  3030. /*======================================================
  3031. ************ Picker ************
  3032. ======================================================*/
  3033. /* global $:true */
  3034. + function($) {
  3035. "use strict";
  3036. //Popup 和 picker 之类的不要共用一个弹出方法,因为这样会导致 在 popup 中再弹出 picker 的时候会有问题。
  3037. $.openPopup = function(popup, className) {
  3038. $.closePopup();
  3039. popup = $(popup);
  3040. popup.show();
  3041. popup.width();
  3042. popup.addClass("weui-popup__container--visible");
  3043. var modal = popup.find(".weui-popup__modal");
  3044. modal.width();
  3045. modal.transitionEnd(function() {
  3046. modal.trigger("open");
  3047. });
  3048. }
  3049. $.closePopup = function(container, remove) {
  3050. container = $(container || ".weui-popup__container--visible");
  3051. container.find('.weui-popup__modal').transitionEnd(function() {
  3052. var $this = $(this);
  3053. $this.trigger("close");
  3054. container.hide();
  3055. remove && container.remove();
  3056. })
  3057. container.removeClass("weui-popup__container--visible")
  3058. };
  3059. $(document).on("click", ".close-popup, .weui-popup__overlay", function() {
  3060. $.closePopup();
  3061. })
  3062. .on("click", ".open-popup", function() {
  3063. $($(this).data("target")).popup();
  3064. })
  3065. .on("click", ".weui-popup__container", function(e) {
  3066. if($(e.target).hasClass("weui-popup__container")) $.closePopup();
  3067. })
  3068. $.fn.popup = function() {
  3069. return this.each(function() {
  3070. $.openPopup(this);
  3071. });
  3072. };
  3073. }($);
  3074. /* ===============================================================================
  3075. ************ Notification ************
  3076. =============================================================================== */
  3077. /* global $:true */
  3078. +function ($) {
  3079. "use strict";
  3080. var noti, defaults, timeout, start, diffX, diffY;
  3081. var touchStart = function(e) {
  3082. var p = $.getTouchPosition(e);
  3083. start = p;
  3084. diffX = diffY = 0;
  3085. noti.addClass("touching");
  3086. };
  3087. var touchMove = function(e) {
  3088. if(!start) return false;
  3089. e.preventDefault();
  3090. e.stopPropagation();
  3091. var p = $.getTouchPosition(e);
  3092. diffX = p.x - start.x;
  3093. diffY = p.y - start.y;
  3094. if(diffY > 0) {
  3095. diffY = Math.sqrt(diffY);
  3096. }
  3097. noti.css("transform", "translate3d(0, "+diffY+"px, 0)");
  3098. };
  3099. var touchEnd = function() {
  3100. noti.removeClass("touching");
  3101. noti.attr("style", "");
  3102. if(diffY < 0 && (Math.abs(diffY) > noti.height()*0.38)) {
  3103. $.closeNotification();
  3104. }
  3105. if(Math.abs(diffX) <= 1 && Math.abs(diffY) <= 1) {
  3106. noti.trigger("noti-click");
  3107. }
  3108. start = false;
  3109. };
  3110. var attachEvents = function(el) {
  3111. el.on($.touchEvents.start, touchStart);
  3112. el.on($.touchEvents.move, touchMove);
  3113. el.on($.touchEvents.end, touchEnd);
  3114. };
  3115. $.notification = $.noti = function(params) {
  3116. params = $.extend({}, defaults, params);
  3117. noti = $(".weui-notification");
  3118. if(!noti[0]) { // create a new notification
  3119. noti = $('<div class="weui-notification"></div>').appendTo(document.body);
  3120. attachEvents(noti);
  3121. }
  3122. noti.off("noti-click"); //the click event is not correct sometime: it will trigger when user is draging.
  3123. if(params.onClick) noti.on("noti-click", function() {
  3124. params.onClick(params.data);
  3125. });
  3126. noti.html($.t7.compile(params.tpl)(params));
  3127. noti.show();
  3128. noti.addClass("weui-notification--in");
  3129. noti.data("params", params);
  3130. var startTimeout = function() {
  3131. if(timeout) {
  3132. clearTimeout(timeout);
  3133. timeout = null;
  3134. }
  3135. timeout = setTimeout(function() {
  3136. if(noti.hasClass("weui-notification--touching")) {
  3137. startTimeout();
  3138. } else {
  3139. $.closeNotification();
  3140. }
  3141. }, params.time);
  3142. };
  3143. startTimeout();
  3144. };
  3145. $.closeNotification = function() {
  3146. timeout && clearTimeout(timeout);
  3147. timeout = null;
  3148. var noti = $(".weui-notification").removeClass("weui-notification--in").transitionEnd(function() {
  3149. $(this).remove();
  3150. });
  3151. if(noti[0]) {
  3152. var params = $(".weui-notification").data("params");
  3153. if(params && params.onClose) {
  3154. params.onClose(params.data);
  3155. }
  3156. }
  3157. };
  3158. defaults = $.noti.prototype.defaults = {
  3159. title: undefined,
  3160. text: undefined,
  3161. media: undefined,
  3162. time: 4000,
  3163. onClick: undefined,
  3164. onClose: undefined,
  3165. data: undefined,
  3166. tpl: '<div class="weui-notification__inner">' +
  3167. '{{#if media}}<div class="weui-notification__media">{{media}}</div>{{/if}}' +
  3168. '<div class="weui-notification__content">' +
  3169. '{{#if title}}<div class="weui-notification__title">{{title}}</div>{{/if}}' +
  3170. '{{#if text}}<div class="weui-notification__text">{{text}}</div>{{/if}}' +
  3171. '</div>' +
  3172. '<div class="weui-notification__handle-bar"></div>' +
  3173. '</div>'
  3174. };
  3175. }($);
  3176. + function($) {
  3177. "use strict";
  3178. var timeout;
  3179. $.toptip = function(text, duration, type) {
  3180. if(!text) return;
  3181. if(typeof duration === typeof "a") {
  3182. type = duration;
  3183. duration = undefined;
  3184. }
  3185. duration = duration || 3000;
  3186. var className = type ? 'bg-' + type : 'bg-danger';
  3187. var $t = $('.weui-toptips').remove();
  3188. $t = $('<div class="weui-toptips"></div>').appendTo(document.body);
  3189. $t.html(text);
  3190. $t[0].className = 'weui-toptips ' + className
  3191. clearTimeout(timeout);
  3192. if(!$t.hasClass('weui-toptips_visible')) {
  3193. $t.show().width();
  3194. $t.addClass('weui-toptips_visible');
  3195. }
  3196. timeout = setTimeout(function() {
  3197. $(".weui-toptips_visible").remove();
  3198. }, duration);
  3199. }
  3200. }($);
  3201. /* ===============================================================================
  3202. ************ Swipeout ************
  3203. =============================================================================== */
  3204. /* global $:true */
  3205. +function ($) {
  3206. "use strict";
  3207. var cache = [];
  3208. var TOUCHING = 'swipeout-touching'
  3209. var Swipeout = function(el) {
  3210. this.container = $(el);
  3211. this.mover = this.container.find('>.weui-cell__bd')
  3212. this.attachEvents();
  3213. cache.push(this)
  3214. }
  3215. Swipeout.prototype.touchStart = function(e) {
  3216. var p = $.getTouchPosition(e);
  3217. this.container.addClass(TOUCHING);
  3218. this.start = p;
  3219. this.startX = 0;
  3220. this.startTime = + new Date;
  3221. var transform = this.mover.css('transform').match(/-?[\d\.]+/g)
  3222. if (transform && transform.length) this.startX = parseInt(transform[4])
  3223. this.diffX = this.diffY = 0;
  3224. this._closeOthers()
  3225. this.limit = this.container.find('>.weui-cell__ft').width() || 68; // 因为有的时候初始化的时候元素是隐藏的(比如在对话框内),所以在touchstart的时候计算宽度而不是初始化的时候
  3226. };
  3227. Swipeout.prototype.touchMove= function(e) {
  3228. if(!this.start) return true;
  3229. var p = $.getTouchPosition(e);
  3230. this.diffX = p.x - this.start.x;
  3231. this.diffY = p.y - this.start.y;
  3232. if (Math.abs(this.diffX) < Math.abs(this.diffY)) { // 说明是上下方向在拖动
  3233. this.close()
  3234. this.start = false
  3235. return true;
  3236. }
  3237. e.preventDefault();
  3238. e.stopPropagation();
  3239. var x = this.diffX + this.startX
  3240. if (x > 0) x = 0;
  3241. if (Math.abs(x) > this.limit) x = - (Math.pow(-(x+this.limit), .7) + this.limit)
  3242. this.mover.css("transform", "translate3d("+x+"px, 0, 0)");
  3243. };
  3244. Swipeout.prototype.touchEnd = function() {
  3245. if (!this.start) return true;
  3246. this.start = false;
  3247. var x = this.diffX + this.startX
  3248. var t = new Date - this.startTime;
  3249. if (this.diffX < -5 && t < 200) { // 向左快速滑动,则打开
  3250. this.open()
  3251. } else if (this.diffX >= 0 && t < 200) { // 向右快速滑动,或者单击,则关闭
  3252. this.close()
  3253. } else if (x > 0 || -x <= this.limit / 2) {
  3254. this.close()
  3255. } else {
  3256. this.open()
  3257. }
  3258. };
  3259. Swipeout.prototype.close = function() {
  3260. this.container.removeClass(TOUCHING);
  3261. this.mover.css("transform", "translate3d(0, 0, 0)");
  3262. this.container.trigger('swipeout-close');
  3263. }
  3264. Swipeout.prototype.open = function() {
  3265. this.container.removeClass(TOUCHING);
  3266. this._closeOthers()
  3267. this.mover.css("transform", "translate3d(" + (-this.limit) + "px, 0, 0)");
  3268. this.container.trigger('swipeout-open');
  3269. }
  3270. Swipeout.prototype.attachEvents = function() {
  3271. var el = this.mover;
  3272. el.on($.touchEvents.start, $.proxy(this.touchStart, this));
  3273. el.on($.touchEvents.move, $.proxy(this.touchMove, this));
  3274. el.on($.touchEvents.end, $.proxy(this.touchEnd, this));
  3275. }
  3276. Swipeout.prototype._closeOthers = function() {
  3277. //close others
  3278. var self = this
  3279. cache.forEach(function (s) {
  3280. if (s !== self) s.close()
  3281. })
  3282. }
  3283. var swipeout = function(el) {
  3284. return new Swipeout(el);
  3285. };
  3286. $.fn.swipeout = function (arg) {
  3287. return this.each(function() {
  3288. var $this = $(this)
  3289. var s = $this.data('swipeout') || swipeout(this);
  3290. $this.data('swipeout', s);
  3291. if (typeof arg === typeof 'a') {
  3292. s[arg]()
  3293. }
  3294. });
  3295. }
  3296. $('.weui-cell_swiped').swipeout() // auto init
  3297. }($);
  3298. //tab
  3299. (function ($) {
  3300. var oldFnTab = $.fn.tab;
  3301. $.fn.tab = function (options) {
  3302. options = $.extend({defaultIndex: 0, activeClass: 'weui-bar__item_on', onToggle: $.noop}, options);
  3303. const $tabbarItems = this.find('.weui-tabbar__item, .weui-navbar__item');
  3304. const $tabBdItems = this.find('.weui-tab__content');
  3305. this.toggle = function (index) {
  3306. const $defaultTabbarItem = $tabbarItems.eq(index);
  3307. $defaultTabbarItem.addClass(options.activeClass).siblings().removeClass(options.activeClass);
  3308. const $defaultTabBdItem = $tabBdItems.eq(index);
  3309. $defaultTabBdItem.fadeIn().siblings().fadeOut();
  3310. options.onToggle(index);
  3311. };
  3312. const self = this;
  3313. this.on('click', '.weui-tabbar__item, .weui-navbar__item', function (e) {
  3314. const index = $(this).index();
  3315. self.toggle(index);
  3316. });
  3317. this.toggle(options.defaultIndex);
  3318. return this;
  3319. };
  3320. $.fn.tab.noConflict = function () {
  3321. return oldFnTab;
  3322. };
  3323. })($);
  3324. function share(){
  3325. var sharetpl='<div class="weui-share" onclick="$(this).remove();">\n' +
  3326. '<div class="weui-share-box">\n' +
  3327. '点击右上角发送给指定朋友或分享到朋友圈 <i></i>\n' +
  3328. '</div>\n' +
  3329. '</div>';
  3330. var sharetpl = $.t7.compile(sharetpl);
  3331. $("body").append(sharetpl());
  3332. }
  3333. $(function(){
  3334. var weixinimg=[];var weixinsrc=[];weixinimg=$('.weixin');for(var i=0;i<weixinimg.length;i++){weixinsrc[i]=weixinimg[i].src;};$('.weixin').click(function(){var index=$('.weixin').index(this);wx.previewImage({current:weixinsrc[index],urls:weixinsrc});});
  3335. });