TouchSlider.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * TouchSlider
  3. * @author qiqiboy
  4. * @github https://github.com/qiqiboy/touchslider
  5. */
  6. ;
  7. (function(ROOT, struct, undefined){
  8. "use strict";
  9. var VERSION='2.0.1';
  10. var lastTime=0,
  11. nextFrame=ROOT.requestAnimationFrame ||
  12. ROOT.webkitRequestAnimationFrame ||
  13. ROOT.mozRequestAnimationFrame ||
  14. ROOT.msRequestAnimationFrame ||
  15. function(callback){
  16. var currTime=+new Date,
  17. delay=Math.max(1000/60,1000/60-(currTime-lastTime));
  18. lastTime=currTime+delay;
  19. return setTimeout(callback,delay);
  20. },
  21. cancelFrame=ROOT.cancelAnimationFrame ||
  22. ROOT.webkitCancelAnimationFrame ||
  23. ROOT.webkitCancelRequestAnimationFrame ||
  24. ROOT.mozCancelRequestAnimationFrame ||
  25. ROOT.msCancelRequestAnimationFrame ||
  26. clearTimeout,
  27. DOC=ROOT.document,
  28. divstyle=DOC.createElement('div').style,
  29. cssVendor=function(){
  30. var tests="-webkit- -moz- -o- -ms-".split(" "),
  31. prop;
  32. while(prop=tests.shift()){
  33. if(camelCase(prop+'transform') in divstyle){
  34. return prop;
  35. }
  36. }
  37. return '';
  38. }(),
  39. transition=cssTest('transition'),
  40. toString=Object.prototype.toString,
  41. slice=[].slice,
  42. class2type={},
  43. event2type={},
  44. event2code={
  45. click:4,
  46. mousewheel:5,
  47. dommousescroll:5,
  48. keydown:6,
  49. resize:7
  50. },
  51. POINTERTYPES={
  52. 2:'touch',
  53. 3:'pen',
  54. 4:'mouse',
  55. pen:'pen'
  56. },
  57. STARTEVENT=[],
  58. MOVEEVENT=[],
  59. EVENT=function(){
  60. var ret={},
  61. states={
  62. start:1,
  63. down:1,
  64. move:2,
  65. end:3,
  66. up:3,
  67. cancel:3
  68. };
  69. each("mouse touch pointer MSPointer-".split(" "),function(prefix){
  70. var _prefix=/pointer/i.test(prefix)?'pointer':prefix;
  71. ret[_prefix]=ret[_prefix]||{};
  72. POINTERTYPES[_prefix]=_prefix;
  73. each(states,function(endfix,code){
  74. var ev=camelCase(prefix+endfix);
  75. ret[_prefix][ev]=code;
  76. event2type[ev.toLowerCase()]=_prefix;
  77. event2code[ev.toLowerCase()]=code;
  78. if(code==1){
  79. STARTEVENT.push(ev);
  80. }else{
  81. MOVEEVENT.push(ev);
  82. }
  83. });
  84. });
  85. each("otransitionend oTransitionEnd webkitTransitionEnd mozTransitionEnd MSTransitionEnd transitionend".split(" "),function(ev){
  86. STARTEVENT.push(ev);
  87. event2code[ev.toLowerCase()]=8;
  88. });
  89. return ret;
  90. }(),
  91. POINTERS={
  92. touch:{},
  93. pointer:{},
  94. mouse:{}
  95. };
  96. each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(name){
  97. class2type["[object "+name+"]"]=name.toLowerCase();
  98. });
  99. function type(obj){
  100. if(obj==null){
  101. return obj+"";
  102. }
  103. return typeof obj=='object'||typeof obj=='function' ? class2type[toString.call(obj)]||"object" :
  104. typeof obj;
  105. }
  106. function isArrayLike(elem){
  107. var tp=type(elem);
  108. return !!elem && tp!='function' && tp!='string' && (elem.length===0 || elem.length && (elem.nodeType==1 || (elem.length-1) in elem));
  109. }
  110. function camelCase(str){
  111. return (str+'').replace(/^-ms-/, 'ms-').replace(/-([a-z]|[0-9])/ig, function(all, letter){
  112. return (letter+'').toUpperCase();
  113. });
  114. }
  115. function cssTest(name){
  116. var prop=camelCase(name),
  117. _prop=camelCase(cssVendor+prop);
  118. return (prop in divstyle) && prop || (_prop in divstyle) && _prop || '';
  119. }
  120. function isFunction(func){
  121. return type(func)=='function';
  122. }
  123. function pointerLength(obj){
  124. var len=0,key;
  125. if(type(obj.length)=='number'){
  126. len=obj.length;
  127. }else if('keys' in Object){
  128. len=Object.keys(obj).length;
  129. }else{
  130. for(key in obj){
  131. if(obj.hasOwnProperty(key)){
  132. len++;
  133. }
  134. }
  135. }
  136. return len;
  137. }
  138. function pointerItem(obj,n){
  139. return 'item' in obj?obj.item(n):function(){
  140. var i=0,key;
  141. for(key in this){
  142. if(i++==n){
  143. return this[key];
  144. }
  145. }
  146. }.call(obj,n);
  147. }
  148. function each(arr, iterate){
  149. if(isArrayLike(arr)){
  150. if(type(arr.forEach)=='function'){
  151. return arr.forEach(iterate);
  152. }
  153. var i=0,len=arr.length,item;
  154. for(;i<len;i++){
  155. item=arr[i];
  156. if(type(item)!='undefined'){
  157. iterate(item,i,arr);
  158. }
  159. }
  160. }else{
  161. var key;
  162. for(key in arr){
  163. iterate(key,arr[key],arr);
  164. }
  165. }
  166. }
  167. function children(elem){
  168. var ret=[];
  169. each(elem.children||elem.childNodes,function(elem){
  170. if(elem.nodeType==1){
  171. ret.push(elem);
  172. }
  173. });
  174. return ret;
  175. }
  176. function getStyle(elem,prop){
  177. var style=ROOT.getComputedStyle&&ROOT.getComputedStyle(elem,null)||elem.currentStyle||elem.style;
  178. return style[prop];
  179. }
  180. function setStyle(elem,props){
  181. each(props,function(name,value){
  182. var prop;
  183. switch(name){
  184. case 'float':
  185. prop=cssTest('cssFloat')?'cssFloat':'styleFloat';
  186. break;
  187. default:
  188. prop=camelCase(name);
  189. }
  190. try{
  191. elem.style[prop]=value;
  192. }catch(e){}
  193. });
  194. }
  195. function addListener(elem,evstr,handler){
  196. if(type(evstr)=='object'){
  197. return each(evstr,function(evstr,handler){
  198. addListener(elem,evstr,handler);
  199. });
  200. }
  201. each(evstr.split(" "),function(ev){
  202. if(elem.addEventListener){
  203. elem.addEventListener(ev,handler,false);
  204. }else if(elem.attachEvent){
  205. elem.attachEvent('on'+ev,handler);
  206. }else elem['on'+ev]=handler;
  207. });
  208. }
  209. function offListener(elem,evstr,handler){
  210. if(type(evstr)=='object'){
  211. return each(evstr,function(evstr,handler){
  212. offListener(elem,evstr,handler);
  213. });
  214. }
  215. each(evstr.split(" "),function(ev){
  216. if(elem.removeEventListener){
  217. elem.removeEventListener(ev,handler,false);
  218. }else if(elem.detachEvent){
  219. elem.detachEvent('on'+ev,handler);
  220. }else elem['on'+ev]=null;
  221. });
  222. }
  223. function removeRange(){
  224. var range;
  225. if(ROOT.getSelection){
  226. range=getSelection();
  227. if('empty' in range)range.empty();
  228. else if('removeAllRanges' in range)range.removeAllRanges();
  229. }else{
  230. DOC.selection.empty();
  231. }
  232. }
  233. function EASE(t,b,c,d){
  234. return -c * ((t=t/d-1)*t*t*t - 1) + b;
  235. }
  236. function filterEvent(oldEvent){
  237. var ev={},
  238. which=oldEvent.which,
  239. button=oldEvent.button,
  240. pointers,pointer;
  241. each("wheelDelta detail which keyCode".split(" "),function(prop){
  242. ev[prop]=oldEvent[prop];
  243. });
  244. ev.oldEvent=oldEvent;
  245. ev.type=oldEvent.type.toLowerCase();
  246. ev.eventType=event2type[ev.type]||ev.type;
  247. ev.eventCode=event2code[ev.type]||0;
  248. ev.pointerType=POINTERTYPES[oldEvent.pointerType]||oldEvent.pointerType||ev.eventType;
  249. ev.target=oldEvent.target||oldEvent.srcElement||DOC.documentElement;
  250. if(ev.target.nodeType===3){
  251. ev.target=ev.target.parentNode;
  252. }
  253. ev.preventDefault=function(){
  254. oldEvent.preventDefault && oldEvent.preventDefault();
  255. ev.returnValue=oldEvent.returnValue=false;
  256. }
  257. if(pointers=POINTERS[ev.eventType]){
  258. switch(ev.eventType){
  259. case 'mouse':
  260. case 'pointer':
  261. var id=oldEvent.pointerId||0;
  262. ev.eventCode==3?delete pointers[id]:pointers[id]=oldEvent;
  263. break;
  264. case 'touch':
  265. POINTERS[ev.eventType]=pointers=oldEvent.touches;
  266. break;
  267. }
  268. if(pointer=pointerItem(pointers,0)){
  269. ev.clientX=pointer.clientX;
  270. ev.clientY=pointer.clientY;
  271. }
  272. ev.button=which<4?Math.max(0,which-1):button&4&&1||button&2; // left:0 middle:1 right:2
  273. ev.length=pointerLength(pointers);
  274. }
  275. return ev;
  276. }
  277. struct.prototype={
  278. version:VERSION,
  279. constructor:struct,
  280. latestTime:0,
  281. init:function(config){
  282. var self=this,
  283. handler=this.handler=function(ev){
  284. self.handleEvent(ev);
  285. }
  286. this.events={};
  287. this.duration=isNaN(parseInt(config.duration))?600:parseInt(config.duration);
  288. this.direction=parseInt(config.direction)==0?0:1;
  289. this.current=parseInt(config.start)||0;
  290. this.mouse=config.mouse==null?true:!!config.mouse;
  291. this.mousewheel=!!config.mousewheel;
  292. this.interval=parseInt(config.interval)||5000;
  293. this.playing=config.autoplay==null?true:!!config.autoplay;
  294. this.arrowkey=!!config.arrowkey;
  295. this.fullsize=config.fullsize==null?true:!!config.fullsize;
  296. this.align=config.align||'center';
  297. this.pages=children(this.container);
  298. this.length=this.pages.length;
  299. this.pageData=[];
  300. addListener(this.container,STARTEVENT.join(" ")+" click"+(this.mousewheel?" mousewheel DOMMouseScroll":""),handler);
  301. addListener(DOC,MOVEEVENT.join(" ")+(this.arrowkey?" keydown":""),handler);
  302. addListener(ROOT,'resize',handler);
  303. each(this.pages,function(page){
  304. self.pageData.push({
  305. cssText:page.style.cssText||''
  306. });
  307. });
  308. this.pageData.container=this.container.style.cssText||'';
  309. this.on({
  310. before:function(){clearTimeout(this.playTimer);},
  311. dragStart:function(){clearTimeout(this.playTimer);removeRange();},
  312. after:this.firePlay
  313. }).firePlay();
  314. this.comment=document.createComment(' Powered by TouchSlider v'+this.version+' https://github.com/qiqiboy/touchslider ');
  315. this.container.appendChild(this.comment);
  316. this.resize();
  317. },
  318. resize:function(){
  319. var self=this,
  320. type=this.direction?'height':'width',
  321. pst=getStyle(this.container,'position'),
  322. css;
  323. this.size=this.getSize(this.offsetParent=this.container[pst=='absolute'||pst=='fixed'?'offsetParent':'parentNode']||DOC.body);
  324. css={
  325. float:'left',
  326. display:'inline'
  327. }
  328. each(this.pages,function(page){
  329. if(self.fullsize){
  330. css[type]=self.size-self.getMarginSize(page)-self.getPaddingSize(page)-self.getBorderSize(page)+'px';
  331. }
  332. if(type=='height'){
  333. css['clear']='both';
  334. }
  335. setStyle(page,css);
  336. });
  337. this.total=this.getSum(0,this.length);
  338. css={};
  339. if(pst=='static'){
  340. css={position:'relative'};
  341. }
  342. css[transition]='none';
  343. css[type]=this.total+'px';
  344. css[this.direction?'top':'left']=this.getPos(this.current)+'px';
  345. cancelFrame(this.timer);
  346. setStyle(this.container,css);
  347. clearTimeout(this.playTimer);
  348. return this.firePlay();
  349. },
  350. on:function(ev,callback){
  351. var self=this;
  352. if(type(ev)=='object'){
  353. each(ev,function(ev,callback){
  354. self.on(ev,callback);
  355. });
  356. }else{
  357. if(!this.events[ev]){
  358. this.events[ev]=[];
  359. }
  360. this.events[ev].push(callback);
  361. }
  362. return this;
  363. },
  364. fire:function(ev){
  365. var self=this,
  366. args=slice.call(arguments,1);
  367. each(this.events[ev]||[],function(func){
  368. if(isFunction(func)){
  369. func.apply(self,args);
  370. }
  371. });
  372. return this;
  373. },
  374. isStatic:function(){
  375. return !this.timer && !this.drag;
  376. },
  377. prev:function(){
  378. return this.slide((this.current-1+this.length)%this.length);
  379. },
  380. next:function(){
  381. return this.slide((this.current+1)%this.length);
  382. },
  383. play:function(){
  384. this.playing=true;
  385. return this.firePlay();
  386. },
  387. firePlay:function(){
  388. var self=this;
  389. if(this.playing){
  390. this.playTimer=setTimeout(function(){
  391. self.next();
  392. },this.interval);
  393. }
  394. return this;
  395. },
  396. pause:function(){
  397. this.playing=false;
  398. clearTimeout(this.playTimer);
  399. return this;
  400. },
  401. slide:function(_index){
  402. var self=this,
  403. dir=this.direction,
  404. stime=+new Date,
  405. duration=this.duration,
  406. current=this.current,
  407. index=Math.min(Math.max(0,_index),this.length-1),
  408. curSize=this.getSum(index,index+1),
  409. curPos=parseFloat(getStyle(this.container,dir?'top':'left'))||0,
  410. type=dir?'top':'left',
  411. css={},tarPos;
  412. tarPos=this.getPos(index);
  413. duration*=Math.min(1,Math.abs(tarPos-curPos)/curSize)||10;
  414. this.current=index;
  415. this.latestTime=stime+duration;
  416. this.fire('before',current,index);
  417. this.end=function(){
  418. delete self.timer;
  419. self.fire('after',index,current);
  420. }
  421. if(transition){
  422. this.timer=1;
  423. css[transition]=type+' '+duration+'ms ease';
  424. css[type]=tarPos+'px';
  425. setStyle(this.container,css);
  426. }else{
  427. cancelFrame(this.timer);
  428. ani();
  429. }
  430. function ani(){
  431. var offset=Math.min(duration,+new Date-stime),
  432. s=EASE(offset,0,1,duration)
  433. cp=(tarPos-curPos)*s+curPos;
  434. self.container.style[type]=cp+'px';
  435. if(offset==duration){
  436. self.end();
  437. }else{
  438. self.timer=nextFrame(ani);
  439. }
  440. }
  441. },
  442. handleEvent:function(oldEvent){
  443. var ev=filterEvent(oldEvent),
  444. canDrag=ev.button<1&&ev.length<2&&(!this.pointerType||this.pointerType==ev.eventType)&&(this.mouse||ev.pointerType!='mouse');
  445. switch(ev.eventCode){
  446. case 2:
  447. if(canDrag&&this.rect){
  448. var index=this.current,
  449. dir=this.direction,
  450. rect=[ev.clientX,ev.clientY],
  451. _rect=this.rect,
  452. offset=rect[dir]-_rect[dir];
  453. if(this.drag==null && _rect.toString()!=rect.toString()){
  454. this.drag=Math.abs(offset)>=Math.abs(rect[1-dir]-_rect[1-dir]);
  455. this.drag && this.fire('dragStart',ev);
  456. }
  457. if(this.drag){
  458. if(!this.pages[index+(offset>0?-1:1)]){
  459. offset/=Math.abs(offset)/this.size+2;
  460. }
  461. this.container.style[dir?'top':'left']=this.startPos+offset+'px';
  462. this.fire('dragMove',ev);
  463. this._offset=offset;
  464. ev.preventDefault();
  465. }
  466. }
  467. break;
  468. case 1:
  469. case 3:
  470. if(canDrag){
  471. var self=this,
  472. index=this.current,
  473. type=this.direction?'top':'left',
  474. isDrag,offset,tm,nn,sub,curPos,tarPos,myWidth;
  475. if(ev.length&&(ev.eventCode==1||this.drag)){
  476. nn=ev.target.nodeName.toLowerCase();
  477. clearTimeout(this.eventTimer);
  478. if(!this.pointerType){
  479. this.pointerType=ev.eventType;
  480. }
  481. this.startPos=parseFloat(getStyle(this.container,type))||0;
  482. if(transition){
  483. this.container.style[transition]='none';
  484. }else if(this.timer){
  485. cancelFrame(this.timer);
  486. delete this.timer;
  487. }
  488. this.rect=[ev.clientX,ev.clientY];
  489. this.time=+new Date;
  490. this.container.style[type]=this.startPos+'px';
  491. if(ev.eventType!='touch' && (nn=='a' || nn=='img')){
  492. ev.preventDefault();
  493. }
  494. }else if(tm=this.time){
  495. offset=this._offset||0;
  496. isDrag=this.drag;
  497. curPos=this.startPos+offset;
  498. tarPos=this.getPos(index);
  499. each("rect drag time startPos _offset".split(" "),function(prop){
  500. delete self[prop];
  501. });
  502. if(isDrag){
  503. sub=offset>0?1:-1;
  504. while(sub*(curPos-tarPos)>this.getOuterSize(this.pages[index])/2&&this.pages[index-sub]){
  505. tarPos=this.getPos(index-=sub);
  506. }
  507. if(Math.abs(offset)>20&&+new Date-tm<500){
  508. index-=sub;
  509. }
  510. this.fire('dragEnd',ev);
  511. ev.preventDefault();
  512. }
  513. if(curPos!=tarPos){
  514. this.slide(index);
  515. }else if(isDrag){
  516. this.firePlay();
  517. }
  518. this.eventTimer=setTimeout(function(){
  519. delete self.pointerType;
  520. },400);
  521. }
  522. }
  523. break;
  524. case 4:
  525. if(this.timer){
  526. ev.preventDefault();
  527. }
  528. break;
  529. case 5:
  530. ev.preventDefault();
  531. if(this.isStatic() && +new Date-this.latestTime>Math.max(1000-this.duration,0)){
  532. var wd=ev.wheelDelta||-ev.detail;
  533. Math.abs(wd)>=3 && this[wd>0?'prev':'next']();
  534. }
  535. break;
  536. case 6:
  537. var nn=ev.target.nodeName.toLowerCase();
  538. if(this.isStatic() && nn!='input' && nn!='textarea' && nn!='select'){
  539. switch(ev.keyCode||ev.which){
  540. case 33:
  541. case 37:
  542. case 38:
  543. this.prev();
  544. break;
  545. case 32:
  546. case 34:
  547. case 39:
  548. case 40:
  549. this.next();
  550. break;
  551. case 35:
  552. this.slide(this.length-1);
  553. break;
  554. case 36:
  555. this.slide(0);
  556. break;
  557. }
  558. }
  559. break;
  560. case 7:
  561. this.resize();
  562. break;
  563. case 8:
  564. if(oldEvent.propertyName==(this.direction?'top':'left')){
  565. this.container.style[transition]='none';
  566. this.end();
  567. }
  568. break;
  569. }
  570. },
  571. getSum:function(from,to){
  572. var sum=0;
  573. while(from<to){
  574. sum+=this.getOuterSize(this.pages[from++],true);
  575. }
  576. return sum;
  577. },
  578. getPos:function(index){
  579. var type=this.direction?'Top':'Left',
  580. myWidth=this.getOuterSize(this.pages[index],true),
  581. sum=this.getSum(0,index)+this['getMargin'+type+'Size'](this.container)+this['getBorder'+type+'Size'](this.container);
  582. switch(this.align){
  583. case 'top':
  584. case 'left':
  585. return -sum;
  586. case 'bottom':
  587. case 'right':
  588. return this.size-myWidth-sum;
  589. default:
  590. return (this.size-myWidth)/2-sum;
  591. }
  592. },
  593. getOuterSize:function(elem,withMargin){
  594. return elem[this.direction?'offsetHeight':'offsetWidth']+(withMargin?this.getMarginSize(elem):0);
  595. },
  596. getInnerSize:function(elem){
  597. return this.getOuterSize(elem)-this.getBorderSize(elem);
  598. },
  599. getSize:function(elem){
  600. return elem[this.direction?'offsetHeight':'offsetWidth']-this.getPaddingSize(elem)-this.getBorderSize(elem);
  601. },
  602. destroy:function(){
  603. var pageData=this.pageData;
  604. offListener(this.container,STARTEVENT.join(" ")+" click"+(this.mousewheel?" mousewheel DOMMouseScroll":""),this.handler);
  605. offListener(DOC,MOVEEVENT.join(" ")+(this.arrowkey?" keydown":""),this.handler);
  606. offListener(ROOT,'resize',this.handler);
  607. each(this.pages,function(page,index){
  608. page.style.cssText=pageData[index].cssText;
  609. });
  610. this.container.style.cssText=pageData.container;
  611. this.container.removeChild(this.comment);
  612. this.length=0;
  613. return this.pause();
  614. },
  615. refresh:function(){
  616. this.pages=children(this.container);
  617. this.length=this.pages.length;
  618. this.current=Math.max(Math.min(this.length-1,this.current),0);
  619. return this.resize();
  620. },
  621. append:function(elem,index){
  622. if(null==index){
  623. index=this.pages.length;
  624. }
  625. this.pageData.splice(index,0,{
  626. cssText:elem.style.cssText||''
  627. });
  628. this.container.insertBefore(elem,this.pages[index]||null);
  629. return this.refresh();
  630. },
  631. prepend:function(elem){
  632. return this.append(elem,0);
  633. },
  634. insertBefore:function(elem,index){
  635. return this.append(elem,index-1);
  636. },
  637. insertAfter:function(elem,index){
  638. return this.append(elem,index+1);
  639. },
  640. remove:function(index){
  641. this.container.removeChild(this.pages[index]);
  642. this.pageData.splice(index,1);
  643. return this.refresh();
  644. }
  645. }
  646. each("margin padding border".split(" "),function(type){
  647. each("Top Left Right Bottom".split(" "),function(dir){
  648. var prop=type+dir;
  649. struct.prototype[camelCase('get-'+prop)+'Size']=function(elem){
  650. return parseFloat(getStyle(elem,prop+(type=='border'?'Width':'')))||0;
  651. }
  652. });
  653. struct.prototype[camelCase('get-'+type)+'Size']=function(elem){
  654. return this[camelCase('get-'+type)+(this.direction?'Top':'Left')+'Size'](elem)+this[camelCase('get-'+type)+(this.direction?'Bottom':'Right')+'Size'](elem);
  655. }
  656. });
  657. if(typeof exports === 'object') {
  658. module.exports = struct;
  659. } else if(typeof define=='function' && define.amd){
  660. define('TouchSlider',function(){
  661. return struct;
  662. });
  663. }else ROOT.TouchSlider=struct;
  664. })(window, function(wrap,config){
  665. if(!(this instanceof arguments.callee)){
  666. return new arguments.callee(wrap,config);
  667. }
  668. this.container=typeof wrap=='string'?document.getElementById(wrap):wrap;
  669. this.init(config||{});
  670. });