Xtiper

Xtiper 是一款整合 PC 、移动端的弹层弹窗(甚至还有弹幕)解决方案。采用原生的 javascript 编写,体积小,不依赖任何 js 库,不加载任何图片,使用方便。

当前为 2022-08-14 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/449512/1081247/Xtiper.js

  1. (function(){
  2. let cssResource = `@charset "utf-8";
  3. html, body {overflow-x:hidden;}
  4. body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,code,pre,form,fieldset,legend,input,button,textarea,area,blockquote,th,td,p {margin:0; padding:0;}
  5. .xtiper {position:relative;}
  6. .xtiper_msg {transition-duration:0.2s; transition-timing-function:ease-out; transition-property:transform,opacity;}
  7. .xtiper_msg {max-width:752px; position:fixed; left:50%; height:50px; line-height:50px; font-size:14px; border-radius:3px; overflow:hidden; z-index:99999; opacity:0; box-shadow:0 0 10px rgba(0,0,0,0.2);}
  8. .xtiper_msg_black {background-color:rgba(0,0,0,0.75); color:#fff;}
  9. .xtiper_msg_white {background-color:rgba(255,255,255,0.95); color:#222;}
  10. .xtiper_msg_middle {top:50%; margin-top:-25px; transform:scale(0,0);}
  11. .xtiper_msg_top {transform:translate(0, -100%) scale(1, 1); top:0;}
  12. .xtiper_msg_bottom {transform:translate(0, 100%) scale(1, 1); bottom:0;}
  13. .xtiper_msg.xon {opacity:1;}
  14. .xtiper_msg_middle.xon {transform:scale(1,1);}
  15. .xtiper_msg_top.xon {transform:translate(0, 0) scale(1, 1);}
  16. .xtiper_msg_bottom.xon {transform:translate(0, 0) scale(1, 1);}
  17. .xtiper_msg p {padding:0 24px; word-spacing:nowrap;}
  18. .xtiper_danmu {border:3px solid transparent; left:0; transition-property:none; opacity:1; background-origin:content-box; font-size:16px; font-weight:bold;}
  19. .xtiper_danmu_animate {animation:danmu_animate 6s 1 linear; -webkit-animation:danmu_animate 6s 1 linear;}
  20. .xtiper_danmu_light {border:3px solid red;}
  21.  
  22. @keyframes danmu_animate
  23. {
  24. 100% {transform:translateX(-102%);}
  25. }
  26.  
  27. .xtiper_tips {position:absolute; z-index:99999; max-width:200px; opacity:0; transform:scale(0,0); transition-duration:0.1s; transition-timing-function:ease-in; transition-property:opacity,transform; box-shadow:0 0 5px rgba(0,0,0,0.3);}
  28. .xtiper_tips.xon {transition-duration:0.2s; opacity:1; transform:scale(1,1);}
  29. .xtiper_tips p {padding:10px 16px; background-color:#000; border-radius:3px; color:#fff; line-height:18px; font-size:12px; position:relative; z-index:2;}
  30. .xtiper_tips em {display:block; position:absolute; width:10px; height:10px; background-color:#000; transform: rotate(45deg); box-shadow:0 0 5px rgba(0,0,0,0.3); z-index:1;}
  31. .xtiper_tips_left em {top:12px; right:-4px;}
  32. .xtiper_tips_right em {top:12px; left:-4px;}
  33. .xtiper_tips_top em {left:12px; bottom:-4px;}
  34. .xtiper_tips_bottom em {left:12px; top:-4px;}
  35.  
  36. .xtiper_win {z-index:99999;}
  37. .xtiper_win_fixed {width:100%; height:100%; position:fixed; top:0; left:0; z-index:99999;}
  38. .xtiper_bg {width:100%; height:100%; position:absolute; top:0; left:0; z-index:1; background-color:rgba(0,0,0,0); transition-duration:0.1s; transition-timing-function:ease-in; transition-property:background-color,opacity;}
  39. .xtiper_bg.xmin {display:none;}
  40. .xtiper_bg_white {background-color:rgba(255,255,255,0); transition:0.05s ease-in;}
  41. .xtiper_win.xon .xtiper_bg {background-color:rgba(0,0,0,0.5);}
  42. .xtiper_win.xon .xtiper_bg_white {background-color:rgba(255,255,255,0.5); transition:0.05s ease-in;}
  43. .xtiper_main {width:300px; background-color:#fff; position:absolute; box-shadow:0 0 10px rgba(0,0,0,0.2); z-index:2; opacity:0; transition-duration:0.15s; transition-timing-function:ease-in; transition-property:opacity,transform; transform:scale(0,0);}
  44. .xtiper_main.xapp {background-color:transparent;}
  45. .xtiper_main_photo {transition-property:opacity,transform,height,top;}
  46. .xtiper_main_photo.xon {transition-property:opacity,transform,height;}
  47. .xtiper_win.xon .xtiper_main {transform:scale(1,1); opacity:1;}
  48. .xtiper_win.xon .xtiper_main, .xtiper_win.xon .xtiper_bg {transition-duration:0.2s; transition-timing-function:ease-in;}
  49. .xtiper_win.xoff .xtiper_bg {opacity:0;}
  50. .xtiper_win.xoff .xtiper_main {transform:scale(0,0); opacity:0;}
  51. .xtiper_tit {height:40px; line-height:40px; color:#222; font-size:14px; background-color:#f8f8f8; padding:0 18px; position:relative; user-select:none; cursor:move;}
  52. .xtiper_tit:after {content:""; display:block; width:100%; height:1px; background-color:#eee; position:absolute; bottom:0; left:0;}
  53. .xtiper_tit_none {height:8px; background-color:#f0f0f0;}
  54. .xtiper_tit.xminmax {cursor:default;}
  55. .xtiper_tit p {text-overflow:ellipsis; overflow:hidden; white-space:nowrap; margin-right:28px;}
  56. .xtiper_tit.xmcss1 p {margin-right:62px;}
  57. .xtiper_tit.xmcss2 p {margin-right:96px;}
  58. .xtiper_tit.xmin p {margin-right:62px;}
  59.  
  60. .xtiper_minmax {position:absolute; top:5px; right:6px;}
  61. .xtiper_close {z-index:10;}
  62. .xtiper_close, .xtiper_min, .xtiper_max {width:30px; height:30px; cursor:pointer; box-sizing:border-box; margin-right:4px; float:left; background-size:18px; background-repeat:no-repeat; background-position:center center; position:relative;}
  63. .xtiper_minmax div:last-child {margin-right:0;}
  64. .xtiper_close:before, .xtiper_close:after {content:""; display:block; width:14px; height:2px; background-color:#2d2c3b; position:absolute; top:14px; left:8px;}
  65. .xtiper_close:before {transform:rotate(45deg);}
  66. .xtiper_close:after {transform:rotate(-45deg);}
  67. .xtiper_close:hover, .xtiper_min:hover, .xtiper_max:hover {opacity:0.8;}
  68. .xtiper_close:before, .xtiper_close:after {transition-duration:0.2s; transition-timing-function:ease-in; transition-property:transform;}
  69. .xtiper_close:hover:before {transform:rotate(135deg);}
  70. .xtiper_close:hover:after {transform:rotate(45deg);}
  71. .xtiper_close_notit {margin-right:0; background-color:#333; border:3px solid #fff; position:absolute; top:-10px; right:-10px; border-radius:50%; transition-duration:0.2s; transition-timing-function:ease-in; transition-property:background-color;}
  72. .xtiper_close_notit:before, .xtiper_close_notit:after {background-color:#fff; top:11px; left:5px;}
  73. .xtiper_close_notit:hover {opacity:1; background-color:#2b84d0;}
  74. .xtiper_close_notitmin:before, .xtiper_close_notitmin:after {top:7px; left:3px; width:10px;}
  75. .xtiper_close_notitmin {width:20px; height:20px; border-width:2px}
  76. .xtiper_close_photoapp {top:6px; right:6px; background-color:transparent;}
  77. .xtiper_close_photoapp:hover {background-color:transparent;}
  78. .xtiper_close_photoapp:hover:before {transform:rotate(45deg);}
  79. .xtiper_close_photoapp:hover:after {transform:rotate(-45deg);}
  80. .xtiper_close_load {position:absolute; top:0; right:0;}
  81.  
  82. .xtiper_photo {position:relative; overflow:hidden; transition-property:transform,opacity;}
  83. .xtiper_photo_ul {padding:0 60px; height:100%;}
  84. .xtiper_photo_ul ul {height:calc(100% - 26px); position:relative; overflow:hidden;}
  85. .xtiper_photo_li {width:100%; height:100%; position:absolute; top:0; left:0; text-align:center; opacity:0; transform:scale(0, 0); transition-duration:0.3s; transition-timing-function:ease-out; transition-property:transform,opacity;}
  86. .xtiper_photo_li.xon {opacity:1; transform:scale(1, 1);}
  87. .xtiper_photo_li.xold_prev {transform:scale(1, 1) translate(100%, 0);}
  88. .xtiper_photo_li.xold_next {transform:scale(1, 1) translate(-100%, 0);}
  89.  
  90. .xtiper_sheet {width:100%; background-color:#fff; bottom:0; left:0; position:absolute; z-index:2; transition:0.1s ease-in; transition-property:transform; transform:translate(0, 100%);}
  91. .xtiper_sheet_ul, .xtiper_sheet_tit {background-color:#efeff4;}
  92. .xtiper_win.xon .xtiper_sheet {transition:0.2s ease-in; transform:translate(0, 0);}
  93. .xtiper_win.xoff .xtiper_sheet {transform:translateY(100%);}
  94. .xtiper_sheet_left {text-align:left;}
  95. .xtiper_sheet_right {text-align:right;}
  96. .xtiper_sheet_center {text-align:center;}
  97. .xtiper_sheet_tit {padding:15px; font-size:15px; color:#222; line-height:20px; font-weight:bold;}
  98. .xtiper_sheet_li {font-size:14px; height:48px; line-height:48px; background-color:#fff; border-top:1px solid #d9d9d9; cursor:pointer; color:#222; user-select:none; -ms-user-select:none;}
  99. .xtiper_sheet_li a {display:block; width:100%; color:#222; text-decoration:none;}
  100. .xtiper_sheet_li a:hover {color:#222; text-decoration:none;}
  101. .xtiper_sheet_li p {padding:0 15px;}
  102. .xtiper_sheet_li.xlast {margin-top:8px; border-top:0;}
  103.  
  104. .xtiper_min {background-image:url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M949.2 560.2H74.8c-26.6 0-48.2-21.6-48.2-48.2 0-26.6 21.6-48.2 48.2-48.2H949.2c26.6 0 48.2 21.6 48.2 48.2 0 26.6-21.6 48.2-48.2 48.2z' fill='%232d2c3b'/%3E%3C/svg%3E");}
  105. .xtiper_min.xon {margin-right:0; background-image:url("data:image/svg+xml,%3Csvg width='2000' height='2000' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M879.1 783.6h-60.4a34.3 34.3 0 0 1 0-68.6h60.4c14.3 0 26.6-11.8 26.6-26.6V142.6c0-14.3-11.8-26.6-26.6-26.6H332.8c-14.3 0-26.6 11.8-26.6 26.6v60.4a34.3 34.3 0 0 1-68.6 0V142.6c0-52.2 42.5-94.72 94.72-94.7h546.3c52.2 0 94.72 42.5 94.72 94.7v546.3c0.5 52.2-42.5 94.72-94.2 94.7z' fill='%232c2c2c'/%3E%3Cpath d='M708.1 964.3H162.3c-57.9 0-103.9-47.1-103.9-103.9V312.6c0-57.9 47.1-103.9 103.9-103.9h546.3c57.9 0 103.9 47.1 103.9 103.9v546.8c0.5 58.4-46.08 104.96-104.4 104.96zM162.3 276.72c-19.5 0-35.84 16.4-35.84 35.8v546.8c0 19.5 16.4 35.84 35.84 35.84h546.3c19.5 0 35.84-16.4 35.84-35.84V312.6c0-19.5-16.4-35.84-35.84-35.8H162.3z' fill='%232d2c3b'/%3E%3C/svg%3E");}
  106. .xtiper_max {background-image:url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M944.0 0.8H79.1C35.8 0.8 0.3 36.2 0.3 79.4v864.5c0 43.2 35.4 78.6 78.7 78.6h865.9c43.3 0 78.7-35.4 78.7-78.6V79.4C1023.7 36.2 988.3 0.8 944.0 0.8z m0 943.1H79.1V79.4h865.9v864.5z m0 0' fill='%23231814'/%3E%3Cpath d='M342.8 735.7l137.8-137.5c15.7-15.7 15.7-39.3 0-55.0-15.7-15.7-39.4-15.7-55.1 0l-137.8 137.5-90.5-90.4V826.0h236.2l-90.5-90.4z m228.3-243.6c11.8 0 19.7-3.9 27.6-11.8l137.8-137.5 90.5 90.4V197.3H590.7l90.5 90.4-137.8 137.5c-15.7 15.7-15.7 39.3 0 55.0 7.9 7.9 19.7 11.8 27.5 11.8z m0 0' fill='%232d2c3b'/%3E%3C/svg%3E");}
  107. .xtiper_max.xon {background-image:url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M944.0 0.8H79.1C35.8 0.8 0.3 36.2 0.3 79.4v864.5c0 43.2 35.4 78.6 78.7 78.6h865.9c43.3 0 78.7-35.4 78.7-78.6V79.4C1023.7 36.2 988.3 0.8 944.0 0.8z m0 943.1H79.1V79.4h865.9v864.5z m0 0' fill='%23231814'/%3E%3Cpath d='M346.7 621.7l-137.8 137.5c-15.7 15.7-15.7 39.3 0 55.0 15.7 15.7 39.4 15.7 55.1 0l137.8-137.5 90.5 90.4V531.3H256.2l90.5 90.4zM787.5 197.3c-11.8 0-19.7 3.9-27.6 11.8l-137.8 137.5-90.5-90.4v235.8h236.2l-90.5-90.4 137.8-137.5c15.7-15.7 15.7-39.3 0-55.0-7.9-7.9-19.7-11.8-27.5-11.8z' fill='%232d2c3b'/%3E%3C/svg%3E");}
  108. .xtiper_times {color:#e85445;}
  109. .xtiper_pad {padding:15px;}
  110. .xtiper_tip {font-size:14px; line-height:20px; min-height:60px; overflow:hidden;}
  111. .xtiper_btn ul {text-align:center; display:flex; overflow:hidden; border-top:1px solid #eaeaea; background-color:#fff;}
  112. .xtiper_btn ul:after {content:""; display:block; clear:both;}
  113. .xtiper_btn li {float:left; overflow:hidden; position:relative;}
  114. .xtiper_btn li:after {content:""; display:block; width:1px; height:40px; overflow:hidden; position:absolute; top:0; right:0; background-color:#eaeaea;}
  115. .xtiper_btn li.xactive:after {background-color:rgba(255,255,255,0.2);}
  116. .xtiper_btn1 li {width:100%; float:none;}
  117. .xtiper_btn2 li {width:50%;}
  118. .xtiper_btn3 li {width:33.3%; -webkit-box-flex:1; -ms-flex:1; flex:1;}
  119. .xtiper_btn4 li {width:25%; -webkit-box-flex:1; -ms-flex:1; flex:1;}
  120. .xtiper_btn li button {width:100%; height:40px; background-color:#fff; cursor:pointer; color:#222; font-size:14px; border:0;}
  121. .xtiper_btn li.xactive button {color:#fff;}
  122. .xtiper_btn li.xactive button {background-color:#a8a8a8;}
  123. .xtiper_btn_success li.xactive button, .xtiper_btn_hello li.xactive button, .xtiper_btn_success .xtiper_btnbor, .xtiper_btn_hello .xtiper_btnbor {background-color:#37b72c;}
  124. .xtiper_btn_error li.xactive button, .xtiper_btn_error .xtiper_btnbor {background-color:#e75445;}
  125. .xtiper_btn_warning li.xactive button, .xtiper_btn_ask li.xactive button, .xtiper_btn_warning .xtiper_btnbor, .xtiper_btn_ask .xtiper_btnbor {background-color:#f89310;}
  126. .xtiper_btn1 li.xactive button {background-color:#fff; color:#222;}
  127. .xtiper_btn li:last-child:after {display:none;}
  128. .xtiper_btn li button:hover {opacity:0.9;}
  129. .xtiper_btnbor {width:100%; height:4px; overflow:hidden; background-color:#c3c3c3; position:relative;}
  130. .xtiper_btnbor:after {content:""; display:block; width:100%; height:4px; background-color:rgba(0,0,0,0.1); position:absolute; top:0; left:0;}
  131. .xtiper_btn1 .xtiper_btnbor:after {display:none;}
  132. .xtiper_btn2 li:nth-child(2) {opacity:0.92;}
  133. .xtiper_btn3 li:nth-child(1) {opacity:0.84;}
  134. .xtiper_btn3 li:nth-child(2) {opacity:0.92;}
  135. .xtiper_btn4 li:nth-child(1) {opacity:0.76;}
  136. .xtiper_btn4 li:nth-child(2) {opacity:0.84;}
  137. .xtiper_btn4 li:nth-child(3) {opacity:0.92;}
  138. .xtiper_pr {position:relative;}
  139. .xtiper_content {height:100%; overflow:auto; position:relative;}
  140. .xtiper_content.xtit {height:calc(100% - 40px);}
  141. .xtiper_content.xmin {height:calc(100% - 8px);}
  142. .xtiper_over {overflow:hidden;}
  143. .xtiper_content .zw {width:100%; height:100%; overflow:hidden; position:absolute; top:0; left:0; display:none;}
  144. .xtiper_main.xon .xtiper_content .zw {display:block;}
  145. .xtiper_con {padding-top:8px; padding-bottom:12px;}
  146. .xtiper_con_icon {padding-left:42px;}
  147. .xtiper_conin {max-height:400px; overflow-x:hidden; overflow-y:auto;}
  148. .xtiper_conin::-webkit-scrollbar {width:5px;}
  149. .xtiper_conin::-webkit-scrollbar-track {background-color:#f1f1f1; border-radius:3px;}
  150. .xtiper_conin::-webkit-scrollbar-thumb {background-color:#c1c1c1; border-radius:3px;}
  151. .xtiper_loadin {width:34px; height:34px; display:block; position:absolute; top:50%; margin-top:-17px; left:50%; margin-left:-17px; opacity:0; transition:0.1s ease-in; transition-property:opacity; z-index:2;}
  152. .xtiper_loadin span {width:280px; position:absolute; top:36px; left:50%; margin-left:-140px; text-align:center; height:24px; line-height:24px; font-size:14px; color:#222; white-space:nowrap;}
  153. .xtiper_win.xon .xtiper_loadin {opacity:1; transition:0.2s ease-in;}
  154. .xtiper_icon {width:34px; height:34px; display:inline-block; background-size:100% 100%; background-repeat:no-repeat; position:absolute; top:0; left:0; vertical-align:middle;}
  155. .xtiper_icon img {width:34px; height:34px;}
  156. .xtiper_icon_min {width:20px; height:20px; position:static; top:auto; left:auto; transform:translateY(-1px); margin-right:5px;}
  157. .xtiper_icon_min img {width:20px; height:20px;}
  158. .xtiper_icon_success {background-image:url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M512.7 0.1C230.4 0.1 0.8 229.8 0.8 512.1c0 282.3 229.6 511.9 511.0 511.9 282.3 0 511.9-229.6 511.9-511.9C1024.6 229.8 795.0 0.1 512.7 0.1z m0 950.5c-241.8 0-438.5-196.7-438.5-438.5 0-241.8 196.7-438.5 438.5-438.5 241.7 0 438.5 196.6 438.5 438.5-0.0 241.7-196.8 438.5-438.5 438.5z' fill='%2337b72c'/%3E%3Cpath d='M754.8 337.0L470.1 630.1l-178.5-155.2c-15.8-13.7-39.7-12.0-53.4 3.7-13.7 15.8-12.0 39.7 3.7 53.4l205.2 178.4a37.7 37.7 0 0 0 10.9 6.7 37.8 37.8 0 0 0 15.9 2.7 37.9 37.9 0 0 0 15.2-3.0c0.0-0.0 0.0 0.0 0.0-0.0a37.7 37.7 0 0 0 10.4-7.7l309.4-317.5c14.6-14.0 14.3-38.9-0.7-53.5-14.0-14.6-38.9-14.3-53.5 0.7z' fill='%2337b72c'/%3E%3C/svg%3E");}
  159. .xtiper_icon_error {background-image:url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M512.7 1023.0C230.4 1023.0 0.7 794.4 0.7 512.1 0.8 229.8 230.4 0.1 512.7 0.1c282.3 0 511.9 229.6 511.9 511.0 0 282.2-229.6 511.9-511.9 511.9z m0-950.4c-241.8 0-438.5 196.6-438.5 438.5 0 241.7 196.7 438.5 438.5 438.5 241.7 0 438.5-196.7 438.5-438.5 0-241.8-196.8-438.5-438.5-438.5z m51.4 439.0l158.1-156.3c14.4-14.2 14.5-37.4 0.3-51.7-14.2-15.4-37.4-14.5-52.6-0.3l-157.4 156.5-155.9-156.4c-15.3-15.2-37.4-14.3-51.7 0-14.3 14.2-14.3 37.4 0 51.7l155.7 156.1-157.0 155.3c-14.4 14.2-14.5 37.3-0.3 51.7 7.2 7.2 16.6 10.9 25.0 10.9 9.3 0 18.6-3.6 25.8-10.6l157.2-155.5 158.4 159.0c7.2 6.2 16.6 10.7 25.0 10.7 9.3 0 18.7-4.5 25.8-10.6 14.3-14.3 14.4-37.4 0.1-51.7l-158.3-158.8z' fill='%23e75445'/%3E%3C/svg%3E");}
  160. .xtiper_icon_warning {background-image:url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M512.7 0.1C230.4 0.1 0.8 229.8 0.8 512.1c0 282.3 229.6 511.9 511.0 511.9 282.3 0 511.9-229.6 511.9-511.9C1024.6 229.8 795.0 0.1 512.7 0.1z m0 950.5c-241.8 0-438.5-196.7-438.5-438.5 0-241.8 196.7-438.5 438.5-438.5 241.7 0 438.5 196.6 438.5 438.5 0 241.7-196.8 438.5-438.5 438.5z' fill='%23f89310'/%3E%3Cpath d='M511.6 681.4c-15.5 0-28.6 5.4-39.4 16.1s-16.1 23.7-16.1 38.0c0 17.5 5.6 31.1 16.8 40.8 11.2 9.7 24.3 14.6 39.4 14.6 14.8 0 27.7-4.9 38.8-14.8 11.1-9.9 16.6-23.4 16.6-40.6 0-15.3-5.5-28.3-16.4-38.0-10.0-10.7-24.2-16.1-39.7-16.1zM514.5 232.4c-17.5 0-31.6 5.7-42.3 17.2s-16.1 27.4-16.1 47.9c0 15.0 1.1 39.8 3.3 74.3l11.8 177.0c2.2 22.9 5.9 39.0 11.1 51.2 5.2 11.2 14.4 16.8 27.7 16.8 13.1 0 22.4-5.8 28.1-17.4 5.7-11.6 9.4-28.2 11.1-49.9l15.9-182.2c1.7-16.7 2.6-33.3 2.6-49.5 0-27.6-3.6-48.7-10.7-63.4-7.2-14.7-21.3-21.0-42.5-21.0z' fill='%23f89310'/%3E%3C/svg%3E");}
  161. .xtiper_icon_ask {background-image:url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M512.7 0.1C230.4 0.1 0.8 229.8 0.8 512.1c0 282.3 229.6 511.9 511.0 511.9 282.3 0 511.9-229.6 511.9-511.9C1024.6 229.8 795.0 0.1 512.7 0.1z m0 950.5c-241.8 0-438.5-196.7-438.5-438.5 0-241.8 196.7-438.5 438.5-438.5 241.7 0 438.5 196.6 438.5 438.5 0 241.7-196.8 438.5-438.5 438.5z' fill='%23f89310'/%3E%3Cpath d='M513.9 681.3c-15.8 0-29.1 5.3-39.9 15.9-10.8 10.6-16.3 23.7-16.3 39.2 0 17.5 5.6 31.1 16.8 40.8 11.2 9.7 24.3 14.6 39.4 14.6 14.5 0 27.3-4.9 38.4-14.8 11.1-9.9 16.6-23.4 16.6-40.6 0-15.5-5.3-28.6-15.9-39.2-10.6-10.6-23.7-15.9-39.2-15.9zM617.4 252.0c-27.3-13.2-58.9-19.8-94.6-19.8-38.4 0-72.1 7.9-100.9 23.7-28.8 15.8-50.8 35.7-65.8 59.7-15.0 24.0-22.5 47.7-22.5 71.1 0 11.3 4.7 21.9 14.2 31.6 9.5 9.7 21.1 14.6 34.9 14.6 23.4 0 39.3-13.9 47.7-41.8 8.9-26.6 19.7-46.7 32.5-60.4 12.8-13.7 32.8-20.5 59.9-20.5 23.2 0 42.1 6.8 56.7 20.3 14.7 13.6 21.0 30.2 21.0 49.9 0 10.1-2.4 19.5-7.2 28.1-4.8 8.6-10.7 16.4-17.7 23.5s-18.4 17.4-34.2 31.2c-17.0 15.8-32.3 29.4-42.9 40.8-10.6 11.5-19.1 24.8-25.5 39.9-6.4 15.2-9.6 33.1-9.6 53.8 0 16.5 4.4 28.0 13.1 37.3 8.7 8.4 19.5 12.6 32.3 12.6 24.6 0 39.3-12.8 43.0-38.4 2.7-12.1 4.7-20.5 6.1-25.3 1.4-4.8 3.3-9.6 5.7-14.4 2.5-4.8 6.2-10.1 11.3-15.9 5.0-5.8 11.8-12.5 20.1-20.1 30.3-27.1 51.3-46.4 63.0-57.8 11.7-11.5 21.8-25.1 30.3-40.8 8.5-15.8 12.7-34.1 12.7-55.1 0-26.6-7.5-51.2-22.4-73.9-14.9-22.7-36.0-40.6-63.4-53.8z' fill='%23f89310'/%3E%3C/svg%3E");}
  162. .xtiper_icon_hello {background-image:url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M512.7 0.1C230.4 0.1 0.8 229.8 0.8 512.1c0 282.3 229.6 511.9 511.0 511.9 282.3 0 511.9-229.6 511.9-511.9C1024.6 229.8 795.0 0.1 512.7 0.1z m0 950.5c-241.8 0-438.5-196.7-438.5-438.5 0-241.8 196.7-438.5 438.5-438.5 241.7 0 438.5 196.6 438.5 438.5-0.0 241.7-196.8 438.5-438.5 438.5z' fill='%2337b72c'/%3E%3Cpath d='M355.5 478.0c9.8-9.7 15.2-22.5 15.2-36.2v-72.1c0-27.0-22.8-50.8-50.7-50.8-28.0 0-50.8 22.8-50.8 50.8v72.1c0 27.0 22.8 50.8 50.8 50.8 13.3 0 25.9-5.1 35.5-14.6zM706.5 615.4c-13.7-11.8-37.6-8.9-49.4 4.9-41.6 46.3-84.9 65.0-145.1 65.0-62.8 0-100.7-17.2-144.8-65.7-12.2-14.2-35.0-17.0-49.7-5.2-15.1 13.1-17.4 35.3-5.0 49.9 59.1 66.8 114.9 92.8 199.5 92.8 82.0 0 145.4-29.5 199.6-92.9 12.1-13.0 9.8-36.7-5.1-49.6zM704.0 319.8c-28.0 0-50.7 22.8-50.7 50.8v72.1c0 28.1 22.8 50.8 50.7 50.8 28.0 0 50.7-22.8 50.7-50.8v-72.1c0-27.0-22.8-50.8-50.7-50.8z' fill='%2337b72c'/%3E%3C/svg%3E");}
  163. .xtiper_icon_load {background-image:url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M979.73 513.01c-0.96-1.70-2.66-2.65-4.46-2.65h-69.90c0-84.45-26.02-162.63-70.11-227.32-0.53-0.85-0.95-1.91-1.52-2.76-4.57-6.59-9.67-11.69-14.55-19.02-1.81-2.37-3.51-4.78-5.42-7.12-7.22-8.92-14.87-17.20-22.73-25.38-0.74-0.85-1.49-1.59-2.23-2.34-25.50-26.88-56.41-49.50-89.13-67.56-0.83-0.53-1.70 0-2.55-1.49-9.35-5.10-19.02-9.77-28.89-14.13-2.44 0-4.78-2.23-7.22-3.29-8.39-3.51-15.94-6.59-25.6-8.50-4.15-1.38-8.18-2.86-12.32-4.15-7.54-2.23-15.30-4.16-23.05-6.05-5.21-1.17-10.31-2.55-15.62-3.51-2.12-0.42-3.18-1.17-6.37-1.49-7.33-1.28-14.77-2.02-22.10-2.98-2.65-0.30-4.25-0.74-7.91 0-13.28-1.27-26.45-2.23-39.63-2.23-80.51 0-159.12 24.96-226.58 72.76-21.46 15.30-26.77 45.25-11.68 67.02 15.09 21.78 44.72 27.09 66.28 11.79l3.31-0.71c52.37-36.11 112.60-55.77 176.33-54.92a329.67 329.67 0 0 1 24.64 1.24c3.29 0.32 6.59 0.85 9.99 1.27 6.37 0.85 12.75 1.70 18.00 2.97 3.83 0.75 7.65 1.70 11.37 2.66 6.16 1.48 12.20 2.92 18.16 4.68 2.87 0.85 5.64 1.91 8.50 2.86 6.90 2.34 13.70 4.78 20.39 7.54 1.49 0.64 2.98 1.38 4.46 2.02 7.86 3.47 15.51 7.11 22.94 11.15 0.32 0.21 0.64 0.32 0 0.53 25.18 14.02 48.23 31.55 68.52 51.95 0.32 0.32 0.63 0.74 0.96 0 6.27 5.31 12.32 13.06 17.95 19.97 1.17 1.48 2.34 3.08 3.51 4.56 41.22 52.16 66.07 118.12 66.07 189.93h-69.89c-1.81 0-3.51 0.96-4.46 2.65-0.96 1.70-0.74 3.72 0.21 5.21l117.38 178.24c0.96 1.38 2.44 2.33 3.19 2.33 1.70 0 3.29-0.95 3.19-2.33l117.38-178.24c0.96-1.52 1.17-3.51 0.21-5.21zM687.56 761.37l-3.30 0.71c-52.37 36.11-112.60 55.77-176.33 54.92a329.29 329.29 0 0 1-24.64-1.25c-3.29-0.32-6.59-0.85-9.99-1.27-6.37-0.85-12.75-1.70-19.00-2.97-3.83-0.74-7.65-1.70-11.36-2.66-6.17-1.48-12.20-2.92-18.16-4.67-2.87-0.85-5.64-1.91-8.50-2.87-6.90-2.33-13.70-4.78-20.39-7.54-1.49-0.64-2.98-1.38-4.46-2.02-7.86-3.47-15.51-7.11-22.94-11.15-0.32-0.21-0.64-0.32 0-0.53-25.18-14.02-48.22-31.55-68.52-51.95-0.32-0.32-0.63-0.74-0.95 0-6.27-5.31-12.32-13.06-17.95-19.97-1.17-1.49-2.35-3.08-3.51-4.56-41.21-52.16-66.07-118.12-66.07-189.93h69.89c1.81 0 3.51-0.96 4.46-2.65 0.96-1.70 0.74-3.72-0.21-5.21L168.24 327.54c-0.96-1.38-2.45-2.34-3.19-2.34-1.70 0-3.29 0.95-3.19 2.34L44.48 505.79c-0.95 1.52-1.17 3.50-0.22 5.21 0.96 1.70 2.66 2.65 4.46 2.65h69.90c0 84.45 26.02 162.63 70.11 227.32 0.53 0.85 0.95 1.91 1.52 2.76 4.57 6.59 9.67 11.69 14.55 19.02 1.81 2.37 3.51 4.78 5.42 7.12 7.22 8.92 14.87 17.20 22.73 25.38 0.74 0.85 1.49 1.59 2.23 2.34 25.50 26.87 56.41 49.50 89.13 67.55 0.83 0.53 1.70 0 2.55 1.49 9.35 5.10 19.02 9.77 28.90 14.13 2.44 0 4.78 2.23 7.22 3.29 8.39 3.51 15.94 6.59 25.60 8.50 4.14 1.38 8.18 2.87 12.32 4.15 7.54 2.23 15.30 4.16 23.05 6.05 5.21 1.17 10.30 2.55 15.62 3.50 2.12 0.42 3.19 1.17 6.37 1.49 7.33 1.28 14.77 2.02 22.10 2.97 2.66 0.30 4.25 0.75 7.91 0 13.28 1.28 26.45 2.23 39.63 2.23 80.51 0 159.12-24.96 226.58-72.76 21.45-15.30 26.77-45.26 11.68-67.02-15.08-21.78-44.72-27.09-66.28-11.79z' fill='%23333333'/%3E%3C/svg%3E");}
  164. .xtiper_icon_load {animation:revolve 1.5s infinite linear; -webkit-animation:revolve 1.5s infinite linear;}
  165. @keyframes revolve
  166. {
  167. 0% {transform:rotate(0deg);}
  168. 100% {transform:rotate(360deg);}
  169. }
  170.  
  171. @media (max-width: 760px) {
  172. .xtiper_msg {max-width:80%;}
  173. }
  174. @media (max-width: 480px) {
  175. .xtiper_msg {max-width:300px;}
  176. .xtiper_photo_ul {padding:0;}
  177. .xtiper_photo_btn {display:none;}
  178. }
  179.  
  180. .xtiper_photo_li p {width:100%; max-height:100%; min-height:100px; position:absolute; top:50%; transform:translate(0, -50%); background-position:center center; background-repeat:no-repeat; background-size:contain; background-color:#fff;}
  181. .xtiper_photo_li a {display:block; width:100%; height:100%; position:relative; z-index:2;}
  182. .xtiper_photo_load {position:absolute; top:50%; left:50%; margin-left:-17px; margin-top:-17px; z-index:1;}
  183. .xtiper_photo_li img {max-width:100%; visibility:hidden;}
  184. .xtiper_photo_li.xapp img {width:100%; visibility:visible; position:relative; z-index:2;}
  185. .xtiper_photo_btn {position:absolute; top:50%; transform:translate(0, -50%); width:32px; height:46px; overflow:hidden; cursor:pointer; z-index:2;}
  186. .xtiper_photo_prev {left:16px;}
  187. .xtiper_photo_next {right:16px;}
  188. .xtiper_photo_btn:before, .xtiper_photo_btn:after {content:""; display:block; width:26px; height:4px; background-color:#666; position:absolute; border-radius:4px; z-index:1;}
  189. .xtiper_photo_btn:hover {opacity:0.7;}
  190. .xtiper_photo_prev:before {transform:rotate(-45deg); top:13px; left:3px;}
  191. .xtiper_photo_prev:after {transform:rotate(45deg); top:29px; left:3px;}
  192. .xtiper_photo_next:before {transform:rotate(45deg); top:13px; right:3px;}
  193. .xtiper_photo_next:after {transform:rotate(-45deg); top:29px; right:3px;}
  194. .xtiper_photo_num {position:absolute; bottom:5px; text-align:center; left:50%; transform:translate(-50%, 0); font-size:13px; z-index:10; height:26px; line-height:26px; overflow:hidden; user-select:none; -ms-user-select:none;}
  195. .xtiper_nummax {padding-left:8px;}
  196. .xtiper_photo_num, .xtiper_nummax {display:none;}
  197. .xtiper_photo_num.xon, .xtiper_nummax.xon {display:inline-block;}
  198. `;
  199. let styleNode = document.createElement("style");
  200. styleNode.innerHTML= cssResource;
  201. document.head.append(styleNode);
  202. })();
  203.  
  204. /*
  205. * author: ovsexia
  206. * version: 2.7.0
  207. * name: Xtiper
  208. * describe: 弹层弹窗解决方案
  209. * License: Mozilla Public License Version 2.0
  210. */
  211.  
  212. ;!function(window, undefined){
  213.  
  214. let Xclass = function(config){
  215. let that = this;
  216.  
  217. //按钮失焦
  218. that.loseblur();
  219.  
  220. //客户端
  221. that.ifmob = /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent);
  222.  
  223. //主id
  224. let rand = Math.random().toString().split('.')[1];
  225. let mainid = 'xtiper_'+rand;
  226. that.mainid = mainid;
  227.  
  228. //参数配置
  229. config = that.namefix(config);
  230. that.c = config;
  231. let xcstr = '';
  232. if(typeof(config.reset)!="undefined" && config.reset!==null && config.reset===false){
  233. for(let key in config){
  234. if(config[key]!=null){
  235. xcstr += config[key].toString();
  236. }
  237. }
  238. that.xcstr = that.xcstrRep(xcstr);
  239. }else{
  240. that.xcstr = xcstr;
  241. }
  242.  
  243. //关闭
  244. if(config.model=='close'){
  245. that.close(config.closeid);
  246. return false;
  247. }
  248.  
  249. //关闭
  250. if(config.model=='closeAll'){
  251. that.closeAll();
  252. return false;
  253. }
  254.  
  255. //入口
  256. that.creat();
  257. };
  258.  
  259. Xclass.pt = Xclass.prototype;
  260.  
  261. //让所有按钮失去焦点
  262. Xclass.pt.loseblur = function(){
  263. let button = document.getElementsByTagName('button');
  264. if(button.length>0){
  265. for(let i=0; i<button.length; i++){
  266. button[i].blur();
  267. }
  268. }
  269. let input = document.getElementsByTagName('input');
  270. if(input.length>0){
  271. for(let i=0; i<input.length; i++){
  272. input_type = input[i].getAttribute('type');
  273. if(input_type && (input_type=='button' || input_type=='submit')){
  274. input[i].blur();
  275. }
  276. }
  277. }
  278. };
  279.  
  280. Xclass.pt.creat = function(){
  281. let that = this;
  282. let c = that.c;
  283.  
  284. //1.构造内部html
  285. let html = that.html();
  286. if(!html){
  287. return false;
  288. }
  289.  
  290. //2.输出html代码到body
  291. let body = document.body;
  292. let div = document.createElement('div');
  293. div.setAttribute('id', that.mainid);
  294. div.setAttribute('class', 'xtiper');
  295. div.innerHTML = html;
  296. body.appendChild(div);
  297. let xtipdiv = document.getElementById(that.mainid);
  298. that.xtipdiv = xtipdiv;
  299.  
  300. //3.添加classname、属性
  301. that.attr();
  302.  
  303. //4.添加动画效果
  304. that.on();
  305.  
  306. //5.后续处理
  307. that.after();
  308. };
  309.  
  310. //参数名称补全
  311. Xclass.pt.namefix = function(c){
  312. //方位
  313. if(c.pos){
  314. c.pos = c.pos.toLowerCase();
  315. if(c.pos=='t'){
  316. c.pos = 'top';
  317. }else if(c.pos=='b'){
  318. c.pos = 'bottom';
  319. }else if(c.pos=='l'){
  320. c.pos = 'left';
  321. }else if(c.pos=='r'){
  322. c.pos = 'right';
  323. }else if(c.pos=='m'){
  324. c.pos = 'middle';
  325. }
  326. }
  327.  
  328. //类型
  329. if(c.type){
  330. c.type = c.type.toLowerCase();
  331. if(c.type=='r'){
  332. c.type = 'ready';
  333. }else if(c.type=='n'){
  334. c.type = 'noready';
  335. }else if(c.type=='notready'){
  336. c.type = 'noready';
  337. }else if(c.type=='u'){
  338. c.type = 'url';
  339. }else if(c.type=='h'){
  340. c.type = 'html';
  341. }else if(c.type=='p'){
  342. c.type = 'photo';
  343. }else if(c.type=='w'){
  344. c.type = 'white';
  345. }else if(c.type=='b'){
  346. c.type = 'black';
  347. }else if(c.type=='a'){
  348. c.type = 'alert';
  349. }else if(c.type=='c'){
  350. c.type = 'confirm';
  351. }
  352. }
  353.  
  354. c.iconColor = '';
  355. //图标
  356. if(c.icon){
  357. if(typeof(c.icon)=='object'){
  358. c.iconColor = c.icon[1];
  359. c.icon = c.icon[0];
  360. }
  361. c.icon = c.icon.toLowerCase();
  362. c.iconFlag = true;
  363. if(c.icon=='s'){
  364. c.icon = 'success';
  365. }else if(c.icon=='e'){
  366. c.icon = 'error';
  367. }else if(c.icon=='w'){
  368. c.icon = 'warning';
  369. }else if(c.icon=='a'){
  370. c.icon = 'ask';
  371. }else if(c.icon=='h'){
  372. c.icon = 'hello';
  373. }
  374. if(c.icon !== 'success' && c.icon !== 'error' && c.icon !== 'warning' && c.icon !== 'ask' && c.icon !== 'hello'){
  375. c.iconFlag = false;
  376. }
  377. }
  378.  
  379. //文字对齐
  380. if(c.align){
  381. c.align = c.align.toLowerCase();
  382. if(c.align=='l'){
  383. c.align = 'left';
  384. }else if(c.align=='c'){
  385. c.align = 'center';
  386. }else if(c.align=='r'){
  387. c.align = 'right';
  388. }
  389. }
  390. return c;
  391. };
  392.  
  393. //构造内部html
  394. Xclass.pt.html = function(){
  395. let that = this;
  396. let c = that.c;
  397. let xtipdiv = that.xtipdiv;
  398.  
  399. let html = '';
  400. //短消息
  401. if(c.model=='msg'){
  402. html += '<p>';
  403. if(c.icon){
  404. html += c.iconFlag===true ? '<i class="xtiper_icon xtiper_icon_'+c.icon+' xtiper_icon_min"></i>' : '<img class="xtiper_icon xtiper_icon_min" src="'+c.icon+'" />';
  405. }
  406. html += c.tip+'</p>';
  407. }
  408. //弹幕
  409. else if(c.model=='danmu'){
  410. let danmuli = document.getElementsByClassName('xtiper_danmu');
  411. if(danmuli.length>300 || document.hidden){
  412. return false;
  413. }
  414.  
  415. html += '<p>';
  416. if(c.icon){
  417. html += c.iconFlag===true ? '<i class="xtiper_icon xtiper_icon_'+c.icon+' xtiper_icon_min"></i>' : '<img class="xtiper_icon xtiper_icon_min" src="'+c.icon+'" />';
  418. }
  419. html += c.tip+'</p>';
  420. }
  421. //气泡层
  422. else if(c.model=='tips'){
  423. that.newelement = document.getElementById(c.element) || c.element;
  424. if(c.bgcolor){
  425. html += '<p style="background-color:'+c.bgcolor+';'+(c.color ? ' color:'+c.color+';"' : '')+'">'+c.tip+'</p>';
  426. }else{
  427. html += '<p>'+c.tip+'</p>';
  428. }
  429. html += '<em style="background-color:'+c.bgcolor+';"></em>';
  430. if(c.closeBtn===true){
  431. html += '<div class="xtiper_close xtiper_close_notit xtiper_close_notitmin"></div>';
  432. }
  433. }
  434. //弹窗层
  435. else if(c.model=='win'){
  436. if(c.type=='alert'){
  437. c.btn = c.btn!=null ? c.btn : ['确定'];
  438. c.btn1 = c.btn1!=null ? c.btn1 : null;
  439. c.btn2 = null;
  440. c.btn3 = null;
  441. c.btn4 = null;
  442. }else if(c.type=='confirm'){
  443. c.btn = c.btn!=null ? c.btn : ['确定', '取消'];
  444. c.btn1 = c.btn1!=null ? c.btn1 : null;
  445. c.btn2 = c.btn2!=null ? c.btn2 : null;
  446. c.btn3 = c.btn3!=null ? c.btn3 : null;
  447. c.btn4 = c.btn4!=null ? c.btn4 : null;
  448. }
  449.  
  450. xtiper_con_icon = c.icon ? ' xtiper_con_icon' : '';
  451. let btnclass = new Array();
  452. btnclass[0] = c.btn1!=null ? ' class="xactive"' : '';
  453. btnclass[1] = c.btn2!=null ? ' class="xactive"' : '';
  454. btnclass[2] = c.btn3!=null ? ' class="xactive"' : '';
  455. btnclass[3] = c.btn4!=null ? ' class="xactive"' : '';
  456. if(c.btnbg && c.btnbg.length){ //自定义按钮颜色
  457. for(let i=0; i<c.btnbg.length; i++){
  458. btnclass[i] = c.btnbg[i]===true ? ' class="xactive"' : '';
  459. }
  460. }
  461.  
  462. let btnfun = new Array();
  463. btnfun[0] = c.btn1 || null;
  464. btnfun[1] = c.btn2 || null;
  465. btnfun[2] = c.btn3 || null;
  466. btnfun[3] = c.btn4 || null;
  467. that.btnfun = btnfun;
  468.  
  469. if(c.maxWidth){
  470. c.width = that.maxSize(c.width, c.maxWidth);
  471. }
  472.  
  473. if(c.shade===true){
  474. html += '<div class="xtiper_bg"></div>';
  475. }
  476. html += '<div class="xtiper_main"'+(c.width ? 'style="width:'+c.width+';"' : '')+'>';
  477. html += '<div class="xtiper_tit"><p>'+c.title+'</p><div class="xtiper_minmax">';
  478. if(c.min===true){
  479. html += '<div class="xtiper_min"></div>';
  480. }
  481. html += '<div class="xtiper_close"></div>';
  482. html += '</div></div>';
  483. let iconer = that.iconer();
  484. html += '<div class="xtiper_pad"><div class="xtiper_pr"><div class="xtiper_tip">'+iconer+'<div class="xtiper_con'+xtiper_con_icon+'"><div class="xtiper_conin">'+c.tip;
  485. if(c.type=='alert' && c.times > 0){
  486. c.times++;
  487. html += '(<span class="xtiper_times">'+c.times+'</span>)';
  488. }
  489. html += '</div></div></div></div></div>';
  490. html += '<div class="xtiper_btn'+(c.icon && c.iconFlag===true ? ' xtiper_btn_'+c.icon : '')+' xtiper_btn'+c.btn.length+'"><ul>';
  491.  
  492. for(let i=0; i<4; i++){
  493. if(c.btn[i]){
  494. html += '<li'+btnclass[i]+'><button'+(btnclass[i] && c.iconColor && c.type=='confirm' ? ' style="background-color:'+c.iconColor+'"' : '')+'>'+c.btn[i]+'</button></li>';
  495. }
  496. }
  497.  
  498. html += '</ul><div class="xtiper_btnbor"'+(c.iconColor ? ' style="background-color:'+c.iconColor+'"' : '')+'></div></div></div>';
  499. }
  500. //页面层
  501. else if(c.model=='open'){
  502. //是否已经触发过
  503. ifxoff = that.findxoff();
  504. if(ifxoff===true){
  505. return false;
  506. }
  507.  
  508. if(c.maxWidth){
  509. c.width = that.maxSize(c.width, c.maxWidth);
  510. }
  511. if(c.maxHeight){
  512. c.height = that.maxSize(c.height, c.maxHeight);
  513. }
  514.  
  515. //满屏页面不能最大化
  516. if(c.width=='100%' && c.height=='100%'){
  517. c.max = false;
  518. }
  519. let width = that.getsize(c.width);
  520. let height = that.getsize(c.height) || ['', ''];
  521. if(height[1]=='%'){
  522. let bheight = window.innerHeight * height[0] / 100;
  523. height[0] = Math.round(bheight);
  524. height[1] = 'px';
  525. }
  526. let height_css = '';
  527. if(c.title){
  528. height_css = ' xtit';
  529. }else{
  530. if(c.move=== true){
  531. height_css = ' xmin';
  532. }
  533. }
  534.  
  535. let newcontent;
  536. let xtiper_over = '';
  537. if(c.over===false){
  538. xtiper_over = ' xtiper_over';
  539. }
  540. if(c.type=='ready' || c.type=='noready'){ //内容
  541. let fir = c.content.substr(0, 1), element, content, reg;
  542. if(fir=='#'){
  543. element = document.getElementById(c.content.substr(1, c.content.length));
  544. }else if(fir=='.'){
  545. element = document.getElementsByClassName(c.content.substr(1, c.content.length))[0];
  546. }else{
  547. return false;
  548. }
  549. if(!element){
  550. return false;
  551. }
  552. if(c.type=='ready'){
  553. content = element.outerHTML;
  554. //过滤主div标签的id
  555. regid = /\#([A-z0-9_-]*)/;
  556. content_id = (c.content).match(regid);
  557. if(content_id && content_id[1]){
  558. //reg = /\s+(id\=["']idname["'])/g;
  559. reg = new RegExp('\\s+(id\\\=["\']' + content_id[1] + '["\'])', 'g');
  560. content = content.replace(reg, '');
  561. }
  562. }else{
  563. content = element.innerHTML;
  564. reg = /\<\!\-{2}[\s\n]*([\S\s]*)[\s\n]*\-{2}\>/;
  565. let match = content.match(reg);
  566. if(!match || !match[1]){
  567. return false;
  568. }
  569. content = match[1];
  570. }
  571. newcontent = '<div class="xtiper_content'+xtiper_over+''+height_css+'"'+(c.bgcolor ? ' style="background-color:'+c.bgcolor+'"' : '')+'>'+content+'</div>';
  572. }else if(c.type=='url'){ //页面
  573. let scrolling = 'auto';
  574. if(c.over===false){
  575. scrolling = 'no';
  576. }
  577. newcontent = '<div class="xtiper_content'+height_css+' xtiper_over"'+(c.bgcolor ? ' style="background-color:'+c.bgcolor+'"' : '')+'><div class="zw"></div><iframe parentid="'+that.mainid+'" id="'+that.mainid+'_id" name="'+that.mainid+'_name" scrolling="'+scrolling+'" allowtransparency="true" frameborder="0" src="'+c.content+'" style="width:100%; height:100%;"></iframe></div>';
  578. }else if(c.type=='html'){ //html代码
  579. newcontent = '<div class="xtiper_content'+xtiper_over+''+height_css+'"'+(c.bgcolor ? ' style="background-color:'+c.bgcolor+'"' : '')+'>'+c.content+'</div>';
  580. }else if(c.type=='photo'){ //相册
  581. let img = document.getElementsByTagName('img');
  582. if(img.length==0){
  583. return false;
  584. }
  585. let photo = new Array();
  586. for(let i=0; i<img.length; i++){
  587. if(that.dataset(img[i], 'xphoto')==c.content){
  588. photo.push(img[i]);
  589. }
  590. }
  591. if(!photo || photo.length==0){
  592. return false;
  593. }
  594. let li = '<div class="xtiper_photo_num'+(c.iftitle===true ? ' xon' : '')+'"'+(c.color ? 'style="color:'+c.color+';"' : '')+'><span class="xtiper_words"></span><span class="xtiper_nummax'+(c.iforder===true ? ' xon' : '')+'"><span class="xtiper_num">'+c.index+'</span> / '+photo.length+'</span></div>';
  595. if(photo.length>1){
  596. li += '<div class="xtiper_photo_btn xtiper_photo_prev"></div><div class="xtiper_photo_btn xtiper_photo_next"></div>';
  597. }
  598. li += '<div class="xtiper_photo_ul"><ul>';
  599. let xhref, xsrc;
  600. let xindex = c.index - 1;
  601. for(let i=0; i<photo.length; i++){
  602. xhref = that.dataset(photo[i], 'xhref') ? that.dataset(photo[i], 'xhref') : '';
  603. xsrc = that.dataset(photo[i], 'xsrc') ? that.dataset(photo[i], 'xsrc') : photo[i].src;
  604. li += '<li class="xtiper_photo_li'+(i==xindex ? ' xon' : '')+(that.ifmob===true ? ' xapp' : '')+'" data-xtitle="'+photo[i].title+'"><p style="background-image:url(\''+xsrc+'\');">'+(xhref ? '<a href="'+xhref+'" target="_blank">' : '')+'<img src="'+xsrc+'">'+(xhref ? '</a>' : '')+(i==xindex && that.ifmob===true ? '<span class="xtiper_icon xtiper_icon_load xtiper_photo_load"></span>' : '')+'</p></li>';
  605. }
  606. li += '</ul></div>';
  607. newcontent = '<div class="xtiper_content'+xtiper_over+''+height_css+'"'+(c.bgcolor ? ' style="background-color:'+c.bgcolor+'"' : '')+'>'+li+'</div>';
  608. }
  609.  
  610. if(c.shade===true){
  611. html += '<div class="xtiper_bg"></div>';
  612. }
  613. if(c.app===true){
  614. html += '<div class="xtiper_sheet'+(that.ifmob===true && c.type=='photo' ? ' xapp' : '')+'" style="height:'+height[0]+""+height[1]+';">';
  615. if(c.title){
  616. html += '<div class="xtiper_sheet_tit xtiper_sheet_left">'+c.title+'</div>';
  617. }
  618. }else{
  619. html += '<div class="xtiper_main'+(that.ifmob===true && c.type=='photo' ? ' xapp' : '')+'" style="width:'+width[0]+""+width[1]+'; height:'+height[0]+""+height[1]+';">';
  620. if(c.title){
  621. html += '<div class="xtiper_tit'+(c.move===true ? '' : ' xminmax')+'"><p>'+c.title+'</p><div class="xtiper_minmax">';
  622. if(c.min===true){
  623. html += '<div class="xtiper_min"></div>';
  624. }
  625. if(c.max===true){
  626. html += '<div class="xtiper_max"></div>';
  627. }
  628. if(c.closeBtn===true){
  629. html += '<div class="xtiper_close"></div>';
  630. }
  631. html += '</div></div>';
  632. }else{
  633. if(c.move===true){
  634. html += '<div class="xtiper_tit xtiper_tit_none"></div>';
  635. }
  636. if(c.closeBtn===true){
  637. html += '<div class="xtiper_close xtiper_close_notit'+(c.photoapp===true ? ' xtiper_close_photoapp' : '')+'"></div>';
  638. };
  639. }
  640. }
  641. html += newcontent;
  642. html += '</div>';
  643. }
  644. //加载层
  645. else if(c.model=='load'){
  646. html = '<div class="xtiper_bg xtiper_bg_white"></div><div class="xtiper_loadin"><div class="xtiper_icon xtiper_icon_load"></div>';
  647. if(c.tip){
  648. html += '<span>'+c.tip+'</span>';
  649. }
  650. html += '</div>';
  651. if(c.closeBtn===true){
  652. html += '<div class="xtiper_close xtiper_close_load"></div>';
  653. }
  654. }
  655. //面板菜单
  656. else if(c.model=='sheet'){
  657. let btnfun = new Array();
  658. btnfun[0] = c.btn1 ? c.btn1 : null; btnfun[1] = c.btn2 ? c.btn2 : null;
  659. btnfun[2] = c.btn3 ? c.btn3 : null; btnfun[3] = c.btn4 ? c.btn4 : null;
  660. btnfun[4] = c.btn5 ? c.btn5 : null; btnfun[5] = c.btn6 ? c.btn6 : null;
  661. btnfun[6] = c.btn7 ? c.btn7 : null; btnfun[7] = c.btn8 ? c.btn8 : null;
  662. that.btnfun = btnfun;
  663.  
  664. let align = 'xtiper_sheet_' + c.align;
  665.  
  666. html += '<div class="xtiper_bg"></div><div class="xtiper_sheet">';
  667. if(c.title){
  668. html += '<div class="xtiper_sheet_tit '+align+'">'+c.title+'</div>';
  669. }
  670. html += '<ul class="xtiper_sheet_ul '+align+'">';
  671. let licon, href, target;
  672. for(let i=0; i<c.btn.length; i++){
  673. if(btnfun[i]){
  674. if(typeof(btnfun[i])=='function'){
  675. licon = '<p>'+c.btn[i]+'</p>';
  676. }else{
  677. if(typeof(btnfun[i])=='object'){
  678. href = btnfun[i][0];
  679. target = btnfun[i][1] ? btnfun[i][1] : '';
  680. if(target && target.substr(0, 1)!='_'){
  681. target = '_'+target;
  682. }
  683. target = ' target="'+target+'"';
  684. }else{
  685. href = btnfun[i];
  686. target = '';
  687. }
  688. licon = '<a href="'+href+'"'+target+'><p>'+c.btn[i]+'</p></a>';
  689. }
  690. }else{
  691. licon = '<p>'+c.btn[i]+'</p>';
  692. }
  693. html += '<li class="xtiper_sheet_li">'+licon+'</li>';
  694. }
  695. if(!c.force){
  696. html += '<li class="xtiper_sheet_li xlast"><p>'+c.btnClose+'</p></li>';
  697. }
  698. html += '</ul></div>';
  699. }
  700. return html;
  701. };
  702.  
  703. Xclass.pt.iconer = function(){
  704. let that = this;
  705. let c = that.c;
  706.  
  707. let html = '';
  708. if(c.icon){
  709. if(c.iconFlag===true){
  710. html = '<i class="xtiper_icon xtiper_icon_'+c.icon+'"></i>';
  711. }else{
  712. html = '<img class="xtiper_icon" src="'+c.icon+'" />';
  713. }
  714. }
  715. return html;
  716. };
  717.  
  718. Xclass.pt.findxoff = function(){
  719. let that = this;
  720. let c = that.c;
  721.  
  722. let xoff = document.getElementsByClassName('xtiper');
  723. let xoffdiv;
  724. for(let i=0; i<xoff.length; i++){
  725. let xcstr = that.dataset(xoff[i], 'xcstr');
  726. if(xcstr && xcstr==that.xcstr){
  727. xoffdiv = xoff[i];
  728. }
  729. }
  730.  
  731. if(xoffdiv){
  732. that.xtipdiv = xoffdiv;
  733. that.mainid = xoffdiv.getAttribute('id');
  734. xoffdiv.style.zIndex = c.zindex;
  735. setTimeout(function(){
  736. let maincss = c.app===true ? 'xtiper_sheet' : 'xtiper_main';
  737. let xtiper_main = xoffdiv.getElementsByClassName(maincss)[0];
  738. let data_width = that.dataset(xoffdiv, 'xwidth');
  739. let data_height = that.dataset(xoffdiv, 'xheight');
  740. let xleft = (window.innerWidth - data_width) / 2;
  741. let xtop = (window.innerHeight - data_height) / 2;
  742. if(maincss=='xtiper_main'){
  743. xtiper_main.style.width = data_width+'px';
  744. xtiper_main.style.height = data_height+'px';
  745. xtiper_main.style.left = xleft+'px';
  746. xtiper_main.style.top = xtop+'px';
  747. let xtiper_min = xoffdiv.getElementsByClassName('xtiper_min')[0];
  748. let xtiper_max = xoffdiv.getElementsByClassName('xtiper_max')[0];
  749. if(xtiper_min){
  750. xtiper_min.style.display = '';
  751. xtiper_min.classList.remove('xon');
  752. }
  753. if(xtiper_max){
  754. xtiper_max.style.display = '';
  755. xtiper_max.classList.remove('xon');
  756. }
  757. }
  758. if(c.lock===true){
  759. that.lock();
  760. }
  761. xoffdiv.classList.remove('xoff');
  762. }, 1);
  763. return true;
  764. }else{
  765. return false;
  766. }
  767. };
  768.  
  769. //设置data
  770. Xclass.pt.dataset = function(element, datakey, dataval){
  771. //读取
  772. if(dataval==null){
  773. if(element){
  774. return element.getAttribute('data-'+datakey);
  775. }
  776. }
  777. //设置
  778. else{
  779. element.setAttribute('data-'+datakey, dataval);
  780. }
  781. };
  782.  
  783. //添加classname、属性
  784. Xclass.pt.attr = function(){
  785. let that = this;
  786. let c = that.c;
  787. let xtipdiv = that.xtipdiv;
  788.  
  789. //短消息
  790. if(c.model=='msg'){
  791. xtipdiv.classList.add('xtiper_msg');
  792. xtipdiv.classList.add('xtiper_msg_'+c.pos);
  793. xtipdiv.classList.add('xtiper_msg_'+c.type);
  794. xtipdiv.style.whiteSpace = 'nowrap';
  795.  
  796. let xwidth = xtipdiv.offsetWidth;
  797. xwidth = xwidth / 2;
  798. xtipdiv.style.marginLeft = '-'+xwidth+'px';
  799. xtipdiv.style.whiteSpace = '';
  800. }
  801. //弹幕
  802. else if(c.model=='danmu'){
  803. xtipdiv.classList.add('xtiper_msg');
  804. xtipdiv.classList.add('xtiper_msg_'+c.type);
  805. xtipdiv.classList.add('xtiper_danmu');
  806.  
  807. function randomNum(n, m){
  808. return Math.round(Math.random()*(m-n))+n;
  809. }
  810.  
  811. let bheight = Math.round(window.innerHeight * 0.65);
  812. let danmuTop = randomNum(10, bheight);
  813. let bwidth = document.body.offsetWidth + 22;
  814. xtipdiv.style.transform = 'translateX('+bwidth+'px)';
  815. xtipdiv.style.top = danmuTop+'px';
  816.  
  817. let danmuli = document.getElementsByClassName('xtiper_danmu');
  818. if(danmuli.length>1){
  819. if(c.light===true){
  820. xtipdiv.classList.add('xtiper_danmu_light');
  821. }
  822. }
  823. }
  824. //气泡层
  825. else if(c.model=='tips'){
  826. xtipdiv.classList.add('xtiper_tips');
  827. xtipdiv.classList.add('xtiper_tips_'+c.pos);
  828. xtipdiv.style.width = xtipdiv.offsetWidth + 'px';
  829.  
  830. //定位
  831. let newelement = document.getElementById(c.element) || c.element;
  832. let S = document.documentElement.scrollTop || document.body.scrollTop;
  833. let C = newelement.getBoundingClientRect();
  834. let W = newelement.offsetWidth;
  835. let H = newelement.offsetHeight;
  836. let dtop = S + C.top;
  837. let dleft = C.left;
  838. let B = 10;
  839.  
  840. if(c.pos=='left'){
  841. let selfWidth = xtipdiv.offsetWidth;
  842. dleft = dleft - selfWidth - B;
  843. }else if(c.pos=='right'){
  844. dleft = dleft + W + B;
  845. }else if(c.pos=='top'){
  846. let selfHeight = xtipdiv.offsetHeight;
  847. dtop = dtop - selfHeight - B;
  848. }else if(c.pos=='bottom'){
  849. dtop = dtop + H + B;
  850. }
  851. xtipdiv.style.left = dleft + 'px';
  852. xtipdiv.style.top = dtop + 'px';
  853. }
  854. //弹窗层
  855. else if(c.model=='win' || c.model=='open'){
  856. xtipdiv.classList.add('xtiper_win');
  857. if(c.shade===true){
  858. xtipdiv.classList.add('xtiper_win_fixed');
  859. }
  860. let maincss = c.app===true ? 'xtiper_sheet' : 'xtiper_main';
  861. let xtiper_main = xtipdiv.getElementsByClassName(maincss)[0];
  862. let xtiper_tit = xtipdiv.getElementsByClassName('xtiper_tit')[0];
  863. //原始窗口大小
  864. that.dataset(xtipdiv, 'xwidth', xtiper_main.offsetWidth);
  865. that.dataset(xtipdiv, 'xheight', xtiper_main.offsetHeight);
  866. if(c.reset===false){
  867. that.dataset(xtipdiv, 'xreset', 1);
  868. }
  869.  
  870. if(c.model=='open' && that.xcstr){
  871. that.dataset(xtipdiv, 'xcstr', that.xcstr);
  872. }
  873.  
  874. if(c.min===true || c.max===true){
  875. let xmcss = 'xmcss';
  876. let y = 0;
  877. if(c.min===true){
  878. y++;
  879. }
  880. if(c.max===true){
  881. y++;
  882. }
  883. xmcss = xmcss + y;
  884. if(xtiper_tit){
  885. xtiper_tit.classList.add(xmcss);
  886. }
  887. }
  888.  
  889. let xleft, xtop;
  890. if(c.model=='win'){
  891. let width = that.getsize(c.width);
  892. if(width && width[1]=='%'){
  893. xleft = (100 - width[0]) / 2 + '%';
  894. }else{
  895. xleft = (window.innerWidth - xtiper_main.offsetWidth) / 2 + 'px';
  896. }
  897. xtop = (window.innerHeight - xtiper_main.offsetHeight) / 2 + 'px';
  898. xtiper_main.style.height = xtiper_main.offsetHeight + 'px';
  899. xtiper_main.style.left = xleft;
  900. xtiper_main.style.top = xtop;
  901. }else if(c.model=='open'){
  902. if(c.type=='ready'){
  903. xtiper_main.getElementsByClassName('xtiper_content')[0].firstChild.style.display = '';
  904. }
  905.  
  906. if(c.app===false){
  907. let width = that.getsize(c.width);
  908.  
  909. if(c.type=='photo' && c.autoHeight===true){
  910. let xindex = c.index - 1;
  911. let imgdiv = xtipdiv.getElementsByClassName('xtiper_photo_li')[xindex].getElementsByTagName('img')[0];
  912. imgdiv.onload = function(){
  913. let img = imgdiv.offsetHeight;
  914. img = img + 100;
  915. if(img > window.innerHeight){
  916. if(c.title){
  917. img = window.innerHeight;
  918. }else{
  919. img = window.innerHeight - 26;
  920. }
  921. }
  922. xtop = (window.innerHeight - img) / 2;
  923. xtop = c.y ? xtop + c.y : xtop;
  924. xtop = xtop + 'px';
  925. xtiper_main.style.height = img + 'px';
  926.  
  927. if(width[1]=='%'){
  928. xleft = (100 - width[0]) / 2;
  929. xleft = c.x ? xleft + c.x : xleft;
  930. xleft = xleft + width[1];
  931. }else{
  932. xleft = (window.innerWidth - xtiper_main.offsetWidth) / 2;
  933. xleft = c.x ? xleft + c.x : xleft;
  934. xleft = xleft + 'px';
  935. }
  936. xtiper_main.style.left = xleft;
  937. xtiper_main.style.top = xtop;
  938. }
  939. }else{
  940. xtiper_main.style.height = xtiper_main.offsetHeight + 'px';
  941. xtop = (window.innerHeight - xtiper_main.offsetHeight) / 2;
  942. xtop = c.y ? xtop + c.y : xtop;
  943. xtop = xtop + 'px';
  944. }
  945.  
  946. if(width[1]=='%'){
  947. xleft = (100 - width[0]) / 2;
  948. xleft = c.x ? xleft + c.x : xleft;
  949. xleft = xleft + width[1];
  950. }else{
  951. xleft = (window.innerWidth - xtiper_main.offsetWidth) / 2;
  952. xleft = c.x ? xleft + c.x : xleft;
  953. xleft = xleft + 'px';
  954. }
  955.  
  956. xtiper_main.style.left = xleft;
  957. xtiper_main.style.top = xtop;
  958. }
  959. }
  960.  
  961. if(c.shade===false){
  962. xtiper_main.style.position = 'fixed';
  963. }
  964. }
  965. //加载层
  966. else if(c.model=='load'){
  967. xtipdiv.classList.add('xtiper_win');
  968. xtipdiv.classList.add('xtiper_win_fixed');
  969. }
  970. //面板菜单
  971. else if(c.model=='sheet'){
  972. xtipdiv.classList.add('xtiper_win');
  973. xtipdiv.classList.add('xtiper_win_fixed');
  974. }
  975.  
  976. if(c.zindex){
  977. xtipdiv.style.zIndex = c.zindex;
  978. }
  979. };
  980.  
  981. //添加动画效果
  982. Xclass.pt.on = function(){
  983. let that = this;
  984. let c = that.c;
  985. let xtipdiv = that.xtipdiv;
  986.  
  987. setTimeout(function(){
  988. xtipdiv.classList.add('xon');
  989. }, 1);
  990. };
  991.  
  992. //后续处理
  993. Xclass.pt.after = function(){
  994. let that = this;
  995. let c = that.c;
  996. let xtipdiv = that.xtipdiv;
  997.  
  998. //短消息、气泡层
  999. if(c.model=='msg' || c.model=='tips'){
  1000. //自动关闭
  1001. that.autoClose();
  1002.  
  1003. if(c.model=='tips'){
  1004. //绑定关闭按钮及遮罩点击关闭
  1005. that.shade();
  1006. }
  1007. }
  1008. //弹幕
  1009. else if(c.model=='danmu'){
  1010. that.danmuStar();
  1011. xtipdiv.addEventListener('mouseenter', function() {
  1012. that.danmuStop();
  1013. });
  1014. xtipdiv.addEventListener('mouseleave', function() {
  1015. that.danmuStar();
  1016. });
  1017. }
  1018. //弹窗层、页面层
  1019. else if(c.model=='win' || c.model=='open'){
  1020. if(c.model=='win'){
  1021. //绑定按钮事件
  1022. let button = xtipdiv.getElementsByTagName('button');
  1023. let btnfun = that.btnfun;
  1024. for(let i=0; i<4; i++){
  1025. that.bclick(button[i], btnfun[i], true);
  1026. }
  1027. }
  1028.  
  1029. //绑定最小化
  1030. if(c.min){
  1031. let minbtn = xtipdiv.getElementsByClassName('xtiper_min')[0];
  1032. if(minbtn){
  1033. minbtn.addEventListener('click', function() {
  1034. that.minmax('min');
  1035. });
  1036. }
  1037. }
  1038.  
  1039. //绑定最大化
  1040. if(c.max){
  1041. let maxbtn = xtipdiv.getElementsByClassName('xtiper_max')[0];
  1042. if(maxbtn){
  1043. maxbtn.addEventListener('click', function() {
  1044. that.minmax('max');
  1045. });
  1046. }
  1047. }
  1048.  
  1049. //绑定鼠标拖动
  1050. if(c.move===true){
  1051. that.drag(true);
  1052. }
  1053.  
  1054. //绑定关闭按钮及遮罩点击关闭
  1055. that.shade();
  1056.  
  1057. //绑定键盘事件
  1058. if(c.model=='win' || c.model=='open'){
  1059. that.key();
  1060. }
  1061.  
  1062. //自动关闭
  1063. if(c.model=='win' && c.type=='alert' && c.times>0){
  1064. that.autoClose();
  1065. }
  1066.  
  1067. //相册按钮
  1068. if(c.type=='photo'){
  1069. that.photo();
  1070.  
  1071. let xindex = c.index - 1;
  1072. let li = xtipdiv.getElementsByClassName('xtiper_photo_li')[xindex];
  1073. let xtiper_words = xtipdiv.getElementsByClassName('xtiper_words')[0];
  1074. xtiper_words.innerHTML = that.dataset(li, 'xtitle');
  1075. }
  1076.  
  1077. //回调函数
  1078. if(c.success && typeof(c.success)=='function'){
  1079. c.success(that);
  1080. }
  1081. }
  1082. //加载层
  1083. else if(c.model=='load'){
  1084. //自动关闭
  1085. that.autoClose();
  1086.  
  1087. //绑定关闭按钮
  1088. that.shade();
  1089. }
  1090. //面板菜单
  1091. else if(c.model=='sheet'){
  1092. //绑定关闭按钮及遮罩点击关闭
  1093. that.shade();
  1094. let btnfun = that.btnfun;
  1095.  
  1096. let xtipdiv_appli = xtipdiv.getElementsByClassName('xtiper_sheet_li');
  1097. let btnlen = xtipdiv_appli.length;
  1098. if(!c.force){
  1099. btnlen = btnlen - 1;
  1100. }
  1101.  
  1102. //绑定按钮事件
  1103. for(let i=0; i<btnlen; i++){
  1104. that.bclick(xtipdiv_appli[i], btnfun[i]);
  1105. }
  1106.  
  1107. if(!c.force){
  1108. xtipdiv_appli[btnlen].addEventListener('click', function() {
  1109. that.close();
  1110. if(c.end){
  1111. c.end();
  1112. }
  1113. });
  1114. }
  1115. }
  1116.  
  1117. //锁定滚动条
  1118. that.lock();
  1119. };
  1120.  
  1121. Xclass.pt.ulli = function(li, aa, xx, yy, close){
  1122. let that = this;
  1123. let xtipdiv = that.xtipdiv;
  1124. let xtiper_content = xtipdiv.getElementsByClassName('xtiper_content')[0];
  1125. let opacity;
  1126.  
  1127. for(let i=0; i<li.length; i++){
  1128. if(li[i].classList.contains('xon')===true){
  1129. if(aa=='left'){
  1130. if(xx){
  1131. li[i].style.left = xx + 'px';
  1132. }else{
  1133. li[i].style.left = '';
  1134. }
  1135. }else{
  1136. li[i].style.left = xx + 'px';
  1137. li[i].style.top = yy + 'px';
  1138. opacity = 1 - ((yy / 4 * 3) / 120);
  1139. if(opacity < 0){
  1140. opacity = 0;
  1141. }
  1142. xtiper_content.style.backgroundColor = 'rgba(0, 0, 0, '+opacity+')';
  1143. if(close===true){
  1144. if(yy > 120){
  1145. that.close();
  1146. }else{
  1147. li[i].style.left = '';
  1148. li[i].style.top = '';
  1149. xtiper_content.style.backgroundColor = 'rgba(0, 0, 0, 1)';
  1150. }
  1151. }
  1152. }
  1153. }
  1154. }
  1155. };
  1156.  
  1157. Xclass.pt.photo = function(){
  1158. let that = this;
  1159. let c = that.c;
  1160. let xtipdiv = that.xtipdiv;
  1161.  
  1162. let ul = xtipdiv.getElementsByClassName('xtiper_photo_ul')[0];
  1163. let li = xtipdiv.getElementsByClassName('xtiper_photo_li');
  1164. let prev = xtipdiv.getElementsByClassName('xtiper_photo_prev')[0];
  1165. let next = xtipdiv.getElementsByClassName('xtiper_photo_next')[0];
  1166.  
  1167. if(prev && li.length>1){
  1168. prev.addEventListener('click', function(){
  1169. that.photoBtn('prev');
  1170. });
  1171. }
  1172. if(next && li.length>1){
  1173. next.addEventListener('click', function(){
  1174. that.photoBtn('next');
  1175. });
  1176. }
  1177.  
  1178. //移动端
  1179. if(that.ifmob===true && li.length>1){
  1180. let aa = null;
  1181. let moveX1, moveX2, moveY1, moveY2, xx, yy;
  1182. ul.addEventListener('touchstart', function(e){
  1183. moveX1 = e.changedTouches[0].pageX;
  1184. moveY1 = e.changedTouches[0].pageY;
  1185. that.touchmove(false);
  1186. });
  1187.  
  1188. ul.addEventListener('touchmove', function(e){
  1189. moveX2 = e.changedTouches[0].pageX;
  1190. moveY2 = e.changedTouches[0].pageY;
  1191. xx = moveX2 - moveX1;
  1192. yy = moveY2 - moveY1;
  1193. if(Math.abs(xx)>Math.abs(yy)){
  1194. aa = aa ? aa : 'left';
  1195. }else{
  1196. aa = aa ? aa : 'top';
  1197. }
  1198. that.ulli(li, aa, xx, yy);
  1199. });
  1200.  
  1201. ul.addEventListener('touchend', function(e){
  1202. if(moveX1 > moveX2){
  1203. if((moveX1 - moveX2 > 40) && aa=='left'){
  1204. that.photoBtn('next');
  1205. }
  1206. }else{
  1207. if((moveX2 - moveX1 > 40) && aa=='left'){
  1208. that.photoBtn('prev');
  1209. }
  1210. }
  1211. that.ulli(li, aa, '', yy, true);
  1212. aa = null;
  1213. });
  1214.  
  1215. ul.addEventListener('click', function(e){
  1216. that.close();
  1217. });
  1218. }else{
  1219. ul.addEventListener('touchstart', function(e){
  1220. return false;
  1221. });
  1222.  
  1223. ul.addEventListener('touchend', function(e){
  1224. return false;
  1225. });
  1226.  
  1227. ul.addEventListener('click', function(e){
  1228. return false;
  1229. });
  1230. }
  1231. };
  1232.  
  1233. Xclass.pt.photoBtn = function(type){
  1234. let that = this;
  1235. let c = that.c;
  1236. let xtipdiv = that.xtipdiv;
  1237.  
  1238. let li = xtipdiv.getElementsByClassName('xtiper_photo_li');
  1239. let xtiper_main = xtipdiv.getElementsByClassName('xtiper_main')[0];
  1240. if(xtiper_main.classList.contains('xtiper_main_photo')===true){
  1241. return false;
  1242. }
  1243. xtiper_main.classList.add('xtiper_main_photo');
  1244. let index = 0, old = 0;
  1245. for(let i=0; i<li.length; i++){
  1246. if(li[i].classList.contains('xon')===true){
  1247. index = old = i;
  1248. }
  1249. }
  1250. if(type=='prev'){
  1251. index--;
  1252. if(index < 0){
  1253. index = li.length - 1;
  1254. }
  1255. }else if(type=='next'){
  1256. index++;
  1257. if(index > li.length - 1){
  1258. index = 0;
  1259. }
  1260. }
  1261.  
  1262. that.now = index;
  1263.  
  1264. let xnum = index + 1;
  1265. let xtiper_num = xtiper_main.getElementsByClassName('xtiper_num')[0];
  1266. xtiper_num.innerHTML = xnum;
  1267. let xtiper_words = xtiper_main.getElementsByClassName('xtiper_words')[0];
  1268.  
  1269. let img;
  1270. for(let i=0;i<li.length;i++){
  1271. if(i==index){
  1272. li[i].classList.add('xon');
  1273. xtiper_words.innerHTML = that.dataset(li[i], 'xtitle');
  1274. xtiper_num.innerHTML = xnum;
  1275. if(c.autoHeight===true){
  1276. img = li[i].getElementsByTagName('img')[0].offsetHeight;
  1277. img = img + 100;
  1278. if(img > window.innerHeight){
  1279. if(c.title){
  1280. img = window.innerHeight;
  1281. }else{
  1282. img = window.innerHeight - 26;
  1283. }
  1284. }
  1285. xtiper_main.style.height = img+'px';
  1286. xtiper_main.style.top = ((window.innerHeight - img)/2)+'px';
  1287. }
  1288. }else{
  1289. li[i].classList.remove('xon');
  1290. }
  1291. if(i==old){
  1292. li[i].classList.add('xold_'+type);
  1293. }else{
  1294. li[i].classList.remove('xold_prev');
  1295. li[i].classList.remove('xold_next');
  1296. }
  1297. }
  1298. setTimeout(function(){
  1299. li[old].classList.remove('xold_'+type);
  1300. xtiper_main.classList.remove('xtiper_main_photo');
  1301. }, 401);
  1302. };
  1303.  
  1304. Xclass.pt.appScroll = function(e){
  1305. e.preventDefault();
  1306. };
  1307.  
  1308. Xclass.pt.touchmove = function(type){
  1309. let that = this;
  1310.  
  1311. if(type===false){
  1312. document.body.addEventListener('touchmove', that.appScroll, {passive: false});
  1313. }else{
  1314. document.body.removeEventListener('touchmove', that.appScroll, {passive: false});
  1315. }
  1316. };
  1317.  
  1318. Xclass.pt.xcstrRep = function(str){
  1319. str = str.replace(/[\s\n\r]/g, ''); //空格换行回车
  1320. str = encodeURIComponent(str).toLowerCase();
  1321.  
  1322. let reparr = [[/true/g, '1'],[/false/g, '0'],[/%/g, ''],[/\(/g, ''],[/\)/g, ''],[/open/g, 'o'],[/ready/g, 'r'],[/noready/g, 'n'],[/url/g, 'u'],[/html/g, 'h'],[/photo/g, 'p'],[/function/g, 'f'],[/99999/g, '9']];
  1323. for(let i=0; i<reparr.length; i++){
  1324. str = str.replace(reparr[i][0], reparr[i][1]);
  1325. }
  1326.  
  1327. return str;
  1328. };
  1329.  
  1330. Xclass.pt.maxSize = function(oldval, newval){
  1331. let that = this;
  1332.  
  1333. let oldsize = that.getsize(oldval) || '';
  1334. let newsize = that.getsize(newval);
  1335. if(oldsize && oldsize[1]=='px' && newsize[1]=='%'){
  1336. if(oldsize[0] > window.innerWidth){
  1337. return (newsize[0]>100 ? 100 : newsize[0])+'%';
  1338. }else{
  1339. return oldval;
  1340. }
  1341. }else{
  1342. return oldval;
  1343. }
  1344. };
  1345.  
  1346. //弹幕开始
  1347. Xclass.pt.danmuStar = function(){
  1348. let that = this;
  1349. let c = that.c;
  1350. let xtipdiv = that.xtipdiv;
  1351.  
  1352. xtipdiv.classList.add('xtiper_danmu_animate');
  1353. if(xtipdiv.style.animationDuration==''){
  1354. xtipdiv.style.animationDuration = '6s';
  1355. }
  1356.  
  1357. let danmutime = Number(xtipdiv.style.animationDuration.replace(/s/, ''));
  1358. that.dataset(xtipdiv, 'xdanmu', danmutime);
  1359.  
  1360. that.outtime = setTimeout(function(){
  1361. that.close();
  1362. }, (danmutime*1000)+1);
  1363. };
  1364.  
  1365. //弹幕停止
  1366. Xclass.pt.danmuStop = function(){
  1367. let that = this;
  1368. let c = that.c;
  1369. let xtipdiv = that.xtipdiv;
  1370.  
  1371. let bwidth = document.body.offsetWidth + 22;
  1372. let newtranslate = xtipdiv.getBoundingClientRect().left;
  1373. xtipdiv.style.transform = 'translateX('+newtranslate+'px)';
  1374.  
  1375. if(that.outtime){
  1376. clearInterval(that.outtime);
  1377. that.outtime = null;
  1378. }
  1379.  
  1380. let progress = newtranslate / bwidth;
  1381. let lesstime = 6 * progress;
  1382. if(lesstime < 0.4){
  1383. lesstime = 0.4;
  1384. }
  1385. that.dataset(xtipdiv, 'xdanmu', lesstime);
  1386. xtipdiv.style.animationDuration = lesstime+'s';
  1387. xtipdiv.classList.remove('xtiper_danmu_animate');
  1388. };
  1389.  
  1390. //绑定按钮事件
  1391. Xclass.pt.bclick = function(btn, fun, ifclose){
  1392. let that = this;
  1393.  
  1394. if(btn){
  1395. if(fun && typeof(fun)=='function'){
  1396. btn.addEventListener('click', function() {
  1397. fun();
  1398. that.close();
  1399. });
  1400. }else{
  1401. if(ifclose===true){
  1402. btn.addEventListener('click', function() {
  1403. that.close();
  1404. });
  1405. }
  1406. }
  1407. }
  1408. };
  1409.  
  1410. //自动关闭
  1411. Xclass.pt.autoClose = function(){
  1412. let that = this;
  1413. let c = that.c;
  1414. let xtipdiv = that.xtipdiv;
  1415.  
  1416. //倒计时
  1417. if(xtipdiv.getElementsByClassName('xtiper_times')[0]){
  1418. let times = c.times - 1;
  1419. let i = times;
  1420. let fn = function() {
  1421. xtiper_times = xtipdiv.getElementsByClassName('xtiper_times')[0];
  1422. xtiper_times.innerHTML = i;
  1423. if(i<=0){
  1424. that.close();
  1425. clearInterval(that.timer);
  1426. that.timer = null;
  1427. }
  1428. i--;
  1429. };
  1430. that.timer = setInterval(fn, 1000);
  1431. fn();
  1432. }else{
  1433. let times = c.times;
  1434. if(times && times!=0){
  1435. setTimeout(function(){
  1436. that.close();
  1437. }, times*1000);
  1438. }
  1439. }
  1440. };
  1441.  
  1442. //锁定滚动条
  1443. Xclass.pt.lock = function(){
  1444. let that = this;
  1445. let c = that.c;
  1446. let xtipdiv = that.xtipdiv;
  1447.  
  1448. if(c.lock===true){
  1449. that.dataset(xtipdiv, 'xlock', 1);
  1450. document.documentElement.style.overflowY = 'hidden';
  1451. that.touchmove(false);
  1452. }
  1453. };
  1454.  
  1455. //解除锁定滚动条
  1456. Xclass.pt.unlock = function(){
  1457. let that = this;
  1458. let flag = 0;
  1459. let winli = document.getElementsByClassName('xtiper_win');
  1460.  
  1461. for(let i=0; i<winli.length; i++){
  1462. if(that.dataset(winli[i], 'xlock')==1 && winli[i].classList.contains('xoff')===false){
  1463. flag++;
  1464. }
  1465. if(winli[i].classList.contains('xoff')===true && winli[i].getAttribute('id')==that.mainid){
  1466. flag++;
  1467. }
  1468. }
  1469. if(flag<=1){
  1470. document.documentElement.style.overflowY = '';
  1471. }
  1472. that.touchmove(true);
  1473. };
  1474.  
  1475. //绑定最大化、最小化
  1476. Xclass.pt.minmax = function(mtype, act){
  1477. let that = this;
  1478. let c = that.c;
  1479. let xtipdiv = that.xtipdiv;
  1480.  
  1481. let iftype, setwidth, setheight;
  1482. if(mtype=='min'){
  1483. iftype = that.dataset(xtipdiv, 'xmin');
  1484. setwidth = '190px';
  1485. setheight = '40px';
  1486. }else if(mtype=='max'){
  1487. iftype = that.dataset(xtipdiv, 'xmax');
  1488. setwidth = '100%';
  1489. setheight = '100%';
  1490. }
  1491.  
  1492. let xtiper_tit = xtipdiv.getElementsByClassName('xtiper_tit')[0];
  1493. let xtiper_main = xtipdiv.getElementsByClassName('xtiper_main')[0];
  1494. let xtiper_content = xtipdiv.getElementsByClassName('xtiper_content')[0];
  1495. let minbtn = xtipdiv.getElementsByClassName('xtiper_min')[0];
  1496. let maxbtn = xtipdiv.getElementsByClassName('xtiper_max')[0];
  1497. let xtiper_bg = xtipdiv.getElementsByClassName('xtiper_bg')[0];
  1498.  
  1499. if(iftype==1 || act==1){ //还原
  1500. xtiper_main.style.width = that.dataset(xtipdiv, 'xwidth')+'px';
  1501. xtiper_main.style.height = that.dataset(xtipdiv, 'xheight')+'px';
  1502. let data_width = xtiper_main.offsetWidth;
  1503. let data_height = xtiper_main.offsetHeight;
  1504. let xleft = (window.innerWidth - data_width) / 2;
  1505. let xtop = (window.innerHeight - data_height) / 2;
  1506. xtiper_main.style.left = xleft+'px';
  1507. xtiper_main.style.top = xtop+'px';
  1508. xtiper_tit.classList.remove('xminmax');
  1509. xtiper_tit.classList.remove('xmin');
  1510. xtiper_tit.getElementsByTagName('p')[0].setAttribute('title', '');
  1511. that.dataset(xtipdiv, 'xmin', '');
  1512. that.dataset(xtipdiv, 'xmax', '');
  1513. if(minbtn){
  1514. minbtn.classList.remove('xon');
  1515. minbtn.style.display = '';
  1516. }
  1517. if(maxbtn){
  1518. maxbtn.classList.remove('xon');
  1519. maxbtn.style.display = '';
  1520. }
  1521. that.drag(true);
  1522.  
  1523. //最小化还原遮罩
  1524. if((c.model=='win' || c.model=='open') && c.shade===true && c.min===true){
  1525. xtipdiv.classList.add('xtiper_win_fixed');
  1526. xtiper_bg.classList.remove('xmin');
  1527. xtiper_main.style.position = '';
  1528. }
  1529. }else{ //变形
  1530. xtiper_main.style.width = setwidth;
  1531. xtiper_main.style.height = setheight;
  1532. xtiper_tit.classList.add('xminmax');
  1533.  
  1534. if(mtype=='min'){
  1535. xtiper_tit.classList.add('xmin');
  1536. xtiper_tit.getElementsByTagName('p')[0].setAttribute('title', xtiper_tit.getElementsByTagName('p')[0].innerHTML);
  1537. that.dataset(xtipdiv, 'xmin', 1);
  1538. xtiper_main.style.top = 'auto';
  1539. xtiper_main.style.bottom = '0';
  1540. xtiper_main.style.left = '0';
  1541. minbtn.classList.add('xon');
  1542. if(maxbtn){
  1543. maxbtn.style.display = 'none';
  1544. }
  1545.  
  1546. //最小化关闭遮罩
  1547. if((c.model=='win' || c.model=='open') && c.shade===true && c.min===true){
  1548. xtipdiv.classList.remove('xtiper_win_fixed');
  1549. xtiper_bg.classList.add('xmin');
  1550. xtiper_main.style.position = 'fixed';
  1551. }
  1552. }else if(mtype=='max'){
  1553. that.dataset(xtipdiv, 'xmax', 1);
  1554. xtiper_main.style.top = '0';
  1555. xtiper_main.style.left = '0';
  1556. maxbtn.classList.add('xon');
  1557. if(minbtn){
  1558. minbtn.style.display = 'none';
  1559. }
  1560. }
  1561. that.drag(false);
  1562. }
  1563. };
  1564.  
  1565. //绑定鼠标拖动
  1566. Xclass.pt.drag = function(open){
  1567. let that = this;
  1568. let c = that.c;
  1569. let xtipdiv = that.xtipdiv;
  1570.  
  1571. let drag = xtipdiv.getElementsByClassName('xtiper_tit')[0];
  1572. if(!drag){
  1573. return false;
  1574. }
  1575. let drag_main = xtipdiv.getElementsByClassName('xtiper_main')[0];
  1576.  
  1577. if(open===true){
  1578. drag.onmousedown = function(event){
  1579. //允许3/4的区域拖动到页面外
  1580. let overX = drag_main.offsetWidth/4*3;
  1581. let overY = drag_main.offsetHeight/4*3;
  1582.  
  1583. drag_main.classList.add('xon');
  1584. event = event || window.event;
  1585. let diffX = event.clientX - drag_main.offsetLeft;
  1586. let diffY = event.clientY - drag_main.offsetTop;
  1587. if(typeof drag_main.setCapture !== 'undefined'){
  1588. drag_main.setCapture();
  1589. };
  1590. document.onmousemove = function(event){
  1591. event = event || window.event;
  1592. let moveX = event.clientX - diffX;
  1593. let moveY = event.clientY - diffY;
  1594. if(moveX < - overX){
  1595. moveX = - overX;
  1596. }else if(moveX > document.body.offsetWidth - drag_main.offsetWidth + overX){
  1597. moveX = document.body.offsetWidth - drag_main.offsetWidth + overX;
  1598. }
  1599. if(moveY < 0){
  1600. moveY = 0
  1601. }else if(moveY > window.innerHeight - drag_main.offsetHeight + overY){
  1602. moveY = window.innerHeight - drag_main.offsetHeight + overY;
  1603. }
  1604. drag_main.style.left = moveX + 'px';
  1605. drag_main.style.top = moveY + 'px'
  1606. };
  1607. document.onmouseup = function(event){
  1608. drag_main.classList.remove('xon');
  1609. this.onmousemove = null;
  1610. this.onmouseup = null;
  1611. //修复低版本ie bug
  1612. if(typeof drag_main.releaseCapture != 'undefined'){
  1613. drag_main.releaseCapture();
  1614. }
  1615. };
  1616. };
  1617. }else{
  1618. drag.onmousedown = function(event){
  1619. return false;
  1620. document.onmousemove = function(event){
  1621. return false;
  1622. };
  1623. document.onmouseup = function(event){
  1624. return false;
  1625. };
  1626. }
  1627. }
  1628. };
  1629.  
  1630. //绑定关闭按钮及遮罩点击关闭
  1631. Xclass.pt.shade = function(){
  1632. let that = this;
  1633. let c = that.c;
  1634. let xtipdiv = that.xtipdiv;
  1635.  
  1636. let close = xtipdiv.getElementsByClassName('xtiper_close')[0];
  1637. if(close){
  1638. close.addEventListener('click', function() {
  1639. that.close();
  1640. if(c.end && typeof(c.end)=='function'){
  1641. c.end();
  1642. }
  1643. });
  1644. }
  1645.  
  1646. if(c.shadeClose){
  1647. let bg = xtipdiv.getElementsByClassName('xtiper_bg')[0];
  1648. bg.addEventListener('click', function() {
  1649. if(c.model=='sheet' && c.force){
  1650. xtip.msg(c.force);
  1651. return false;
  1652. }else{
  1653. that.close();
  1654. if(c.end && typeof(c.end)=='function'){
  1655. c.end();
  1656. }
  1657. }
  1658. });
  1659. }
  1660. };
  1661.  
  1662. //键盘事件
  1663. Xclass.pt.key = function(){
  1664. let that = this;
  1665. let c = that.c;
  1666. let xtipdiv = that.xtipdiv;
  1667.  
  1668. document.onkeydown = function(event) {
  1669. let e = event || window.event || arguments.callee.caller.arguments[0];
  1670. if(e){
  1671. if(e.keyCode==27){ //按 Esc
  1672. that.close();
  1673. }else if(e.keyCode==13) { //按 Enter
  1674. if(c.model=='win'){
  1675. //多按钮取消回车事件
  1676. if(c.btn2 || c.btn3){
  1677. return false;
  1678. }
  1679. that.close();
  1680. if(c.btn1 && typeof(c.btn1)=='function'){
  1681. c.btn1();
  1682. c.btn1 = null;
  1683. }
  1684. return false;
  1685. }
  1686. }
  1687. else{
  1688. return e;
  1689. }
  1690. }
  1691. };
  1692. };
  1693.  
  1694. /*
  1695. * 关闭层
  1696. * 关闭层id
  1697. * 是否检查锁定层 checkLock
  1698. */
  1699. Xclass.pt.close = function(closeid){
  1700. let that = this;
  1701. let c = that.c;
  1702. let checkLock = false;
  1703. let xtipdiv = null;
  1704.  
  1705. if(closeid){
  1706. xtipdiv = document.getElementById(closeid);
  1707. if(!xtipdiv){
  1708. return false;
  1709. }
  1710. if(that.dataset(xtipdiv, 'xlock')==1){
  1711. checkLock = true;
  1712. }
  1713. }else{
  1714. xtipdiv = that.xtipdiv;
  1715. if(c.lock===true){
  1716. checkLock = true;
  1717. }
  1718. }
  1719.  
  1720. if(!xtipdiv){
  1721. return false;
  1722. }
  1723.  
  1724. //弹幕类型不用延时
  1725. let closenow = false;
  1726. if(xtipdiv.classList.contains('xtiper_danmu')===true){
  1727. closenow = true;
  1728. }else{
  1729. closenow = false;
  1730. }
  1731.  
  1732. //不用延时关闭
  1733. if(closenow===true){
  1734. let parent_xtipdiv = xtipdiv.parentNode;
  1735. if(parent_xtipdiv){
  1736. parent_xtipdiv.removeChild(xtipdiv);
  1737. }
  1738. }else{
  1739. if(that.dataset(xtipdiv, 'xreset')==1){
  1740. xtipdiv.classList.add('xoff');
  1741. if(c.lock===true){
  1742. that.unlock();
  1743. }
  1744. setTimeout(function(){
  1745. xtipdiv.style.zIndex = '-99999';
  1746. if(c.min===true){
  1747. that.minmax('min', 1);
  1748. }
  1749. if(c.max===true){
  1750. that.minmax('max', 1);
  1751. }
  1752. if(c.model=='open' && c.type=='photo'){
  1753. if(that.ifmob===true){
  1754. let xtiper_content = xtipdiv.getElementsByClassName('xtiper_content')[0];
  1755. xtiper_content.style.backgroundColor = 'rgba(0, 0, 0, 1)';
  1756. }
  1757. let li = xtipdiv.getElementsByClassName('xtiper_photo_li');
  1758. if(li.length>0){
  1759. for(let i=0; i<li.length; i++){
  1760. li[i].style.left = '';
  1761. li[i].style.top = '';
  1762. }
  1763. }
  1764. }
  1765. }, 201);
  1766. }else{
  1767. xtipdiv.classList.remove('xon');
  1768. setTimeout(function(){
  1769. let parent_xtipdiv = xtipdiv.parentNode;
  1770. if(parent_xtipdiv){
  1771. parent_xtipdiv.removeChild(xtipdiv);
  1772. }
  1773. }, 201);
  1774. }
  1775. }
  1776.  
  1777. //关闭层有锁定属性的才执行解除锁定
  1778. if(checkLock===true){
  1779. that.unlock();
  1780. }
  1781. };
  1782.  
  1783. /*
  1784. * 关闭所有层
  1785. */
  1786. Xclass.pt.closeAll = function(){
  1787. let that = this;
  1788.  
  1789. let msgall = document.getElementsByClassName('xtiper');
  1790. if(msgall.length<=0){
  1791. return false;
  1792. }
  1793. for(let i=0; i<msgall.length; i++){
  1794. that.close(msgall[i].getAttribute('id'));
  1795. }
  1796. document.documentElement.style.overflowY = '';
  1797. that.touchmove(true);
  1798. };
  1799.  
  1800. //单位处理
  1801. Xclass.pt.getsize = function(size){
  1802. if(size){
  1803. reg = /([0-9]+)(px|\%)/;
  1804. size_arr = size.match(reg);
  1805. arr = new Array();
  1806. arr[0] = Number(size_arr[1]);
  1807. arr[1] = size_arr[2];
  1808. return arr;
  1809. }
  1810. };
  1811.  
  1812. //设置高度
  1813. Xclass.pt.setSize = function(type, px){
  1814. let that = this;
  1815. let c = that.c;
  1816. if(c.model=='open'){
  1817. let xtipdiv = that.xtipdiv;
  1818. let xtiper_main = xtipdiv.getElementsByClassName('xtiper_main')[0];
  1819. px = parseInt(px);
  1820. if(type=='height'){
  1821. let xtop = (window.innerHeight - px) / 2;
  1822. xtiper_main.style.height = px+'px';
  1823. xtiper_main.style.top = xtop+'px';
  1824. }
  1825. }
  1826. };
  1827.  
  1828. //设置高度
  1829. Xclass.pt.setHeight = function(px){
  1830. let that = this;
  1831. that.setSize('height', px);
  1832. };
  1833.  
  1834. window.xtip = {
  1835. ver: '2.7.0',
  1836.  
  1837. msg: function(tip, config){
  1838. if(!tip){
  1839. return false;
  1840. }
  1841. config = config || {};
  1842. let o = {};
  1843. o.model = 'msg';
  1844. o.tip = tip;
  1845. o.times = config.times || 2;
  1846. o.type = config.type || 'black';
  1847. o.pos = config.pos || 'middle';
  1848. o.icon = config.icon || '';
  1849. o.zindex = config.zindex || 99999;
  1850.  
  1851. return(this.run(o));
  1852. },
  1853.  
  1854. danmu: function(tip, config){
  1855. if(!tip){
  1856. return false;
  1857. }
  1858. config = config || {};
  1859. let o = {};
  1860. o.model = 'danmu';
  1861. o.tip = tip;
  1862. o.type = config.type || 'black';
  1863. o.icon = config.icon || '';
  1864. o.light = config.light!=null ? config.light : false;
  1865. o.zindex = config.zindex || 99999;
  1866.  
  1867. return(this.run(o));
  1868. },
  1869.  
  1870. tips: function(tip, element, config){
  1871. if(!tip || !element){
  1872. return false;
  1873. }
  1874. config = config || {};
  1875. let o = {};
  1876. o.model = 'tips';
  1877. o.tip = tip;
  1878. if(typeof(element)=='string'){
  1879. let fir = element.substr(0, 1);
  1880. if(fir=='#'){
  1881. element = element.substr(1, element.length);
  1882. }
  1883. }
  1884. o.element = element;
  1885. o.bgcolor = config.bgcolor || '#000000';
  1886. if(config.color){
  1887. o.color = config.color;
  1888. }else{
  1889. let reg = /rgba\((255\,){3}[0-9.]+/;
  1890. let rgba = reg.test(o.bgcolor);
  1891. if(o.bgcolor=='#fff' || o.bgcolor=='#ffffff' || o.bgcolor=='white' || o.bgcolor=='rgb(255, 255, 255)' || o.bgcolor=='rgba(255, 255, 255)' || rgba===true){
  1892. o.color = '#333333';
  1893. }else{
  1894. o.color = '#ffffff';
  1895. }
  1896. }
  1897. o.times = config.times || 2;
  1898. o.pos = config.pos || 'right';
  1899. o.closeBtn = config.closeBtn || false;
  1900. o.zindex = config.zindex || 99999;
  1901.  
  1902. return(this.run(o));
  1903. },
  1904.  
  1905. alert: function(tip, config){
  1906. config = config || {};
  1907. let o = {};
  1908. o.type = 'alert';
  1909. o.tip = tip || '';
  1910. o.icon = config.icon || '';
  1911. o.title = config.title || '提示';
  1912. if(config.btn){
  1913. o.btn = typeof(config.btn)=='string' ? [config.btn] : [config.btn[0]];
  1914. }else{
  1915. o.btn = ['确定'];
  1916. }
  1917. o.btn1 = config.btn1!=null ? config.btn1 : null;
  1918. o.btnbg = [];
  1919. o.times = config.times || 0;
  1920. o.shade = config.shade!=null ? config.shade : true;
  1921. if(o.shade===true){
  1922. o.shadeClose = config.shadeClose!=null ? config.shadeClose : true;
  1923. }else{
  1924. o.shadeClose = false;
  1925. }
  1926.  
  1927. return(this.win(o));
  1928. },
  1929.  
  1930. confirm: function(tip, config){
  1931. config = config || {};
  1932. let o = {};
  1933. o.type = 'confirm';
  1934. o.tip = tip || '';
  1935. o.icon = config.icon || 'warning';
  1936. o.title = config.title || '警告';
  1937. o.btn = config.btn || ['确定', '取消'];
  1938. if(o.btn && o.btn.length > 2){
  1939. let newbtn = [];
  1940. for(let i=0; i<2; i++){
  1941. newbtn.push(o.btn[i]);
  1942. }
  1943. o.btn = newbtn;
  1944. }
  1945. o.btn1 = config.btn1!=null ? config.btn1 : null;
  1946. o.btn2 = config.btn2!=null ? config.btn2 : null;
  1947. o.btnbg = [true, false];
  1948. o.shade = config.shade!=null ? config.shade : true;
  1949. if(o.shade===true){
  1950. o.shadeClose = config.shadeClose!=null ? config.shadeClose : true;
  1951. }else{
  1952. o.shadeClose = false;
  1953. }
  1954.  
  1955. return(this.win(o));
  1956. },
  1957.  
  1958. win: function(config){
  1959. if(!config){
  1960. return false;
  1961. }
  1962. let o = {};
  1963. o.model = 'win';
  1964. o.tip = config.tip || '';
  1965. o.times = config.times || 0;
  1966. o.type = config.type || 'confirm';
  1967. o.icon = config.icon || '';
  1968. o.title = config.title || '提示';
  1969. o.shade = config.shade!=null ? config.shade : true;
  1970. if(o.shade===true){
  1971. o.shadeClose = config.shadeClose!=null ? config.shadeClose : true;
  1972. }else{
  1973. o.shadeClose = false;
  1974. }
  1975. o.lock = config.lock || false;
  1976. o.btn = config.btn || null;
  1977. if(o.btn && o.btn.length > 4){
  1978. let newbtn = [];
  1979. for(let i=0; i<4; i++){
  1980. newbtn.push(o.btn[i]);
  1981. }
  1982. o.btn = newbtn;
  1983. }
  1984. o.btn1 = config.btn1!=null ? config.btn1 : null;
  1985. o.btn2 = config.btn2!=null ? config.btn2 : null;
  1986. o.btn3 = config.btn3!=null ? config.btn3 : null;
  1987. o.btn4 = config.btn4!=null ? config.btn4 : null;
  1988. o.btnbg = config.btnbg || [];
  1989. o.width = config.width || '';
  1990. o.maxWidth = config.maxWidth || '';
  1991. o.end = typeof(config.end)=='function' ? config.end : null;
  1992. o.min = config.min!=null ? config.min : false;
  1993. o.move = true;
  1994. o.app = false;
  1995. o.zindex = config.zindex || 99999;
  1996. o.success = config.success || null;
  1997.  
  1998. return(this.run(o));
  1999. },
  2000.  
  2001. photo: function(content, config){
  2002. if(!content){
  2003. return false;
  2004. }
  2005. config = config || {};
  2006. let o = {};
  2007. o.type = 'photo';
  2008. o.title = config.title || '';
  2009. o.autoHeight = config.height ? false : true;
  2010. o.width = config.width || '600px';
  2011. o.height = config.height || '400px';
  2012. o.content = content;
  2013. o.app = config.app!=null ? config.app : false;
  2014. o.lock = true;
  2015. o.reset = true;
  2016. o.index = config.index || 1;
  2017. o.iftitle = config.iftitle!=null ? config.iftitle : true;
  2018. o.iforder = config.iforder!=null ? config.iforder : true;
  2019.  
  2020. return(this.open(o));
  2021. },
  2022.  
  2023. photoApp: function(content, config){
  2024. if(!content){
  2025. return false;
  2026. }
  2027. config = config || {};
  2028. let o = {};
  2029. o.type = 'photo';
  2030. o.width = '100%';
  2031. o.height = '100%';
  2032. o.bgcolor = 'rgba(0, 0, 0, 1)';
  2033. o.title = false;
  2034. o.move = false;
  2035. o.shade = true;
  2036. o.shadeClose = false;
  2037. o.closeBtn = true;
  2038. o.content = content;
  2039. o.photoapp = true;
  2040. o.lock = true;
  2041. o.reset = true;
  2042. o.index = config.index || 1;
  2043. o.iftitle = config.iftitle!=null ? config.iftitle : true;
  2044. o.iforder = config.iforder!=null ? config.iforder : true;
  2045.  
  2046. return(this.open(o));
  2047. },
  2048.  
  2049. open: function(config){
  2050. if(!config==null || !config.type || !config.content){
  2051. return false;
  2052. }
  2053. let o = {};
  2054. o.model = 'open';
  2055. o.type = config.type;
  2056. o.content = config.content;
  2057. o.id = config.id || '';
  2058. o.title = config.title || '';
  2059. if(config.autoHeight){
  2060. o.autoHeight = config.autoHeight;
  2061. }else{
  2062. o.autoHeight = config.height ? false : true;
  2063. }
  2064. o.width = config.width || '600px';
  2065. o.height = config.height || '400px';
  2066. o.maxWidth = config.maxWidth || '';
  2067. o.maxHeight = config.maxHeight || '';
  2068. o.x = config.x || '';
  2069. o.y = config.y || '';
  2070. o.x = sizef(o.x);
  2071. o.y = sizef(o.y);
  2072. function sizef(str) {
  2073. if(str){
  2074. if(!isNaN(str)){
  2075. return Number(str);
  2076. }else{
  2077. let reg = /\-?[0-9\.]*(px|%)*/, match, num;
  2078. if(str){
  2079. match = str.match(reg);
  2080. if(!match[1] || (match[1] && match[1]=='px')){
  2081. match[0] = match[0].replace(/px/g, '');
  2082. num = Number(match[0]);
  2083. }else{
  2084. num = '';
  2085. }
  2086. return num;
  2087. }
  2088. }
  2089. }else{
  2090. return '';
  2091. }
  2092. }
  2093.  
  2094. o.bgcolor = config.bgcolor || '';
  2095. let reg = /rgba\((0\,){3}[0-9.]+/;
  2096. let rgba = reg.test(o.bgcolor);
  2097. if(o.bgcolor=='#000' || o.bgcolor=='#000000' || o.bgcolor=='black' || o.bgcolor=='rgb(0, 0, 0)' || o.bgcolor=='rgba(0, 0, 0)' || rgba===true){
  2098. o.color = '#ffffff';
  2099. }else{
  2100. o.color = '';
  2101. }
  2102. o.shade = config.shade!=null ? config.shade : true;
  2103. if(o.shade===true){
  2104. o.shadeClose = config.shadeClose!=null ? config.shadeClose : true;
  2105. }else{
  2106. o.shadeClose = false;
  2107. }
  2108. o.end = typeof(config.end)=='function' ? config.end : null;
  2109. o.min = config.min!=null ? config.min : false;
  2110. o.max = config.max!=null ? config.max : false;
  2111. o.closeBtn = config.closeBtn!=null ? config.closeBtn : true;
  2112. o.move = config.move!=null ? config.move : true;
  2113. o.lock = config.lock!=null ? config.lock : false;
  2114. o.over = config.over!=null ? config.over : true;
  2115. o.index = config.index || 1;
  2116. o.app = config.app!=null ? config.app : false;
  2117. if(o.app===true){
  2118. if(o.type=='photo'){
  2119. return(this.photoApp(o.content, o.index));
  2120. }else{
  2121. o.height = config.height || '';
  2122. o.lock = true;
  2123. o.shade = true;
  2124. o.shadeClose = true;
  2125. }
  2126. }
  2127. o.reset = config.reset!=null ? config.reset : true;
  2128. o.zindex = config.zindex || 99999;
  2129. o.photoapp = config.photoapp || false;
  2130. o.iftitle = config.iftitle!=null ? config.iftitle : true;
  2131. o.iforder = config.iforder!=null ? config.iforder : true;
  2132. o.success = config.success || null;
  2133.  
  2134. return(this.run(o));
  2135. },
  2136.  
  2137. load: function(tip, config){
  2138. config = config || {};
  2139. let o = {};
  2140. o.model = 'load';
  2141. o.tip = tip || '';
  2142. o.times = config.times || 0;
  2143. o.lock = config.lock!=null ? config.lock : false;
  2144. o.zindex = config.zindex || 99999;
  2145. o.closeBtn = config.closeBtn!=null ? config.closeBtn : false;
  2146.  
  2147. return(this.run(o));
  2148. },
  2149.  
  2150. sheet: function(config){
  2151. if(!config || !config.btn){
  2152. return false;
  2153. }
  2154. let o = {};
  2155. o.model = 'sheet';
  2156. o.title = config.title || '';
  2157. o.align = config.align || 'center';
  2158. let btn = new Array();
  2159. for(let i=0; i<8; i++){
  2160. if(config.btn[i]){
  2161. btn[i] = config.btn[i];
  2162. }
  2163. }
  2164. o.btn = btn;
  2165. o.btn1 = config.btn1 || null; o.btn2 = config.btn2 || null;
  2166. o.btn3 = config.btn3 || null; o.btn4 = config.btn4 || null;
  2167. o.btn5 = config.btn5 || null; o.btn6 = config.btn6 || null;
  2168. o.btn7 = config.btn7 || null; o.btn8 = config.btn8 || null;
  2169.  
  2170. o.force = config.force || '';
  2171. o.btnClose = config.btnClose || '取消';
  2172. o.lock = true;
  2173. o.shadeClose = true;
  2174. o.end = typeof(config.end)=='function' ? config.end : null;
  2175. o.zindex = config.zindex || 99999;
  2176.  
  2177. return(this.run(o));
  2178. },
  2179.  
  2180. //核心方法
  2181. run: function(options){
  2182. let x = new Xclass(options);
  2183. return x.mainid;
  2184. },
  2185.  
  2186. close: function(closeid){
  2187. let o = {};
  2188. o.model = 'close';
  2189. o.closeid = closeid;
  2190.  
  2191. return(this.run(o));
  2192. },
  2193.  
  2194. closeAll: function(){
  2195. let o = {};
  2196. o.model = 'closeAll';
  2197.  
  2198. return(this.run(o));
  2199. },
  2200. };
  2201. }(window);