-
Notifications
You must be signed in to change notification settings - Fork 18
/
xxy.min.js
30 lines (29 loc) · 15.9 KB
/
xxy.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* XXY is open source and released under the MIT Licence.
* Copyright (c) 2017 xiexiuyue
* email : abc_xf@126.com
**/
(function(){function b(b){return window.parent.document.getElementById(b)}function v(h,p){if(b(h))return!1;var d=window.parent.document.createElement("style");d.id=h;"styleSheet"in d?(d.setAttribute("type","text/css"),d.styleSheet.cssText=p):d.innerHTML=p;window.parent.document.getElementsByTagName("head")[0].appendChild(d)}Function.prototype.bind||(Function.prototype.bind=function(b){if("function"!==typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
var h=Array.prototype.slice.call(arguments,1),d=this,a=function(){},c=function(){return d.apply(this instanceof a&&b?this:b,h.concat(Array.prototype.slice.call(arguments)))};a.prototype=this.prototype;c.prototype=new a;return c});if(!b("xxy-addDom"))try{var y=window.parent.document.createElement("div");y.id="xxy-addDom";window.parent.document.body.appendChild(y)}catch(h){console.error("Please put the script below the body tag (not the bottom)--xxy")}if("object"==typeof window.xxy)return console.error("Close the global object of XXY--xxy"),
!1;v("xxy-style-popup","#xxy-addDom .xxy-popup-box{position:fixed;top:0;left:0;z-index:99;z-index:99999999;overflow:hidden;width:100%;height:100%;background:rgba(0,0,0,.5);font-size:14px}#xxy-addDom .xxy-popup-box .inner{position:absolute;top:0;right:0;bottom:0;left:0;margin:auto;width:80%;height:0;max-width:280px;background:#fff;color:#646464}#xxy-addDom .xxy-popup-box .inner .inner_box{border:.01px solid #adadad;background:#fff;-webkit-transform:translateY(-50%);transform:translateY(-50%);-ms-transform:translateY(-50%)}#xxy-addDom .xxy-popup-box .xxy-popup-title{width:100%;border-bottom:1px solid #e8e8e8;background-color:#eee;color:#646464;text-align:left;text-indent:.7em;font-size:13px;line-height:2.1em}#xxy-addDom .xxy-popup-box .print{overflow:auto;padding:15px 20px 0;max-height:250px}#xxy-addDom .xxy-popup-box .or{margin:0 auto;width:90%}#xxy-addDom .xxy-popup-box button{border-radius:0px;margin:1em 0;padding:.6em 0;width:48%;border-width:0;border-radius:.4em;color:#fff}#xxy-addDom .xxy-popup-box .xxy-popup-done{background:#febb2c}#xxy-addDom .xxy-popup-box .xxy-popup-cancal{margin-left:4%;background:#eb4b27}#xxy-addDom .xxy-popup-box .off{float:right;margin-right:.4em;font-size:1.3em}#xxy-addDom .print_inner p span:nth-child(1){text-align:right}#xxy-addDom .print_inner p span:nth-child(2){text-align:center}#xxy-addDom .print_inner span{display:inline-block;width:48%}#xxy-addDom .print_inner p .important{color:#febb2c}");
v("xxy-style-toast","#xxy-addDom .xxy-toast{z-index: 999999999;text-align:center;opacity:1;transition:all 1s;-webkit-transition:all 1s;position:fixed;bottom:2em;left:50%;-webkit-transition-timing-function:ease;-webkit-transition-duration:2s;-webkit-transition-property:color;-webkit-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);min-width:2em;width:100%;box-sizing:border-box}#xxy-addDom .xxy-toast>*{max-width:69%;display:inline-block;margin:0 auto;padding:.2em 1em;border-radius:.9em;background:rgba(0,0,0,.6);color:#fff;font-size:15px;line-height:1.7em}");
v("xxy-style-touch",".xxy-down-viewbox{position:relative;overflow:hidden;margin:auto;min-width:200px;min-height:200px;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);-ms-transform:translate3d(0,0,0);-webkit-backface-visibility:hidden;-ms-backface-visibility:hidden;backface-visibility:hidden;-webkit-perspective:1000;-ms-perspective:1000;perspective:1000}.xxy-down-viewbox>div{overflow:auto;width:100%;height:100%;border:0 solid transparent;background:#eee}.xxy-down-viewbox>div:before{top: .2rem;content:attr(data-befor)}.xxy-down-viewbox>div:after,.xxy-down-viewbox>div:before{position:absolute;width:100%;color:#646464;text-align:center}.xxy-down-viewbox>div:after{bottom:.2rem;content:attr(data-after)}.xxy-down-viewbox>div>*{position:relative;z-index:1;background:#fff}");
window.xxy=function(){var h={skin:void 0,mask:.5,an:!1},p=function(d){d.preventDefault()};return{mixin:function(d,a){for(var c in a)d[c]=a[c]},getParent:function(d,a,c,f){try{if(d[a]===c&&void 0!=d[a])f(d);else if(d&&"BODY"!=d.tagName){var b=d.parentNode,u=[].slice.call(arguments);u[0]=b;this.getParent.apply(this,u)}else return!1}catch(g){}},config:function(d){if("[object Object]"!==Object.prototype.toString.call(d))return console.error("Parameters should be objects--xxy\n docs: https://github.com/0123cf/xxy"),
!1;this.mixin(h,d)},popupClose:function(){},popup:function(d,a,c){function f(a,d){for(var c=0;c<a.length;c++)if("function"==typeof a[c]){a[c](d);break}}function t(){q.style.cssText="transition: all 100ms;-webkit-transition: all 300msopacity: 1;webkitTransform: scale(1,1);transform: scale(1,1)"}function u(){try{l.parentNode.removeChild(l),window.parent.document.body.removeEventListener("touchmove",p,!1),document.documentElement.style.overflow="initial",document.body.style.overflow="initial"}catch(A){}}
var g=arguments,m="\u63d0\u793a",k="",w="\u786e\u8ba4",x="\u53d6\u6d88",e=!1,r=g.length;b("xxy-popup-box")&&b("xxy-popup-box").parentNode.removeChild(b("xxy-popup-box"));document.documentElement.style.overflow="hidden";document.body.style.overflow="hidden";for(var n=0;n<arguments.length;n++)"function"==typeof arguments[n]?e=!0:"";switch(e?--r:r){case 1:k=g[0];break;case 2:m=g[0];k=g[1];break;case 3:k=g[0];w=g[1];x=g[2];break;case 4:m=g[0];k=g[1];w=g[2];x=g[3];break;default:console.error("Parameter format error\uff01--xxy")}"ios"==
h.skin&&(e=b("xxy-style-popup"),"styleSheet"in b("xxy-style-popup")?(e.setAttribute("type","text/css"),e.styleSheet.cssText="#xxy-addDom .xxy-popup-box{position:fixed;top:0;left:0;z-index:99;z-index:99999999;overflow:hidden;width:100%;height:100%;background:rgba(0,0,0,.5);font-size:14px}#xxy-addDom .xxy-popup-box .inner{position:absolute;top:0;right:0;bottom:0;left:0;margin:auto;width:80%;height:0;max-width:280px;background:rgba(255,255,255,.95)}#xxy-addDom .xxy-popup-box .inner .inner_box{background:#fff;-webkit-transform:translateY(-50%);transform:translateY(-50%);-ms-transform:translateY(-50%);border-radius:13px}#xxy-addDom .xxy-popup-box .xxy-popup-title{font-size:18px;font-weight:500;text-align:center;padding-top:5px;line-height:2em}#xxy-addDom .xxy-popup-box .print{overflow:auto;padding:0 15px 15px 15px;max-height:250px}#xxy-addDom .xxy-popup-box .or{margin:0 auto;border-bottom-left-radius:13px;border-bottom-right-radius:13px;overflow:hidden}#xxy-addDom .xxy-popup-box button{border-radius:0px;;border-width:0;color:#007aff;background:#fff;background:rgba(255,255,255,.95);font-size:17px;line-height:44px;position:relative;overflow:hidden;box-sizing:border-box;width:50%;height:44px;padding:0 5px;cursor:pointer;text-align:center;white-space:nowrap;text-overflow:ellipsis;color:#007aff;background:rgba(255,255,255,.95);-webkit-box-flex:1;border-top:1px solid #cdcdcd}#xxy-addDom .xxy-popup-box .xxy-popup-cancal{border-left:1px solid #cdcdcd}#xxy-addDom .xxy-popup-box .off{float:right;margin-right:.4em;font-size:1.3em}#xxy-addDom .print_inner p span:nth-child(1){text-align:right}#xxy-addDom .print_inner p span:nth-child(2){text-align:center}#xxy-addDom .print_inner span{display:inline-block;width:48%}#xxy-addDom .print_inner p .important{color:#febb2c}"):
e.innerHTML="#xxy-addDom .xxy-popup-box{position:fixed;top:0;left:0;z-index:99;z-index:99999999;overflow:hidden;width:100%;height:100%;background:rgba(0,0,0,.5);font-size:14px}#xxy-addDom .xxy-popup-box .inner{position:absolute;top:0;right:0;bottom:0;left:0;margin:auto;width:80%;height:0;max-width:280px;background:rgba(255,255,255,.95)}#xxy-addDom .xxy-popup-box .inner .inner_box{background:#fff;-webkit-transform:translateY(-50%);transform:translateY(-50%);-ms-transform:translateY(-50%);border-radius:13px}#xxy-addDom .xxy-popup-box .xxy-popup-title{font-size:18px;font-weight:500;text-align:center;padding-top:5px;line-height:2em}#xxy-addDom .xxy-popup-box .print{overflow:auto;padding:0 15px 15px 15px;max-height:250px}#xxy-addDom .xxy-popup-box .or{margin:0 auto;border-bottom-left-radius:13px;border-bottom-right-radius:13px;overflow:hidden}#xxy-addDom .xxy-popup-box button{border-radius:0px;;border-width:0;color:#007aff;background:#fff;background:rgba(255,255,255,.95);font-size:17px;line-height:44px;position:relative;overflow:hidden;box-sizing:border-box;width:50%;height:44px;padding:0 5px;cursor:pointer;text-align:center;white-space:nowrap;text-overflow:ellipsis;color:#007aff;background:rgba(255,255,255,.95);-webkit-box-flex:1;border-top:1px solid #cdcdcd}#xxy-addDom .xxy-popup-box .xxy-popup-cancal{border-left:1px solid #cdcdcd}#xxy-addDom .xxy-popup-box .off{float:right;margin-right:.4em;font-size:1.3em}#xxy-addDom .print_inner p span:nth-child(1){text-align:right}#xxy-addDom .print_inner p span:nth-child(2){text-align:center}#xxy-addDom .print_inner span{display:inline-block;width:48%}#xxy-addDom .print_inner p .important{color:#febb2c}");
m=['<div style="'+("background: rgba(0,0,0,"+h.mask+");")+'" class = "xxy-popup-box" id = "xxy-popup-box">','<div class = "inner" style="transition: all 100ms;-webkit-transition: all 300msopacity: 0;webkitTransform: scale(1.2,1.2);transform: scale(1.2,1.2)"><div class = "inner_box"><div class = "xxy-popup-inner"><div class = "xxy-popup-title"> <i class = "iconfont icon-tishi"></i> ',m,'</div><div id = "xxy_popup_inner_print" class = "print">',k,'</div></div><div class = "or"><button class = "xxy-popup-done" id = "xxy-popup-done">',
w,'</button><button class = "xxy-popup-cancal" id = "xxy-popup-cancal">',x,"</button></div></div></div></div>"].join("");document.body.insertAdjacentHTML?b("xxy-addDom").insertAdjacentHTML("beforeend",m):b("xxy-addDom").innerHTML+=m;var l=b("xxy-popup-box"),q=window.parent.document.querySelector("#xxy-popup-box .inner");h.an||t();h.an&&window.setTimeout(function(){t()},50);b("xxy_popup_inner_print").ontouchmove=function(a){a.stopPropagation()};try{window.parent.document.body.addEventListener("touchmove",
p,!1)}catch(A){var z=function(){l.parentNode.removeChild(l);try{window.parent.document.body.removeEventListener("touchmove",p,!1)}catch(C){}document.documentElement.style.overflow="auto"};b("xxy-popup-done").onclick=function(){f(g,0);z()};b("xxy-popup-done").onclick=function(){f(g,1);z()};return!1}b("xxy-popup-box").addEventListener("click",function(a){a=a.target;if("xxy-popup-done"==a.id||"xxy-popup-cancal"==a.id)u(),"xxy-popup-done"==a.id&&f(g,0),"xxy-popup-cancal"==a.id&&f(g,1)});this.popupClose=
u},alert:function(){for(var d=[].slice.call(arguments),a=d.length,c=0;c<arguments.length;c++)"function"==typeof arguments[c]?--a:"";3==a&&d.push("");this.popup.apply(this,d);d=window.parent.document.querySelector("#xxy-addDom #xxy-popup-cancal");c=window.parent.document.querySelector("#xxy-addDom .xxy-popup-box button");d.innerText=3==a?arguments[2]?arguments[2]:"\u786e\u8ba4":"\u786e\u8ba4";d.style.cssText="display: block;margin-left: auto;margin-right: auto;width: 100%;border-left-width: 0px;";
c.style.display="none"},template:function(d){var a=document.createElement("style");if(-1==d.indexOf("<"))try{var c=document.querySelector(d).innerHTML}catch(f){console.log("%c[xxy] \u53c2\u6570\u6709\u8bef","color: red");return}else c=d;xxy.popup("");a.innerHTML="off{display: block}";document.head.appendChild(a);document.querySelector("#xxy-popup-box").innerHTML=c;document.querySelector("#xxy-popup-box").addEventListener("click",function(c){this.getParent(c.target,"tagName","OFF",function(c){this.popupClose();
document.head.removeChild(a)}.bind(this))}.bind(this))},toast:function(d,a){if(a){if("[object Object]"!==Object.prototype.toString.call(a))switch(Object.prototype.toString.call(a)){case "[object Number]":a={exp:a};break;case "[object String]":a={site:a}}}else a={};var c=(a.exp||2500)+10,f=document.createElement("div");if(b("xxy-toast")){var t=b("xxy-toast");t.parentNode.removeChild(t);this.toastRemveTime&&window.clearTimeout(this.toastRemveTime)}f.innerHTML="<div>"+d+"</div>";f.id="xxy-toast";f.className=
"xxy-toast";b("xxy-addDom").appendChild(f);(function(){switch(a.site){case "center":f.style.cssText="bottom: calc(50% - 1.5em);";break;case "top":f.style.cssText="top: 20vw; bottom: auto;"}if(a.more)if("[object Object]"==Object.prototype.toString.call(a.more))for(var c in a.more)f.children[0].style.cssText+=";"+c+":"+a.more[c];else console.log("%c XXY: \u53c2\u6570\u9519\u8bef","color: red")})();this.toastRemveTime=window.setTimeout(function(){b("xxy-toast").parentNode.removeChild(b("xxy-toast"))},
c)},touch:function a(){function c(a,c){if(!window.getComputedStyle)return!1;var f=a.querySelector(".view"),b=a.querySelector(".inner"),m=parseInt(window.getComputedStyle(a).height);b.addEventListener("touchstart",function(c){c=c.touche||c.touches[0];var a=f.scrollTop,b=window.getComputedStyle(this).height;b=window.parseInt(b);this.style.transitionDuration="0ms";this.startTop=a;this.startSite={y:c.clientY};this.domHeight=b},!1);b.addEventListener("touchmove",function(a){var b=f.scrollTop,g=this.startSite.y,
e=(a.touche||a.touches[0]).clientY,k=c.body?window.innerHeight:m,n=e-g;n-=n/1.37;if(e>g){if(1<b||!c.move)return!1;a.preventDefault();a=n-this.startTop;33<a?f.setAttribute("data-befor","\u91ca\u653e\u7acb\u5373\u5237\u65b0"):f.setAttribute("data-befor","\u4e0b\u62c9\u5237\u65b0");this.style.transform="translate3d(0, "+a+"px, 0)";this.topGap=a;this.direction="down"}else if(b+k+1>=this.domHeight){a.preventDefault();if(!c.move)return!1;this.direction="up";33<-n?f.setAttribute("data-after","\u91ca\u653e\u7acb\u5373\u5237\u65b0"):
f.setAttribute("data-after","\u4e0a\u62c9\u52a0\u8f7d");this.style.transform="translate3d(0, "+n+"px, 0)";this.topGap=-n}},!1);b.addEventListener("touchend",function(a){var b=this,g=this.direction;a.stopPropagation();if(!this.direction)return!1;c.done=function(){b.style.transitionDuration="500ms";b.style.transform="translate3d(0, 0px, 0)";b.direction=void 0};if(33>this.topGap)return c.done(),!1;f.setAttribute("data-befor","\u6b63\u5728\u5237\u65b0..");f.setAttribute("data-after","\u6b63\u5728\u5237\u65b0..");
"down"==g&&c.down&&c.down();"up"==g&&c.up&&c.up();b.style.transitionDuration="500ms";b.style.transform="translate3d(0, "+("up"==g?-28:28)+"px, 0)"},!1)}a.bind({});return{bind:function(a,b){c(a,b)}}},slider:function(){function a(a,b){function c(){n=setInterval(function(){f();m(0,h*e);setTimeout(function(){e++;m(.3,h*e);g()},500)},b.time)}function f(){0==e?e=q.length:e==l.length-1&&(e=q.length-1)}function g(){for(var a=0;a<q.length;a++)q[a].classList.remove("active");q[e%q.length].classList.add("active")}
function m(a,c){k.style.transition=a+"s";k.style.transform="translateX("+c+"px)";k.style.webkitTransform="translateX("+c+"px)"}var k=a.children[0],h=-a.getBoundingClientRect().width,p=0,e=0,r=0,n=void 0,l=void 0,q=void 0;(function(){document.body.insertAdjacentHTML?k.insertAdjacentHTML("beforeend",k.innerHTML):k.innerHTML+=k.innerHTML;l=k.children;k.style.width=l.length+"00%";for(var c=0;c<l.length;c++)l[c].style.width=100/l.length+"%";var b=document.createElement("div");b.setAttribute("id","point");
for(c=0;c<l.length/2;c++){var f=document.createElement("span");0==c&&f.classList.add("active");b.appendChild(f)}a.appendChild(b);q=a.querySelectorAll("#point span")})();c();a.running=!1;a.addEventListener("touchstart",function(a){p=a.changedTouches[0].clientX;k.style.transition="0s";clearInterval(n);f()});a.addEventListener("touchmove",function(a){a.preventDefault();this.running=!0;a=a.changedTouches[0].clientX-p;r=h*e+a;m(0,r);b.self.gap(a)});a.addEventListener("touchend",function(a){a.stopPropagation();
var b=a.target;b.running=!0;(function B(a){if("slider-right"==a.id||"slider-left"==a.id)e="slider-right"==a.id?e+1:e-1,m(.3,h*e),g(),c(),b.running=!1;else if(a&&"BODY"!=a.tagName)B(a.parentNode);else return!1})(b);if(!b.running)return!1;this.running&&(.2<e-r/h?e--:-.2>e-r/h?e++:"");0>e?e=0:e>l.length-1&&(e=l.length-1);m(.3,h*e);g();c();this.running=!1})}return{on:function(a,b){this[a]=b},gap:function(){},bind:function(c,b){b||(b={time:1E4});b.self=this;a(c,b)}}}}}()})();