Basic.js 186 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838
  1. ///<jscompress sourcefile="Banner.js" />
  2. //电脑端banner滑块控件命名空间
  3. Namespace.register("U.MD.UI.slider");
  4. /**
  5. 电脑端banner滑块控件
  6. */
  7. /**
  8. @box {object} 存放控件的div的id
  9. @imgarr {array} 存放图片的数组
  10. @speed {string} 轮播速度
  11. @cut {bool} 判断左右切换按钮是否出现
  12. @dot {bool} 判断小圆点是否出现
  13. @cb {回调callback} 引用方法
  14. **/
  15. U.MD.UI.slider = function (box, imgarr, attr) {
  16. //定义传输进来的参数
  17. var _speed = attr.speed;
  18. var _arrow = attr.arrow;
  19. var _dot = attr.dot;
  20. var _moveFun = attr.moveFun;
  21. //快速创建存放图片的ul
  22. var _sliderimgul = $$("ul", { className: 'U_MD_UI_slider_ImgList' }, box);
  23. //在数组的第一个插入最后一张图片
  24. imgarr.unshift(imgarr[imgarr.length - 1]);
  25. //在arrImg[]最后放第一张图片
  26. imgarr.push(imgarr[1]);
  27. //for循环创建需要的li
  28. for (i = 0; i < imgarr.length; i++) {
  29. var _sliderimgli = $$("li", { className: '' }, _sliderimgul),
  30. _sliderImg = $$("img", { className: '', src: imgarr[i] }, _sliderimgli); //"onerror": U.MD.C.imgError,
  31. }
  32. //快速创建存放左右按钮的ul
  33. var _sliderbtnul = $$("ul", { className: 'U_MD_UI_slider_Btn' }, box),
  34. _sliderbtnlil = $$("li", { className: 'U_MD_UI_slider_Left', innerHTML: '<' }, _sliderbtnul),
  35. _sliderbtnlir = $$("li", { className: 'U_MD_UI_slider_Right', innerHTML: '>' }, _sliderbtnul);
  36. //快速创建存放小圆点的ul
  37. var _sliderpointul = $$("ul", { className: 'U_MD_UI_slider_Point' }, box);
  38. //快速创建li,li的长度为图片的减两张(补图法)
  39. for (i = 0; i < imgarr.length - 3; i++) {
  40. //第一个li时,定义第一个li的class
  41. if (i == 0) {
  42. $$("li", { className: 'U_MD_UI_slider_On' }, _sliderpointul)[0];
  43. }
  44. $$("li", { className: '' }, _sliderpointul)[i];
  45. }
  46. //定义父元素的宽度
  47. var _boxidwidth = box.offsetWidth;
  48. //定义父元素的高度
  49. var _boxidheight = box.offsetHeight;
  50. //定义class为U_MD_UI_slider_ImgList
  51. var _sliderimglist = box.getElementsByClassName("U_MD_UI_slider_ImgList")[0];
  52. var _sliderimgli = _sliderimglist.getElementsByTagName("li");
  53. //定义class为U_MD_UI_slider_Btn
  54. var _sliderbtn = document.getElementsByClassName("U_MD_UI_slider_Btn")[0];
  55. //定义class为U_MD_UI_slider_Point
  56. var _sliderpoint = box.getElementsByClassName('U_MD_UI_slider_Point')[0];
  57. //定义class为_sliderbtn的所有li
  58. var _btnli = _sliderbtn.getElementsByTagName("li");
  59. //定义class为_sliderimglist的li长度
  60. var _listlen = _sliderimglist.getElementsByTagName("li").length;
  61. //定义图片索引为1
  62. var _listindex = 1;
  63. //定义_sliderpoint里的li
  64. var _pointdot = _sliderpoint.getElementsByTagName("li");
  65. //定义_pointdot.length
  66. var _dotlen = _pointdot.length;
  67. //定义小圆点索引为0
  68. var _dotindex = 0;
  69. //初始化timer
  70. var timer = null;
  71. //如果obj.dot为true则显示小圆点
  72. if (_dot) {
  73. _sliderpoint.style.display = "block";
  74. } else {
  75. _sliderpoint.style.display = "none";
  76. }
  77. /** Banner宽度和高度跟随父元素 **/
  78. //定义_sliderimglist里的li
  79. var _sliderli = _sliderimglist.getElementsByTagName("li");
  80. //所有图片的高宽等于盒子
  81. for (var i = 0; i < _sliderli.length; i++) {
  82. _sliderli[i].style.width = _boxidwidth + "px";
  83. _sliderli[i].style.height = _boxidheight + "px";
  84. }
  85. //存放图片的ul的总宽度(盒子长度*图片数量)
  86. _sliderimglist.style.width = (_boxidwidth * imgarr.length) + "px";
  87. //第一张图片的位置
  88. _sliderimglist.style.left = -_boxidwidth + "px";
  89. //左右切换按钮宽度跟随盒子宽度
  90. _sliderbtn.style.width = _boxidwidth + "px";
  91. /** 鼠标停留计时器停止或启动、左右按钮显示 **/
  92. //鼠标停留
  93. box.onmouseover = function () {
  94. //如果obj.cut为true则显示按钮
  95. if (_arrow) {
  96. _sliderbtn.style.display = "block";
  97. } else {
  98. _sliderbtn.style.display = "none";
  99. }
  100. //清除计时器
  101. clearInterval(timer);
  102. }
  103. //鼠标离开
  104. box.onmouseout = function () {
  105. _sliderbtn.style.display = "none";
  106. //启动计时器
  107. timer = setInterval(auto, _speed);
  108. }
  109. //定义当前时间
  110. var sTime = new Date();
  111. //左边按钮
  112. _btnli[0].onclick = function () {
  113. //定义点击后的时间
  114. var nTime = new Date();
  115. //点击后时间距离下次点击要大于500ms才能继续下次点击
  116. if (nTime - sTime > 500) {
  117. //图片索引和小圆点索引减少
  118. _listindex--;
  119. _dotindex--;
  120. if (_listindex == 0) {
  121. //调用move函数
  122. move(_sliderimglist, { left: -_boxidwidth * _listindex }, function () {
  123. _listindex = _listlen - 2;
  124. this.style.left = -_listindex * _boxidwidth + "px";
  125. });
  126. } else {
  127. move(_sliderimglist, { left: -_boxidwidth * _listindex });
  128. }
  129. //小圆点移动
  130. _dotindex = _dotindex == -1 ? _dotlen - 1 : _dotindex;
  131. moveBtn(_dotindex);
  132. _moveFun && _moveFun(_dotindex + 1);
  133. }
  134. sTime = new Date();
  135. }
  136. //右边按钮
  137. _btnli[1].onclick = function () {
  138. //定义点击后的时间
  139. var nTime = new Date();
  140. //点击后时间距离下次点击要大于500ms才能继续下次点击
  141. if (nTime - sTime > 500) {
  142. //图片索引和小圆点索引增加
  143. _listindex++;
  144. _dotindex++;
  145. //小圆点索引清零
  146. _dotindex = _dotindex % _dotlen;
  147. //图片到最后一张时索引清零重新计算
  148. if (_listindex == _listlen - 1) {
  149. move(_sliderimglist, { left: -_boxidwidth * _listindex }, function () {
  150. _listindex = 1;
  151. this.style.left = -_listindex * _boxidwidth + "px";
  152. });
  153. } else {
  154. move(_sliderimglist, { left: -_boxidwidth * _listindex });
  155. }
  156. //小圆点移动
  157. moveBtn(_dotindex);
  158. _moveFun && _moveFun(_dotindex + 1);
  159. }
  160. sTime = new Date();
  161. }
  162. //定义自动轮播
  163. timer = setInterval(auto, _speed);
  164. if (_dotindex == 0) {
  165. console.log(_dotindex + 1);
  166. }
  167. //自动轮播
  168. function auto() {
  169. /* for (var i = 0; i < _sliderimgli.length; i++) {
  170. _sliderimgli[i]._listindex = i;
  171. //点击小圆点
  172. //_listindex = this._listindex;
  173. console.log(_listindex+1);
  174. }*/
  175. //图片索引和小圆点索引
  176. _listindex = ++_listindex % _listlen;
  177. _dotindex++;
  178. //小圆点索引清零
  179. _dotindex = _dotindex % _dotlen;
  180. //图片到最后一张时索引清零重新计算
  181. if (_listindex == _listlen - 1) {
  182. move(_sliderimglist, { left: -_boxidwidth * _listindex }, function () {
  183. _listindex = 1;
  184. this.style.left = -_listindex * _boxidwidth + "px";
  185. });
  186. } else {
  187. move(_sliderimglist, { left: -_boxidwidth * _listindex });
  188. }
  189. moveBtn(_dotindex);
  190. _moveFun && _moveFun(_dotindex + 1);
  191. }
  192. //遍历小圆点
  193. for (var i = 0; i < _dotlen; i++) {
  194. _pointdot[i]._listindex = i;
  195. //点击小圆点
  196. _pointdot[i].onclick = function () {
  197. _dotindex = this._listindex;
  198. _listindex = _dotindex + 1;
  199. move(_sliderimglist, { left: -_boxidwidth * _listindex });
  200. moveBtn(_dotindex);
  201. //console.log(_dotindex);
  202. }
  203. }
  204. //小圆点样式
  205. function moveBtn(_dotindex) {
  206. for (var j = 0; j < _dotlen; j++) {
  207. _pointdot[j].className = "";
  208. }
  209. _pointdot[_dotindex].className = "U_MD_UI_slider_On";
  210. }
  211. }
  212. /*
  213. 切换过程函数
  214. @dom {object} 需要移动的对象
  215. @json {Array}向某个方向移动的距离
  216. @callback {回调callback}
  217. */
  218. function move(dom, json, callback) {
  219. //清除计时器
  220. clearInterval(dom.timer);
  221. dom.timer = setInterval(function () {
  222. //true这个计时器用来标记json中所有的attr已到达target目标
  223. var mark = true;
  224. for (var attr in json) {
  225. var cur = null;
  226. if (attr == "opacity") {
  227. cur = getStyle(dom, attr) * 100;
  228. } else {
  229. cur = parseInt(getStyle(dom, attr)) || 0;
  230. }
  231. var target = json[attr];
  232. // console.log(target);
  233. // console.log(cur);
  234. var speed = (target - cur) * .2;
  235. speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
  236. if (cur != target) {
  237. if (attr == "opacity") {
  238. dom.style.filter = "alpha(opacity = " + (cur + speed) + ")"; //ie
  239. dom.style[attr] = (cur + speed) / 100; //0~1
  240. } else {
  241. dom.style[attr] = cur + speed + "px";
  242. }
  243. //false表明当前的这个attr没有达到目标
  244. mark = false;
  245. }
  246. //console.log(cur);
  247. //console.log(1);
  248. }
  249. if (mark) {
  250. clearInterval(dom.timer);
  251. callback && callback.call(dom);
  252. }
  253. }, 100 / 3);
  254. }
  255. function getStyle(dom, attr) {
  256. return dom.currentStyle ? dom.currentStyle[attr] : getComputedStyle(dom, null)[attr];
  257. };
  258. ///<jscompress sourcefile="Calendar.js" />
  259. Namespace.register("U.MD.UI.calendar");
  260. /**
  261. * 日历控件调用API函数
  262. * @param el 对象元素
  263. * @param parentnode 添加到的父元素
  264. * @param datetimeboolean 【boolean】是否显示选择时分秒功能
  265. */
  266. U.MD.UI.Calendar = U.MD.UI.calendar = function (el, parentnode, datetimeboolean) {
  267. if (!el)
  268. return
  269. if (typeof datetimeboolean == 'boolean' && datetimeboolean == false) {
  270. U.MD.UI.calendar.datetimeformat = datetimeboolean
  271. } else {
  272. U.MD.UI.calendar.datetimeformat = true;
  273. }
  274. U.MD.UI.calendar.create(el, parentnode);
  275. }
  276. U.MD.UI.calendar.NOW = new Date(); /*获取当天时间*/
  277. U.MD.UI.calendar.CURRENTYEAR = U.MD.UI.calendar.NOW.getFullYear(); /*今年*/
  278. U.MD.UI.calendar.CURRENTMONTH = U.MD.UI.calendar.NOW.getMonth(); /*今月*/
  279. U.MD.UI.calendar.CURRENTDAY = U.MD.UI.calendar.NOW.getDate(); /*今日*/
  280. U.MD.UI.calendar.year = U.MD.UI.calendar.CURRENTYEAR; /*可变年*/
  281. U.MD.UI.calendar.month = U.MD.UI.calendar.CURRENTMONTH; /*可变月*/
  282. U.MD.UI.calendar.day = U.MD.UI.calendar.CURRENTDAY; /*可变日*/
  283. U.MD.UI.calendar.hour = '00'; /*时*/
  284. U.MD.UI.calendar.minute = '00'; /*分*/
  285. U.MD.UI.calendar.second = '00'; /*秒*/
  286. U.MD.UI.calendar.datetimeformat = true; /*是否以时分秒时间格式输出*/
  287. U.MD.UI.calendar.fouseinp = null; /*当前聚焦的input*/
  288. U.MD.UI.calendar.board = null; /*最外层div*/
  289. U.MD.UI.calendar.tit = null; /*日期标题*/
  290. U.MD.UI.calendar.mark = 1; /*标记量*/
  291. U.MD.UI.calendar.template = [ /*html模板块*/
  292. /*功能*/
  293. '<div class="U_MD_UI_calendar_features">' +
  294. '<div class="U_MD_UI_calendar_closeBtn" id="U_MD_UI_calendar_closeBtn">关闭</div>' +
  295. '<div class="U_MD_UI_calendar_features_a">' +
  296. '<div class="U_MD_UI_calendar_prev U_MD_UI_calendar_btn" id="prevDate"></div>' +
  297. '<div class="U_MD_UI_calendar_tit" id="calendar_tit"></div>' +
  298. '<input type="text" id="calendar_tit_btn" style="display: none;">' +
  299. '<div class="U_MD_UI_calendar_next U_MD_UI_calendar_btn" id="nextDate"></div>' +
  300. '</div>' +
  301. '<i></i>' +
  302. '</div>',
  303. /*星期*/
  304. '<div id="calendar_day">' +
  305. '<ul class="U_MD_UI_calendar_week">' +
  306. '<li>日</li>' +
  307. '<li>一</li>' +
  308. '<li>二</li>' +
  309. '<li>三</li>' +
  310. '<li>四</li>' +
  311. '<li>五</li>' +
  312. '<li>六</li>' +
  313. '</ul>' +
  314. '<ul class="U_MD_UI_calendar_c" id="calendar_week_c"></ul>' +
  315. '</div>',
  316. /*选择月*/
  317. '<div class="U_MD_UI_calendar_month" id="calendar_month" style="display: none">' +
  318. '<ul class="U_MD_UI_calendar_month_c">' +
  319. '<li><span>1月</span></li>' +
  320. '<li><span>2月</span></li>' +
  321. '<li><span>3月</span></li>' +
  322. '<li><span>4月</span></li>' +
  323. '<li><span>5月</span></li>' +
  324. '<li><span>6月</span></li>' +
  325. '<li><span>7月</span></li>' +
  326. '<li><span>8月</span></li>' +
  327. '<li><span>9月</span></li>' +
  328. '<li><span>10月</span></li>' +
  329. '<li><span>11月</span></li>' +
  330. '<li><span>12月</span></li>' +
  331. '</ul>' +
  332. '</div>',
  333. /*选择年*/
  334. '<div id="calendar_year" class="U_MD_UI_calendar_month" style="display: none">' +
  335. '<ul class="U_MD_UI_calendar_month_c">' +
  336. '<li></li>' +
  337. '<li></li>' +
  338. '<li></li>' +
  339. '<li></li>' +
  340. '<li></li>' +
  341. '<li></li>' +
  342. '<li></li>' +
  343. '<li></li>' +
  344. '<li></li>' +
  345. '<li></li>' +
  346. '<li></li>' +
  347. '<li></li>' +
  348. '</ul>' +
  349. '</div>',
  350. /*选择时间*/
  351. '<span id="U_MD_UI_calendar_timeText" class="U_MD_UI_calendar_timeText">选择时间</span>' +
  352. '<div class="U_MD_UI_calendar_timeBox">' +
  353. '<div id="U_MD_UI_calendar_clearText" class="U_MD_UI_calendar_timeBtn">清空</div>' +
  354. '<div id="U_MD_UI_calendar_nowTime" class="U_MD_UI_calendar_timeBtn">现在</div>' +
  355. '<div id="U_MD_UI_calendar_okBtn" class="U_MD_UI_calendar_timeBtn">确定</div>' +
  356. '</div>',
  357. /*选择时间内容*/
  358. '<div id="calendar_timeChoose" class="U_MD_UI_calendar_timeChoose" style="display: none">' +
  359. '</div>'
  360. ];
  361. /**
  362. * 创建日历的壳
  363. * @param els 对象元素
  364. * @param els 父元素
  365. */
  366. U.MD.UI.calendar.create = function (els, parentnode) {
  367. if (els == U.MD.UI.calendar.fouseinp && U.MD.UI.calendar.board.style.display == 'block')
  368. return
  369. if (parentnode && U.MD.UI.calendar.board) {
  370. U.MD.UI.calendar.board.parentNode.removeChild(U.MD.UI.calendar.board);
  371. U.MD.UI.calendar.board = null;
  372. }
  373. var _top = document.documentElement.scrollTop || document.body.scrollTop,
  374. _left = document.documentElement.scrollLeft || document.body.scrollLeft;
  375. var _offsetHtml = [Math.abs(els.getBoundingClientRect().left) + _left, Math.abs(els.getBoundingClientRect().top) + _top]; /*获取元素相对于html文档的距离*/
  376. U.MD.UI.calendar.fouseinp = els; /*当前聚焦的input*/
  377. if (!U.MD.UI.calendar.board) { /*判断是否有创建日历内容*/
  378. U.MD.UI.calendar.showBoard(els, _offsetHtml, parentnode); /*创建日历内容*/
  379. } else {
  380. U.MD.UI.calendar.resetData(_offsetHtml);
  381. }
  382. U.MD.UI.calendar.showDay(); /*日期显示*/
  383. }
  384. /**
  385. * 时分秒模板控制
  386. * @param that 对象元素
  387. * @param text 改变的文字
  388. */
  389. U.MD.UI.calendar.toggleChooseText = function (that) {
  390. var _child = U.selectEl('.U_MD_UI_calendar_c_a')[0].children, //模板元素
  391. _len = _child.length; //长度
  392. if (that.innerText == '返回日期') { //点击的字
  393. U.MD.UI.calendar.changeDisplay(_lastTemplate, _child[_len - 1]); //切换模板
  394. that.innerText = "选择时间"; //改变文字
  395. U.selectEl(that).removeClass("U_MD_UI_calendar_timeTextClick"); //删除选中class
  396. return; //调出函数
  397. }
  398. for (var i = 0; i < _len - 1; i++) { //循环模板
  399. _child[i].style.display != 'none' && (_child[i].style.display = 'none', _lastTemplate = _child[i]); //隐藏
  400. }
  401. _child[_len - 1].style.display = 'block'; //显示选择时分秒模板
  402. that.innerText = "返回日期"; //改变文字
  403. U.selectEl(that).addClass("U_MD_UI_calendar_timeTextClick"); //添加class
  404. }
  405. /**
  406. * 数据重置
  407. * @param offsethtml 偏移量
  408. */
  409. U.MD.UI.calendar.resetData = function (offsethtml) {
  410. U.MD.UI.calendar.board.style.display = 'block'; /*让日历显示*/
  411. U.MD.UI.calendar.mark = 1;
  412. U.selectEl('#calendar_day')[0].style.display = 'block';
  413. U.selectEl('#calendar_month')[0].style.display = 'none';
  414. U.selectEl('#calendar_year')[0].style.display = 'none';
  415. U.MD.UI.calendar.board.style.left = offsethtml[0] + 'px'; /*改变日历显示的x轴*/
  416. U.MD.UI.calendar.board.style.top = offsethtml[1] + U.MD.UI.calendar.fouseinp.clientHeight + 10 + 'px'; /*改变日历显示的y轴*/
  417. U.MD.UI.calendar.year = U.MD.UI.calendar.CURRENTYEAR;
  418. U.MD.UI.calendar.month = U.MD.UI.calendar.CURRENTMONTH;
  419. U.MD.UI.calendar.ChooseDefault(true);
  420. }
  421. /**
  422. * 创建时间选择模块
  423. * @param addel 添加父元素
  424. */
  425. U.MD.UI.calendar.createChooseTime = function (addel) {
  426. var _dataObj = [
  427. ["时", "分", "秒"],
  428. [24, 60, 60],
  429. ["hour", "minute", "second"]
  430. ],
  431. _lastTemplate;
  432. var _ct = $$('div', { id: 'calendar_time', className: 'U_MD_UI_calendar_time', innerHTML: U.MD.UI.calendar.template[4] }, U.MD.UI.calendar.board);
  433. for (var i = 0; i < _dataObj[0].length; i++) {
  434. var _row = $$('div', { className: "U_MD_UI_calendar_timeRow" }, addel);
  435. $$('span', { className: "U_MD_UI_calendar_timeRowText", innerText: _dataObj[0][i] }, _row);
  436. var _rowCon = $$('div', { className: "U_MD_UI_calendar_timeRowCon" }, _row),
  437. _ul = $$('ul', { className: "U_MD_UI_calendar_timeRowUl", name: _dataObj[2][i] }, _rowCon);
  438. for (var j = 0; j < _dataObj[1][i]; j++) {
  439. var _text = j.toString().length == 1 ? '0' + j : j;
  440. $$('li', {
  441. innerText: _text,
  442. onclick: function () {
  443. var _parentUl = this.parentNode,
  444. _activeLi = _parentUl.querySelector('.U_MD_UI_calendar_timeRowActive');
  445. U.selectEl(_activeLi).removeClass('U_MD_UI_calendar_timeRowActive');
  446. U.selectEl(this).addClass('U_MD_UI_calendar_timeRowActive');
  447. switch (_parentUl.name) {
  448. case 'hour':
  449. U.MD.UI.calendar.hour = this.innerText;
  450. break;
  451. case 'minute':
  452. U.MD.UI.calendar.minute = this.innerText;
  453. break;
  454. case 'second':
  455. U.MD.UI.calendar.second = this.innerText;
  456. break;
  457. }
  458. }
  459. }, _ul);
  460. }
  461. }
  462. if (!U.MD.UI.calendar.datetimeformat) {
  463. _ct.style.display = 'none';
  464. }
  465. U.selectEl('#U_MD_UI_calendar_timeText')[0].onclick = function () { //绑定进入选择时分秒的模块时间
  466. U.MD.UI.calendar.toggleChooseText(this)
  467. }
  468. U.selectEl('#U_MD_UI_calendar_clearText')[0].onclick = function () { //绑定清空事件
  469. U.MD.UI.calendar.fouseinp.value ? U.MD.UI.calendar.fouseinp.value = '' : U.MD.UI.calendar.fouseinp.innerText = '';
  470. U.MD.UI.calendar.ChooseDefault(true);
  471. U.MD.UI.calendar.board.style.display = 'none';
  472. }
  473. U.selectEl('#U_MD_UI_calendar_nowTime')[0].onclick = function () { //绑定输出今天事件
  474. U.MD.UI.calendar.outPutDate(true);
  475. }
  476. U.selectEl('#U_MD_UI_calendar_okBtn')[0].onclick = function () { //绑定确定事件
  477. U.MD.UI.calendar.outPutDate(false);
  478. }
  479. }
  480. /**
  481. * 创建日历
  482. * @param input 当前聚焦的input
  483. * @param offsetHtml 元素相对于html文档的距离
  484. */
  485. U.MD.UI.calendar.showBoard = function (input, offsetHtml, parentnode) {
  486. var _template = U.MD.UI.calendar.template,
  487. /*转局部变量*/
  488. _parentNode = parentnode || document.body,
  489. _templateHTML = _template[1] + _template[2] + _template[3] + _template[5];
  490. if (!parentnode) {
  491. U.MD.UI.calendar.board = $$('div', { "className": "U_MD_UI_calendar_bigboard", style: { left: offsetHtml[0] + "px", top: offsetHtml[1] + input.clientHeight + 10 + "px" } }, _parentNode); /*创建日历元素*/
  492. } else {
  493. U.MD.UI.calendar.board = $$('div', { "className": "U_MD_UI_calendar_bigboard" }, parentnode);
  494. }
  495. U.MD.UI.calendar.board.innerHTML = _template[0]; /*给上html模板的第一个*/
  496. _dayC = $$('div', { "className": 'U_MD_UI_calendar_c_a', innerHTML: _templateHTML }, U.MD.UI.calendar.board); /*创建剩下的内容,把html模板内容丢进去*/
  497. U.MD.UI.calendar.tit = U.selectEl('#calendar_tit')[0]; /*获取日历标题*/
  498. _mc = U.selectEl('#calendar_month > ul > li'); /*获取选择月模块的li*/
  499. _titInp = U.selectEl('#calendar_tit_btn')[0]; /*获取日历标题的input*/
  500. _timer = null; /*定义一个定时器*/
  501. U.MD.UI.calendar.createChooseTime($('#calendar_timeChoose')[0]);
  502. U.MD.UI.calendar.tit.onclick = function () { /*给日历标题绑定点击事件*/
  503. clearTimeout(_timer); /*清除定时器*/
  504. if (U.MD.UI.calendar.mark == 1) { /*标记数是1*/
  505. U.MD.UI.calendar.tit.innerText = U.MD.UI.calendar.year; /*日历标题赋值可变月*/
  506. U.MD.UI.calendar.changeDisplay($('#calendar_month')[0], U.selectEl('#calendar_day')[0]); /*选择月显示,选择天隐藏*/
  507. U.MD.UI.calendar.mark = 2; /*标记数赋值2,以表示当前停留在选择月模块*/
  508. U.MD.UI.calendar.ChooseDefault();
  509. } else if (U.MD.UI.calendar.mark == 2) { /*标记数是2*/
  510. _timer = setTimeout(function () { /*赋值一个定时器*/
  511. U.MD.UI.calendar.changeDisplay($('#calendar_year')[0], U.selectEl('#calendar_month')[0]); /*选择年显示,选择月隐藏*/
  512. U.MD.UI.calendar.dateTenYear(); /*调用显示10年内容函数*/
  513. U.MD.UI.calendar.mark = 3; /*标记数复制3,以表示档期那停球在选择年模块*/
  514. U.MD.UI.calendar.ChooseDefault();
  515. }, 250); /*0.25秒后执行*/
  516. }
  517. }
  518. U.MD.UI.calendar.tit.ondblclick = function () { /*给日历标题绑定双击事件*/
  519. clearTimeout(_timer); /*清除定时器,防止进入单击事件*/
  520. if (U.MD.UI.calendar.mark === 2) { /*标记数是2*/
  521. _obj = U.MD.UI.calendar.changeDisplay(_titInp, this, 'inline-block'); /*日历标题文本框显示,日历标题隐藏*/
  522. _obj[0].value = this.innerText; /*把日历title赋值给编辑input*/
  523. _obj[0].focus(); /*编辑input给上聚焦*/
  524. }
  525. }
  526. _titInp.onkeydown = function (e) { /*给日历标题文本框一个键盘事件*/
  527. switch (e.keyCode) {
  528. case 13:
  529. /*编辑input 回车来更改内容*/
  530. var _arr2 = U.MD.UI.calendar.changeDisplay(U.MD.UI.calendar.tit, this, 'inline-block'); /*显示日历title, 隐藏编辑input*/
  531. _arr2[0].innerText = U.MD.UI.calendar.year = !isNaN(parseInt(this.value)) ? parseInt(this.value) : U.MD.UI.calendar.CURRENTYEAR; /*把编辑input的内容赋值给日历title*/
  532. break;
  533. }
  534. };
  535. _titInp.onblur = function () { /*给日历标题文本框一个失去焦点*/
  536. var _arr3 = U.MD.UI.calendar.changeDisplay(U.MD.UI.calendar.tit, this, 'inline-block'); /*同上*/
  537. _arr3[0].innerText = U.MD.UI.calendar.year = !isNaN(parseInt(this.value)) ? parseInt(this.value) : U.MD.UI.calendar.CURRENTYEAR;
  538. }
  539. U.selectEl('#prevDate')[0].onclick = function () { /*给向左的小三角绑定点击事件*/
  540. if (U.MD.UI.calendar.mark == 1) { _lessNum = -1 } /*标记数是1,-1月*/
  541. else if (U.MD.UI.calendar.mark == 2) { _lessNum = -12 } /*标记数是2,-12月*/
  542. else if (U.MD.UI.calendar.mark == 3) { _lessNum = -120 }; /*标记数是3, -120月*/
  543. U.MD.UI.calendar.fullDate(_lessNum, false);
  544. };
  545. U.selectEl('#nextDate')[0].onclick = function () { /*给向右的小三角绑定点击事件*/
  546. if (U.MD.UI.calendar.mark == 1) { _addNum = 1 } /*标记数是1,+1月*/
  547. else if (U.MD.UI.calendar.mark == 2) { _addNum = 12 } /*标记数是1,+12月*/
  548. else if (U.MD.UI.calendar.mark == 3) { _addNum = 120 }; /*标记数是1,+120月*/
  549. U.MD.UI.calendar.fullDate(_addNum, true);
  550. };
  551. for (var i = 0; i < _mc.length; i++) { /*给选择月的模块li循环*/
  552. _mc[i].onclick = function () { /*给每个绑定一个点击事件*/
  553. U.MD.UI.calendar.changeDisplay($('#calendar_day')[0], U.selectEl('#calendar_month')[0]); /*选择天显示,选择月隐藏*/
  554. U.MD.UI.calendar.month = parseInt(this.innerText) - 1; /*赋值选的月*/
  555. U.MD.UI.calendar.showDay(); /*刷新数据*/
  556. U.MD.UI.calendar.mark = 1; /*标记量赋值1*/
  557. }
  558. }
  559. U.selectEl('#U_MD_UI_calendar_closeBtn')[0].onclick = function () { /*给关闭按钮绑定一个事件*/
  560. U.UF.EV.stopBubble();
  561. U.MD.UI.calendar.board.style.display = 'none'; /*让日历空间隐藏*/
  562. }
  563. }
  564. /**
  565. * 创建或更新选择天模块的内容
  566. */
  567. U.MD.UI.calendar.showDay = function () { /*显示日期*/
  568. _monthFristDay = new Date(U.MD.UI.calendar.year, U.MD.UI.calendar.month, 1).getDay(); /*当月第一天的星期*/
  569. _lastMonthDay = new Date(U.MD.UI.calendar.year, U.MD.UI.calendar.month, 0).getDate(); /*上个月的最后一天*/
  570. _fullDay = new Date(U.MD.UI.calendar.year, U.MD.UI.calendar.month + 1, 0).getDate(); /*当月总天数*/
  571. _totalDay = (_t = _monthFristDay + _fullDay) % 7 === 0 ? _t : _t + (7 - _t % 7); /*当月总共需要显示天数*/
  572. _dayC = U.selectEl('#calendar_week_c')[0];
  573. _dayC.innerHTML = '';
  574. for (var _i = 0; _i < _totalDay; _i++) {
  575. _li = $$('li', {}, _dayC);
  576. if (_i < _monthFristDay) { /*如果小于当月第一天的星期,这里显示的是上月最后几天的号显示*/
  577. $$('span', { "className": 'U_MD_UI_calendar_unavailable', innerText: (_lastMonthDay - _monthFristDay + _i + 1) }, _li);
  578. } else if (_i < (_fullDay + _monthFristDay)) { /*如果小于(当月总天数 + 当月第一天的星期)*/
  579. var _d = _i - _monthFristDay + 1,
  580. _week = new Date(U.MD.UI.calendar.year, U.MD.UI.calendar.month, _d).getDay(),
  581. _today = U.MD.UI.calendar.NOW.getDate() === _d && (U.MD.UI.calendar.CURRENTMONTH === U.MD.UI.calendar.month && U.MD.UI.calendar.CURRENTYEAR === U.MD.UI.calendar.year);
  582. _dayV = _d;
  583. if (_week === 6 || _week === 0) { /*如果是周末字体显示为红色,否则给黑色*/
  584. _today ? $$('span', {
  585. "className": 'U_MD_UI_calendar_day U_MD_UI_calendar_today U_MD_UI_calendar_weekend',
  586. innerText: _d,
  587. "onclick": function () {
  588. U.MD.UI.calendar.day = this.innerText;
  589. U.MD.UI.calendar.outPutDate()
  590. }
  591. }, _li) : $$('span', {
  592. "className": 'U_MD_UI_calendar_day U_MD_UI_calendar_weekend',
  593. innerText: _d,
  594. "onclick": function () {
  595. U.MD.UI.calendar.day = this.innerText;
  596. U.MD.UI.calendar.outPutDate()
  597. }
  598. }, _li);
  599. } else if (_today) { /*如果是今天,打重点*/
  600. $$('span', {
  601. "className": 'U_MD_UI_calendar_day U_MD_UI_calendar_today',
  602. innerText: _d,
  603. "onclick": function () {
  604. U.MD.UI.calendar.day = this.innerText;
  605. U.MD.UI.calendar.outPutDate()
  606. }
  607. }, _li)
  608. } else { /*默认样式*/
  609. $$('span', {
  610. "className": 'U_MD_UI_calendar_day',
  611. innerText: _d,
  612. "onclick": function () {
  613. U.MD.UI.calendar.day = this.innerText;
  614. U.MD.UI.calendar.outPutDate()
  615. }
  616. }, _li)
  617. }
  618. } else { /*显示下个月的星期,给上字体是灰色的样式*/
  619. $$('span', { "className": 'U_MD_UI_calendar_unavailable', innerText: (_i - (_fullDay + _monthFristDay) + 1) }, _li)
  620. }
  621. }
  622. U.MD.UI.calendar.tit.innerText = U.MD.UI.calendar.year + '-' + (U.MD.UI.calendar.month + 1) + '月'; /*转换格式,然后丢到日历标题文本框里*/
  623. }
  624. /**
  625. * 年月控制器
  626. * @param num 需要减的月数
  627. * @param check 如果是true表示点击了向右的小三角,是false表示点击了向左的小三角
  628. */
  629. U.MD.UI.calendar.fullDate = function (num, check) {
  630. var _year = (_n = Math.abs(num) / 12) >= 1 ? _n >>> 0 : 0,
  631. /*如果月份/12大于1,也就是超过12月或者说1年, _n>>>0取出整数部分*/
  632. _month = Math.abs(num) % 12; /*月份膜上12剩下的就是月份*/
  633. !check && (_month = -_month);
  634. !check && (_year = -_year);
  635. U.MD.UI.calendar.month += _month; /*月份加一或减一*/
  636. U.MD.UI.calendar.year += _year; /*年份加一或减一*/
  637. if (check) {
  638. if (U.MD.UI.calendar.month > 11) { /*如果月份大于11*/
  639. U.MD.UI.calendar.month = 0; /*月份清空*/
  640. U.MD.UI.calendar.year++; /*年份加一*/
  641. }
  642. } else {
  643. if (U.MD.UI.calendar.month < 0) { /*如果月份小于0*/
  644. U.MD.UI.calendar.month = 11; /*可变月赋值11,即表示12月*/
  645. U.MD.UI.calendar.year--; /*可变年减一*/
  646. }
  647. }
  648. if (U.MD.UI.calendar.mark == 1) { U.MD.UI.calendar.showDay() }; /*更新日期显示*/
  649. if (U.MD.UI.calendar.mark == 2) { U.MD.UI.calendar.tit.innerText = U.MD.UI.calendar.year }; /*标记数是2,即代表在选择月模块,*/
  650. if (U.MD.UI.calendar.mark == 3) { U.MD.UI.calendar.dateTenYear() }; /*标记数是3,即代表在选择年模块,*/
  651. }
  652. /**
  653. * 转换输出格式
  654. * @param symbol 分割符号
  655. * @param isnow 【boolean】 是否获取当前时间
  656. * @returns {*} 返回字符串
  657. */
  658. U.MD.UI.calendar.formartDate = function (symbol, isnow) {
  659. var _symbol, y, m, d, h, m, s;
  660. _symbol = symbol || '-'
  661. y = isnow ? U.MD.UI.calendar.CURRENTYEAR : U.MD.UI.calendar.year;
  662. m = isnow ? U.MD.UI.calendar.CURRENTMONTH + 1 : U.MD.UI.calendar.month + 1;
  663. d = isnow ? U.MD.UI.calendar.CURRENTDAY : U.MD.UI.calendar.day;
  664. m = (m.toString())[1] ? m : '0' + m;
  665. d = (d.toString())[1] ? d : '0' + d;
  666. var _dateStr = y + _symbol + m + _symbol + d;
  667. if (typeof U.MD.UI.calendar.datetimeformat == 'boolean' && U.MD.UI.calendar.datetimeformat) {
  668. if (isnow) {
  669. var _nowDate = new Date();
  670. U.MD.UI.calendar.hour = _nowDate.getHours();
  671. U.MD.UI.calendar.minute = _nowDate.getMinutes();
  672. U.MD.UI.calendar.second = _nowDate.getSeconds();
  673. }
  674. h = (U.MD.UI.calendar.hour.toString())[1] ? U.MD.UI.calendar.hour : '0' + U.MD.UI.calendar.hour;
  675. m = (U.MD.UI.calendar.minute.toString())[1] ? U.MD.UI.calendar.minute : '0' + U.MD.UI.calendar.minute;
  676. s = (U.MD.UI.calendar.second.toString())[1] ? U.MD.UI.calendar.second : '0' + U.MD.UI.calendar.second;
  677. _dateStr += " " + h + ":" + m + ":" + s;
  678. }
  679. return _dateStr;
  680. }
  681. /**
  682. * 创建选择天时需要循环绑定的函数
  683. */
  684. /*
  685. U.MD.UI.calendar.outPutDate = function () {
  686. if (U.MD.UI.calendar.fouseinp.value) {
  687. U.MD.UI.calendar.fouseinp.value = U.MD.UI.calendar.formartDate(U.MD.UI.calendar.year, U.MD.UI.calendar.month + 1, this.innerText);
  688. } else {
  689. U.MD.UI.calendar.fouseinp.innerText = U.MD.UI.calendar.formartDate(U.MD.UI.calendar.year, U.MD.UI.calendar.month + 1, this.innerText);
  690. }
  691. U.MD.UI.calendar.board.style.display = 'none';
  692. }
  693. */
  694. /**
  695. * 创建选择天时需要循环绑定的函数
  696. */
  697. U.MD.UI.calendar.outPutDate = function (isNow) {
  698. if (U.MD.UI.calendar.fouseinp.tagName === 'INPUT') {
  699. U.MD.UI.calendar.fouseinp.value = U.MD.UI.calendar.formartDate('-', isNow); /*选择天后进入转换年月日输入格式函数*/
  700. } else {
  701. U.MD.UI.calendar.fouseinp.innerText = U.MD.UI.calendar.formartDate('-', isNow); /*选择天后进入转换年月日输入格式函数*/
  702. }
  703. U.MD.UI.calendar.CheckedDay && U.MD.UI.calendar.CheckedDay();
  704. U.MD.UI.calendar.board.style.display = 'none'; /*隐藏日历控件*/
  705. }
  706. /**
  707. * 显示与隐藏
  708. * @param blockEl 需要显示的元素
  709. * @param noneEl 需要隐藏的元素
  710. * @param val 显示的方式
  711. * @returns {*[]} 返回数组[显示元素,隐藏元素]
  712. */
  713. U.MD.UI.calendar.changeDisplay = function (blockEl, noneEl, val) {
  714. val = val || 'block'; /*默认block*/
  715. if (blockEl && typeof blockEl === 'object') { blockEl.setAttribute('style', 'display:' + val) } /*如果blockEL存在且blockEl是个对象,进行属性的赋值*/
  716. if (noneEl && typeof noneEl === 'object') { noneEl.setAttribute('style', 'display:none') }; /*如果noneEl存在且noneEl是个对象,进行属性的赋值*/
  717. return [blockEl, noneEl];
  718. }
  719. /**
  720. * 更新选择年的模块内容
  721. */
  722. U.MD.UI.calendar.dateTenYear = function () {
  723. _yearArr = U.selectEl('#calendar_year > ul > li'); /*获取选择年模块里的li*/
  724. _startYear = U.MD.UI.calendar.year - (U.MD.UI.calendar.year % 10); /**/
  725. for (var i = 0; i < _yearArr.length; i++) {
  726. _yearArr[i].onclick = function () {
  727. U.MD.UI.calendar.mark = 2; /*标记数赋值2*/
  728. U.MD.UI.calendar.year = parseInt(this.innerText); /*修改年的的值*/
  729. U.MD.UI.calendar.changeDisplay($('#calendar_month')[0], U.selectEl('#calendar_year')[0]); /*显示选择月板块,隐藏选择年的板块*/
  730. U.MD.UI.calendar.tit.innerText = this.innerText; /*改变日历title显示格式*/
  731. }
  732. _yearArr[i].innerHTML = ''; /*清空li里面的内容*/
  733. if (i == 0 || i == _yearArr.length - 1) { /*头尾年*/
  734. $$('span', { "className": "U_MD_UI_calendar_unavailable", innerText: (_startYear + i - 1) }, _yearArr[i]);
  735. } else if ((_startYear + i - 1) === U.MD.UI.calendar.CURRENTYEAR) { /*当前年*/
  736. $$('span', { style: { "background-color": "#eed1bc" }, innerText: (_startYear + i - 1) }, _yearArr[i])
  737. } else { /*默认输出*/
  738. $$('span', { innerText: (_startYear + i - 1) }, _yearArr[i])
  739. }
  740. }
  741. U.MD.UI.calendar.tit.innerText = (t = (U.MD.UI.calendar.year - (U.MD.UI.calendar.year % 10))) + '-' + (t + 9); /*改变日历title显示格式*/
  742. }
  743. /**
  744. * 时分秒数据初始化
  745. * @param deafultflag 【boolean】是否初始化数据
  746. */
  747. U.MD.UI.calendar.ChooseDefault = function (deafultflag) {
  748. if (U.MD.UI.calendar.datetimeformat) { //判断是否显示时分秒模板
  749. if (deafultflag) { //是否初始化数据
  750. U.MD.UI.calendar.hour = '00'; //重置
  751. U.MD.UI.calendar.minute = '00'; //重置
  752. U.MD.UI.calendar.second = '00'; //重置
  753. U.selectEl(U.MD.UI.calendar.board).find('.U_MD_UI_calendar_timeRowActive').removeClass('U_MD_UI_calendar_timeRowActive'); //清除选中的样式
  754. !$('#U_MD_UI_calendar_timeText').length && U.MD.UI.calendar.createChooseTime($('#calendar_timeChoose')[0]); //是否有加载时分秒模块
  755. }
  756. U.selectEl('#calendar_time')[0].style.display = "block"; //显示选择时间的功能区
  757. U.selectEl('#calendar_timeChoose')[0].style.display = 'none'; //隐藏选择时分秒选择区
  758. U.selectEl('#U_MD_UI_calendar_timeText')[0].innerText = "选择时间"; //重置
  759. U.selectEl('#U_MD_UI_calendar_timeText').removeClass("U_MD_UI_calendar_timeTextClick"); //重置
  760. } else {
  761. U.selectEl('#calendar_time')[0].style.display = 'none'; //重置
  762. U.selectEl('#calendar_timeChoose')[0].style.display = 'none'; //重置
  763. }
  764. }
  765. U.MD.UI.calendar.SetCallBack = function (funcname, func) {
  766. if (typeof func != 'function' || !"CheckedDay ".match(funcname + ' '))
  767. return 0;
  768. U.MD.UI.calendar[funcname] = func
  769. };
  770. ///<jscompress sourcefile="City.js" />
  771. Namespace.register("U.MD.UI.city");
  772. /**
  773. * [Control description] 城市控件接口
  774. * @param {[html元素]} element [需要使用城市控件的元素(默认放置到element下面)]
  775. */
  776. U.MD.UI.city = function (element) {
  777. U.UF.EV.stopBubble(); //阻止事件冒泡 防止被body的事件覆盖
  778. if (!element || !element.tagName) { //如果element存在tagName 则一定是html元素 否则不执行城市控件
  779. return;
  780. }
  781. if (_cityBox = U.selectEl("#U_MD_UI_city_cityBox")[0]) {
  782. var _rect = element.getBoundingClientRect();
  783. _cityBox.style.top = _rect.top + _rect.height + document.documentElement.scrollTop + "px";
  784. //调整控件的top位置
  785. _cityBox.style.left = _rect.left + document.documentElement.scrollLeft + "px";
  786. //调整控件的left位置
  787. U.selectEl(_cityBox).removeClass("U_MD_UI_city_hidden");
  788. //删除掉hidden的class名(显示城市控件) 目的: 去除掉display为none的样式
  789. U.MD.UI.city.Attr.inputNode = element; //获取最终结果的表单元素 可能会不同 因此 inputNode需要重新赋值
  790. return;
  791. }
  792. var _city = U.MD.UI.city; //简写命名空间
  793. _city.create(element); //将控件html代码添加到body上 并调整控件位置
  794. _city.Attr = { //存放节点 与 变量 的json对象
  795. "inputNode": element //判断是哪个表单点击的 为赋值所用
  796. };
  797. _city.init(); //函数初始化(添加js功能)
  798. };
  799. U.MD.UI.city.Attr = {}; //存放元素与变量的json全局变量 未赋值
  800. U.MD.UI.city.usedCity = null; //存放常用市数据的变量
  801. U.MD.UI.city.province = null; //存放省数据的变量
  802. U.MD.UI.city.city = {}; //存放市数据的变量
  803. U.MD.UI.city.area = {}; //存放区数据的变量
  804. U.MD.UI.city.htmlTemplate = ' <ul class="U_MD_UI_city_menuBox"> <!--控件的头部-->\n' +
  805. '\n' +
  806. ' <!--U_MD_UI_city_menuChecked 选中菜单的按钮时所用的"className":红色-->\n' +
  807. ' <!--U_MD_UI_city_filled 表示待填写class 为增删class占位置 防出错 以下都是-->\n' +
  808. ' <!--U_MD_UI_city_menuoChecked 选择城市后所添加的class 红色小圆点-->\n' +
  809. ' <li id="U_MD_UI_city_usedCityMenu" data-city-mark="U_MD_UI_city_usedCityCont" class="U_MD_UI_city_menuChecked" data-city-res="">\n' +
  810. ' <span>常用市</span>\n' +
  811. ' </li>\n' +
  812. '\n' +
  813. ' <li id="U_MD_UI_city_provinceMenu" data-city-mark="U_MD_UI_city_provinceCont" class="U_MD_UI_city_filled" data-city-res="">\n' +
  814. ' <span>省/直辖市</span>\n' +
  815. ' </li>\n' +
  816. '\n' +
  817. ' <li id="U_MD_UI_city_cityMenu" data-city-mark="U_MD_UI_city_cityCont" class="U_MD_UI_city_filled U_MD_UI_city_hidden" data-city-res="">\n' +
  818. ' <span>请选择</span>\n' +
  819. ' </li>\n' +
  820. '\n' +
  821. ' <li id="U_MD_UI_city_areaMenu" data-city-mark="U_MD_UI_city_areaCont" class="U_MD_UI_city_filled U_MD_UI_city_hidden" data-city-res="">\n' +
  822. ' <span>请选择</span>\n' +
  823. ' </li>\n' +
  824. ' </ul>\n' +
  825. '\n' +
  826. '\n' +
  827. ' <!--以下为主要内容区域-->\n' +
  828. ' <!-- ----------------------------------------------------------------------------- -->\n' +
  829. ' <ul id="U_MD_UI_city_usedCityCont" class="U_MD_UI_city_filled U_MD_UI_city_Cont"> <!-- &lt;!&ndash;常用城市盒子节点&ndash;&gt; -->\n' +
  830. ' <li id="U_MD_UI_city_liTemplate"><span>光明新区</span></li>\n' +
  831. ' <!-- U_MD_UI_city_liTemplate 为内容区域的li的模板 可无视 已display为none -->\n' +
  832. ' <!--U_MD_UI_city_Cont_ochecked 选中城市的按钮时所用的"className":红色-->\n' +
  833. ' </ul>\n' +
  834. '\n' +
  835. '\n' +
  836. ' <ul class="U_MD_UI_city_filled U_MD_UI_city_Cont U_MD_UI_city_hidden" id="U_MD_UI_city_provinceCont"> <!-- &lt;!&ndash;存放省的盒子节点&ndash;&gt; -->\n' +
  837. ' </ul>\n' +
  838. '\n' +
  839. '\n' +
  840. ' <ul class="U_MD_UI_city_filled U_MD_UI_city_Cont U_MD_UI_city_hidden" id="U_MD_UI_city_cityCont"> <!-- &lt;!&ndash;存放市的盒子节点&ndash;&gt; -->\n' +
  841. ' </ul>\n' +
  842. '\n' +
  843. '\n' +
  844. ' <ul class="U_MD_UI_city_filled U_MD_UI_city_Cont U_MD_UI_city_hidden" id="U_MD_UI_city_areaCont"> <!-- &lt;!&ndash;存放地区的盒子节点&ndash;&gt; -->\n' +
  845. ' </ul>';
  846. //html代码
  847. /**
  848. * 添加html代码,并且判断html代码是否存在 若存在 则不添加
  849. * @param {[html元素]} element [需要使用城市控件的元素(默认放置到element下面)]
  850. */
  851. U.MD.UI.city.create = function (element) {
  852. var _cityBox = $$("div", { id: 'U_MD_UI_city_cityBox', className: 'U_MD_UI_city_cityBox U_MD_UI_city_hidden' }, document.body);
  853. _cityBox.innerHTML += U.MD.UI.city.htmlTemplate;
  854. var _rect = element.getBoundingClientRect();
  855. _cityBox.style.top = _rect.top + _rect.height + document.documentElement.scrollTop + "px";
  856. //调整控件的top位置
  857. _cityBox.style.left = _rect.left + document.documentElement.scrollLeft + "px";
  858. //调整控件的left位置
  859. U.MD.UI.city.Attr.inputNode = element;
  860. //获取最终结果的表单元素 可能会不同 因此 inputNode需要重新赋值
  861. U.selectEl(_cityBox).removeClass("U_MD_UI_city_hidden");
  862. //删除掉hidden的class名(显示城市控件) 目的: 去除掉display为none的样式
  863. };
  864. /**
  865. * 函数初始化
  866. */
  867. U.MD.UI.city.init = function () {
  868. var _city = U.MD.UI.city; //简写命名空间
  869. _city.getUsedCity(); //获取常用市所有数据
  870. _city.inputEvent(); //添加监听事件: 点击表单显示城市控件并发送后台请求数据 与 点击body区域隐藏城市控件
  871. _city.menuEvent(); //添加监听事件: 点击菜单显示对应的内容
  872. };
  873. /**
  874. * 为表单添加点击事件
  875. */
  876. U.MD.UI.city.inputEvent = function () {
  877. var _city = U.MD.UI.city; //简写命名空间
  878. var _attr = _city.Attr; //简写全局属性json名
  879. var _hidden = "U_MD_UI_city_hidden"; //class样式名 由于太长赋值给变量 _hidden 控制元素display的样式
  880. var _cityBox = U.selectEl("#U_MD_UI_city_cityBox")[0]; //城市控件总盒子节点
  881. U.selectEl(document).bind('click', function () { //点击body时 隐藏城市控件
  882. U.selectEl(_cityBox).addClass(_hidden);
  883. //添加掉hidden的class名 目的: 添加display为none的样式
  884. }, false);
  885. U.selectEl(_cityBox).bind('click', function (e) { //防止点击城市控件时 被body的事件覆盖而隐藏 因此加上防止冒泡处理
  886. U.UF.EV.stopBubble(e);
  887. //阻止事件冒泡
  888. });
  889. U.selectEl("#U_MD_UI_city_areaCont")[0].onclick = function () {
  890. if ($("#U_MD_UI_city_areaCont")[0]) {
  891. U.selectEl("#U_MD_UI_city_cityBox")[0].style.display = "none";
  892. }
  893. }
  894. };
  895. /**
  896. * 为每个菜单添加点击事件
  897. */
  898. U.MD.UI.city.menuEvent = function () {
  899. var _city = U.MD.UI.city; //简写命名空间
  900. var _attr = _city.Attr; //简写全局属性json名
  901. var _menuAllNode = U.selectEl("[data-city-mark]"); //所有菜单节点;
  902. var _hidden = "U_MD_UI_city_hidden"; //class样式名 由于太长赋值给变量 _hidden 控制元素display的样式
  903. for (var i = 0, len = _menuAllNode.length; i < len; i++) { //循环所有菜单元素
  904. var _el = _menuAllNode[i]; //获取每个菜单 赋值给变量el
  905. U.selectEl(_el).bind('click', function () { //添加点击事件
  906. _city.menuClassControl(this, "U_MD_UI_city_menuChecked", "data-city-mark", _hidden); //为每个菜单添加对应每个区域的事件
  907. });
  908. if (_el.id === "U_MD_UI_city_provinceMenu") { //如果点击的是 省/直辖市 菜单 则获取对应的数据
  909. U.selectEl(_el).bind('click', function () {
  910. _city.getProvince(); //省/直辖市菜单的点击事件 获取数据
  911. })
  912. }
  913. }
  914. };
  915. /**
  916. * 获取数据常用市的所有数据
  917. */
  918. U.MD.UI.city.getUsedCity = function () {
  919. var _city = U.MD.UI.city; //简写命名空间
  920. var _attr = _city.Attr; //简写全局属性json名
  921. var _usedCityMenu = U.selectEl("#U_MD_UI_city_usedCityMenu")[0]; //常用市菜单按钮
  922. var _liTemplate = U.selectEl("#U_MD_UI_city_liTemplate")[0]; //要clone的li的模板
  923. var _usedCityCont = U.selectEl("#U_MD_UI_city_usedCityCont")[0]; //常用市内容区域
  924. if (!_city.usedCity) { //如果 常用市(_city.usedCity) 无数据 则发送请求到后台获取数据 并打印出来
  925. U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Controls", "City_UsedCity"], function (r) {
  926. _city.usedCity = r.value;
  927. _city.allDataPrint(_usedCityMenu, _city.usedCity, _liTemplate, "usedCity", _usedCityCont); //打印数据
  928. });
  929. }
  930. };
  931. /**
  932. * 获取省/直辖市的所有数据
  933. */
  934. U.MD.UI.city.getProvince = function () {
  935. var _city = U.MD.UI.city; //简写命名空间
  936. var _attr = _city.Attr; //简写全局属性json名
  937. var _provinceMenu = U.selectEl("#U_MD_UI_city_provinceMenu")[0]; //省菜单按钮
  938. var _liTemplate = U.selectEl("#U_MD_UI_city_liTemplate")[0]; //要clone的li的模板
  939. var _provinceCont = U.selectEl("#U_MD_UI_city_provinceCont")[0]; //省内容区域
  940. if (!_city.province) { //如果 省/直辖市(_city.province) 无数据 则发送请求到后台获取数据 并打印出来
  941. U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Controls", "City_Province"], function (r) {
  942. _city.province = r.value;
  943. _city.allDataPrint(_provinceMenu, _city.province, _liTemplate, "province", _provinceCont); //打印数据
  944. });
  945. }
  946. };
  947. /**
  948. * 通过code 获取市的所有数据
  949. * @param code 省级的id
  950. */
  951. U.MD.UI.city.getCity = function (code) {
  952. var _city = U.MD.UI.city; //简写命名空间
  953. var _attr = _city.Attr; //简写全局属性json名
  954. var _cityMenu = U.selectEl("#U_MD_UI_city_cityMenu")[0]; //市菜单按钮
  955. var _liTemplate = U.selectEl("#U_MD_UI_city_liTemplate")[0]; //要clone的li的模板
  956. var _cityCont = U.selectEl("#U_MD_UI_city_cityCont")[0]; //市内容区域
  957. var _hidden = "U_MD_UI_city_hidden"; //class样式名 由于太长赋值给变量 _hidden 控制元素display的样式
  958. if (!_city.city[code]) { //_city.city = json 而_city.city[code]则是对应的数组值 例如:我点击广东后 获取到了广东的id 则我要通过 广东的id 获取下级的市数据 因此如果json中没有该值 则向后台发送请求获取
  959. _city.menuClassControl(_cityMenu, "U_MD_UI_city_menuChecked", "data-city-mark", _hidden); //相当于点击菜单 将城市的菜单于内容 "先"显示出来 再加载数据 防止多次点击
  960. U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Controls", "City_PidFind", code, 1], function (r) {
  961. _city.city[code] = r.value;
  962. //_city.city = {}
  963. //r.value = [{},{},{}]
  964. //为了能判断该code下是否有数据 因此需要在_city.city下添加一个 以code为键名 r.value为值的数组
  965. //例如:_city.city = {} code = 123 r.value = [{a:1},{a:1},{a:1}] 最后会变成 _city.city = {123:[{a:1},{a:1},{a:1}]}
  966. _city.allDataPrint(_cityMenu, _city.city[code], _liTemplate, "city", _cityCont); //打印数据
  967. });
  968. } else { //如果json下有数据 则直接打印该数据
  969. _city.menuClassControl(_cityMenu, "U_MD_UI_city_menuChecked", "data-city-mark", _hidden); //相当于点击菜单 将城市的菜单与内容区域 显示出来
  970. _city.allDataPrint(_cityMenu, _city.city[code], _liTemplate, "city", _cityCont); //打印数据
  971. }
  972. };
  973. /**
  974. * 通过code 获取区级的所有数据 函数的意思可参看上面getCity的注释
  975. * @param code 参数为市级的id
  976. */
  977. U.MD.UI.city.getarea = function (code) {
  978. var _city = U.MD.UI.city; //简写命名空间
  979. var _attr = _city.Attr; //简写全局属性json名
  980. var _areaMenu = U.selectEl("#U_MD_UI_city_areaMenu")[0]; //区菜单按钮
  981. var _hidden = "U_MD_UI_city_hidden"; //class样式名 由于太长赋值给变量 _hidden 控制元素display的样式
  982. var _liTemplate = U.selectEl("#U_MD_UI_city_liTemplate")[0]; //要clone的li的模板
  983. var _areaCont = U.selectEl("#U_MD_UI_city_areaCont")[0]; //区内容区域
  984. if (!_city.area[code]) {
  985. _city.menuClassControl(_areaMenu, "U_MD_UI_city_menuChecked", "data-city-mark", _hidden); //相当于点击菜单 将城市的菜单于内容 "先"显示出来 再加载数据 防止多次点击
  986. U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Controls", "City_PidFind", code, 2], function (r) {
  987. _city.area[code] = r.value;
  988. _city.allDataPrint(_areaMenu, _city.area[code], _liTemplate, "area", _areaCont);
  989. });
  990. } else {
  991. _city.menuClassControl(_areaMenu, "U_MD_UI_city_menuChecked", "data-city-mark", _hidden); //相当于点击菜单 将城市的菜单于内容 "先"显示出来 再加载数据 防止多次点击
  992. _city.allDataPrint(_areaMenu, _city.area[code], _liTemplate, "area", _areaCont);
  993. }
  994. };
  995. /**
  996. * 打印传过来的数组json数据
  997. * @param {[type]} menu [与之对应的菜单元素]
  998. * @param {[type]} data [是一个数组json]
  999. * @param {[type]} template [是一个li模板 clone用的]
  1000. * @param {[type]} type [数据类型("province"、"usedCity"....) 为判断所用]
  1001. * @param {[type]} parent [父节点("cityCont,areaCont...") 也叫做内容区域 ]
  1002. */
  1003. U.MD.UI.city.allDataPrint = function (menu, data, template, type, parent) {
  1004. var _city = U.MD.UI.city; //简写命名空间
  1005. var _attr = _city.Attr; //简写全局属性json名
  1006. var _usedCityMenu = U.selectEl("#U_MD_UI_city_usedCityMenu")[0]; //常用市菜单按钮
  1007. var _provinceMenu = U.selectEl("#U_MD_UI_city_provinceMenu")[0]; //省菜单按钮
  1008. var _len = data.length; //数组json的长度
  1009. var _menu = menu; //菜单元素 赋值给 _menu变量
  1010. for (var i = 0; i < _len; i++) {
  1011. // 遍历 data数据(数组json)
  1012. var _span = _city.dataPrint(data[i], template, type, parent);
  1013. //单个数据打印 PS:由于data是一个 数组json([{a:1},{a:2},{a:3}]) 因此 需要将获取对应的数据 并添加在 对应的 parent(内容区域) 上
  1014. _span.onclick = function () {
  1015. var _type = U.selectEl(this).attr("data-city-type");
  1016. //获取点击的span标签的属于哪一类型 (比如: 点击省的数据 是 province 市的数据 则时 city)
  1017. var _code = U.selectEl(this).attr("data-city-code");
  1018. //获取数据编码 为寻找下一层所用
  1019. U.selectEl(_menu.children[0]).addClass("U_MD_UI_city_menuoChecked");
  1020. //点击后为 对应的相对应的菜单添加红色小圆点样式 例如:点击省/直辖市菜单下的 广东后 省/直辖市就会多一个红色小圆点的样式
  1021. _menu.children[0].innerText = this.innerText;
  1022. //改变对应菜单的名字为:点击数据的值 例如:点击"省/直辖市"菜单 下的广东 则 菜单的名字则变为 广东 PS: children[0] 为 li下的span标签
  1023. U.selectEl(_menu).attr("data-city-res", this.innerText);
  1024. //给自定义属性 data-city-res 添加为: 点击数据的值 PS: 为获取最终值给表单所用
  1025. _city.contClassControl(this, "U_MD_UI_city_Cont_ochecked");
  1026. //给所选的内容数据添加红色背景 并且删除同一内容区域拥有红色背景的其他元素
  1027. switch (_type) {
  1028. //此处为 判断 点击 各类型数据需要做的动作 type为判断哪种类型 比如: type值为 "province" 则是 省/直辖市菜单下的 数据 点击这些数据后 就是要做的事情
  1029. case "province":
  1030. _city.getCity(_code);
  1031. //将数据的 code 值传入给 城市函数 来获取城市数据 PS: 获取市的数据需要获取他们的parentid 而code则是他们的parentid
  1032. _city.initAllClass(_usedCityMenu);
  1033. //点击省/直辖市下的数据的话 则初始化 常用市菜单 与 相对应的内容区域样式
  1034. break;
  1035. case "usedCity":
  1036. if (this.innerText === "重庆") { //由于重庆这个城市比较特殊 因此需要在常用市那将重庆转为省数据
  1037. _city.getCity(_code);
  1038. } else {
  1039. _city.getarea(_code);
  1040. }
  1041. //在将数据的 code 值传入给 城市函数 来获取城市数据 PS: 获取市的数据需要获取他们的parentid 而code则是他们的parentid
  1042. _city.initAllClass(_provinceMenu);
  1043. //点击常用市下的数据的话 则初始化 省/直辖市菜单 与 相对应的内容区域样式
  1044. break;
  1045. case "city":
  1046. _city.getarea(_code);
  1047. //在将数据的 code 值传入给 区函数 来获取区数据 PS: 获取区的数据需要获取他们的parentid 而code则是他们的parentid
  1048. break;
  1049. case "area":
  1050. _city.getRes("data-city-res");
  1051. //由于该控件是 省-市-区 因此 当点击区里的数据时 则调用获取最终值的函数
  1052. break;
  1053. }
  1054. }
  1055. }
  1056. };
  1057. /**
  1058. * 打印单个数据api(创建节点,赋id 赋innerText 等等)
  1059. * @param {[json对象]} data [json对象的数据]
  1060. * @param {[元素]} template [需要clone的li模板]
  1061. * @param {[字符串]} type [属于哪种城市类型]
  1062. * @param {[元素]} parent [父节点]
  1063. * @return {[元素]} [克隆完后的一条li下的span节点]
  1064. */
  1065. U.MD.UI.city.dataPrint = function (data, template, type, parent) {
  1066. var _city = U.MD.UI.city; //简写命名空间
  1067. var _liNode = _city.clone(template), //克隆已建好的li模板
  1068. _spanNode = _liNode.children[0]; //获取li的span节点
  1069. var _shortName = data.short_name; //获取城市名字缩写
  1070. var _name = data.name; //获取名字全称
  1071. _liNode.id = type + data.id; //添加id
  1072. _spanNode.innerText = _shortName; //添加文字内容
  1073. if (_shortName === "北京" || _shortName === "上海" || _shortName === "天津" || _shortName === "重庆") { //由于这4个城市的 缩写 和省的名字相同 因此 需要将数据名 改成name 详见数据库
  1074. if (parent.id === "U_MD_UI_city_cityCont") {
  1075. _spanNode.innerText = _name; //添加文字内容
  1076. }
  1077. }
  1078. if (parent.id === "U_MD_UI_city_areaCont") { //由于区级数据库 的缩写少了一个区 例如:显示出来的 龙岗区 被缩成 龙岗 因此需要将值等于他们的全称
  1079. _spanNode.innerText = _name; //添加文字内容
  1080. }
  1081. _spanNode.id = "span_" + type + data.id;
  1082. U.selectEl(_spanNode).attr("data-city-code", data.id); //添加自定义属性 编号
  1083. U.selectEl(_spanNode).attr("data-city-type", type); //添加自定义属性 类型
  1084. parent.appendChild(_liNode); //添加到parent节点上
  1085. return _spanNode; //返回该元素
  1086. };
  1087. /**
  1088. * 添加选中时的class 并删除已有该class的元素
  1089. * @param {[元素]} el [点击菜单的元素]
  1090. * @param {[字符串]} cs [选中菜单时的class]
  1091. * @param {[字符串]} dataattr [菜单的自定义属性 与 对应内容区域的id相同]
  1092. * @param {[字符串]} hiddenCs [对应内容区域的class]
  1093. */
  1094. U.MD.UI.city.menuClassControl = function (el, cs, dataattr, hiddenCs) {
  1095. var _city = U.MD.UI.city; //简写命名空间
  1096. var _attr = _city.Attr; //简写全局属性json名
  1097. var _cityMenu = U.selectEl("#U_MD_UI_city_cityMenu")[0]; //市菜单按钮
  1098. var _areaMenu = U.selectEl("#U_MD_UI_city_areaMenu")[0]; //区菜单按钮
  1099. var _cityCont = U.selectEl("#U_MD_UI_city_cityCont")[0]; //市内容区域
  1100. var _areaCont = U.selectEl("#U_MD_UI_city_areaCont")[0]; //区内容区域
  1101. var _oEl = U.selectEl("." + cs)[0];
  1102. //找到拥有该class的元素
  1103. if (_oEl) { U.selectEl(_oEl).removeClass(cs) };
  1104. //如果找的到该元素 则删除此元素的class
  1105. U.selectEl(el).addClass(cs);
  1106. //为el元素添加该class
  1107. var _oElCont = U.selectEl("#" + U.selectEl(_oEl).attr(dataattr))[0];
  1108. //找到拥有该class的菜单元素的自定义属性的值 并找到对应区域块的元素(区域块元素的id 与 自定义属性的值相等)
  1109. var _elCont = U.selectEl("#" + U.selectEl(el).attr(dataattr))[0];
  1110. //同上 找到点击菜单元素的自定义属性的值
  1111. U.selectEl(_oElCont).addClass(hiddenCs);
  1112. //添加名为hiddenCs 的className (添加与删除 display为none)
  1113. U.selectEl(_elCont).removeClass(hiddenCs);
  1114. //elCont元素的display为block
  1115. var _id = el.id;
  1116. switch (_id) { //以下为点击菜单时所作出的不同执行命令
  1117. case "U_MD_UI_city_usedCityMenu":
  1118. case "U_MD_UI_city_provinceMenu": //当为菜单常用市 或者 省直辖市时 将区 与 市菜单 与对应内容区域 清空初始化
  1119. U.selectEl(_cityMenu).addClass(hiddenCs);
  1120. U.selectEl(_areaMenu).addClass(hiddenCs);
  1121. U.selectEl(_cityCont).addClass(hiddenCs);
  1122. U.selectEl(_areaCont).addClass(hiddenCs);
  1123. _cityMenu.children[0].innerText = "请选择";
  1124. _areaMenu.children[0].innerText = "请选择";
  1125. _cityCont.innerHTML = "";
  1126. _areaCont.innerHTML = "";
  1127. U.selectEl(_cityMenu).attr("data-city-res", "");
  1128. U.selectEl(_areaMenu).attr("data-city-res", "");
  1129. break;
  1130. case "U_MD_UI_city_cityMenu": //当为市菜单时 将 区菜单 与对应内容区域 清空初始化
  1131. U.selectEl(el).removeClass(hiddenCs);
  1132. U.selectEl(_areaMenu).addClass(hiddenCs);
  1133. U.selectEl(_areaCont).addClass(hiddenCs);
  1134. _areaMenu.children[0].innerText = "请选择";
  1135. _areaCont.innerHTML = "";
  1136. break;
  1137. case "U_MD_UI_city_areaMenu":
  1138. U.selectEl(el).removeClass(hiddenCs);
  1139. break;
  1140. }
  1141. };
  1142. /**
  1143. * 内容区域的class 的控制函数 PS:添加红色背景的样式
  1144. * @param {[type]} el [所选中的数据元素]
  1145. * @param {[type]} ocheckcs [所需要对el添加的样式]
  1146. */
  1147. U.MD.UI.city.contClassControl = function (el, ocheckcs) {
  1148. var _city = U.MD.UI.city; //简写命名空间
  1149. var _oEls = U.selectEl("." + ocheckcs);
  1150. //找到拥有该class的所有元素
  1151. var _type = U.selectEl(el).attr("data-city-type");
  1152. //获取他们的该元素的类型
  1153. for (var i = 0, len = _oEls.length; i < len; i++) { //遍历oEls
  1154. var _otype = U.selectEl(_oEls[i]).attr("data-city-type");
  1155. if (_oEls[i] && _otype === _type) {
  1156. //如果找的到该元素 并且还是同一内容区域的元素 则删除他的class 例如:(市内容区域下)点击深圳后 在点广州 则 广州的背景颜色为红色 深圳的背景颜色为初始颜色
  1157. U.selectEl(_oEls[i]).removeClass(ocheckcs)
  1158. }
  1159. }
  1160. U.selectEl(el).addClass(ocheckcs);
  1161. //为el元素添加该class
  1162. };
  1163. /**
  1164. * 此函数专门为 初始化 常用市 或者 省/直辖市的样式而写的 例如:点击常用市下的数据后 省/直辖市的菜单与对应的内容 样式初始化为不选中
  1165. * @param el 只能放 常用市菜单(元素) 和 省/直辖市菜单(元素)
  1166. */
  1167. U.MD.UI.city.initAllClass = function (el) {
  1168. var _city = U.MD.UI.city; //简写命名空间
  1169. el.className = "U_MD_UI_city_filled"; //将菜单li的样式初始化 U_MD_UI_city_filled无样式属性 摆设占位置用
  1170. el.children[0].className = ""; //将li里的span样式也初始化
  1171. U.selectEl(el).attr("data-city-res", ""); //将span的自定义属性也初始化
  1172. var oEl = U.selectEl(".U_MD_UI_city_Cont_ochecked"); //获取内容区域中被选中的span元素
  1173. for (var i = 0; i < oEl.length; i++) {
  1174. U.selectEl(oEl[i]).removeClass("U_MD_UI_city_Cont_ochecked"); //判断是否存在此元素 如果存在 则删除被选中的样式
  1175. }
  1176. if (el.id === "U_MD_UI_city_provinceMenu") { //比如: 点完省/直辖市内容区域的数据时 传过来的el则会是常用市菜单元素 然后常用市菜单的innerText则会初始化回常用市
  1177. el.children[0].innerText = "省/直辖市";
  1178. }
  1179. if (el.id === "U_MD_UI_city_usedCityMenu") { //同上
  1180. el.children[0].innerText = "常用市";
  1181. }
  1182. };
  1183. /**
  1184. * 通过获取自定义属性的值 查出最终值
  1185. * @param dataattr 自定义属性的名字
  1186. */
  1187. U.MD.UI.city.getRes = function (dataattr) {
  1188. var _city = U.MD.UI.city; //简写命名空间
  1189. var _attr = _city.Attr; //简写全局属性json名
  1190. var _inputNode = _attr.inputNode;
  1191. var _cityBox = U.selectEl("#U_MD_UI_city_cityBox")[0]; //城市控件总盒子节点
  1192. var _hidden = "U_MD_UI_city_hidden"; //class样式名 由于太长赋值给变量 _hidden 控制元素display的样式
  1193. var resAll = U.selectEl("[" + dataattr + "]"); //获取所有拥有该自定义属性的元素 得到一个数组
  1194. var _arr = []; //声明一个空数组 存放最终值
  1195. for (var i = 0, len = resAll.length; i < len; i++) { //遍历所有自定义元素
  1196. var _val = U.selectEl(resAll[i]).attr(dataattr); //获取他们的自定义值
  1197. if (_val) { //判断值是否存在
  1198. _arr.push(_val); //若存在 则将最终值依次添加到arr数组里
  1199. }
  1200. }
  1201. _inputNode.value = (_arr.join("-")); //最后分割数组用“-” 隔开 添加到表单上
  1202. U.selectEl(_cityBox).addClass(_hidden); //最后隐藏控件
  1203. };
  1204. U.MD.UI.city.clone = function (ele) { //克隆节点
  1205. var node = ele.cloneNode();
  1206. var child = ele.children;
  1207. for (var i = 0; i < child.length; i++) {
  1208. var childNode = child[i].cloneNode();
  1209. node.appendChild(childNode);
  1210. }
  1211. return node;
  1212. };;
  1213. ///<jscompress sourcefile="Color.js" />
  1214. //色板
  1215. Namespace.register("U.MD.UI.ColorPicker");
  1216. /**
  1217. * 创建颜色选区
  1218. * @barelement [object] 要插入表格的地方
  1219. * @ callfun [fun] 点击事件
  1220. */
  1221. U.MD.UI.colorPicker = U.MD.UI.ColorPicker = function (barelement, callfun) {
  1222. var div = $$("div", {
  1223. style: {
  1224. width: "180px",
  1225. height: "140px",
  1226. border: "1px solid #CDCDCD",
  1227. backgroundColor: " #FFF",
  1228. padding: "10px 10px 10px 5px",
  1229. zIndex: 1
  1230. },
  1231. "className": "MD_ColorPicker"
  1232. }, barelement); //创建外部div对象
  1233. var _i,
  1234. _colorarea = [ //字体颜色区域
  1235. "#ffffff",
  1236. "#ffccc9",
  1237. "#ffce93",
  1238. "#fffc9e",
  1239. "#ffffc7",
  1240. "#9aff99",
  1241. "#96fffb",
  1242. "#cdffff",
  1243. "#cbcefb",
  1244. "#cfcfcf",
  1245. "#fd6864",
  1246. "#fe996b",
  1247. "#fffe65",
  1248. "#fcff2f",
  1249. "#67fd9a",
  1250. "#38fff8",
  1251. "#68fdff",
  1252. "#9698ed",
  1253. "#c0c0c0",
  1254. "#fe0000",
  1255. "#f8a102",
  1256. "#ffcc67",
  1257. "#f8ff00",
  1258. "#34ff34",
  1259. "#68cbd0",
  1260. "#34cdf9",
  1261. "#6665cd",
  1262. "#9b9b9b",
  1263. "#cb0000",
  1264. "#f56b00",
  1265. "#ffcb2f",
  1266. "#ffc702",
  1267. "#32cb00",
  1268. "#00d2cb",
  1269. "#3166ff",
  1270. "#6434fc",
  1271. "#656565",
  1272. "#9a0000",
  1273. "#ce6301",
  1274. "#cd9934",
  1275. "#999903",
  1276. "#009901",
  1277. "#329a9d",
  1278. "#3531ff",
  1279. "#6200c9",
  1280. "#343434",
  1281. "#680100",
  1282. "#963400",
  1283. "#986536",
  1284. "#646809",
  1285. "#036400",
  1286. "#34696d",
  1287. "#00009b",
  1288. "#303498",
  1289. "#000000",
  1290. "#330001",
  1291. "#643403",
  1292. "#663234",
  1293. "#343300",
  1294. "#013300",
  1295. "#003532",
  1296. "#010066",
  1297. "#340096"
  1298. ];
  1299. var button; //定义一个变量
  1300. for (_i = 0; _i < _colorarea.length; _i++) { //创建循环,循环对象为创建的数组
  1301. button = $$('button', {
  1302. style: {
  1303. background: _colorarea[_i],
  1304. width: "15px",
  1305. height: "15px",
  1306. float: "left",
  1307. margin: "5px 0 0 5px",
  1308. border: " 1px solid transparent"
  1309. }
  1310. }, div); //创建button对象
  1311. button.onclick = function (e) {
  1312. div.style.display = 'none' /*选择完色块后隐藏色板*/
  1313. U.UF.EV.stopBubble(e); /*阻止事件冒泡*/
  1314. callfun(this.style.background);
  1315. } //设置点击事件
  1316. }
  1317. U.selectEl(document).bind('click', function () { /*绑定事件*/
  1318. if (div.style.display != 'none') /*点击别的地方隐藏*/
  1319. div.style.display = 'none'
  1320. });
  1321. U.UF.EV.stopBubble();
  1322. return div; //返回div对象
  1323. };
  1324. ///<jscompress sourcefile="Common.js" />
  1325. //工具空间,宝航字体、字号。。。
  1326. //字体
  1327. Namespace.register("U.MD.UI.Font");
  1328. //字号
  1329. Namespace.register("U.MD.UI.WordSize");
  1330. /*
  1331. * 字体选择框生成方法
  1332. */
  1333. U.MD.UI.Font = function () {
  1334. var font = $$("select", { style: { fontFamily: "宋体", fontSize: "16px" }, "className": "MD_fontFamily" }); //创建select对象
  1335. $$("option", { value: "宋体", style: { fontFamily: "宋体" }, innerHTML: "宋体" }, font); //定义option对象宋体,附属select
  1336. $$("option", { value: "sans-serif", style: { fontFamily: "sans-serif" }, innerHTML: "sans-serif" }, font); //定义option对象sans-serif,附属select
  1337. $$("option", { value: "微软雅黑", style: { fontFamily: "微软雅黑" }, innerHTML: "微软雅黑" }, font); //定义option对象微软雅黑,附属select
  1338. $$("option", { value: "楷体", style: { fontFamily: "楷体" }, innerHTML: "楷体" }, font); //定义option对象楷体,附属select
  1339. $$("option", { value: "黑体", style: { fontFamily: "黑体" }, innerHTML: "黑体" }, font); //定义option对象黑体,附属select
  1340. $$("option", { value: "隶书", style: { fontFamily: "隶书" }, innerHTML: "隶书" }, font); //定义option对象隶书,附属select
  1341. $$("option", { value: "andale mono", style: { fontFamily: "andale mono" }, innerHTML: "andale mono" }, font); //定义option对象andale mono,附属select
  1342. $$("option", { value: "arial black", style: { fontFamily: "arial black" }, innerHTML: "arial black" }, font); //定义option对象arial black,附属select
  1343. return font; //返回select对象
  1344. }
  1345. /*
  1346. * 字号选择框生成方法
  1347. */
  1348. U.MD.UI.WordSize = function () {
  1349. var fontsize = $$("select", { "className": "MD_fontSize" }); //创建select对象
  1350. $$("option", { value: "56px", style: { fontSize: "14px" }, innerHTML: "初号" }, fontsize); //定义option对象初号,附属select
  1351. $$("option", { value: "48px", style: { fontSize: "14px" }, innerHTML: "小初" }, fontsize); //定义option对象小初,附属select
  1352. $$("option", { value: "34.7px", style: { fontSize: "14px" }, innerHTML: "一号" }, fontsize); //定义option对象一号,附属select
  1353. $$("option", { value: "32px", style: { fontSize: "14px" }, innerHTML: "小一" }, fontsize); //定义option对象小一,附属select
  1354. $$("option", { value: "29.3px", style: { fontSize: "14px" }, innerHTML: "二号" }, fontsize); //定义option对象二号,附属select
  1355. $$("option", { value: "24px", style: { fontSize: "14px" }, innerHTML: "小二" }, fontsize); //定义option对象小二,附属select
  1356. $$("option", { value: "21.3px", style: { fontSize: "14px" }, innerHTML: "三号" }, fontsize); //定义option对象三号,附属select
  1357. $$("option", { value: "20px", style: { fontSize: "14px" }, innerHTML: "小三" }, fontsize); //定义option对象小三,附属select
  1358. $$("option", { value: "18.7px", style: { fontSize: "14px" }, innerHTML: "四号" }, fontsize); //定义option对象四号,附属select
  1359. $$("option", { value: "16px", style: { fontSize: "14px" }, innerHTML: "小四" }, fontsize); //定义option对象小四,附属select
  1360. $$("option", { value: "14px", style: { fontSize: "14px" }, innerHTML: "五号" }, fontsize); //定义option对象五号,附属select
  1361. $$("option", { value: "12px", style: { fontSize: "14px" }, innerHTML: "小五" }, fontsize); //定义option对象小五,附属select
  1362. $$("option", { value: "10px", style: { fontSize: "14px" }, innerHTML: "10" }, fontsize); //定义option对象10px,附属select
  1363. $$("option", { value: "12px", style: { fontSize: "14px" }, innerHTML: "12" }, fontsize); //定义option对象12px,附属select
  1364. $$("option", { value: "14px", style: { fontSize: "14px" }, innerHTML: "14" }, fontsize); //定义option对象14px,附属select
  1365. $$("option", { value: "16px", style: { fontSize: "14px" }, innerHTML: "16" }, fontsize); //定义option对象16px,附属select
  1366. $$("option", { value: "18px", style: { fontSize: "14px" }, innerHTML: "18" }, fontsize); //定义option对象18px,附属select
  1367. $$("option", { value: "20px", style: { fontSize: "14px" }, innerHTML: "20" }, fontsize); //定义option对象20px,附属select
  1368. $$("option", { value: "22px", style: { fontSize: "14px" }, innerHTML: "22" }, fontsize); //定义option对象22px,附属select
  1369. $$("option", { value: "24px", style: { fontSize: "14px" }, innerHTML: "24" }, fontsize); //定义option对象24px,附属select
  1370. $$("option", { value: "26px", style: { fontSize: "14px" }, innerHTML: "26" }, fontsize); //定义option对象26px,附属select
  1371. $$("option", { value: "28px", style: { fontSize: "14px" }, innerHTML: "28" }, fontsize); //定义option对象28px,附属select
  1372. $$("option", { value: "36px", style: { fontSize: "14px" }, innerHTML: "36" }, fontsize); //定义option对象36px,附属select
  1373. $$("option", { value: "42px", style: { fontSize: "14px" }, innerHTML: "42" }, fontsize); //定义option对象42px,附属select
  1374. $$("option", { value: "48px", style: { fontSize: "14px" }, innerHTML: "48" }, fontsize); //定义option对象48px,附属select
  1375. $$("option", { value: "72px", style: { fontSize: "14px" }, innerHTML: "72" }, fontsize); //定义option对象72px,附属select
  1376. return fontsize; //返回select对象
  1377. };
  1378. ///<jscompress sourcefile="Dialog.js" />
  1379. //#region alert弹窗代码、confirm对话框
  1380. //UI窗体区域
  1381. Namespace.register("U.UF.UI") //窗体的命名空间
  1382. //#region 对话框
  1383. /**
  1384. * 创建对话框
  1385. * @content {string/elemnet} 内容
  1386. * @determineFun {function} 确认回调函数
  1387. * @cancelFun {function} 取消回调函数
  1388. */
  1389. U.UF.UI.Confirm = U.UF.UI.confirm = function (content, determineFun, cancelFun) {
  1390. //创建对话框主体元素
  1391. var _confirm = $$("div", { "style": { "cssText": "width: 100%; background: rgb(255,255,255);overflow:hidden; " } });
  1392. //创建内容区域
  1393. var _content = $$("div", { "style": { "cssText": "width: 100%;" } }, _confirm);
  1394. //判断内容是否为元素
  1395. if (U.UF.C.isElement(content)) {
  1396. //如果为元素则动态添加到对话框中
  1397. U.selectEl(_content).append(content);
  1398. } else {
  1399. _content.style.cssText = "text-align: center; margin: 10px;";
  1400. //如果为文字则修改inerHTML。
  1401. _content.innerHTML = content || '内容';
  1402. }
  1403. //创建页脚部分
  1404. var _footer = $$("div", { "style": { "cssText": "height:28px; margin:14px 0;" } }, _confirm);
  1405. //创建确定按钮 绑定点击事件,默认点击后执行关闭窗体函数
  1406. $$("div", {
  1407. "style": {
  1408. "cssText": "text-align: center; color: rgb(255,255,255); width: 92px; line-height:28px; background: rgb(48,126,208); border-radius: 5px;float: right; margin-right:29px; "
  1409. },
  1410. innerHTML: "确定",
  1411. onclick: function () {
  1412. var _bool = true;
  1413. if (U.UF.C.isFunction(determineFun)) {
  1414. _bool = determineFun(); //判断是否存在回调 有则执行。
  1415. }
  1416. if (_bool !== false) {
  1417. U.UF.F.closeWindow(_form.form); //关闭窗口函数
  1418. }
  1419. }
  1420. }, _footer);
  1421. //创建取消按钮 绑定点击事件,默认点击后执行关闭窗体函数
  1422. $$("div", {
  1423. "style": {
  1424. "cssText": "text-align: center; color: rgb(255,255,255); width: 92px; line-height:28px; background: rgb(48,126,208); border-radius: 5px;background: rgb(170,170,170); float: right; margin-right:21px;margin-left:29px;"
  1425. },
  1426. "innerHTML": "取消",
  1427. "onclick": function () {
  1428. U.UF.C.isFunction(cancelFun) && cancelFun(); //判断是否存在回调 有则执行。
  1429. U.UF.F.closeWindow(_form.form); //关闭窗口函数
  1430. }
  1431. }, _footer);
  1432. //调用Uform窗体创建函数将主体内容添加到窗体中
  1433. var _form = new U.UF.UI.form(
  1434. "提示",
  1435. _confirm, {
  1436. "style": {
  1437. "cssText": "font-size: 14px; background: rgb(255,255,255); width: 310px; position: fixed; box-shadow: 0 0 10px 3px rgb(0,0,0); border-radius: 5px;"
  1438. }
  1439. }, {
  1440. "istop": true,
  1441. "isenlarge": false,
  1442. "isstretching": false,
  1443. "isnarrow": false
  1444. }, {
  1445. "style": {
  1446. "cssText": " background: rgb(59,88,120); padding: 5px; color: rgb(255,255,255); "
  1447. }
  1448. });
  1449. return _form;
  1450. }
  1451. /**
  1452. * 创建提示框
  1453. * @content {string/elemnet} 内容
  1454. * @callBackFun {function} 回调函数
  1455. */
  1456. U.UF.UI.Dialog = U.UF.UI.Dialog = function (content, callBackFun) {
  1457. var _dialog = $$("div", { "style": { "cssText": "width: 100%; background: #fff; overflow:hidden; " } }); //创建提示框主体
  1458. var _content = $$("div", { "style": { "cssText": "text-align: center; margin: 30px 20px 30px 20px; " } }, _dialog); //创建内容区域
  1459. //判断内容是否为元素
  1460. if (U.UF.C.isElement(content)) {
  1461. U.selectEl(_content).append(content); //如果为元素则动态添加到对话框中
  1462. } else {
  1463. _content.innerHTML = content || '内容'; //如果为文字则修改inerHTML。
  1464. }
  1465. //创建页脚部分
  1466. var footer = $$("div", { "style": { "cssText": "height:45px;" } }, _dialog);
  1467. //调用Uform窗体创建函数将主体内容添加到窗体中
  1468. var _form = new U.UF.UI.form("提示框", _dialog, {
  1469. "style": {
  1470. "cssText": "font-size: 14px; width: 300px; background:#fff; position: fixed; top: 100px; left: 40%; box-shadow: 0 0 10px 3px black; border-radius: 5px;"
  1471. }
  1472. },
  1473. null, {
  1474. "style": { "cssText": "background: #3b5878; padding: 10px; color:#fff;" }
  1475. });
  1476. //创建确定按钮 并绑定点击函数,默认点击后执行关闭窗体函数
  1477. $$("div", {
  1478. "style": {
  1479. "cssText": "text-align: center; color: #fff; width: 30%; padding: 5px; background: #307ed0; border-radius: 5px;float: right; margin: 0 12px 12px 0;"
  1480. },
  1481. innerHTML: "确定", // 绑定innerHTML
  1482. onclick: function () {
  1483. U.UF.C.isFunction(callBackFun) && callBackFun(); //判断是否存在回调 有则执行。
  1484. U.UF.F.closeWindow(_form.form); //关闭窗口函数
  1485. }
  1486. }, footer);
  1487. }
  1488. //#endregion
  1489. //#region alert
  1490. /*
  1491. 创建点击确认对话框
  1492. */
  1493. U.UF.UI.alertClick = function (content, attr) {
  1494. //创建点击确认对话框的主体区域
  1495. var _content = $$("div", { "class": "USBalert_text", "style": { width: "100%" } });
  1496. //判断内容是否为元素
  1497. if (U.UF.C.isElement(content)) {
  1498. //如果为元素则动态添加到对话框中
  1499. U.selectEl(_content).append(content);
  1500. } else {
  1501. $$("div", { "style": { cssText: "text-align:center;padding:10px; margin:10px auto; word-break:break-word;" }, innerHTML: content || '内容' }, _content);
  1502. }
  1503. //创建页脚
  1504. var _footer = $$("div", { "class": "USBalert_onclicks", style: { height: "43px" } }, _content);
  1505. //调用Uform窗体创建函数将主体内容添加到窗体中
  1506. var _form = new U.UF.UI.form("提示框", _content, {
  1507. "style": {
  1508. "cssText": "font-size: 16px; width:320px; background: rgb(255,255,255);box-shadow: 0 0 10px 3px rgb(0,0,0); border-radius: 5px;"
  1509. }
  1510. }, {
  1511. "isnarrow": false,
  1512. "isenlarge": false,
  1513. isstretching: false
  1514. }, {
  1515. "style": {
  1516. "cssText": "background: rgb(59,88,120); padding: 10px; color: rgb(255,255,255);"
  1517. }
  1518. });
  1519. //创建确定按钮 并绑定点击函数,默认点击后执行关闭窗体函数
  1520. $$("div", { "style": { "cssText": "text-align: center; color: #fff; width: 30%;max-width:150px; padding: 5px; background: #307ed0; border-radius: 5px;float: right; margin: 0 12px 12px 0;" }, innerHTML: "确定", onclick: function () { U.UF.F.closeWindow(_form.form); } }, _footer);
  1521. }
  1522. /**
  1523. * 创建对话框
  1524. */
  1525. U.Alert = U.alert = function (c, t) {
  1526. !t ? t = 3000 : "";
  1527. var bg = $$("div", {
  1528. "style": {
  1529. "cssText": "padding: 12px 25px 12px 25px;font-size: 16px;max-width:300px;min-width:100px;color: rgba(255,255,255,1);background: rgba(0,0,0,0.75);border-radius: 10px;position: fixed;top:20%;left:0px;right:0px;margin:0px auto;text-align:center; word-break: break-word; "
  1530. //white-space: nowrap; -o-text-overflow: ellipsis; text-overflow: ellipsis;
  1531. },
  1532. innerHTML: c
  1533. }, document.body);
  1534. U.UF.F.topWindow(bg);
  1535. setTimeout(function () {
  1536. bg.parentNode.removeChild(bg);
  1537. }, t);
  1538. }
  1539. //#endregion
  1540. //#endregion
  1541. ;
  1542. ///<jscompress sourcefile="Email.js" />
  1543. //电脑端banner滑块控件命名空间
  1544. Namespace.register("U.MD.UI.email");
  1545. /**
  1546. 电脑端banner滑块控件
  1547. */
  1548. U.MD.UI.email = function () {
  1549. };
  1550. ///<jscompress sourcefile="Face.js" />
  1551. //PC端表情包
  1552. Namespace.register("U.MD.UI.face");
  1553. /*
  1554. ** 添加表情包
  1555. ** @param {element} button 插入表情包的元素
  1556. ** @param {element} el 输入框的元素
  1557. */
  1558. U.MD.UI.face = function (button, el) {
  1559. var i, _el1, _el2;
  1560. if ($("#U_MD_UI_face")[0]) { //判断是否存在表情包
  1561. if ($("#U_MD_UI_face")[0].style.display == "none") { //如果存在,判断是否隐藏
  1562. U.selectEl("#U_MD_UI_face")[0].style.display = "block"; //如果隐藏 则显示表情包
  1563. } else {
  1564. U.selectEl("#U_MD_UI_face")[0].style.display = "none"; //否则,隐藏
  1565. }
  1566. } else { //不存在表情包,创建表情包
  1567. var _el = $$("div", { "style": { "position": "relative" } }, U.selectEl(button)[0]); //创建表情包的总样式
  1568. _el1 = $$("div", { "id": "U_MD_UI_face", "className": "U_MD_UI_face", "onmousedown": U.UF.EV.stopBubble }, _el); //创建表情包的阻止冒泡事件
  1569. _el2 = $$("div", { "className": "U_MD_UI_face_H" }, _el1); //创建存放表情的父级元素
  1570. for (i = 0; i <= 104; i++) { //循环打印所有的表情包 共104个
  1571. $$("button", {
  1572. "className": "U_MD_UI_face_C",
  1573. "style": { "opacity": "0" },
  1574. "onclick": U.UF.C.closure(function (i) {
  1575. U.UF.EV.stopBubble();
  1576. U.MD.UI.face.printEmoticon(_el1, i, U.UF.E.getRangeAt(), el)
  1577. }, [i])
  1578. }, _el2); //创建单个表情,并且给每个表情赋值一个点击事件,参数为表情框元素,第几个表情,光标位置,输入框的位置,点击后打印表情到输入框的位置
  1579. }
  1580. //获取整个body部分的点击事件
  1581. U.selectEl('body').unbind('click', U.MD.UI.face.externalClick);
  1582. U.selectEl('body').bind('click', U.MD.UI.face.externalClick);
  1583. }
  1584. el.focus();
  1585. };
  1586. U.MD.UI.face.externalClick = function (e) {
  1587. if (window.event.srcElement.tagName != "BUTTON" && U.selectEl("#U_MD_UI_face")[0]) { //判断点击的是否是发送表情的按钮
  1588. U.selectEl("#U_MD_UI_face")[0].style.display = "none"; //如果不是,则隐藏掉表情包
  1589. }
  1590. }
  1591. /* 点击表情框处理
  1592. *
  1593. * @param {element} el1 表情框元素
  1594. * @param {number} i 第几个表情。通过i的值代表是哪个表情
  1595. * @param {range} range 光标的位置,先获取光标对象,然后通过光标对象获取光标位置
  1596. * @param {element}
  1597. 对应路径 /img/ChatingFaceGif/[face](i).gif
  1598. */
  1599. U.MD.UI.face.printEmoticon = function (el1, i, range, el) {
  1600. var _imageurl = "/img/ChatingFaceGif/[face](" + i + ").gif"; //表情路径
  1601. if (!range) {
  1602. $$("img", { "onerror": U.MD.C.imgError, "src": _imageurl, "contentEditable": "true" }, U.selectEl(el)[0]);
  1603. } else {
  1604. var img = '<img contentEditable="true" src="' + _imageurl + '">';
  1605. U.UF.E.addRange(img, null, true);
  1606. }
  1607. U.selectEl(el1)[0].style.display = "none";
  1608. };
  1609. ///<jscompress sourcefile="Form.js" />
  1610. //#region 窗体
  1611. //UI窗体区域
  1612. Namespace.register("U.UF.UI") //窗体的命名空间
  1613. //#region 窗体
  1614. /** 初始化uform窗体,创建一个窗体,调用方式如下
  1615. * new new U.UF.UI.form(
  1616. * "测试内容",
  1617. * "中间内容",
  1618. * { "style": { "width": "570px", "height": "80%", "maxHeight": "700px"} },
  1619. * );
  1620. * @param string 头部标题 必填
  1621. * @param string|element 中间区域的内容 必填
  1622. * @param object 窗体的属性 {id :"1", style:{"width":"100px", "height":"100px"}} 选填 有默认的属性,原函数有注释
  1623. * @param object 窗体功能的属性 { istop: true, isdrag: true, isstretching:true,isenlarge:true,isnarrow:true,isclose:true } 选填
  1624. * @param object 头部的属性 {style:{"width":"100px"}} 选填 有默认的属性,原函数有注释
  1625. * @param object 内容的属性 { style:{"height":"100px"}} 选填 有默认属性,原函数有注释
  1626. * @param object 关闭、放大、缩小按钮区域的属性设置 { "style":{"left":"100px"}} 选填,有默认属性,原函数有注释
  1627. * @param element 窗体追加到制定的元素 选填 有默认的属性,原函数有注释
  1628. */
  1629. U.UF.UI.form = function (title, content, formattr, formfun, headattr, contentattr, headbottomattr, parentel) {
  1630. var _this = this;
  1631. //所有的窗体中找到是否已经创建的窗体
  1632. if (formattr && U.UF.UI.form.allForm[formattr.id]) {
  1633. var _this = U.UF.UI.form.allForm[formattr.id]; //得到原来的窗体
  1634. if (U.UF.C.isElement(_this.content) && _this.content.tagName == "IFRAME") {
  1635. content = _this.content;
  1636. }
  1637. }
  1638. //初始化未赋值,用到的变量
  1639. else {
  1640. //设置窗体唯一的识别
  1641. this.id = formattr && formattr.id ? formattr.id : Guid.newGuid();
  1642. //初始化成功后添加到所有窗体管理的对象中,以便于用户查找窗体和管理
  1643. U.UF.UI.form.allForm[this.id] = this;
  1644. }
  1645. _this.form; //窗体
  1646. _this.header; //头部
  1647. _this.middle; //中间区域
  1648. _this.title = title; //窗体的标题
  1649. _this.content = content; //需要插入的元素,包含div和iframe等元素,以前站外应用的功能是靠这个方式去实现的
  1650. _this.formattr = formattr; //窗体的属性
  1651. _this.headattr = headattr; //头部的属性
  1652. _this.contentattr = contentattr; //内容的属性
  1653. _this.headbottomattr = headbottomattr; //头部功能区域整体的属性设置
  1654. //下面是用户功能处理包含是否允许一直置顶、是否允许拖动、是否拉伸、是否允许放大、是否允许缩小、是否允许关闭
  1655. //如果用户没有传入功能处理
  1656. if (formfun == null) {
  1657. formfun = {}; //初始化一个功能处理类
  1658. }
  1659. _this.istop = null;
  1660. if (formfun.istop != null) { //是否允许一直置顶
  1661. _this.istop = formfun.istop;
  1662. }
  1663. _this.isdrag = true;
  1664. if (formfun.isdrag != null) { //是否允许拖动
  1665. _this.isdrag = formfun.isdrag; //是否允许拖动
  1666. }
  1667. _this.isstretching = true;
  1668. if (formfun.isstretching != null) { //是否拉伸
  1669. _this.isstretching = formfun.isstretching;
  1670. }
  1671. _this.isenlarge = true;
  1672. if (formfun.isenlarge != null) { //是否允许放大
  1673. _this.isenlarge = formfun.isenlarge;
  1674. }
  1675. _this.isnarrow = true;
  1676. if (formfun.isnarrow != null) { //是否允许缩小
  1677. _this.isnarrow = formfun.isnarrow; //是否允许缩小
  1678. }
  1679. _this.isclose = true;
  1680. _this.closecallback = formfun.closecallback; //关闭回调
  1681. if (formfun.isclose != null) { //是否允许关闭
  1682. _this.isclose = formfun.isclose; //是否允许关闭
  1683. }
  1684. _this.parentel = parentel || document.body; //窗体添加到制定的元素处理
  1685. _this.create(); //重新添加处理
  1686. return _this; //返回处理
  1687. }
  1688. //所有给给创建的窗体管理
  1689. U.UF.UI.form.allForm = {};
  1690. //窗体的方法
  1691. U.UF.UI.form.prototype = {
  1692. /** 初始化uform窗体
  1693. */
  1694. create: function () {
  1695. var i, //用于循环
  1696. _resizefun,
  1697. _formel, //窗体元素
  1698. _headel, //窗体头部元素
  1699. _contentel, //内容区域的元素
  1700. _contentchildel, //内容区域的
  1701. _stretchingel, //拉伸元素
  1702. _stretchinginfo, //拉伸的信息
  1703. _headbottom, //头部按钮区域
  1704. _enlargeel, //放大按钮
  1705. _mousedown, //
  1706. _formattr = this.formattr || {}, //窗体属性
  1707. _headattr = this.headattr || {}, //头部属性
  1708. _contentattr = this.contentattr || {}, //内容的属性
  1709. _replaceel = U.UF.UI.form.allForm[_formattr.id] ? U.UF.UI.form.allForm[_formattr.id].form : null //得到之前创建的窗体,如果窗体存在,那么下面创建后直接替换
  1710. ;
  1711. //窗体的统一属性设置,默认属性
  1712. if (_formattr.style) {
  1713. _formattr.style.cssText = _formattr.style.cssText || "";
  1714. _formattr.style.cssText = "width: 70%; position: fixed; background-color: #fff; z-index: 10; border-radius: 1px; overflow: hidden; -moz-box-shadow:rgb(38 38 38) 0px 0px 12px 1px; -webkit-box-shadow:rgb(38 38 38) 0px 0px 12px 1px; box-shadow:rgb(38 38 38) 0px 0px 12px 1px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius:5px;" + _formattr.style.cssText;
  1715. } else {
  1716. _formattr.style = {
  1717. cssText: "width: 70%; position: fixed; background-color: #fff; z-index: 10; border-radius: 1px; overflow: hidden; -moz-box-shadow:rgb(38 38 38) 0px 0px 12px 1px; -webkit-box-shadow:rgb(38 38 38) 0px 0px 12px 1px; box-shadow:rgb(38 38 38) 0px 0px 12px 1px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius:5px;"
  1718. };
  1719. }
  1720. _formattr.close = U.UF.C.apply(this, function () { //关闭窗体;
  1721. U.UF.F.closeWindow(this.form); //关闭窗体
  1722. });
  1723. _formattr.usform = "true"; //设置窗体的属性,作为窗体的识别,有助于调用的用户通过js找到所有的窗体
  1724. _formattr.id = _formattr.id || ""; //窗体的id
  1725. _formattr.style = _formattr.style || {}; //窗体的样式
  1726. if (_formattr.onresize) {
  1727. _resizefun = _formattr.onresize;
  1728. _mousedown = _formattr.onmousedown;
  1729. _formattr.onresize = U.UF.C.apply(this, function () { //当窗体大小发生变化的处理
  1730. this.size(); //大小变化处理
  1731. if (_resizefun) {
  1732. _resizefun(); //大小变化回调
  1733. }
  1734. });
  1735. _formattr.onmousedown = U.UF.C.apply(this, function () {
  1736. //窗体点击置顶的处理
  1737. if (this.istop !== false) {
  1738. this.top(); //大小变化处理
  1739. }
  1740. if (_mousedown) {
  1741. _mousedown(); //大小变化回调
  1742. }
  1743. });
  1744. } else if (_formattr.onresize !== false) {
  1745. _formattr.onresize = U.UF.C.apply(this, function () { //当窗体大小发生变化的处理
  1746. this.size(); //大小变化处理
  1747. });
  1748. }
  1749. //创建大窗体,设置窗体属性
  1750. var _formel = $$("div", _formattr);
  1751. //判断是否允许一直置顶
  1752. if (this.istop === true) {
  1753. _formel.style.zIndex = "9999";
  1754. _formel["__top__"] = "false"; //设置不允许点击切换置顶
  1755. } else if (this.istop === false) {
  1756. _formel["__top__"] = "false"; //设置不允许点击切换置顶
  1757. }
  1758. this.form = _formel; //窗体全局变量设置
  1759. //如果用户设置了false,那么就不加载头部
  1760. if (this.title !== false) {
  1761. //窗体头部属性统一设置
  1762. if (_headattr.style) {
  1763. _headattr.style.cssText = _headattr.style.cssText || "";
  1764. _headattr.style.cssText = "text-indent: 10px; color: White; line-height: inherit; font-size: 14px; height: 30px; line-height: 36px; background-color: rgb(48 48 48); overflow: hidden; color: White; font-size: 14px; overflow: hidden; " + _headattr.style.cssText;
  1765. } else {
  1766. _headattr.style = {
  1767. cssText: "text-indent: 10px; color: White; line-height: inherit; font-size: 14px; height: 30px; line-height: 36px; background-color: rgb(48 48 48); overflow: hidden; color: White; font-size: 14px; overflow: hidden; "
  1768. }
  1769. }
  1770. //设置头部有拖拽事件
  1771. if (this.isdrag) { //判断是否允许拖动窗体
  1772. _headattr.onmousedown = function () {
  1773. U.UF.F.drag(_formel); //拖动事件调用
  1774. };
  1775. }
  1776. //创建头部区域
  1777. _headel = $$("div", _headattr, _formel);
  1778. //如果是字符串的处理
  1779. if (U.UF.C.isString(this.title)) {
  1780. _headel.innerHTML = this.title;
  1781. }
  1782. //如果中间区域是元素的处理
  1783. else if (U.UF.C.isElement(this.title)) {
  1784. _headel.appendChild(this.title); //添加所选元素
  1785. }
  1786. this.header = _headel; //设置中间的全局变量
  1787. }
  1788. //创建中间
  1789. _contentel = $$("div", { "style": { "cssText": "width: 100%; position: relative;" } }, _formel);
  1790. //中间的内容
  1791. _contentattr.usbody = "true";
  1792. //窗体头部属性统一设置
  1793. if (_contentattr.style) {
  1794. _contentattr.style.cssText = _contentattr.style.cssText || "";
  1795. //_contentattr.style.cssText = "text-align: left; overflow: auto;" + _contentattr.style.cssText;
  1796. _contentattr.style.cssText = "text-align: left; overflow: hidden;" + _contentattr.style.cssText;
  1797. } else {
  1798. _contentattr.style = {
  1799. cssText: "text-align: left; "
  1800. };
  1801. }
  1802. //在头部不存在的情况下,设置中间内容可以拖动
  1803. if (this.title === false && this.isdrag) {
  1804. _contentel.onmousedown = function () {
  1805. U.UF.F.drag(_formel); //拖动事件调用
  1806. };
  1807. }
  1808. //设置拉伸处理
  1809. if (this.isstretching !== false) {
  1810. //创建窗体拉伸
  1811. _stretchingel = $$("div", { style: { "cssText": "display: block;" } }, _formel);
  1812. //拉伸的信息 key代表样式的结尾,value代表拉伸的方向
  1813. _stretchinginfo = {
  1814. "top": "cursor: n-resize; left: 0px; top: 0px; width: 100%; height: 5px;",
  1815. "rightTop": "cursor: ne-resize; right: -2px; top: -2px; width: 12px; height: 12px;",
  1816. "leftTop": "cursor: nw-resize; top: 0px; left: 0px; width: 12px; height: 12px;",
  1817. "left": "cursor: w-resize; left: 0px; top: 0px; width: 5px; height: 100%;",
  1818. "right": "cursor: e-resize; right: 0px; top: 0px; width: 5px; height: 100%;",
  1819. "bottom": "cursor: s-resize; left: 0px; bottom: 0px; width: 100%; height: 5px;",
  1820. "leftBottom": "cursor: sw-resize; left: -2px; bottom: -2px; width: 12px; height: 12px;",
  1821. "rightBottom": "cursor: se-resize; right: -2px; bottom: -2px; width: 12px; height: 12px;"
  1822. }
  1823. //循环创建拉伸条,包含上、下、左、右、上左、下左、上右、下右
  1824. for (i in _stretchinginfo) {
  1825. $$("div", {
  1826. "style": {
  1827. "cssText": "position: absolute; overflow: hidden; display: block; z-index: 10;" + _stretchinginfo[i]
  1828. },
  1829. "onmousedown": U.UF.C.closure(function (scope, typename) {
  1830. //拉伸函数的调用
  1831. U.UF.F.stretching(_formel, typename, U.UF.C.apply(scope, scope.size));
  1832. }, [this, i])
  1833. }, _stretchingel);
  1834. }
  1835. }
  1836. //头部功能区域
  1837. if (this.title !== false) {
  1838. _headbottom = $$("div", {
  1839. "style": { "cssText": "position: absolute; top: 5px; right: 0px; width: 80px; display: table-cell; vertical-align: middle;" }
  1840. }, _formel);
  1841. }
  1842. if (this.isclose !== false) {
  1843. //关闭窗体的按钮
  1844. $$("div", {
  1845. "style": {
  1846. "cssText": "background-image:url(../../../img/close.png); _background-image:url(/img/close.png);width: 14px; height: 14px; background-repeat: no-repeat; background-size: 100%; float: right; margin-right: 5px;margin-top:6px; cursor: pointer;"
  1847. },
  1848. "title": "点击关闭",
  1849. "onmousedown": U.UF.EV.stopBubble,
  1850. "onclick": U.UF.C.apply(this, function () {
  1851. U.UF.F.closeWindow(this.form); //调用窗体关闭函数
  1852. try {
  1853. //关闭任务栏处理
  1854. if (U.MD.D.T.taskbar.close) {
  1855. U.MD.D.T.taskbar.close({ "forms": _formel });
  1856. U.MD.N.urlWrite("", "可可乐博信息化桌面");
  1857. }
  1858. } catch (e) { }
  1859. //回调处理
  1860. if (U.UF.C.isFunction(this.closecallback)) {
  1861. this.closecallback();
  1862. }
  1863. })
  1864. }, _headbottom);
  1865. }
  1866. //是否允许放大
  1867. if (this.isenlarge !== false) {
  1868. //放大按钮
  1869. _enlargeel = $$("div", {
  1870. "style": {
  1871. "cssText": "background-image:url(../../../img/max.png); _background-image:url(/img/max.png); background-size: 100%; float: right; margin-right: 10px; width: 17px; height: 17px; cursor: pointer;margin-top: 4px;"
  1872. },
  1873. "title": "最大化",
  1874. "onmousedown": U.UF.EV.stopBubble,
  1875. //最大化点击事件处理
  1876. "onclick": function () {
  1877. U.UF.F.windowZooming(_formel); //调用窗体最大化函数
  1878. }
  1879. }, _headbottom);
  1880. //如果有head头部的处理
  1881. if (_headel) {
  1882. //头部双击放大缩小处理处理
  1883. _headel.ondblclick = U.UF.C.apply(_headel, function () {
  1884. //判断双击的元素是否在头部导航上,否则如果头部上有其他的按钮什么的双击了,也会触发放大方法
  1885. if (event.srcElement == this || U.UF.EL.isChild(this, event.srcElement)) {
  1886. _enlargeel.onclick(); //放大的处理
  1887. }
  1888. });
  1889. }
  1890. }
  1891. //是否允许最小化
  1892. if (this.isnarrow !== false) {
  1893. //最小化的按钮处理
  1894. $$("div", {
  1895. "style": {
  1896. "cssText": "background-image:url(../../../img/min.png); _background-image:url(/img/min.png);background-size: 100%; float: right; margin-right: 10px; margin-top: 3px; width: 20px; height: 20px; cursor: pointer;background-repeat: no-repeat;"
  1897. },
  1898. "title": "最小化",
  1899. "onmousedown": U.UF.EV.stopBubble,
  1900. "onclick": function () {
  1901. U.UF.F.windowMinimize(_formel); //窗体最小化处理
  1902. }
  1903. }, _headbottom);
  1904. }
  1905. //如果窗体已经创建,那么直接替换
  1906. if (_replaceel && _replaceel.parentNode != null) {
  1907. _replaceel.parentNode.replaceChild(_formel, _replaceel);
  1908. }
  1909. //元素添加到制定的元素中
  1910. else {
  1911. this.parentel.appendChild(_formel);
  1912. }
  1913. //如果没有设置top和left那么居中弹出
  1914. if (_formel.style.top == "" && _formel.style.left == "" && _formel.style.right == "" && _formel.style.bottom == "") {
  1915. //居中置顶弹出
  1916. U.UF.F.windowTopCenter(_formel);
  1917. }
  1918. //否则置顶
  1919. else {
  1920. U.UF.F.topWindow(_formel);
  1921. }
  1922. //创建中间内容元素
  1923. _contentchildel = $$("div", _contentattr, _contentel);
  1924. //如果是字符串的处理
  1925. if (U.UF.C.isString(this.content)) {
  1926. _contentchildel.innerHTML = this.content;
  1927. }
  1928. //如果中间区域是元素的处理
  1929. else if (U.UF.C.isElement(this.content)) {
  1930. _contentchildel.appendChild(this.content); //添加所选元素
  1931. }
  1932. this.middle = _contentchildel; //中间的内容
  1933. //初始化的时候默认设置大小
  1934. this.size();
  1935. },
  1936. /** 窗体每一次点击置顶
  1937. */
  1938. top: function () {
  1939. U.UF.F.topWindow(this.form); //点击置顶的处理
  1940. },
  1941. /** 窗体大小处理
  1942. */
  1943. size: function () {
  1944. var _headheight = 0; //head头部的高度
  1945. //如果存在head头部,那么获取head头部处理
  1946. if (this.header) {
  1947. _headheight = this.header.clientHeight;
  1948. }
  1949. //设置窗体content区域大小设置
  1950. if (this.header) {
  1951. this.middle.style.height = this.form.clientHeight - this.header.clientHeight + "px";
  1952. } else {
  1953. this.middle.style.height = this.form.clientHeight + "px";
  1954. }
  1955. }
  1956. }
  1957. /** 窗体大小处理
  1958. */
  1959. U.UF.UI.form.windowResize = function () {
  1960. var i,
  1961. _style,
  1962. _bodywidth = US.width, //获取原本在窗体大小没有变化前的width
  1963. _bodyheight = US.height, //获取原本在窗体大小没有变化前的height
  1964. _sizeinfo, //大小信息
  1965. _width, //长度
  1966. _height, //高度
  1967. _formel, //窗体元素
  1968. _forms = U.UF.UI.form.allForm //获取所有的窗体
  1969. ;
  1970. //循环所有的窗体
  1971. for (i in _forms) {
  1972. _formel = _forms[i].form; //获取窗体的处理
  1973. if ($(_formel).css("display") != "none") { //判断窗体是否隐藏
  1974. _style = {}; //设置位置
  1975. _width = U.selectEl(_formel).css("width"); //获取窗体的长
  1976. _height = U.selectEl(_formel).css("height"); //获取窗体的宽
  1977. //计算位置,如果有百分比,则按照百分比的方式进行计算,否则,得到百分比。
  1978. _width = _width.indexOf("%") > -1 ? _width.toInt() / 100 : _formel.offsetWidth / _bodywidth;
  1979. _height = _height.indexOf("%") > -1 ? _height.toInt() / 100 : _formel.offsetWidth / _bodyheight;
  1980. //设置位置,如果没有右对齐,则设置左对齐
  1981. if (_formel.style.right == "" || _formel.style.right == "auto") {
  1982. _style.left = _formel.offsetLeft + (document.body.offsetWidth - _bodywidth) * ((1 - _width) / 2) + "px";
  1983. }
  1984. //如果没有下对齐,则设置上对齐
  1985. if (_formel.style.bottom == "" || _formel.style.bottom == "auto") {
  1986. _style.top = _formel.offsetTop + (document.body.offsetHeight - _bodyheight) * ((1 - _height) / 2) + "px";
  1987. }
  1988. //设置值
  1989. U.selectEl(_formel).addAttrArray({ "style": _style });
  1990. }
  1991. }
  1992. }
  1993. /** 关闭所有的窗体
  1994. */
  1995. U.UF.UI.form.closeWindows = function () {
  1996. var i;
  1997. for (i in U.UF.UI.form.allForm) {
  1998. if (U.UF.UI.form.allForm[i].isclose) {
  1999. U.UF.UI.form.allForm[i].form.close();
  2000. }
  2001. }
  2002. }
  2003. //#endregion
  2004. //#endregion;
  2005. ///<jscompress sourcefile="Music.js" />
  2006. Namespace.register("U.MD.UI.music");
  2007. /**
  2008. * [Control description] 音乐控件总函数
  2009. * @param {[type]} musicList [数组json 格式请看文档]
  2010. * @param {[type]} index [需要播放第几首歌(索引)]
  2011. * @param {[type]} autoplay [是否自动播放] 可填可不填 默认 false
  2012. * @param {[type]} parentEl 所需要添加到的父元素 可填可不填 默认document.body
  2013. */
  2014. U.MD.UI.music = function (musicList, index, autoplay, parentEl) {
  2015. var _music = U.MD.UI.music; //简写命名空间
  2016. var _musicBox;
  2017. if (_musicBox = U.selectEl("#U_MD_UI_music_musicBox")[0]) {
  2018. // U.selectEl(_musicBox).removeClass('U_MD_UI_music_hidden');
  2019. // var _attr = _music.Attr; //简写全局属性json名
  2020. // var _audio = U.selectEl("#U_MD_UI_music_audio"); //audio标签
  2021. // _attr.musicList = musicList; //全局赋值
  2022. // _attr.musicIndex = index; //全局赋值
  2023. // _audio[0].src = musicList[index].src; //添加音乐路径
  2024. // var _Name = U.selectEl("#U_MD_UI_music_Name"); //音乐名字节点
  2025. // _Name[0].innerText = musicList[index].title; //音乐名字赋值
  2026. _musicBox.remove();
  2027. }
  2028. _music.create(parentEl); //创建音乐控件
  2029. _music.Attr = { //存放全局属性
  2030. 'musicList': musicList, //所有数据
  2031. 'musicIndex': index, //当前数据索引
  2032. 'autoplay': autoplay, //第一首是否自动播放
  2033. 'currentTime': null, //音乐当前时间未赋值
  2034. 'endTime': null //音乐结束时间未赋值
  2035. };
  2036. _music.init(); //初始化函数
  2037. };
  2038. U.MD.UI.music.Attr = null; //存放元素与变量的json全局变量 未赋值
  2039. U.MD.UI.music.htmlTemplate = ' <div class="U_MD_UI_music_leftCont">\n' +
  2040. ' <div class="U_MD_UI_music_CoverBox">\n' +
  2041. ' <img src="/img/Controls/Audio/pc/电脑图标.png" alt="" id="U_MD_UI_music_Cover">\n' +
  2042. ' </div> <!-- 音乐封面图片 -->\n' +
  2043. ' </div>\n' +
  2044. ' <div class="U_MD_UI_music_rightCont">\n' +
  2045. ' <div class="U_MD_UI_music_Name" id="U_MD_UI_music_Name"></div> <!-- 音乐名字 -->\n' +
  2046. ' <div class="U_MD_UI_music_leftBtn" id="U_MD_UI_music_leftBtn"></div> <!-- 左按钮 -->\n' +
  2047. ' <div class="U_MD_UI_music_pauseBtn U_MD_UI_music_playBtn" id="U_MD_UI_music_playBtn"></div> <!-- 播放/暂停 按钮 -->\n' +
  2048. ' <div class="U_MD_UI_music_rightBtn" id="U_MD_UI_music_rightBtn"></div> <!-- 右按钮 -->\n' +
  2049. ' <div class="U_MD_UI_music_soundOpen" id="U_MD_UI_music_soundSwitch"></div> <!-- 声音开关按钮 -->\n' +
  2050. ' <div class="U_MD_UI_music_soundBox" id="U_MD_UI_music_soundBox"> <!-- 声音条盒子节点 -->\n' +
  2051. ' <div class="U_MD_UI_music_soundBar" id="U_MD_UI_music_soundBar" style="width: 31px;"></div> <!-- 声音条 -->\n' +
  2052. ' <div class="U_MD_UI_music_soundBall" id="U_MD_UI_music_soundBall" style="left: 31px;"></div> <!-- 声音球 -->\n' +
  2053. ' </div>\n' +
  2054. ' <div class="U_MD_UI_music_listBtn"></div> <!-- 右上角的列表按钮 -->\n' +
  2055. ' <div class="U_MD_UI_music_shrinkBtn" id="U_MD_UI_music_shrinkBtn"></div> <!-- 右上角的缩小按钮 -->\n' +
  2056. ' <div class="U_MD_UI_music_closeBtn" id="U_MD_UI_music_closeBtn"></div> <!-- 右上角的关闭按钮 -->\n' +
  2057. ' </div>\n' +
  2058. ' <div class="U_MD_UI_music_progressBox" id="U_MD_UI_music_progressBox"> <!-- 时间条盒子节点 -->\n' +
  2059. ' <div class="U_MD_UI_music_progressBar" id="U_MD_UI_music_progressBar" style="width: 0.64px;"></div> <!-- 时间条 -->\n' +
  2060. ' <div class="U_MD_UI_music_progressBall" id="U_MD_UI_music_progressBall" style="left: 0.64px;"></div> <!-- 时间球 -->\n' +
  2061. ' </div>\n' +
  2062. ' <audio id="U_MD_UI_music_audio" autoplay="" src=""></audio>';
  2063. /**
  2064. * 添加音乐控件html代码 并且判断是否存在html 防止多次添加
  2065. */
  2066. U.MD.UI.music.create = function (parentEl) {
  2067. var _parentEl = parentEl || document.body;
  2068. var _formclass = { "style": { "border": "none" }, "id": "U_MD_UI_music_musicBox", "className": "U_MD_UI_music_musicBox" };
  2069. var _formattr = { isclose: false, isstretching: false, isenlarge: false, isnarrow: false };
  2070. var _headclass = { "style": { "height": "13px", "background-color": "#cc5b5b" } };
  2071. U.MD.UI.music.player = new U.UF.UI.form(false, U.MD.UI.music.htmlTemplate, _formclass, _formattr, _headclass);
  2072. U.selectEl("#U_MD_UI_music_musicBox")[0].style.overflow = "";
  2073. // U.UF.F.windowMinimize(_formel);
  2074. };
  2075. /**
  2076. * 音乐控件初始化
  2077. */
  2078. U.MD.UI.music.init = function () {
  2079. var _music = U.MD.UI.music; //简写命名空间
  2080. var _attr = _music.Attr; //简写全局属性json名
  2081. var _audio = U.selectEl("#U_MD_UI_music_audio"); //audio标签
  2082. var _musicList = _attr.musicList; //音乐列表数组
  2083. var _musicIndex = _attr.musicIndex; //需要播放的音乐(数组中的第index个)
  2084. _audio[0].src = _musicList[_musicIndex].src; //添加音乐路径
  2085. var _playBtn = U.selectEl("#U_MD_UI_music_playBtn"); //暂停播放按钮节点
  2086. var _Name = U.selectEl("#U_MD_UI_music_Name"); //音乐名字节点
  2087. var _corver = U.selectEl("#U_MD_UI_music_Cover"); //封面图片节点
  2088. if (!_attr.autoplay) { //若autoplay属性 = false 则第一首音乐暂停
  2089. _audio[0].pause();
  2090. }
  2091. _music.openBtnEvent(); //按钮点击开关 音乐控件隐藏
  2092. _music.shrinkBtnEvent(); //缩小事件绑定
  2093. _music.soundControl(); //声音控制器
  2094. _music.playEvent(); //音乐播放与暂停控制器
  2095. _music.switchMusic(); //切换音乐按钮
  2096. _music.progressControl(); //音乐进度条控制器*/
  2097. _audio.bind('durationchange', function () { //当音乐时长已改变时 给节点赋值
  2098. _attr.endTime = this.duration; //总时长赋值
  2099. _musicIndex = _attr.musicIndex; //音乐索引位置重赋值
  2100. _Name[0].innerText = _musicList[_musicIndex].title; //音乐名字赋值
  2101. });
  2102. _audio.bind("ended", function () { //音乐结束后切换下一首
  2103. _musicIndex = _attr.musicIndex; //由于_attr.musicIndex是一个变量 因此 需要重新赋值
  2104. var _listLength = _musicList.length - 1; //获取数组中音乐的长度
  2105. if (_musicIndex === _listLength) { //当音乐在数组中为最后一首时 下一首则为第一首 也就是索引 0
  2106. _attr.musicIndex = 0;
  2107. _musicIndex = _attr.musicIndex;
  2108. _audio[0].src = _musicList[_musicIndex].src;
  2109. } else { //否则则索引+1
  2110. _attr.musicIndex++;
  2111. _musicIndex = _attr.musicIndex;
  2112. _audio[0].src = _musicList[_musicIndex].src;
  2113. }
  2114. });
  2115. };
  2116. /**
  2117. * 关闭按钮点击事件
  2118. */
  2119. U.MD.UI.music.openBtnEvent = function () {
  2120. var _music = U.MD.UI.music; //简写命名空间
  2121. // var _attr = _music.Attr; //简写全局属性json名
  2122. // var _musicBox = U.selectEl("#U_MD_UI_music_musicBox"); //获取音乐控件盒子
  2123. // var _closeBtn = U.selectEl("#U_MD_UI_music_closeBtn"); //获取关闭按钮 在控件里 右上角的 叉叉
  2124. U.selectEl("#U_MD_UI_music_closeBtn").bind('click', function () {
  2125. var _audio = U.selectEl("#U_MD_UI_music_audio"); //audio标签
  2126. if (!_audio[0].paused) {
  2127. U.selectEl("#U_MD_UI_music_playBtn").addClass('U_MD_UI_music_playBtn'); //暂停音乐并修改图标
  2128. _audio[0].pause();
  2129. }
  2130. U.UF.F.closeWindow(_music.player.form); //调用窗体关闭函数
  2131. U.selectEl('#U_MD_D_T_taskbar_music').remove();
  2132. // _musicBox.addClass("U_MD_UI_music_hidden"); //点击关闭按钮后 隐藏音乐控件
  2133. // _musicBox.addClass("U_MD_UI_music_hidden"); //点击关闭按钮后 隐藏音乐控件
  2134. });
  2135. };
  2136. /**
  2137. * 缩小按钮事件绑定
  2138. */
  2139. U.MD.UI.music.shrinkBtnEvent = function () {
  2140. U.selectEl('#U_MD_UI_music_shrinkBtn').bind('click', function () {
  2141. U.UF.F.windowMinimize(U.MD.UI.music.player.form); //窗体最小化处理
  2142. });
  2143. };
  2144. /**
  2145. * 播放/暂停 的点击事件
  2146. */
  2147. U.MD.UI.music.playEvent = function () {
  2148. var _music = U.MD.UI.music; //简写命名空间
  2149. var _attr = _music.Attr; //简写全局属性json名
  2150. var _playbtn = U.selectEl("#U_MD_UI_music_playBtn"); //暂停/播放 按钮
  2151. var _audio = U.selectEl("#U_MD_UI_music_audio"); //audio标签
  2152. _playbtn.bind('click', function () {
  2153. if (!_audio[0].paused) { //如在 无暂停状态(播放状态)
  2154. _playbtn.addClass('U_MD_UI_music_playBtn'); //暂停音乐并修改图标
  2155. _audio[0].pause();
  2156. } else { //否则则时 暂停状态时
  2157. _playbtn.removeClass('U_MD_UI_music_playBtn');
  2158. _audio[0].play(); //播放音乐并修改图标
  2159. }
  2160. });
  2161. };
  2162. /**
  2163. * 音乐按钮切换(上一首 下一首)
  2164. */
  2165. U.MD.UI.music.switchMusic = function () {
  2166. var _music = U.MD.UI.music; //简写命名空间
  2167. var _attr = _music.Attr; //简写全局属性json名
  2168. var _audio = U.selectEl("#U_MD_UI_music_audio"); //audio标签
  2169. var _rightBtn = U.selectEl("#U_MD_UI_music_rightBtn"); //获取下一首的按钮
  2170. var _leftBtn = U.selectEl("#U_MD_UI_music_leftBtn"); //获取上一首的按钮
  2171. var _musicList = _attr.musicList; //获取音乐数组数据
  2172. var _musicIndex = _attr.musicIndex; //获取当前需要播放音乐 的数组索引
  2173. var _listLength = _musicList.length - 1; //获取音乐的数量
  2174. _rightBtn.bind('click', function () { //当点击右边(下一首)的按钮时
  2175. _musicIndex = _attr.musicIndex; //由于_attr.musicIndex是一个变量 因此 需要重新赋值
  2176. if (_musicIndex === _listLength) { //如果当前的歌曲是最后一首时
  2177. _attr.musicIndex = 0; //则条转到第一首歌
  2178. _musicIndex = _attr.musicIndex; //给全局属性赋值
  2179. _audio[0].src = _musicList[_musicIndex].src; //并修改音乐路径
  2180. } else { //否则跳转到下一首歌
  2181. _attr.musicIndex++; //数组索引加1
  2182. _musicIndex = _attr.musicIndex; //给全局属性赋值
  2183. _audio[0].src = _musicList[_musicIndex].src; //并修改音乐路径
  2184. }
  2185. });
  2186. _leftBtn.bind('click', function () { //同上 此处是左按钮(上一首)
  2187. _musicIndex = _attr.musicIndex; //由于_attr.musicIndex是一个变量 因此 需要重新赋值
  2188. if (_musicIndex === 0) {
  2189. _attr.musicIndex = _listLength;
  2190. _musicIndex = _attr.musicIndex;
  2191. _audio[0].src = _musicList[_musicIndex].src;
  2192. } else {
  2193. _attr.musicIndex--;
  2194. _musicIndex = _attr.musicIndex;
  2195. _audio[0].src = _musicList[_musicIndex].src;
  2196. }
  2197. });
  2198. };
  2199. /**
  2200. * 声音事件控制 总函数
  2201. */
  2202. U.MD.UI.music.soundControl = function () {
  2203. var _music = U.MD.UI.music; //简写命名空间
  2204. var _audio = U.selectEl("#U_MD_UI_music_audio"); //audio标签
  2205. var _soundBox = U.selectEl("#U_MD_UI_music_soundBox"); //声音盒子节点
  2206. var _soundBall = U.selectEl("#U_MD_UI_music_soundBall"); //音量球
  2207. var _soundBar = U.selectEl("#U_MD_UI_music_soundBar"); //声音条
  2208. var _boxWidth = _soundBox[0].clientWidth; //获取盒子宽度 = 声音球位置的最大值
  2209. var _volume = 0.5; //声音初始大小
  2210. var _soundSwitch = U.selectEl("#U_MD_UI_music_soundSwitch"); //声音开关图标
  2211. _audio[0].volume = _volume; //给audio标签添加声音
  2212. _soundBall[0].style.left = (_boxWidth * _volume) + "px"; //调整音量球位置 = 总宽度*百分比
  2213. _soundBar[0].style.width = (_boxWidth * _volume) + "px"; //调整声音条宽度 = 总宽度*百分比
  2214. _soundSwitch.bind('click', function () { //声音开关控制函数
  2215. _music.toggleClass(this, 'U_MD_UI_music_soundClose'); //每点击一次 切换样式
  2216. if ($(this).hasClass('U_MD_UI_music_soundClose')) { //判断如果样式为关闭时(静音状态)
  2217. this._volume = _audio[0].volume; //记录原有的声音值
  2218. this._soundBallX = parseFloat(_soundBall.css("left")); //获取音量球的 left值
  2219. this._soundBarW = parseFloat(_soundBar.css("width")); //获取音量条的 宽
  2220. _soundBall[0].style.left = 0; //音量球的left为0
  2221. _soundBar[0].style.width = 0; //音量条的宽为 0
  2222. _audio[0].volume = 0; //audio声音也为0
  2223. } else { //播放状态
  2224. if (!this._volume) { //如果this._volume不存在 则声音赋值时会报错
  2225. return;
  2226. }
  2227. _audio[0].volume = this._volume; //在点一遍开关后 复原到之前记录的值
  2228. _soundBall[0].style.left = this._soundBallX + "px"; //给音量球的left赋值
  2229. _soundBar[0].style.width = this._soundBarW + "px"; //给音量条的宽赋值
  2230. }
  2231. });
  2232. _soundBox.bind('mousedown', function (e) { //点击进度条后 音量球跳转到鼠标点击位置 并且声音跟随增大或减小
  2233. var _boxLeft = _music.getOffsetLeft(this); //body距离盒子左端的left值 = 声音球left的最小值
  2234. var _boxRight = _boxLeft + _boxWidth; //body距离盒子右端的left值 = 声音球left的最大值
  2235. var _mouseX = e.pageX; //获取鼠标按下时的X坐标
  2236. _mouseX = Math.max(_mouseX, _boxLeft); //mouseX 与 boxLeft距离不能小于0 因此 获取两数最大值 原因:声音不能小于0
  2237. _mouseX = Math.min(_mouseX, _boxRight); //mouseX 与 boxRight因此 获取两数最大值 原因:声音不能大于1
  2238. var _dis = _mouseX - _boxLeft; //鼠标划过的距离
  2239. _volume = Math.round(parseFloat(_dis / _boxWidth) * 100) / 100; //距离相对于盒子宽度的值 = 声音百分比大小(此处为保留两位小数点)
  2240. _soundBall[0].style.left = (_boxWidth * _volume) + "px"; //音量球left值 改变成 = 总宽*百分比
  2241. _soundBar[0].style.width = (_boxWidth * _volume) + "px"; //音量条width 改变成 = 总宽*百分比
  2242. _audio[0].volume = _volume; //改变audio标签值
  2243. if (_audio[0].volume <= 0) { //如果声音小于=0 时 则改变成 静音状态时的样式 否则则是非静音状态样式
  2244. _soundSwitch.addClass('U_MD_UI_music_soundClose');
  2245. } else {
  2246. _soundSwitch.removeClass('U_MD_UI_music_soundClose');
  2247. }
  2248. });
  2249. _soundBall.bind('mousedown', function (e) { //音量球拖拽效果
  2250. U.UF.EV.stopBubble(e); //阻止冒泡
  2251. var _oMouseX = e.pageX; //获取鼠标按下时的X坐标
  2252. var _soundDrapMove = function (e) { //拖拽时移动用的函数
  2253. U.UF.EV.stopDefault(e); //取消默认拖拽
  2254. var _mouseX = e.pageX; //鼠标移动时的x坐标
  2255. var _dis = _mouseX - _oMouseX + _oX; //移动的距离
  2256. _dis = Math.max(0, _dis); //限制音量球left不得小于0
  2257. _dis = Math.min(_boxWidth, _dis); //限制音量球left不得大于盒子宽度
  2258. _soundBall[0].style.left = _dis + "px"; //音量球位置
  2259. _soundBar[0].style.width = _dis + "px"; //音量条宽度
  2260. _volume = Math.round(parseFloat(_dis / _boxWidth) * 100) / 100; //声音球距离盒子宽度的left值 = 声音百分比大小(此处为保留两位小数点)
  2261. _audio[0].volume = _volume; //音乐的声音赋值
  2262. if (_audio[0].volume <= 0) { //判断声音小于0则改成静音图标
  2263. _soundSwitch.addClass('U_MD_UI_music_soundClose');
  2264. } else { //否则该成非静音图标
  2265. _soundSwitch.removeClass('U_MD_UI_music_soundClose');
  2266. }
  2267. };
  2268. var _soundDragUp = function () { //拖拽时松开用的函数
  2269. U.selectEl(document).unbind('mousemove', _soundDrapMove);
  2270. U.selectEl(document).unbind('mouseup', _soundDragUp);
  2271. };
  2272. var _oX = parseFloat(_soundBall.css("left")); //获取鼠标按下时音量球的坐标
  2273. U.selectEl(document).bind('mousemove', _soundDrapMove);
  2274. U.selectEl(document).bind('mouseup', _soundDragUp)
  2275. });
  2276. };
  2277. /**
  2278. * 进度条控制 事件总函数
  2279. */
  2280. U.MD.UI.music.progressControl = function () {
  2281. var _music = U.MD.UI.music; //简写命名空间
  2282. var _attr = _music.Attr; //简写全局属性json名
  2283. var _audio = U.selectEl("#U_MD_UI_music_audio"); //audio标签
  2284. var _progressBox = U.selectEl("#U_MD_UI_music_progressBox"); //时间盒子节点
  2285. var _progressBall = U.selectEl("#U_MD_UI_music_progressBall"); //时间球
  2286. var _progressBar = U.selectEl("#U_MD_UI_music_progressBar"); //时间条
  2287. var _playbtn = U.selectEl("#U_MD_UI_music_playBtn"); //播放/暂停 按钮
  2288. var _boxWidth = _progressBox[0].clientWidth; //时间盒子宽度 = 时间球位置的最大值
  2289. var _barFlag = true,
  2290. _currentTime; //声明两个全局变量 为更新时间条所用
  2291. _audio.bind('timeupdate', function () {
  2292. if (!this.paused) { //如在 无暂停状态(播放状态)
  2293. _playbtn.removeClass('U_MD_UI_music_playBtn'); //修改成 播放时用的图标
  2294. } else { //否则 为暂停状态
  2295. _playbtn.addClass('U_MD_UI_music_playBtn'); //修改成暂停用的图标
  2296. }
  2297. if (_barFlag) { //barFlag = true 为 时间球不在拖拽状态时
  2298. _currentTime = this.currentTime; //获取音乐当前播放时间
  2299. var _speed = Math.round(parseFloat(_currentTime / _attr.endTime) * 10000) / 10000; //_speed = 当前时间相对于总时长的 百分比
  2300. _progressBall[0].style.left = (_boxWidth * _speed) + "px"; //时间球的left = _speed(百分比)*总宽度
  2301. _progressBar[0].style.width = (_boxWidth * _speed) + "px"; //时间条的width = _speed(百分比)*总宽度
  2302. }
  2303. });
  2304. _progressBox.bind('mousedown', function (e) { //点击进度条后 时间球跳转到鼠标点击位置 时间跟随改变
  2305. var _boxLeft = _music.getOffsetLeft(this); //body距离盒子左端的left值 = 时间球left的最小值
  2306. var _boxRight = _boxLeft + _boxWidth; //body距离盒子右端的left值 = 时间球left的最大值
  2307. var _mouseX = e.pageX; //获取鼠标按下时的X坐标
  2308. _mouseX = Math.max(_mouseX, _boxLeft); //mouseX 与 boxLeft距离不能小于0 因此 获取两数最大值 原因:声音不能小于0
  2309. _mouseX = Math.min(_mouseX, _boxRight); //mouseX 与 boxRight因此 获取两数最大值 原因:声音不能大于1
  2310. var _dis = _mouseX - _boxLeft; //鼠标划过的距离
  2311. _speed = Math.round(parseFloat(_dis / _boxWidth) * 10000) / 10000; //时间球距离盒子宽度的left值 = 时间当前值/总时长(此处为保留4位小数点)
  2312. _progressBall[0].style.left = (_boxWidth * _speed) + "px";
  2313. _progressBar[0].style.width = (_boxWidth * _speed) + "px";
  2314. _audio[0].currentTime = _attr.endTime * _speed;
  2315. });
  2316. _progressBall.bind('mousedown', function (e) { //时间球拖拽效果
  2317. _barFlag = false; //拖拽时 时间球跟随声音播放向前移动状态暂时屏蔽 详细见 timeupdate监听
  2318. U.UF.EV.stopBubble(e); //阻止冒泡
  2319. var _oMouseX = e.pageX; //获取鼠标按下时的X坐标
  2320. var _progressDrapMove = function (e) { //拖拽移动时的函数
  2321. U.UF.EV.stopDefault(e); //取消默认拖拽
  2322. var _mouseX = e.pageX; //鼠标移动时的x坐标
  2323. var _dis = _mouseX - _oMouseX + _oX; //移动的距离
  2324. _dis = Math.max(0, _dis); //限制音量球left不得小于0
  2325. _dis = Math.min(_boxWidth, _dis); //限制音量球left不得大于盒子宽度
  2326. _progressBall[0].style.left = _dis + "px"; //音量球位置
  2327. _progressBar[0].style.width = _dis + "px"; //音量条宽度
  2328. _speed = Math.round(parseFloat(_dis / _boxWidth) * 10000) / 10000; //时间球距离盒子宽度的left值 = 时间当前值/总时长(此处为保留4位小数点)
  2329. _progressBall[0].style.left = (_boxWidth * _speed) + "px"; //时间球的left = 总宽*百分比
  2330. _progressBar[0].style.width = (_boxWidth * _speed) + "px"; //时间条的width = 总宽*百分比
  2331. _currentTime = _attr.endTime * _speed; //当前时间 = 音乐总时长*百分比
  2332. };
  2333. var _progressDragUp = function () { //拖拽松开后的函数
  2334. _barFlag = true; //拖拽后松开时 时间球跟随声音播放向前移动
  2335. _audio[0].currentTime = _currentTime; //当前重新赋值
  2336. U.selectEl(document).unbind('mousemove', _progressDrapMove); //删除 mousemove的监听事件
  2337. U.selectEl(document).unbind('mouseup', _progressDragUp); //删除mouseup的监听事件
  2338. };
  2339. var _oX = parseFloat(_progressBall.css("left")); //获取鼠标按下时音量球的坐标
  2340. U.selectEl(document).bind('mousemove', _progressDrapMove);
  2341. U.selectEl(document).bind('mouseup', _progressDragUp)
  2342. });
  2343. };
  2344. U.MD.UI.music.getOffsetLeft = function (obj) {
  2345. var tmp = obj.offsetLeft;
  2346. var val = obj.offsetParent;
  2347. while (val != null) {
  2348. tmp += val.offsetLeft;
  2349. val = val.offsetParent;
  2350. }
  2351. return tmp;
  2352. };
  2353. U.MD.UI.music.secondToDate = function (result) {
  2354. var m = Math.floor((result / 60 % 60));
  2355. var s = Math.floor((result % 60));
  2356. if (m < 10) {
  2357. m = "0" + m;
  2358. }
  2359. if (s < 10) {
  2360. s = "0" + s;
  2361. }
  2362. return result = m + ":" + s;
  2363. };
  2364. U.MD.UI.music.toggleClass = function (ele, cls) { //如果存在(不存在),就删除(添加)一个样式
  2365. if ($(ele).hasClass(cls)) {
  2366. U.selectEl(ele).removeClass(cls);
  2367. } else {
  2368. U.selectEl(ele).addClass(cls);
  2369. }
  2370. };;
  2371. ///<jscompress sourcefile="Page.js" />
  2372. //窗体功能命名空间
  2373. Namespace.register("U.UF.P");
  2374. /*
  2375. * 作用:给不同的域添加this的指定方向
  2376. * @param {function} fun 执行函数
  2377. * @param {array} arr 执行函数的参数数组
  2378. * @param {element} el 用于指向域
  2379. */
  2380. U.UF.P.apply = function (fun, arr, el) {
  2381. return function () {
  2382. fun.apply(el, arr);
  2383. }
  2384. }
  2385. U.UF.P.pagepId = 0; //全局变量 分页控件数量
  2386. /*
  2387. ** @param {element} el 需要插入分页控件的位置
  2388. ** @param {number} num 数据的数量
  2389. ** @param {number} pagenum 一页中数据量的多少
  2390. ** @param {number} page 显示当前是第几页
  2391. ** @param {function} fun 回调函数
  2392. */
  2393. U.UF.P.PPage = U.UF.P.page = function (el, num, pagenum, page, fun) {
  2394. this.PageNum = 0; // 全局变量 当前页
  2395. this.Index = 0; //全局变量 索引
  2396. this.Pageall = 0; //全局变量 总页数
  2397. this.init(el, num, pagenum, page, fun); //初始化函数
  2398. }
  2399. U.UF.P.page.prototype = {
  2400. init: function (el, num, pagenum, page, fun) {
  2401. this.PageNum = page; //获取当前页面
  2402. this.Index = page - 1; //获取当前页码的索引
  2403. var _el = U.selectEl(el)[0]; //获取需要插入分页控件的元素
  2404. var _pagesum = Math.ceil(num / pagenum); //获取总页数,数据的数量/一页中的数量,向上取整
  2405. this.Pageall = _pagesum; //获取总页数
  2406. //判断是否拥有分页控件
  2407. if (_el.getElementsByClassName('U_MD_F_Y')[0]) {
  2408. return false; //有的话就不添加新的分页控件
  2409. }
  2410. U.UF.P.pagepId++;
  2411. var _page = $$("div", { "className": "U_MD_F_Y" }, _el); //创建分页控件的整体部分
  2412. var _pagenode = $$("div", { "className": "U_MD_F_YL" }, _page); //创建分页控件的父级
  2413. var _firstEle = $$("div", { "className": "U_MD_F_YLO U_MD_F_Y_Button", "innerHTML": "首页", "title": "首页", "pid": U.UF.P.pagepId + "1" }, _pagenode); //创建分页的首页功能
  2414. var _previousEle = $$("div", { "className": "U_MD_F_YLT U_MD_F_Y_Button", "title": "上一页", "pid": U.UF.P.pagepId + "3" }, _pagenode); //创建分页的上一页功能
  2415. var _pagenum = $$("div", { "className": "U_MD_F_YN" }, _pagenode); //创建中间页码数的整体 , "style": { "cssText": "float:left"}
  2416. var _startpage;
  2417. var _endpage = Math.min(_pagesum, Math.max(page + 5, 10));
  2418. for (_startpage = Math.max(1, Math.min(page - 5, _pagesum - 10)); _startpage <= _endpage; _startpage++) {
  2419. (function (i, el) {
  2420. //创建中间的页码数,最高十页的页码数
  2421. //"className": "list" + U.UF.P.pagepId,
  2422. //"style": { "text-align": "center", "line-height": "31px;" },
  2423. var _centerEle = $$("div", {
  2424. "innerHTML": i,
  2425. "pid": U.UF.P.pagepId + "5"
  2426. }, _pagenum); //创建中间的页码数
  2427. i == page && (_centerEle.className = "U_MD_F_Y_Button_Active");
  2428. _centerEle.onclick = U.UF.P.apply(function (i) { //给每一个页码数添加一个点击事件
  2429. U.UF.P.centerEle(el, _centerEle); //实现点击页码进行跳转
  2430. }, [_startpage], el)
  2431. })(_startpage, this);
  2432. }
  2433. // var j = 0;
  2434. // for (j; j < _forpagesum && i <= _pagesum; j++) {//循环有多少个页码,并且进行创建
  2435. // (function (i, el) {
  2436. // //创建中间的页码数,最高十页的页码数
  2437. // //"className": "list" + U.UF.P.pagepId,
  2438. // //"style": { "text-align": "center", "line-height": "31px;" },
  2439. // var _centerEle = $$("div", {
  2440. // "innerHTML": i, "pid": U.UF.P.pagepId + "5"
  2441. // }, _pagenum); //创建中间的页码数
  2442. // i == page && (_centerEle.className = "U_MD_F_Y_Button_Active");
  2443. // _centerEle.onclick = U.UF.P.apply(function (i) {//给每一个页码数添加一个点击事件
  2444. // U.UF.P.centerEle(el, _centerEle); //实现点击页码进行跳转
  2445. // }, [i], el)
  2446. // })(i, this);
  2447. // i++;
  2448. // }
  2449. var _nextEle = $$("div", { "className": "U_MD_F_YLS U_MD_F_Y_Button", "title": "下一页", "pid": U.UF.P.pagepId + "4" }, _pagenode); //创建下一页功能
  2450. var _lastEle = $$("div", { "className": "U_MD_F_YLF U_MD_F_Y_Button", "innerHTML": "尾页", "title": "尾页", "pid": U.UF.P.pagepId + "2" }, _pagenode); //创建尾页功能
  2451. var _pages = $$("div", { "className": "U_MD_F_YR" }, _page); //创建跳转页面的整体
  2452. // var _pagesk = $$("div", { "className": "U_MD_F_YRL" }, _pages); //创建跳转页面的父级
  2453. $$("span", { "innerHTML": "到" }, _pages); //创建跳转元素
  2454. // var _pagejump = $$("div", {}, _pages); //创建页码输入框的父级
  2455. var _input = $$("input", { "type": "text" }, _pages); //创建页码输入框
  2456. $$("span", { "innerHTML": "页" }, _pages); //创建跳转元素
  2457. var _rightEle = $$("div", { "className": "U_MD_F_YRZ", "pid": U.UF.P.pagepId + "6", "innerHTML": "确定" }, _pages); //创建确定按钮
  2458. if (this.PageNum < _pagesum + 1) { //获取当前页面是否小于总页数
  2459. var _list = U.selectEl(".list" + U.UF.P.pagepId); //获取所有的中间页码数
  2460. for (var j = 1; j < _list.length + 1; j++) { //循环所有的中间页码数
  2461. if (this.PageNum == j) { //判断当前页码数是否等于中间页码数的一个
  2462. U.selectEl(_list[this.PageNum - 1]).addClass("U_MD_F_Y_Button_Active");
  2463. }
  2464. }
  2465. }
  2466. _firstEle.onclick = U.UF.P.apply(this.fPage, [_firstEle, _pagesum, fun], this); //首页功能
  2467. _previousEle.onclick = U.UF.P.apply(this.fPage, [_previousEle, _pagesum, fun], this); //上一页功能
  2468. //中间点击页码跳转功能 参数一:el 指向U.UF.P.page这个域 参数二:el1 点击中间页码的元素
  2469. U.UF.P.centerEle = function (el, el1) {
  2470. U.UF.P.apply(el.fPage, [el1, _pagesum, fun], el)(); //执行点击中间页码的功能
  2471. }
  2472. _nextEle.onclick = U.UF.P.apply(this.fPage, [_nextEle, _pagesum, fun], this); //下一页功能
  2473. _lastEle.onclick = U.UF.P.apply(this.fPage, [_lastEle, _pagesum, fun], this); //尾页功能
  2474. _rightEle.onclick = U.UF.P.apply(this.fPage, [_rightEle, _pagesum, fun, _input], this); //跳页功能
  2475. _input.onkeyup = function () { //做一个键盘按下的功能
  2476. if (event.keyCode == "13") { //判断是否是回车键
  2477. _rightEle.onclick(); //如果是回车键,则 执行确定按钮功能
  2478. }
  2479. }
  2480. },
  2481. /*
  2482. ** 作用:用于首页 上一页 下一页 尾页 输入框跳转 点击中间页码数的功能实现
  2483. ** @param {element} el 获取当前元素
  2484. ** @param {number} pagesum 总页数
  2485. ** @param {function} fun 回调函数
  2486. ** @param {element} input 获取输入框的元素
  2487. */
  2488. fPage: function (el, pagesum, fun, input) {
  2489. _el1 = el.pid; //获取点击元素的pid,用于判断是首页 上一页 下一页 尾页 输入框跳转 点击中间页码数的功能
  2490. _el = _el1.charAt(_el1.length - 1); //截取pid最后一个数字,用于判断是首页 上一页 下一页 尾页 输入框跳转 点击中间页码数的功能
  2491. if (_el == 5) { //判断是否是点击中间页码
  2492. _list = U.selectEl($(el).Parent()).Parent().children[2].children; //获取点击中间页码的该元素的所有页码元素
  2493. } else if (_el == 6) { //判断是否是确定或者是回车按钮的点击
  2494. _list = U.selectEl($(el).Parent()).Parent().children[0].children[2].children; //获取确定或回车按钮的点击的该元素的所有页码元素
  2495. } else { //如果既不是中间页码,也不是回车或者是确定按钮的点击
  2496. _list = U.selectEl(el).Parent().children[2].children; //获取该元素所有的页码元素
  2497. }
  2498. U.selectEl(".U_MD_F_Y_Button_Active", U.selectEl(el).Parent(3)).removeClass("U_MD_F_Y_Button_Active"); //清空所有页码的点击样式
  2499. if (_el == 1) { //pid为1时,执行首页的功能
  2500. if (this.Index == 0) { this.Index++ } //判断当前索引是否为0,如果是 则执行索引++
  2501. if (this.PageNum > 1) { //判断当前页数是否大于1
  2502. U.selectEl(_list[0]).addClass("U_MD_F_Y_Button_Active");
  2503. this.Index = 0; //获取索引为0
  2504. this.PageNum = 1 //获取当前页数为1
  2505. this.pagefun(this.PageNum, _list, el); //执行页码跳转功能
  2506. fun(this.PageNum); //执行数据的跳转 this.PageNum 当前页数
  2507. return;
  2508. }
  2509. U.selectEl(_list[--this.Index]).addClass("U_MD_F_Y_Button_Active");
  2510. } else if (_el == 2) { //pid为2时,执行尾页功能
  2511. if (this.PageNum < this.Pageall) { //判断当前页码是否小于总页数
  2512. this.Index = pagesum; //获取索引值为总页数
  2513. this.PageNum = this.Pageall; //获取全局变量的当前页为总页数
  2514. this.pagefun(this.PageNum, _list, el); //执行页码跳转功能
  2515. fun(this.PageNum); //执行数据的跳转 this.PageNum 当前页数
  2516. return
  2517. } else {
  2518. U.selectEl(_list[this.Index]).addClass("U_MD_F_Y_Button_Active");
  2519. }
  2520. } else if (_el == 3) { //pid为3时,执行上一页功能
  2521. if (this.Index > 0) { //判断当前索引是否大于0
  2522. U.selectEl(_list[--this.Index]).addClass("U_MD_F_Y_Button_Active"); //获取当前页的上一个页码的点击样式
  2523. this.PageNum--; //并且当前页减一
  2524. this.pagefun(this.PageNum, _list, el); //执行页码跳转功能
  2525. fun(this.PageNum); //执行数据的跳转 this.PageNum 当前页数
  2526. return
  2527. } else { // 判断第一页
  2528. U.selectEl(_list[this.Index]).addClass("U_MD_F_Y_Button_Active");
  2529. }
  2530. } else if (_el == 4) { //pid为4时,执行下一页功能
  2531. if (this.PageNum < this.Pageall) { //判断当前页码是否小于总页数
  2532. U.selectEl(_list[++this.Index]).addClass("U_MD_F_Y_Button_Active"); //获取当前页的下一个页码的点击样式
  2533. this.PageNum++; //并且当前页码加一
  2534. this.pagefun(this.PageNum, _list, el); //执行页码跳转功能
  2535. fun(this.PageNum); //执行数据的跳转 this.PageNum 当前页数
  2536. return
  2537. } else { // 判断最后一页
  2538. U.selectEl(_list[this.Index]).addClass("U_MD_F_Y_Button_Active"); //获取最后一页的点击样式
  2539. }
  2540. } else if (_el == 5) { //pid为5时,执行点击中间页码跳转功能
  2541. this.pagefun(el, _list, el); //执行页码跳转功能
  2542. fun(this.PageNum); //执行数据的跳转 this.PageNum 当前页数
  2543. return
  2544. } else if (_el == 6) { //pid为6时,执行输入框功能
  2545. var _number = new RegExp("^[0-9]*$") //写一个正则表达式,只能够输入数字
  2546. if (input.value.match(_number)) { //判断输入的是否是数字
  2547. if (input.value >= 1 && input.value <= this.Pageall) { //判断输入的数字是否大于等于1,并且,输入的数字小于等于总页数
  2548. this.PageNum = input.value; //输入的值为当前页码数
  2549. this.pagefun(this.PageNum, _list, el); //执行页码跳转功能
  2550. fun(this.PageNum); //执行数据的跳转 this.PageNum 当前页数
  2551. } else { //如果输入的不是数字
  2552. U.alert("无效的输入"); //则弹窗提示
  2553. U.selectEl(_list[this.Index]).addClass("U_MD_F_Y_Button_Active"); //并且点击样式不改变
  2554. }
  2555. }
  2556. }
  2557. },
  2558. /*
  2559. ** 作用:用于首页、上一页、下一页、尾页、输入框、点击页码进行页码跳转的功能
  2560. ** @param {element} el 当前页码数
  2561. */
  2562. pagefun: function (el, list, pel) {
  2563. var _list = list; //获取所有的中间页码数
  2564. var elNum = parseInt(el.innerHTML) || el; // 获取当前点击页码
  2565. U.selectEl(".U_MD_F_Y_Button_Active", pel).removeClass("U_MD_F_Y_Button_Active"); //清空所有的中间页码数的点击样式
  2566. var _listLength = Math.ceil(_list.length / 2); // 获取页码长度的一半
  2567. var Index; // 记录点击时的页码的索引
  2568. var preIndex = this.Index; // 上一个页码索引
  2569. var difference = null; // 计算当前页码跟所点击的页码的差异
  2570. var lastPage = parseInt($(_list)[$(_list).length - 1].innerText); // 当前页码的最后一个数的页码
  2571. //判断当前点击页码是否小于页码长度的一半,或者当前点击页码大于当前页码的最后一个数的页码减去页码长度的一半并且当前点击页码小于等于总页码数
  2572. if (!(elNum < _listLength || (elNum > this.Pageall - _listLength && elNum <= this.Pageall))) { //这里有个取反
  2573. // 点击页码中间以后的页码处理 例如 1 2 3 4 .... 8 9 则 5以后的页码点击处理事件
  2574. //判断当前页码的最后一个数除以当前点击页码,向上取整,是否小于当前页码的最后一个数减去当前点击页码,并且索引值不为0
  2575. if (!(Math.ceil(lastPage / elNum) < lastPage - elNum) && this.Index != 0) { //这里有一个取反
  2576. difference = elNum - parseInt(_list[_listLength - 1].innerText); // 计算差异
  2577. [].__proto__.forEach.apply($(_list), [function (value, index, ar) { //forEach循环数组,循环所有获取到的中间页码数,并且获取数组中的每一个元素的索引
  2578. value.innerText = parseInt(value.innerText) + difference; // 跟中间的值进行比较
  2579. }])
  2580. this.Index = _listLength - 1; // 记录索引
  2581. } else {
  2582. // 向页码中间以前的页码点击处理事件
  2583. difference = elNum - parseInt(_list[_listLength - 1].innerText); //计算当前页码跟所点击的页码的差异
  2584. [].__proto__.forEach.apply($(_list), [function (value, index, ar) { //forEach循环数组,循环所有获取到的中间页码数,并且获取数组中的每一个元素的索引
  2585. value.innerText = parseInt(value.innerText) + difference; // 跟中间的值进行比较
  2586. }])
  2587. this.Index = _listLength - 1; // 记录索引
  2588. }
  2589. } else if (elNum > this.Pageall - _listLength && elNum <= this.Pageall) { // 最大页码设置
  2590. var elthis = this;
  2591. [].__proto__.forEach.apply($(_list), [
  2592. function (value, index, ar) { //forEach循环数组,循环所有获取到的中间页码数,并且获取数组中的每一个元素的索引
  2593. value.innerText = elthis.Pageall + 1 - ar.length + index;
  2594. }
  2595. ])
  2596. } else if (elNum < _listLength) { // 最小页码设置
  2597. [].__proto__.forEach.apply($(_list), [function (value, index, ar) { //forEach循环数组,循环所有获取到的中间页码数,并且获取数组中的每一个元素的索引
  2598. value.innerText = index + 1; // 跟中间的值进行比较
  2599. }])
  2600. }
  2601. // 页码点击处理事件
  2602. [].__proto__.forEach.apply(_list, [function (value, index, ar) { //forEach循环数组,循环所有获取到的中间页码数,并且获取数组中的每一个元素的索引
  2603. if (parseInt(value.innerHTML) == elNum) { //判断循环出来的元素的值是否为当前点击页码
  2604. Index = index;
  2605. } //获取索引
  2606. }])
  2607. this.Index = Index; //获取当前索引
  2608. this.PageNum = elNum; // 修改当前页数
  2609. U.selectEl(_list[this.Index]).addClass("U_MD_F_Y_Button_Active"); //并且点击样式不改变
  2610. }
  2611. }
  2612. ///<jscompress sourcefile="Picture.js" />
  2613. Namespace.register("U.MD.UI.picture");
  2614. /**
  2615. * 图片控件调用接口函数
  2616. * @arr {Array || Object} 图片信息数组
  2617. * 形如:
  2618. * ['//img/1.jpg',
  2619. * '//img/2.jpg',
  2620. * '//img/3.jpg',
  2621. * '//img/4.jpg',
  2622. * '//img/5.jpeg',
  2623. * '//img/6.jpg']
  2624. */
  2625. U.MD.UI.picture = function (arr, startPicNum) {
  2626. if ($('#U_MD_UI_PictureForm')[0]) { /*判断窗体是否存在*/
  2627. if ($('#U_MD_UI_PictureForm')[0].style.display === 'none') /*重新将窗体显示到页面中*/
  2628. U.selectEl('#U_MD_UI_PictureForm')[0].style.display = 'block';
  2629. U.MD.UI.picture.DIVBOX = {
  2630. "USERPICS": arr,
  2631. "PICAREA": U.selectEl('#U_MD_UI_Picture_picArea')[0],
  2632. /*获取拖拽的元素*/
  2633. "PICBOX": U.selectEl('#U_MD_UI_Picture_picBox')[0],
  2634. /*获取控件最外层元素*/
  2635. 'FA': U.selectEl('#U_MD_UI_Picture_fa')[0] /*获取功能栏目元素*/
  2636. };
  2637. U.MD.UI.picture.initloadPic(arr, startPicNum)
  2638. return;
  2639. }
  2640. if (!arr.length)
  2641. return
  2642. U.MD.UI.picture.create(arr, startPicNum); /*创建控件的内容*/
  2643. U.MD.UI.picture.DIVBOX.PICAREA.onmousedown = function (e) { U.MD.UI.picture.mDown(U.MD.UI.picture.DIVBOX.PICAREA, U.MD.UI.picture.DIVBOX.PICBOX, e) }
  2644. U.MD.UI.picture.wheel(); /*定义滚轮事件*/
  2645. }
  2646. /*定义功能栏目的图片*/
  2647. U.MD.UI.picture.FA = [
  2648. { src: "/img/pictureView/add.png", id: "U_MD_UI_Picture_add" }, //放大按钮图片素材
  2649. { src: "/img/pictureView/narrow.png", id: "U_MD_UI_Picture_narrow" }, //缩小按钮图片素材
  2650. { src: "/img/pictureView/prev.png", id: "U_MD_UI_Picture_prev" }, //上一张按钮图片素材
  2651. { src: "/img/pictureView/next.png", id: "U_MD_UI_Picture_next" }, //下一张按钮图片素材
  2652. { src: "/img/pictureView/turnLeft.png", id: "U_MD_UI_Picture_turnLeft" }, //左旋转按钮图片素材
  2653. { src: "/img/pictureView/turnRight.png", id: "U_MD_UI_Picture_turnRight" } //右旋转按钮图片素材
  2654. ];
  2655. U.MD.UI.picture.picnumber = 0; /*定义图片数*/
  2656. U.MD.UI.picture.rotatenum = 0; /*定义旋转数*/
  2657. U.MD.UI.picture.originalSize = [] /*定义原始图片尺寸大小的数组*/
  2658. U.MD.UI.picture.pics = []; /*定义存放图片的数组*/
  2659. U.MD.UI.picture.scalingvalue = 50; /*定义缩放大小单位:px*/
  2660. U.MD.UI.picture.focuspicsrc = ''; /*当前图片的src*/
  2661. U.MD.UI.picture.focuspicsize = ''; /*当前图片的文件大小*/
  2662. /**
  2663. * 图片控件创建函数
  2664. * @arr {Array || Object} 图片信息数组
  2665. */
  2666. U.MD.UI.picture.create = function (arr, startPicNum) {
  2667. var _c = $$('div', { style: { height: "100%", "overflow": "hidden" }, id: "U_MD_UI_Picture_bossBox" }); /*创建控件最外层元素*/
  2668. var _box = $$('div', { id: "U_MD_UI_Picture_picBox", className: 'U_MD_UI_Picture_picBox' }, _c);
  2669. $$('div', { id: 'U_MD_UI_Picture_picArea', className: 'U_MD_UI_Picture_picArea' }, _box); /*创建控件第二层元素,也是拖拽时所要触发的元素*/
  2670. var _functionalarea = $$('div', { style: { height: "60px", width: "100%", position: "absolute", bottom: "0", "background-color": "#ffffff", "text-align": "center" }, id: "U_MD_UI_Picture_fa" }, _c); /*创建控件的功能栏目*/
  2671. new U.UF.UI.form(
  2672. "<span id='U_MD_UI_Picture_imgInfo'></span> - <span id='U_MD_UI_Picture_r'>100%</span>",
  2673. _c, { style: { width: document.documentElement.clientWidth / 1.5 + 'px', height: document.documentElement.clientHeight / 1.5 + 'px', position: "absolute" }, id: "U_MD_UI_PictureForm" }, { isdrag: true, isstretching: true, isenlarge: true, isclose: true, isnarrow: true }, { style: { "padding": "10px", "background-color": "#22508c" } }
  2674. ); /*调用窗体*/
  2675. _box.style.height = _box.clientHeight - 60 + 'px'; /*让可拖拽区域的宽-60px*/
  2676. // 全局属性
  2677. U.MD.UI.picture.DIVBOX = {
  2678. "USERPICS": arr,
  2679. "PICAREA": U.selectEl('#U_MD_UI_Picture_picArea')[0],
  2680. /*获取拖拽的元素*/
  2681. "PICBOX": U.selectEl('#U_MD_UI_Picture_picBox')[0],
  2682. /*获取控件最外层元素*/
  2683. 'FA': U.selectEl('#U_MD_UI_Picture_fa')[0] /*获取功能栏目元素*/
  2684. };
  2685. /*创建功能栏目子节点*/
  2686. var _oDiv = $$('div', { style: { display: "inline-block", "line-height": "40px", "margin-top": "10px" } }, U.MD.UI.picture.DIVBOX.FA);
  2687. /*循环功能栏目里面的图片*/
  2688. for (var j = 0; j < U.MD.UI.picture.FA.length; j++) {
  2689. /*创建span*/
  2690. var _span = $$('span', { style: { "background-image": "url(" + U.MD.UI.picture.FA[j].src + ")", width: "40px", height: "40px", display: "inline-block", margin: "0 15px" }, id: U.MD.UI.picture.FA[j].id }, _oDiv);
  2691. }
  2692. U.MD.UI.picture.initloadPic(null, startPicNum);
  2693. /*给上放大的点击事件*/
  2694. U.selectEl('#U_MD_UI_Picture_add')[0].onclick = U.UF.C.apply(this, function () {
  2695. this.changeSize(U.MD.UI.picture.scalingvalue, U.MD.UI.picture.rotatenum)
  2696. });
  2697. /*给上缩小的点击事件*/
  2698. U.selectEl('#U_MD_UI_Picture_narrow')[0].onclick = U.UF.C.apply(this, function () {
  2699. this.changeSize(-U.MD.UI.picture.scalingvalue, U.MD.UI.picture.rotatenum)
  2700. });
  2701. /*给上上一张图片的点击事件*/
  2702. U.selectEl('#U_MD_UI_Picture_prev')[0].onclick = U.UF.C.apply(this, function () {
  2703. this.prevPic(0)
  2704. });
  2705. /*给上下一张图片的点击事件*/
  2706. U.selectEl('#U_MD_UI_Picture_next')[0].onclick = U.UF.C.apply(this, function () {
  2707. this.prevPic(1)
  2708. });
  2709. /*给上左旋转的点击事件*/
  2710. U.selectEl('#U_MD_UI_Picture_turnLeft')[0].onclick = U.UF.C.apply(this, function () {
  2711. this.turn(1)
  2712. });
  2713. /*给上有旋转的点击事件*/
  2714. U.selectEl('#U_MD_UI_Picture_turnRight')[0].onclick = U.UF.C.apply(this, function () {
  2715. this.turn(0)
  2716. });
  2717. _c.onresize = function () {
  2718. _box.style.height = _c.clientHeight - 60 + 'px';
  2719. };
  2720. _box.onresize = function () {
  2721. U.MD.UI.picture.checkHeight();
  2722. }
  2723. }
  2724. U.MD.UI.picture.initloadPic = function (arr, startPicNum) {
  2725. if (arr) {
  2726. U.MD.UI.picture.DIVBOX.PICAREA.innerHTML = "";
  2727. U.MD.UI.picture.DIVBOX.PICAREA.style = null;
  2728. U.MD.UI.picture.picnumber = startPicNum || 0; /*定义图片数*/
  2729. U.MD.UI.picture.rotatenum = 0; /*定义旋转数*/
  2730. U.MD.UI.picture.DIVBOX.USERPICS = arr
  2731. } else {
  2732. U.MD.UI.picture.picnumber = startPicNum >= 0 ? startPicNum : 0;
  2733. }
  2734. //调用创建方法
  2735. U.MD.UI.picture.createPic();
  2736. /*获取所有的图片并赋值*/
  2737. U.MD.UI.picture.pics = U.selectEl('#U_MD_UI_Picture_picArea > ul > li > img');
  2738. U.MD.UI.picture.pics[U.MD.UI.picture.picnumber].onload = U.UF.C.apply(this, function () {
  2739. /*获取当前图片的原始大小并赋值*/
  2740. this.originalSize = this.getImgNaturalDimensions(U.MD.UI.picture.pics[U.MD.UI.picture.picnumber]);
  2741. /*调整大小,位置*/
  2742. this.checkHeight();
  2743. });
  2744. }
  2745. U.MD.UI.picture.createPic = function () {
  2746. /*创建ul*/
  2747. var _ul = $$('ul', { id: "ul" }, U.MD.UI.picture.DIVBOX.PICAREA);
  2748. /*循环数据源*/
  2749. for (var i = 0; i < U.MD.UI.picture.DIVBOX.USERPICS.length; i++) {
  2750. /*创建li*/
  2751. var _li = $$('li', {}, _ul);
  2752. if (typeof U.MD.UI.picture.DIVBOX.USERPICS[i] === 'object') {
  2753. /*如果是第一张,初始化控件一般都是第一张显示*/
  2754. if (i === U.MD.UI.picture.picnumber) {
  2755. $$('img', { "onerror": U.MD.C.imgError, src: U.MD.UI.picture.DIVBOX.USERPICS[i].src }, _li);
  2756. U.MD.UI.picture.focuspicsrc = U.MD.UI.picture.DIVBOX.USERPICS[i].src;
  2757. if (U.MD.UI.picture.DIVBOX.USERPICS[i].size)
  2758. U.MD.UI.picture.focuspicsize = U.MD.UI.picture.DIVBOX.USERPICS[i].size;
  2759. } else {
  2760. $$('img', { "onerror": U.MD.C.imgError, src: U.MD.UI.picture.DIVBOX.USERPICS[i].src, style: { display: "none" } }, _li);
  2761. }
  2762. } else if (typeof U.MD.UI.picture.DIVBOX.USERPICS[i] === 'string') {
  2763. if (i === U.MD.UI.picture.picnumber) {
  2764. /*如果是第一张,初始化控件一般都是第一张显示*/
  2765. $$('img', { "onerror": U.MD.C.imgError, src: U.MD.UI.picture.DIVBOX.USERPICS[i] }, _li);
  2766. U.MD.UI.picture.focuspicsrc = U.MD.UI.picture.DIVBOX.USERPICS[i];
  2767. } else {
  2768. $$('img', { "onerror": U.MD.C.imgError, src: U.MD.UI.picture.DIVBOX.USERPICS[i], style: { display: "none" } }, _li);
  2769. }
  2770. }
  2771. }
  2772. }
  2773. /**
  2774. * 旋转检测
  2775. * @param num 为整数
  2776. * 如果是0也就是false,调用右旋转。如果是1也就是true,调用左旋转。因为有万恶的ie8,所以要滤镜旋转 0-0°,1-90°,2-180°,3-270°,如果需要任意角度旋转去学习阵矩。
  2777. *
  2778. */
  2779. U.MD.UI.picture.turn = function (num) {
  2780. /*判断是左旋,还是右旋,为什么要这么打应该晓得吧*/
  2781. if (num) {
  2782. U.MD.UI.picture.rotatenum--;
  2783. U.MD.UI.picture.rotatenum < 0 ? U.MD.UI.picture.rotatenum = 3 : U.MD.UI.picture.rotatenum;
  2784. } else {
  2785. U.MD.UI.picture.rotatenum++;
  2786. U.MD.UI.picture.rotatenum > 3 ? U.MD.UI.picture.rotatenum = 0 : U.MD.UI.picture.rotatenum;
  2787. }
  2788. U.MD.UI.picture.rotating();
  2789. }
  2790. /**
  2791. * 执行旋转
  2792. */
  2793. U.MD.UI.picture.rotating = function () {
  2794. /*定义常规游览器旋转属性字符*/
  2795. var val = "rotate(" + U.MD.UI.picture.rotatenum * 90 + "deg)";
  2796. /*U.MD.UI.picture.rotatenum % 2 !== 0 判断是否选转90°或者270°*/
  2797. if (U.MD.UI.picture.rotatenum % 2 !== 0) {
  2798. /*赋值大小,-20px是为了留间隙*/
  2799. U.MD.UI.picture.DIVBOX.PICAREA.style.width = U.MD.UI.picture.DIVBOX.PICBOX.clientHeight - 20 + 'px';
  2800. /*开始旋转*/
  2801. U.MD.UI.picture.compatibleRotate(U.MD.UI.picture.DIVBOX.PICAREA, val);
  2802. /*调整位置*/
  2803. U.MD.UI.picture.DIVBOX.PICAREA.style.top = (U.MD.UI.picture.DIVBOX.PICAREA.clientWidth / 2 - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight / 2) + 10 + 'px';
  2804. /*调整位置,以至于中心缩放*/
  2805. U.MD.UI.picture.DIVBOX.PICAREA.style.left = U.MD.UI.picture.DIVBOX.PICBOX.clientWidth / 2 - U.MD.UI.picture.DIVBOX.PICAREA.clientWidth / 2 + 'px';
  2806. /*检测是否是ie8 or ie7*/
  2807. if ((navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i) == "8.") || (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/7./i) == "7.")) {
  2808. U.MD.UI.picture.DIVBOX.PICAREA.style.top = "10px";
  2809. U.MD.UI.picture.DIVBOX.PICAREA.style.left = U.MD.UI.picture.DIVBOX.PICBOX.clientWidth / 2 - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight / 2 + 'px';
  2810. }
  2811. } else {
  2812. /*清空拖拽元素的style*/
  2813. U.MD.UI.picture.DIVBOX.PICAREA.setAttribute('style', '');
  2814. /*开始旋转*/
  2815. U.MD.UI.picture.compatibleRotate(U.MD.UI.picture.DIVBOX.PICAREA, val);
  2816. /*改变长度*/
  2817. U.MD.UI.picture.DIVBOX.PICAREA.style.width = U.MD.UI.picture.originalSize[0] > U.MD.UI.picture.DIVBOX.PICAREA.clientWidth + 150 ? '1290px' : U.MD.UI.picture.DIVBOX.PICAREA.clientWidth + 150;
  2818. /*调整图片大小*/
  2819. U.MD.UI.picture.checkHeight();
  2820. }
  2821. /*改变左上角的title的缩放比*/
  2822. U.selectEl('#U_MD_UI_Picture_r')[0].innerText = Math.round((U.MD.UI.picture.DIVBOX.PICAREA.clientHeight / U.MD.UI.picture.originalSize[1]) * 100) + '%';
  2823. }
  2824. /**
  2825. * 兼容旋转
  2826. * @param el 旋转的元素
  2827. * @param val 旋转的属性值
  2828. */
  2829. U.MD.UI.picture.compatibleRotate = function (el, val) {
  2830. //定义属性
  2831. el.style.webkitTransform = val;
  2832. el.style.MozTransform = val;
  2833. el.style.mturnsTransform = val;
  2834. el.style.OTransform = val;
  2835. el.style.transform = val;
  2836. /*检测是否是ie8 or ie7*/
  2837. if ((navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i) == "8.") || (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/7./i) == "7."))
  2838. el.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(rotation=" + Math.abs(U.MD.UI.picture.rotatenum) + ")";
  2839. }
  2840. /**
  2841. * 图片切换
  2842. * @param num 整数orTRUE,FALSE
  2843. * true代表下一张,false代表上一张
  2844. */
  2845. U.MD.UI.picture.prevPic = function (num) {
  2846. /*在切换图片先把正在显示的图片隐藏掉*/
  2847. U.MD.UI.picture.pics[U.MD.UI.picture.picnumber].style.display = 'none';
  2848. if (num) {
  2849. /*图片位置数++*/
  2850. U.MD.UI.picture.picnumber++;
  2851. /*如果是最后一张,跳到第一张*/
  2852. if (U.MD.UI.picture.picnumber > U.MD.UI.picture.pics.length - 1)
  2853. U.MD.UI.picture.picnumber = 0;
  2854. } else {
  2855. /*图片位置数--*/
  2856. U.MD.UI.picture.picnumber--;
  2857. /*如果是第一张,跳到最后一张*/
  2858. if (U.MD.UI.picture.picnumber < 0)
  2859. U.MD.UI.picture.picnumber = U.MD.UI.picture.pics.length - 1;
  2860. }
  2861. if (U.MD.UI.picture.DIVBOX.USERPICS[U.MD.UI.picture.picnumber].size)
  2862. U.MD.UI.picture.focuspicsize = U.MD.UI.picture.DIVBOX.USERPICS[U.MD.UI.picture.picnumber].size;
  2863. if (U.MD.UI.picture.DIVBOX.USERPICS[U.MD.UI.picture.picnumber].src)
  2864. U.MD.UI.picture.focuspicsrc = U.MD.UI.picture.DIVBOX.USERPICS[U.MD.UI.picture.picnumber].src;
  2865. /*显示需要显示的图片*/
  2866. U.MD.UI.picture.pics[U.MD.UI.picture.picnumber].style.display = 'block';
  2867. /*获取该图片的初始大小*/
  2868. U.MD.UI.picture.originalSize = U.MD.UI.picture.getImgNaturalDimensions(U.MD.UI.picture.pics[U.MD.UI.picture.picnumber]);
  2869. /*清空拖拽元素的style值*/
  2870. U.MD.UI.picture.DIVBOX.PICAREA.setAttribute('style', '');
  2871. /*调整大小,位置*/
  2872. U.MD.UI.picture.checkHeight();
  2873. /*旋转数初始0*/
  2874. U.MD.UI.picture.rotatenum = 0;
  2875. }
  2876. /**
  2877. * 功能:调整图片的大小,图片居中显示,改变左上角的title缩放比例
  2878. */
  2879. U.MD.UI.picture.checkHeight = function () {
  2880. /*长宽比例*/
  2881. var _proportion = U.MD.UI.picture.originalSize[0] / U.MD.UI.picture.originalSize[1];
  2882. /*如果原始图片的宽比显示框的宽要大,进行调整*/
  2883. if (U.MD.UI.picture.originalSize[1] > U.MD.UI.picture.DIVBOX.PICBOX.clientHeight - 40 || U.MD.UI.picture.originalSize[0] > U.MD.UI.picture.DIVBOX.PICBOX.clientWidth) {
  2884. /*-40px上下留白*/
  2885. U.MD.UI.picture.DIVBOX.PICAREA.style.width = Math.floor((U.MD.UI.picture.DIVBOX.PICBOX.clientHeight - 40) * _proportion) + 'px';
  2886. } else {
  2887. /*原比例显示*/
  2888. U.MD.UI.picture.DIVBOX.PICAREA.style.width = U.MD.UI.picture.originalSize[0] + 'px';
  2889. //U.MD.UI.picture.DIVBOX.PICAREA.style.height = U.MD.UI.picture.originalSize[1] + 'px';
  2890. }
  2891. /*居中显示*/
  2892. U.MD.UI.picture.DIVBOX.PICAREA.style.left = (U.MD.UI.picture.DIVBOX.PICBOX.clientWidth - U.MD.UI.picture.DIVBOX.PICAREA.clientWidth) / 2 + 'px';
  2893. U.MD.UI.picture.DIVBOX.PICAREA.style.top = (U.MD.UI.picture.DIVBOX.PICBOX.clientHeight - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight) / 2 + 'px';
  2894. if (typeof U.MD.UI.picture.DIVBOX.USERPICS[0] === 'object')
  2895. U.selectEl('#U_MD_UI_Picture_imgInfo')[0].innerText = U.MD.UI.picture.focuspicsrc.toLowerCase().split('/').splice(-1)[0] + "(" + U.MD.UI.picture.originalSize[0] + "*" + U.MD.UI.picture.originalSize[1] + "px " + U.MD.UI.picture.focuspicsize + ")";
  2896. else if (typeof U.MD.UI.picture.DIVBOX.USERPICS[0] === 'string')
  2897. U.selectEl('#U_MD_UI_Picture_imgInfo')[0].innerText = U.MD.UI.picture.DIVBOX.USERPICS[U.MD.UI.picture.picnumber].toLowerCase().split('/').splice(-1)[0] + "(" + U.MD.UI.picture.originalSize[0] + "*" + U.MD.UI.picture.originalSize[1] + "px)";
  2898. U.selectEl('#U_MD_UI_Picture_r')[0].innerText = Math.round((U.MD.UI.picture.DIVBOX.PICAREA.clientHeight / U.MD.UI.picture.originalSize[1]) * 100) + '%';
  2899. }
  2900. /**
  2901. * 获取图片的原来的大小
  2902. * @param img
  2903. * @returns {*[]} 返回值1:原始长度,值2:原始宽度
  2904. */
  2905. U.MD.UI.picture.getImgNaturalDimensions = function (img) {
  2906. var nWidth, nHeight;
  2907. if (img.naturalWidth) { // 现代浏览器
  2908. nWidth = img.naturalWidth;
  2909. nHeight = img.naturalHeight
  2910. } else { // IE6/7/8
  2911. var image = new Image();
  2912. image.src = img.src;
  2913. nWidth = image.width;
  2914. nHeight = image.height;
  2915. }
  2916. return [nWidth, nHeight]
  2917. }
  2918. /**
  2919. * 拖拽
  2920. * @param dragEl 拖拽的元素
  2921. * @param bossEl 拖拽限制的范围元素
  2922. */
  2923. U.MD.UI.picture.drag = function (dragEl, bossEl) {
  2924. dragEl.onmousedown = function (e) {
  2925. U.MD.UI.picture.mDown(dragEl, bossEl, e)
  2926. }
  2927. }
  2928. /**
  2929. * 点击图片所触发的事件
  2930. * @param {[object]} dragEl [拖拽的元素]
  2931. * @param {[object]} bossEl [拖拽限制的范围元素]
  2932. * @param {[event]} e []
  2933. */
  2934. U.MD.UI.picture.mDown = function (dragEl, bossEl, e) {
  2935. e = e || window.event;
  2936. /*定义拖拽元素到父级的X距离*/
  2937. var _distanceX = e.clientX - dragEl.offsetLeft;
  2938. /*定义拖拽元素到父级的Y距离*/
  2939. var _distanceY = e.clientY - dragEl.offsetTop;
  2940. bossEl.onmousemove = function (e) {
  2941. U.MD.UI.picture.mMove(dragEl, bossEl, _distanceX, _distanceY, e);
  2942. }
  2943. /*鼠标放开,移除事件*/
  2944. bossEl.onmouseup = function (e) {
  2945. bossEl.onmousemove = null;
  2946. bossEl.onmouseup = null;
  2947. };
  2948. /*禁用默认事件*/
  2949. if (e.preventDefault) {
  2950. /*常规游览器*/
  2951. e.preventDefault();
  2952. } else {
  2953. /*ie8*/
  2954. dragEl.ondragstart = function () {
  2955. return false;
  2956. };
  2957. dragEl.onselectstart = function () {
  2958. return false;
  2959. };
  2960. }
  2961. }
  2962. /**
  2963. * 点击拖动图片时触发的事件
  2964. * @param {[object]} dragEl [拖拽的元素]
  2965. * @param {[object]} bossEl [拖拽限制的范围元素]
  2966. * @param {[object]} _distanceX [拖拽元素到父级的X距离]
  2967. * @param {[object]} _distanceY [拖拽元素到父级的Y距离]
  2968. * @param {[event]} e []
  2969. */
  2970. U.MD.UI.picture.mMove = function (dragEl, bossEl, _distanceX, _distanceY, e) {
  2971. e = e || window.event;
  2972. /*移动距离*/
  2973. var _left = e.clientX - _distanceX,
  2974. _top = e.clientY - _distanceY;
  2975. /*判断是否是最顶部,默认显示窗体宽的1/8*/
  2976. _left = U.MD.UI.picture.rotatenum % 2 === 0 ? Math.min(bossEl.clientWidth - bossEl.clientWidth / 8, _left) : Math.min(bossEl.clientWidth - bossEl.clientWidth / 8 - dragEl.clientWidth / 2 + dragEl.clientHeight / 2, _left);
  2977. /*判断是否是最底部,默认显示窗体宽的1/8*/
  2978. _left = U.MD.UI.picture.rotatenum % 2 === 0 ? Math.max(-dragEl.clientWidth + bossEl.clientWidth / 8, _left) : Math.max(-dragEl.clientWidth + bossEl.clientWidth / 8 + dragEl.clientWidth / 2 - dragEl.clientHeight / 2, _left);
  2979. /*判断是否是最左部,默认显示窗体长的1/8*/
  2980. _top = U.MD.UI.picture.rotatenum % 2 === 0 ? Math.min(bossEl.clientHeight - bossEl.clientHeight / 8, _top) : Math.min(bossEl.clientHeight - bossEl.clientHeight / 8 + (dragEl.clientWidth - dragEl.clientHeight) / 2, _top);
  2981. /*判断是否是最右部,默认显示窗体长的1/8*/
  2982. _top = U.MD.UI.picture.rotatenum % 2 === 0 ? Math.max(-dragEl.clientHeight + bossEl.clientHeight / 8, _top) : Math.max(-dragEl.clientHeight + bossEl.clientHeight / 8 - (dragEl.clientWidth - dragEl.clientHeight) / 2, _top);
  2983. /*赋值*/
  2984. dragEl.style.left = _left + 'px';
  2985. dragEl.style.top = _top + 'px';
  2986. }
  2987. /**
  2988. * 滚轮事件
  2989. */
  2990. U.MD.UI.picture.wheel = function () {
  2991. U.MD.UI.picture.DIVBOX.PICBOX.onmousewheel = function () {
  2992. this.getWheelDalta()
  2993. }.bind(this);
  2994. }
  2995. /**
  2996. * 滚轮事件
  2997. * @param e
  2998. */
  2999. U.MD.UI.picture.getWheelDalta = function (e) {
  3000. e = e || window.event;
  3001. var delta = 0;
  3002. // delta的返回值为正时,表示向前滚动;delta的返回值为负时,表示向后滚动;
  3003. if (e.wheelDelta) {
  3004. // IE中,鼠标滚轮信息存放在wheelDelta属性中;向前滚动时,wheelDelta的值是120的倍数;向后滚动时,wheelDelta的值是-120的倍数;
  3005. delta = e.wheelDelta / 120;
  3006. if (window.opera) delta = -delta;
  3007. } else if (e.detail) {
  3008. // Firefox的鼠标滚轮信息存放在detail属性中;向前滚动,detail的值是-3的倍数;向后滚动,detail的值是3的倍数;
  3009. delta = -e.detail / 3;
  3010. }
  3011. // 执行滚轮事件函数
  3012. if (delta > 0) {
  3013. U.MD.UI.picture.changeSize(U.MD.UI.picture.scalingvalue);
  3014. } else {
  3015. U.MD.UI.picture.changeSize(-U.MD.UI.picture.scalingvalue);
  3016. }
  3017. // 阻止默认行为,防止当页面本身就存在滚动条时出现的异常
  3018. prevent(event);
  3019. function prevent(evt) {
  3020. if (evt.preventDefault) {
  3021. evt.preventDefault();
  3022. } else {
  3023. evt.returnValue = false;
  3024. }
  3025. }
  3026. }
  3027. /**
  3028. * 改变图片大小
  3029. * @param multiple 缩放大小
  3030. */
  3031. U.MD.UI.picture.changeSize = function (multiple) {
  3032. /*添加缩放后, 添加缩放前的宽, 添加缩放前的长*/
  3033. var _addOver, _afterH, _afterW;
  3034. /*赋值*/
  3035. _afterH = U.MD.UI.picture.DIVBOX.PICAREA.clientHeight;
  3036. _afterW = U.MD.UI.picture.DIVBOX.PICAREA.clientWidth;
  3037. _addOver = U.MD.UI.picture.DIVBOX.PICAREA.clientWidth + multiple;
  3038. /*最小缩放长400px*/
  3039. if ((_addOver / U.MD.UI.picture.originalSize[0]) * 100 < 20 && _addOver < 200) {
  3040. return;
  3041. } else if (((U.MD.UI.picture.DIVBOX.PICAREA.clientHeight + multiple) / U.MD.UI.picture.originalSize[1]) * 100 > 1000) { /*最大缩放1000%*/
  3042. return
  3043. }
  3044. /*赋值长*/
  3045. U.MD.UI.picture.DIVBOX.PICAREA.style.width = _addOver + 'px';
  3046. /*中心缩放*/
  3047. U.MD.UI.picture.DIVBOX.PICAREA.style.top = U.MD.UI.picture.DIVBOX.PICAREA.offsetTop - (U.MD.UI.picture.DIVBOX.PICAREA.clientHeight - _afterH) / 2 + 'px';
  3048. U.MD.UI.picture.DIVBOX.PICAREA.style.left = U.MD.UI.picture.DIVBOX.PICAREA.offsetLeft - multiple / 2 + 'px';
  3049. /*ie8,7,中心缩放位移*/
  3050. if (((navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i) == "8.") || (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/7./i) == "7.")) && U.MD.UI.picture.rotatenum % 2 !== 0) {
  3051. U.MD.UI.picture.DIVBOX.PICAREA.style.left = U.MD.UI.picture.DIVBOX.PICBOX.clientWidth / 2 - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight / 2 + 'px';
  3052. U.MD.UI.picture.DIVBOX.PICAREA.style.top = U.MD.UI.picture.DIVBOX.PICBOX.clientHeight / 2 - U.MD.UI.picture.DIVBOX.PICAREA.clientWidth / 2 + 'px';
  3053. }
  3054. /*下面都是防止缩放时偏移到窗体外面*/
  3055. var topY = U.MD.UI.picture.DIVBOX.PICAREA.clientHeight + U.MD.UI.picture.DIVBOX.PICAREA.offsetTop <= U.MD.UI.picture.DIVBOX.PICBOX.clientHeight / 8 ||
  3056. ((U.MD.UI.picture.DIVBOX.PICAREA.clientWidth - (U.MD.UI.picture.DIVBOX.PICAREA.clientWidth - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight) / 2 + U.MD.UI.picture.DIVBOX.PICAREA.offsetTop <= U.MD.UI.picture.DIVBOX.PICBOX.clientHeight / 8) && U.MD.UI.picture.rotatenum % 2 !== 0),
  3057. bottomY = U.MD.UI.picture.DIVBOX.PICAREA.offsetTop >= U.MD.UI.picture.DIVBOX.PICBOX.clientHeight - U.MD.UI.picture.DIVBOX.PICBOX.clientHeight / 8 ||
  3058. ((Math.abs(U.MD.UI.picture.DIVBOX.PICBOX.clientHeight - (U.MD.UI.picture.DIVBOX.PICAREA.clientWidth - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight) / 2 - U.MD.UI.picture.DIVBOX.PICAREA.offsetTop) <= U.MD.UI.picture.DIVBOX.PICBOX.clientHeight / 8) && U.MD.UI.picture.rotatenum % 2 !== 0),
  3059. leftX = U.MD.UI.picture.DIVBOX.PICAREA.clientWidth + U.MD.UI.picture.DIVBOX.PICAREA.offsetLeft <= U.MD.UI.picture.DIVBOX.PICBOX.clientWidth / 8 ||
  3060. (U.MD.UI.picture.DIVBOX.PICAREA.clientHeight + (U.MD.UI.picture.DIVBOX.PICAREA.offsetLeft + (U.MD.UI.picture.DIVBOX.PICAREA.clientWidth - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight) / 2 - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight / 2) <= U.MD.UI.picture.DIVBOX.PICBOX.clientWidth / 8 && U.MD.UI.picture.rotatenum % 2 !== 0),
  3061. rightX = U.MD.UI.picture.DIVBOX.PICAREA.offsetLeft >= U.MD.UI.picture.DIVBOX.PICBOX.clientWidth - U.MD.UI.picture.DIVBOX.PICBOX.clientWidth / 8 ||
  3062. ((U.MD.UI.picture.DIVBOX.PICBOX.clientWidth - (U.MD.UI.picture.DIVBOX.PICAREA.clientWidth - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight) / 2 - U.MD.UI.picture.DIVBOX.PICAREA.offsetLeft) <= U.MD.UI.picture.DIVBOX.PICBOX.clientWidth / 8 && U.MD.UI.picture.rotatenum % 2 !== 0);
  3063. if (topY) {
  3064. if (U.MD.UI.picture.rotatenum % 2 === 0) {
  3065. U.MD.UI.picture.DIVBOX.PICAREA.style.top = U.MD.UI.picture.DIVBOX.PICAREA.offsetTop + (_afterH - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight) / 2 + 'px';
  3066. } else {
  3067. U.MD.UI.picture.DIVBOX.PICAREA.style.top = U.MD.UI.picture.DIVBOX.PICAREA.offsetTop + (_afterW - U.MD.UI.picture.DIVBOX.PICAREA.clientWidth) / 2 + 'px';
  3068. }
  3069. }
  3070. if (bottomY) {
  3071. if (U.MD.UI.picture.rotatenum % 2 === 0) {
  3072. U.MD.UI.picture.DIVBOX.PICAREA.style.top = U.MD.UI.picture.DIVBOX.PICAREA.offsetTop - (_afterH - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight) / 2 + 'px';
  3073. } else {
  3074. U.MD.UI.picture.DIVBOX.PICAREA.style.top = U.MD.UI.picture.DIVBOX.PICAREA.offsetTop - (_afterW - U.MD.UI.picture.DIVBOX.PICAREA.clientWidth) / 2 + 'px';
  3075. }
  3076. }
  3077. if (leftX) {
  3078. if (U.MD.UI.picture.rotatenum % 2 === 0) {
  3079. U.MD.UI.picture.DIVBOX.PICAREA.style.left = U.MD.UI.picture.DIVBOX.PICAREA.offsetLeft + (_afterW - U.MD.UI.picture.DIVBOX.PICAREA.clientWidth) / 2 + 'px';
  3080. } else {
  3081. U.MD.UI.picture.DIVBOX.PICAREA.style.left = U.MD.UI.picture.DIVBOX.PICAREA.offsetLeft + (_afterH - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight) / 2 + 'px';
  3082. }
  3083. }
  3084. if (rightX) {
  3085. if (U.MD.UI.picture.rotatenum % 2 === 0) {
  3086. U.MD.UI.picture.DIVBOX.PICAREA.style.left = U.MD.UI.picture.DIVBOX.PICAREA.offsetLeft - (_afterW - U.MD.UI.picture.DIVBOX.PICAREA.clientWidth) / 2 + 'px';
  3087. } else {
  3088. U.MD.UI.picture.DIVBOX.PICAREA.style.left = U.MD.UI.picture.DIVBOX.PICAREA.offsetLeft - (_afterH - U.MD.UI.picture.DIVBOX.PICAREA.clientHeight) / 2 + 'px';
  3089. }
  3090. }
  3091. U.selectEl('#U_MD_UI_Picture_r')[0].innerText = Math.floor((U.MD.UI.picture.DIVBOX.PICAREA.clientWidth / U.MD.UI.picture.originalSize[0]) * 100) + '%';
  3092. };
  3093. ///<jscompress sourcefile="Video.js" />
  3094. Namespace.register("U.MD.UI.video"); //注册命名空间
  3095. /**
  3096. * 创建视频
  3097. * @param src 资源地址
  3098. * @param width 视频宽度
  3099. * @param height 视频高度
  3100. * @param autoplay 是否自动播放
  3101. * @param parent 生成在哪个元素
  3102. */
  3103. U.MD.UI.video = function (src, width, height, autoplay, parent) {
  3104. var _autoplay = autoplay || false; //检测自动播放
  3105. var _intervalTemp = null; //用于记录interval的值
  3106. var _volumeTemp = null; //用于记录临时音量(静音与取消静音用)
  3107. var _moving = false; //记录是否有移动
  3108. var _tempHeight = ""; //全屏恢复的临时高度
  3109. var _tempWidth = ""; //全屏恢复的临时宽度
  3110. var _fullscreen = false; //记录是否处于全屏状态
  3111. /*生成元素*/
  3112. var _els = U.MD.UI.video.appendEle(src, width, height, _autoplay, parent);
  3113. /*添加事件*/
  3114. U.MD.UI.video.addEvent(_els, _intervalTemp, _volumeTemp, _moving, height, width, _fullscreen);
  3115. return _els;
  3116. };
  3117. /**
  3118. * 生成元素
  3119. * @param src 视频资源地址
  3120. * @param width 视频宽度
  3121. * @param height 视频高度
  3122. * @param autoplay 是否自动播放
  3123. * @param parent 父元素
  3124. */
  3125. U.MD.UI.video.appendEle = function (src, width, height, autoplay, parent) {
  3126. var els = {};
  3127. //包括视频和控制器的大div
  3128. els.videoDiv = $$("div", { "className": "U_MD_UI_video_VideoDiv", "style": { "width": width + "px", "height": height + "px" } }, parent);
  3129. //视频主体
  3130. els.video = $$("video", {
  3131. "src": src, //视频资源地址
  3132. "className": "U_MD_UI_video_VideoMain", //视频class
  3133. "autoplay": autoplay, //是否自动播放
  3134. "preload": "auto" //是否预加载(默认自动)
  3135. }, els.videoDiv);
  3136. //控制器主体
  3137. els.controls = $$("div", { "className": "U_MD_UI_video_VideoControls" }, els.videoDiv);
  3138. //暂停/播放按钮
  3139. els.playPauseBtn = $$("div", { "className": "U_MD_UI_video_PlayPauseButton U_MD_UI_video_PlayIcon" }, els.controls);
  3140. //显示当前时间的div
  3141. els.currentTimeDiv = $$("div", { "className": "U_MD_UI_video_Time", "innerHTML": "00:00" }, els.controls);
  3142. //进度条
  3143. els.progress = $$("div", { "className": "U_MD_UI_video_Progress" }, els.controls);
  3144. //进度条实际进度
  3145. els.progressCurrentTime = $$("div", { "className": "U_MD_UI_video_ProgressCurrentTime" }, els.progress);
  3146. //进度条上的圆点
  3147. els.progressCircle = $$("div", { "className": "U_MD_UI_video_ProgressCircle" }, els.progressCurrentTime);
  3148. //显示实际时间的div
  3149. els.DurationDiv = $$("div", {
  3150. "className": "U_MD_UI_video_Time", //设置class
  3151. "innerHTML": "00:00", //设置默认值
  3152. "onselectstart": "return false;" //禁止选择
  3153. }, els.controls);
  3154. //音量按钮
  3155. els.soundControls = $$("div", { "className": "U_MD_UI_video_SoundControls" }, els.controls);
  3156. //音量
  3157. els.soundProgress = $$("div", { "className": "U_MD_UI_video_SoundProgress" }, els.controls);
  3158. //真实音量
  3159. els.soundProgressCurrent = $$("div", { "className": "U_MD_UI_video_SoundProgressCurrent", "style": { "width": "100%" } }, els.soundProgress); //设置class
  3160. //全屏按钮
  3161. els.fullScreenBtn = $$("div", { "className": "U_MD_UI_video_FullScreen" }, els.controls);
  3162. return els;
  3163. };
  3164. /**
  3165. * 给元素添加事件
  3166. * @param els 传入所有元素
  3167. * @param intervalTemp 传入intervalTemp
  3168. * @param volumeTemp 传入volumeTemp
  3169. * @param moving 传入moving
  3170. * @param tempHeight 传入tempHeight
  3171. * @param tempWidth 传入tempWidth
  3172. * @param fullscreen 传入fullscreen
  3173. */
  3174. U.MD.UI.video.addEvent = function (els, intervalTemp, volumeTemp, moving, tempHeight, tempWidth, fullscreen) {
  3175. //给暂停/播放按钮添加事件
  3176. els.playPauseBtn.onclick = function (event) {
  3177. U.MD.UI.playPauseBtnClick(event, els);
  3178. };
  3179. if (els.videoDiv.onwebkitfullscreenchange !== undefined) { //设置全屏状态事件(webkit)
  3180. els.videoDiv.onwebkitfullscreenchange = function () {
  3181. var rtn = U.MD.UI.video.fullscreenChange(fullscreen, tempHeight, tempWidth, els);
  3182. fullscreen = rtn[0];
  3183. tempHeight = rtn[1];
  3184. tempWidth = rtn[2];
  3185. }
  3186. } else if (els.videoDiv.onfullscreenchange !== undefined) { //设置全屏状态事件(w3)
  3187. els.videoDiv.onfullscreenchange = function () {
  3188. var rtn = U.MD.UI.video.fullscreenChange(fullscreen, tempHeight, tempWidth, els); //设置全屏状态事件(w3)
  3189. fullscreen = rtn[0];
  3190. tempHeight = rtn[1];
  3191. tempWidth = rtn[2];
  3192. }
  3193. } else if (els.videoDiv.onmozfullscreenchange !== undefined) { //设置全屏状态事件(moz)
  3194. els.videoDiv.onmozfullscreenchange = function () {
  3195. var rtn = U.MD.UI.video.fullscreenChange(fullscreen, tempHeight, tempWidth, els);
  3196. fullscreen = rtn[0];
  3197. tempHeight = rtn[1];
  3198. tempWidth = rtn[2];
  3199. }
  3200. }
  3201. /**
  3202. * 全屏按钮单击事件
  3203. */
  3204. els.fullScreenBtn.onclick = function () {
  3205. U.MD.UI.video.fullscreenClick(fullscreen, els);
  3206. };
  3207. /**
  3208. * 进度条圆点按下事件
  3209. * @param event 按下事件
  3210. */
  3211. els.progressCircle.onmousedown = function (event) {
  3212. U.MD.UI.video.circleMove(event, moving, els);
  3213. };
  3214. /**
  3215. * 音量条鼠标按下事件
  3216. * @param event 事件
  3217. */
  3218. els.soundProgress.onmousedown = function (event) {
  3219. U.MD.UI.video.soundProgressMove(event, els, moving); //执行soundProgressMove函数
  3220. };
  3221. /**
  3222. * 进度条鼠标按下事件
  3223. * @param event 事件
  3224. */
  3225. els.progress.onmousedown = function (event) {
  3226. U.MD.UI.video.progressMove(event, els, moving); //进度条按下移动函数(点击进度条除圆点以外的地方)
  3227. };
  3228. /**
  3229. * 视频暂停事件,用于设置暂停按钮与停止刷新
  3230. */
  3231. els.video.onpause = function () {
  3232. els.playPauseBtn.className = "U_MD_UI_video_PlayPauseButton U_MD_UI_video_PlayIcon"; //设置暂停按钮的icon(修改class)
  3233. clearInterval(intervalTemp); //清除刷新的interval
  3234. };
  3235. /**
  3236. * 视频播放事件,用于设置播放按钮与启动刷新
  3237. */
  3238. els.video.onplay = function () {
  3239. els.playPauseBtn.className = "U_MD_UI_video_PlayPauseButton U_MD_UI_video_PauseIcon"; //设置开始按钮的icon(修改class)
  3240. intervalTemp = U.MD.UI.video.setInterval(moving, els); //启动刷新
  3241. };
  3242. /**
  3243. * 视频可以播放,刷新数据
  3244. */
  3245. els.video.oncanplay = function () {
  3246. U.MD.UI.video.flushInfo(moving, els.currentTimeDiv, els.DurationDiv, els.progressCurrentTime, els.soundProgressCurrent, els.video); //刷新信息
  3247. };
  3248. /**
  3249. * 静音按钮事件函数
  3250. */
  3251. els.soundControls.onclick = function () {
  3252. volumeTemp = U.MD.UI.video.muteClick(els, volumeTemp, moving);
  3253. };
  3254. /**
  3255. * 控制栏显示/隐藏控制
  3256. */
  3257. els.videoDiv.onclick = function () {
  3258. //U.MD.UI.video.displayControls(event, els);
  3259. };
  3260. };
  3261. /**
  3262. * 让控制栏可以隐藏
  3263. * @param event 视频点击事件
  3264. * @param els 元素集合
  3265. */
  3266. U.MD.UI.video.displayControls = function (event, els) {
  3267. var _target = event.target; //获取目标
  3268. if (_target === els.video || _target === els.videoDiv) { //判断目标点击后是否可以隐藏/显示
  3269. if (els.controls.style.display === "none") { //如果已设置隐藏状态则显示
  3270. els.controls.style.display = "block";
  3271. } else { //否则隐藏控制栏
  3272. els.controls.style.display = "none";
  3273. }
  3274. }
  3275. };
  3276. U.MD.UI.playPauseBtnClick = function (event, els) {
  3277. var _el = event.target; //获取到按钮本身
  3278. if (_el.className === "U_MD_UI_video_PlayPauseButton U_MD_UI_video_PlayIcon") { //暂停状态
  3279. els.video.play(); //开始播放
  3280. } else { //播放状态
  3281. els.video.pause(); //暂停播放
  3282. }
  3283. };
  3284. /**
  3285. * 静音按钮
  3286. * @param els 元素集合
  3287. * @param volumeTemp 临时记录音量
  3288. * @param moving 记录是否正在移动(刷新数据用)
  3289. * @returns {*} 返回volumeTemp
  3290. */
  3291. U.MD.UI.video.muteClick = function (els, volumeTemp, moving) {
  3292. if (els.video.volume !== 0) { //音量非零,静音
  3293. volumeTemp = els.video.volume; //记录当前音量
  3294. els.video.volume = 0; //静音
  3295. U.MD.UI.video.flushInfo(moving, els.currentTimeDiv, els.DurationDiv, els.progressCurrentTime, els.soundProgressCurrent, els.video); //刷新信息
  3296. } else if (els.video.volume === 0 && volumeTemp !== null) { //如果音量等于0(即静音),且用户没有按过静音键
  3297. els.video.volume = volumeTemp; //设置音量
  3298. volumeTemp = null; //将变量值重置
  3299. U.MD.UI.video.flushInfo(moving, els.currentTimeDiv, els.DurationDiv, els.progressCurrentTime, els.soundProgressCurrent, els.video); //刷新信息
  3300. }
  3301. return volumeTemp; //返回volumeTemp
  3302. };
  3303. /**
  3304. * 全屏按钮点击事件
  3305. * @param fullscreen 是否全屏
  3306. * @param els 元素集合
  3307. */
  3308. U.MD.UI.video.fullscreenClick = function (fullscreen, els) {
  3309. if (!fullscreen) { //如果没全屏
  3310. if (els.videoDiv.requestFullScreen) { //请求全屏(w3)
  3311. els.videoDiv.requestFullScreen(); //请求全屏(w3)
  3312. } else if (els.videoDiv.webkitRequestFullScreen) { //请求全屏(webkit)
  3313. els.videoDiv.webkitRequestFullScreen(); //请求全屏(webkit)
  3314. } else if (els.videoDiv.mozRequestFullScreen) { //请求全屏(moz)
  3315. els.videoDiv.mozRequestFullScreen(); //请求全屏(moz)
  3316. }
  3317. } else { //如果已全屏
  3318. if (document.exitFullScreen) { //取消全屏(w3)
  3319. document.exitFullScreen(); //取消全屏(w3)
  3320. } else if (document.webkitCancelFullScreen) { //取消全屏(webkit)
  3321. document.webkitCancelFullScreen(); //取消全屏(webkit)
  3322. } else if (document.webkitExitFullscreen) { //取消全屏(webkit)
  3323. document.webkitExitFullscreen(); //取消全屏(webkit)
  3324. } else if (document.mozExitFullScreen) { //取消全屏(moz)
  3325. document.mozExitFullScreen(); //取消全屏(moz)
  3326. }
  3327. }
  3328. };
  3329. /**
  3330. * 全屏状态改变事件
  3331. * @param fullscreen 记录是否全屏
  3332. * @param tempHeight 临时高度
  3333. * @param tempWidth 临时宽度
  3334. * @param els 元素集合
  3335. * @returns {*[]} 返回部分改变后的变量
  3336. */
  3337. U.MD.UI.video.fullscreenChange = function (fullscreen, tempHeight, tempWidth, els) {
  3338. if (!fullscreen) { //如果没全屏,则进行全屏准备操作
  3339. //tempHeight = els.videoDiv.offsetHeight + "px";//备份视频div高度
  3340. //tempWidth = els.videoDiv.offsetWidth + "px";//备份视频div宽度
  3341. els.videoDiv.style.height = "100vh"; //100vh为覆盖整个页面
  3342. els.videoDiv.style.width = "100vw"; //100vw为覆盖整个页面
  3343. els.videoDiv.style.position = "absolute"; //将视频设置绝对定位
  3344. els.videoDiv.style.top = "0"; //移动到最上
  3345. els.videoDiv.style.left = "0"; //移动到最左
  3346. els.videoDiv.style.zIndex = "999"; //设置zIndex最高
  3347. } else { //退出全屏
  3348. els.videoDiv.style.height = tempHeight + "px"; //恢复高度
  3349. els.videoDiv.style.width = tempWidth + "px"; //恢复宽度
  3350. els.videoDiv.style.position = ""; //清除绝对定位
  3351. els.videoDiv.style.top = ""; //清除top属性
  3352. els.videoDiv.style.left = ""; //清除left属性
  3353. els.videoDiv.style.zIndex = ""; //清除zIndex属性
  3354. }
  3355. fullscreen = !fullscreen; //设置全屏状态
  3356. return [fullscreen, tempHeight, tempWidth];
  3357. };
  3358. /**
  3359. * 时间格式化(数字秒转换成00:00的格式)
  3360. * @param time 待转换的时间(秒) 例:30
  3361. * @returns {string} 返回的时间 例:00:30
  3362. */
  3363. U.MD.UI.video.timeFormat = function (time) {
  3364. var _sec = parseInt(time % 60); //计算秒
  3365. var _min = parseInt(parseInt(time) / 60); //计算分钟
  3366. (_sec < 10) ? _sec = "0" + _sec : _sec; //秒补零
  3367. (_min < 10) ? _min = "0" + _min : _min; //分钟补零
  3368. return _min + ":" + _sec; //返回生成的时间
  3369. };
  3370. /**
  3371. * 刷新数据
  3372. * @param moving 是否正在移动(用于判断要不要刷新)
  3373. * @param currentTimeDiv 当前时间元素
  3374. * @param DurationDiv 视频总长度元素
  3375. * @param progressCurrentTime 进度条当前长度
  3376. * @param soundProgressCurrent 音量当前长度
  3377. * @param video 视频元素
  3378. */
  3379. U.MD.UI.video.flushInfo = function (moving, currentTimeDiv, DurationDiv, progressCurrentTime, soundProgressCurrent, video) {
  3380. if (moving) return; //如果在拖动则不刷新
  3381. currentTimeDiv.innerHTML = U.MD.UI.video.timeFormat(video.currentTime); //当前时间刷新
  3382. DurationDiv.innerHTML = U.MD.UI.video.timeFormat(video.duration); //视频总长度刷新
  3383. progressCurrentTime.style.width = video.currentTime / video.duration * 100 + "%"; //进度条刷新
  3384. soundProgressCurrent.style.width = video.volume * 100 + "%"; //音量刷新
  3385. };
  3386. /**
  3387. * 获取当前元素左边到屏幕最左边的距离
  3388. * @param el 元素
  3389. * @returns {number} 返回距离(不包括单位)
  3390. */
  3391. U.MD.UI.video.getScreenLeft = function (el) {
  3392. var _rtnLeft = el.offsetLeft; //定义一个左边长度
  3393. var _parent = el.offsetParent; //定义这个元素的父元素
  3394. while (_parent != null) { //如果父元素不为空,则进入循环
  3395. _rtnLeft += _parent.offsetLeft; //记录左边距离
  3396. _parent = _parent.offsetParent; //重新定义父元素
  3397. }
  3398. return _rtnLeft; //返回距离
  3399. };
  3400. /**
  3401. * 循环刷新信息
  3402. * @param _moving 是否正在移动
  3403. * @param _els 元素
  3404. * @returns {number} interval
  3405. */
  3406. U.MD.UI.video.setInterval = function (_moving, _els) {
  3407. return setInterval(function () { //设置定时器
  3408. U.MD.UI.video.flushInfo(_moving, _els.currentTimeDiv, _els.DurationDiv, _els.progressCurrentTime, _els.soundProgressCurrent, _els.video); //刷新信息
  3409. }, 500); //每半秒刷新一次
  3410. };
  3411. /**
  3412. * 进度条(圆点)移动事件函数
  3413. * @param event 鼠标按下事件
  3414. * @param moving 是否正在移动
  3415. * @param els 元素
  3416. */
  3417. U.MD.UI.video.circleMove = function (event, moving, els) { //进度条移动函数(圆点)
  3418. moving = true; //设置移动状态
  3419. var _e = event; //读取event
  3420. var _content = event.currentTarget; //获取目标
  3421. var _startX = _e.pageX; //设置一个开始的x点
  3422. var _currentProgress = _content.parentElement; //获取当前进度条元素
  3423. var _progress = _currentProgress.parentElement; //获取进度条元素
  3424. els.videoDiv.onmousemove = function (e) {
  3425. if (e.pageX - U.MD.UI.video.getScreenLeft(_progress) < 0 || e.pageX - U.MD.UI.video.getScreenLeft(_progress) > _progress.offsetWidth) { //如果鼠标位置不在有效范围内则不继续
  3426. return;
  3427. }
  3428. var _iL = e.pageX - _startX; //移动的距离
  3429. //根据实际进度与进度条长度对比进行判断
  3430. if (!(_currentProgress.offsetWidth + _iL > _progress.offsetWidth || _currentProgress.offsetWidth + _iL < 0) && (e.currentTarget.children[0].offsetWidth <= e.currentTarget.children[0].offsetWidth)) {
  3431. //设置进度条位置
  3432. _currentProgress.style.width = (_currentProgress.offsetWidth + _iL) / _progress.offsetWidth * 100 + "%";
  3433. //设置视频位置
  3434. els.video.currentTime = (_currentProgress.offsetWidth + _iL) / _progress.offsetWidth * els.video.duration;
  3435. }
  3436. _startX = e.pageX; //重置开始的x点
  3437. };
  3438. els.videoDiv.onmouseup = function () { //清除事件
  3439. moving = false; //恢复移动状态
  3440. els.videoDiv.onmousemove = function () { //清除移动事件
  3441. };
  3442. els.videoDiv.onmouseup = function () { //清除mouseup事件
  3443. };
  3444. };
  3445. };
  3446. /**
  3447. * 声音进度条拖动函数
  3448. * @param event 事件
  3449. * @param els 元素集合
  3450. * @param moving 是否正在移动
  3451. */
  3452. U.MD.UI.video.soundProgressMove = function (event, els, moving) { //注释见move函数
  3453. event.preventDefault(); //取消事件的默认动作
  3454. var _e = event; //声明event
  3455. var _content = event.currentTarget; //获取soundprogress
  3456. var _startX = _e.pageX; //设置一个开始的x点
  3457. var _currentSound = els.soundProgressCurrent; //当前的音量条元素
  3458. var _x = event.offsetX; //获取现在鼠标相对于音量条的x点
  3459. var _length = _content.offsetWidth; //获取音量条的长度
  3460. els.video.volume = _x / _length; //设置视频音量
  3461. U.MD.UI.video.flushInfo(moving, els.currentTimeDiv, els.DurationDiv, els.progressCurrentTime, els.soundProgressCurrent, els.video); //刷新信息
  3462. /**
  3463. * mousemove函数
  3464. * @param e 事件
  3465. */
  3466. els.videoDiv.onmousemove = function (e) {
  3467. if (e.pageX - U.MD.UI.video.getScreenLeft(els.soundProgress) < 0 || e.pageX - U.MD.UI.video.getScreenLeft(els.soundProgress) > els.soundProgress.offsetWidth) { //如果鼠标位置不在有效范围内则不继续
  3468. return; //返回
  3469. }
  3470. var _iL = e.pageX - _startX; //移动的长度
  3471. if (!(_currentSound.offsetWidth + _iL > _content.offsetWidth || _currentSound.offsetWidth + _iL < 0)) { //判断是否应该移动
  3472. _currentSound.style.width = (_currentSound.offsetWidth + _iL) / _content.offsetWidth * 100 + "%"; //设置样式(进度条长度)
  3473. els.video.volume = _currentSound.offsetWidth / _content.offsetWidth; //设置音量
  3474. }
  3475. _startX = e.pageX; //重置开始的x点
  3476. };
  3477. els.videoDiv.onmouseup = function (e) {
  3478. els.videoDiv.onmousemove = function () { //清除mousemove事件
  3479. };
  3480. els.videoDiv.onmouseup = function () { //清除mouseup事件
  3481. };
  3482. };
  3483. };
  3484. /**
  3485. * 进度条拖动函数
  3486. * @param event 事件
  3487. * @param els 元素集合
  3488. * @param moving 是否正在移动
  3489. */
  3490. U.MD.UI.video.progressMove = function (event, els, moving) { //部分注释见move函数
  3491. event.preventDefault(); //清除默认事件
  3492. if (event.target.className === "U_MD_UI_video_ProgressCircle") { //如果class是圆点的话返回
  3493. return;
  3494. }
  3495. var _e = event; //记录event
  3496. var _content = event.currentTarget; //获取进度条元素
  3497. var _startX = _e.pageX; //定义起点
  3498. var _currentProgress = els.progressCurrentTime; //定义进度条(当前)元素
  3499. var _x = event.layerX || event.offsetX; //鼠标点击的点
  3500. var _length = _content.offsetWidth; //进度条长度
  3501. els.video.currentTime = els.video.duration * (_x / _length); //计算出百分比并设置时间
  3502. U.MD.UI.video.flushInfo(moving, els.currentTimeDiv, els.DurationDiv, els.progressCurrentTime, els.soundProgressCurrent, els.video); //刷新信息
  3503. els.videoDiv.onmousemove = function (e) { //鼠标移动事件
  3504. if (e.pageX - U.MD.UI.video.getScreenLeft(els.progress) < 0 || e.pageX - U.MD.UI.video.getScreenLeft(els.progress) > els.progress.offsetWidth) { //鼠标不在范围内则不继续
  3505. return;
  3506. }
  3507. moving = true; //设置移动状态
  3508. var _iL = e.pageX - _startX; //移动的长度
  3509. if (!(_currentProgress.offsetWidth + _iL > els.progress.offsetWidth || _currentProgress.offsetWidth + _iL < 0)) { //判断加上移动距离后是否合理
  3510. _currentProgress.style.width = (_currentProgress.offsetWidth + _iL) / els.progress.offsetWidth * 100 + "%"; //设置当前进度条的样式(宽度)
  3511. els.video.currentTime = (_currentProgress.offsetWidth + _iL) / els.progress.offsetWidth * els.video.duration; //设置视频现在播放时间
  3512. }
  3513. _startX = e.pageX; //重新设置开始的点
  3514. };
  3515. els.videoDiv.onmouseup = function () { //鼠标点击事件
  3516. moving = false; //设置移动状态
  3517. U.MD.UI.video.flushInfo(moving, els.currentTimeDiv, els.DurationDiv, els.progressCurrentTime, els.soundProgressCurrent, els.video); //刷新信息
  3518. els.videoDiv.onmousemove = function () { //清除事件
  3519. };
  3520. els.videoDiv.onmouseup = function () { //清除事件
  3521. };
  3522. };
  3523. };
  3524. ;