Blame view

web/dist/js/cmpts/slide-frame/slide-frame.js 10.6 KB
2e86c939   xu   “首次提交”
1
define(["css!cmpts/slide-frame/slide-frame.css"],function(){function n(n,t){"use strict";function e(){m=g.children,w=m.length,x=w>4,m.length<2&&(t.continuous=!1),f.transitions&&t.continuous&&m.length<3&&(g.appendChild(m[0].cloneNode(!0)),g.appendChild(g.children[1].cloneNode(!0)),m=g.children),S&&d(),b=new Array(m.length),p=n.getBoundingClientRect().width||n.offsetWidth,g.style.width=p+"px",t.useForImg&&(g.style.height=p*t.useForImg.height/t.useForImg.width+"px");for(var e=m.length;e--;){var i=m[e];i.style.width=p+"px",i.setAttribute("data-index",e),f.transitions&&r(e,E>e?-p:e>E?p:0,0,!0)}t.continuous&&f.transitions&&(r(a(E-1),-p,0,!0),r(a(E+1),p,0,!0)),f.transitions||(g.style.left=E*-p+"px"),n.style.visibility="visible";var s=E;setTimeout(function(){m[a(s+1)].style.visibility="visible",s>0&&(m[a(s-1)].style.visibility="visible")},520),M&&!S&&u(),h(t.setupCallback&&t.setupCallback(E))}function i(){t.continuous?o(E-1):E&&o(E-1)}function s(){t.continuous?o(E+1):E<m.length-1&&o(E+1)}function a(n){return(m.length+n%m.length)%m.length}function o(n,e){if(E!=n){if(S&&d(),f.transitions){var i=Math.abs(E-n)/(E-n);if(t.continuous){var s=i;i=-b[a(n)]/p,i!==s&&(n=-i*m.length+n)}for(var o=Math.abs(E-n)-1;o--;)r(a((n>E?n:E)-o-1),p*i,0,!0);n=a(n),r(E,p*i,isFinite(e)?e||0:T),r(n,0,isFinite(e)?e||0:T),t.continuous&&r(a(n-i),-(p*i),0)}else n=a(n),l(E*-p,n*-p,e||T);E=n,h(t.callback&&t.callback(E)),h(function(){m[a(E+1)].style.visibility="visible",m[a(E)].style.visibility="visible",m[a(E-1)].style.visibility="visible"})}}function r(n,t,e,i){c(n,t,e,i),b[n]=t}function c(n,t,e){var i=m[n],s=i&&i.style;s&&L(function(){s.webkitTransitionDuration=s.transitionDuration=e+"ms",s.webkitTransform=/OS 7/.test(navigator.userAgent)?"translate("+t+"px,0) "+D+" scale(1.0000001)":"translate("+t+"px,0) "+D})}function l(n,e,i){if(!i)return void(g.style.left=e+"px");var s=+new Date,a=setInterval(function(){var o=+new Date-s;return o>i?(g.style.left=e+"px",M&&!S&&u(),t.transitionEnd&&t.transitionEnd.call(event,E,m[E]),void clearInterval(a)):void(g.style.left=(e-n)*(Math.floor(o/i*100)/100)+n+"px")},4)}function u(){S=setTimeout(s,M)}function d(n){n&&(M=0),clearTimeout(S),S=null}var v=function(){},h=function(n){setTimeout(n||v,0)},f={addEventListener:!!window.addEventListener,touch:"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,transitions:function(n){var t=["transitionProperty","WebkitTransition","MozTransition","OTransition","msTransition"];for(var e in t)if(void 0!==n.style[t[e]])return!0;return!1}(document.createElement("swipe"))};if(n){var m,b,p,w,g=n.children[0],x=!0;t=t||{};var E=parseInt(t.startSlide,10)||0,T=t.speed||300,I=!1,y=!0,C=!1,k=!1,L=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(n,t){return setTimeout(n,t||1)}}(),D=t.HWCompositing?" translateZ(0)":"";t.continuous=void 0===t.continuous||t.continuous,t.useResizeEvent=void 0!==t.useResizeEvent&&t.useResizeEvent,t.orientationchange=void 0!==t.orientationchange&&t.orientationchange,t.hasInnerScroll=void 0!==t.hasInnerScroll&&t.hasInnerScroll,t.useForImg=void 0!==t.useForImg?t.useForImg:null;var S,F,M=t.auto||0,_={},z={},q=!1,A=!1,R=0,O=0,W={handleEvent:function(n){switch(n.type){case"touchstart":this.start(n);break;case"touchmove":this.move(n);break;case"touchend":h(this.end(n));break;case"webkitTransitionEnd":case"msTransitionEnd":case"oTransitionEnd":case"otransitionend":case"transitionend":h(this.transitionEnd(n));break;case"resize":t.useResizeEvent&&h(e.call());break;case"orientationchange":t.orientationchange&&h(e.call())}t.stopPropagation&&n.stopPropagation()},start:function(n){var e=n.touches[0];_={x:e.pageX,y:e.pageY,time:+new Date},F=void 0,z={},t.hasInnerScroll&&q&&(A=!0),q=!1,g.addEventListener("touchmove",this,!1),g.addEventListener("touchend",this,!1)},move:function(n){if(!(n.touches.length>1||n.scale&&1!==n.scale)){t.disableScroll&&n.preventDefault();var e=n.touches[0];if(z={x:e.pageX-_.x,y:e.pageY-_.y},I&&z.x<0!=y)return void n.preventDefault();if("undefined"==typeof F&&(F=!!(F||Math.abs(z.x)<Math.abs(z.y))),F)q=!0;else{if(n.preventDefault(),d(),A)return;t.continuous?(c(a(E-1),z.x+b[a(E-1)],0),c(E,z.x+b[E],0),c(a(E+1),z.x+b[a(E+1)],0),t.movecallback&&t.movecallback(E,z.x)):(z.x=z.x/(!E&&z.x>0||E==w-1&&z.x<0?Math.abs(z.x)/p+1:1),c(E-1,z.x+b[E-1],0),c(E,z.x+b[E],0),c(E+1,z.x+b[E+1],0),(0==E||E==w-1)&&t.movecallback&&t.movecallback(E,z.x))}}},end:function(n){if(t.hasInnerScroll&&A&&(A=!1),I&&z.x<0!=y)return void n.preventDefault();var e=+new Date-_.time,i=Number(e)<300&&Math.abs(z.x)>10||Math.abs(z.x)>p/3,s=!E&&z.x>0||E==w-1&&z.x<0;t.continuous&&(s=!1);var o=z.x<0,c=a(o?E-2:E+2),l=a(o?E+2:E-2);F||(i&&!s?(o?(t.continuous?(r(a(E-1),-p,0),r(a(E+2),p,0)):r(E-1,-p,0),r(E,b[E]-p+-1*O,T),r(a(E+1),parseFloat((b[a(E+1)]-p+-1*O).toFixed(1)),T),O=0,E=a(E+1)):(t.continuous?(r(a(E+1),p,0),r(a(E-2),-p,0)):r(E+1,p,0),r(E,b[E]+p+-1*R,T),r(a(E-1),parseFloat((b[a(E-1)]+p+-1*R).toFixed(1)),T),R=0,E=a(E-1)),setTimeout(function(){t.callback&&t.callback(E,o)},10),L(function(){m[l].style.visibility="visible",x&&(m[c].style.visibility="hidden")})):t.continuous?(r(a(E-1),-p,T),r(E,0,T),r(a(E+1),p,T)):o?(E==w-1?k&&0==R&&Math.abs(z.x)>t.limitDist&&(R=-1*t.chockDist):R=0,r(E-1,-p+R,T),r(E,R,T,0),r(E+1,p,T)):(0==E?C&&0==O&&Math.abs(z.x)>t.limitDist&&(O=t.chockDist):O=0,r(E-1,-p,T),r(E,O,T,0),r(E+1,p+O,T))),g.removeEventListener("touchmove",W,!1),g.removeEventListener("touchend",W,!1)},transitionEnd:function(n){parseInt(n.target.getAttribute("data-index"),10)==E&&(M&&!S&&u(),t.transitionEnd&&t.transitionEnd.call(n,E,m[E]))}};return e(),M&&!S&&u(),f.addEventListener?(f.touch&&g.addEventListener("touchstart",W,!1),f.transitions&&(g.addEventListener("webkitTransitionEnd",W,!1),g.addEventListener("msTransitionEnd",W,!1),g.addEventListener("oTransitionEnd",W,!1),g.addEventListener("otransitionend",W,!1),g.addEventListener("transitionend",W,!1)),window.addEventListener("resize",W,!1),window.addEventListener("orientationchange",W,!1)):(window.onresize=function(){t.useResizeEvent&&e()},window.onorientationchange=function(){t.orientationchange&&e()}),{setup:function(){e()},slide:function(n,t){d(),o(n,t)},prev:function(){d(),i()},next:function(){d(),s()},begin:function(){M=t.auto,u()},stop:function(){d()},getPos:function(){return E},getNumSlides:function(){return w},lockdir:function(n){var t={left:!1,right:!0};I=!0,y=!!t[n]},enableDist:function(n){"left"==n&&(C=!0),"right"==n&&(k=!0)},disableDis:function(n){"left"==n&&(C=!1),"right"==n&&(k=!1)},unlockDir:function(){I=!1},kill:function(){d();for(var n=m.length;n--;)m[n],f.transitions;f.addEventListener?(g.removeEventListener("touchstart",W,!1),g.removeEventListener("webkitTransitionEnd",W,!1),g.removeEventListener("msTransitionEnd",W,!1),g.removeEventListener("oTransitionEnd",W,!1),g.removeEventListener("otransitionend",W,!1),g.removeEventListener("transitionend",W,!1),window.removeEventListener("resize",W,!1)):window.onresize=null}}}}var t=Dom7,e=Template7;t.extend=function(){var n,t,e,i,s,a,o=arguments[0]||{},r=1,c=arguments.length,l=!1;for("boolean"==typeof o&&(l=o,o=arguments[1]||{},r=2),"object"==typeof o||utils.isFunction(o)||(o={}),c===r&&(o=this,--r);r<c;r++)if(null!=(n=arguments[r]))for(t in n)e=o[t],i=n[t],o!==i&&(l&&i&&(utils.isPlainObject(i)||(s=utils.isArray(i)))?(s?(s=!1,a=e&&utils.isArray(e)?e:[]):a=e&&utils.isPlainObject(e)?e:{},o[t]=utils.extend(l,a,i)):void 0!==i&&(o[t]=i));return o};var i={create:function(n){this.navElem=n,this._cacheDOM(),this.setTabPos()},_cacheDOM:function(){var n=this;n.navItem=n.navElem.find("li"),n.navScrollInner=n.navElem.find(".h-nav-bar"),n.navScrollBox=n.navElem.find(".h-scroll-bar"),n.scrollBoxW=n.navScrollBox.width(),n.clientW=t(window).width()},setTabPos:function(){var n=this;n.navWidth=0,t.each(n.navElem.find("li"),function(e,i){var s=i.clientWidth,a=i.getBoundingClientRect().left,o=n.clientW/2-s/2-a;o=o>0?0:Math.abs(Math.ceil(o)),i.setAttribute("scroll-left",o),n.navWidth+=t(i).width()}),n.scrollToTab()},scrollToTab:function(n){var t=this,e=n||t.navItem.find(".selected"),i=e.attr("scroll-left");i=parseInt(i,10),t.navScrollBox.scrollLeft(i)}},s='<nav class="slide-frame-nav skin-guess h-tab-nav">   <div class="nav">       <div class="h-scroll-bar h-tab-scroll scroll">           <div class="h-nav-bar">           {{#each tabItems}}<li class="h-nav-item" data-id="{{id}}" data-link="{{link}}" id="s-nav-{{id}}"><a href="javascript:;">{{label}}</a></li>{{/each}}           </div>       </div>   </div>   </nav>',a='<div class="content swipe"><div class="swipe-wrap">   {{#each tabItems}}      <div class="swipe-item h-swipe-list">       <div class="h-list-inner">{{content}}</div>                   </div>   {{/each}}  </div></div>',o=function(n,e,i){this.config={curIndex:0,curClass:"selected",useResizeEvent:!1},this.navContainer=n,this.contentContainer=e,this.config=t.extend(this.config,i,!0),this.navTemplate=s,this.contentTemplate=a,this.useSimpleVersion=!1,this._init()};return t.extend(o.prototype,{_init:function(){this._renderTab(),this._cacheDOM(),this._bindEvent(),this._initSwipe(),i.create(this.navElem)},_renderTab:function(){var n=this,i=n.config.tabItems||[],s=e.compile(n.navTemplate),a=s({tabItems:i,curIndex:n.config.curIndex});n.navContainer.html(a);var s=e.compile(n.contentTemplate),a=s({tabItems:i,curIndex:n.config.curIndex});n.contentContainer.html(a);var a=n.config,o=n.navContainer.find(".h-nav-item"),r=n.contentContainer.find(".h-swipe-list");o.removeClass(a.curClass),r.removeClass(a.curClass),t(o[a.curIndex]).addClass(a.curClass),t(r[a.curIndex]).addClass(a.curClass)},_cacheDOM:function(){var n=this;n.navElem=n.navContainer.find(".h-tab-nav"),n.navItems=n.navContainer.find(".h-nav-item"),n.swipeList=n.contentContainer.find(".h-swipe-list")},_initSwipe:function(){var t=this,e=t.config;t.useSimpleVersion||(t.swipeTab=n(t.contentContainer.find(".swipe")[0],{startSlide:e.curIndex,continuous:!1,hasInnerScroll:!0,orientationchange:e.useOrientationchange,callback:function(n){t._updateTab(n)}}))},_updateTab:function(n){var t=this,e=t.config;n!==e.curIndex&&(t.navItems.eq(e.curIndex).removeClass(e.curClass),t.swipeList.eq(e.curIndex).removeClass(e.curClass),t.navItems.eq(n).addClass(e.curClass),t.swipeList.eq(n).addClass(e.curClass),i.scrollToTab(t.navItems.eq(n)),e.curIndex=n,t.navItems.eq(e.curIndex).trigger("afterTabChange",[e.tabItems[n].id]))},_bindEvent:function(){var n=this;n.navContainer.on("click",".h-nav-item",function(){var e=t(this),i=e.index();n.useSimpleVersion?n._updateTab(i):n.swipeTab&&n.swipeTab.slide(i)})}}),{create:function(n,t,e){return void 0==n||0==t?void console.log("params container is required!!"):new o(n,t,e)}}});