source: branches/2.2.0.1/calendar/js/dhtmlx/codebase/ext/dhtmlxscheduler_touch.js @ 4001

Revision 4001, 9.7 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1615 - Componente novo para agenda......................................

Line 
1/*
2dhtmlxScheduler v.2.3
3
4This software is allowed to use under GPL or you need to obtain Commercial or Enterise License
5to use it in not GPL project. Please contact sales@dhtmlx.com for details
6
7(c) DHTMLX Ltd.
8*/
9TouchScroll=function(D,E,A,B){this.debug=!!E;this.compat=!!B;this.rough=!!A;this.axisX=this.axisY=true;if(typeof D!="object"){D=document.getElementById(D)}this._init();D.addEventListener("touchstart",this,false);D.addEventListener("webkitTransitionEnd",this,false);if(this.debug){D.addEventListener("mousedown",this,false)}this.node=D;for(var C=0;C<D.childNodes.length;C++){if(D.childNodes[C].nodeType==1){this.area=D.childNodes[C];break}}if(window.getComputedStyle(this.node).position=="static"){this.node.style.position="relative"}this.area.style.cssText+="-webkit-transition: -webkit-transform; -webkit-user-select:none; -webkit-transform-style:preserve-3d;";this.scrolls={}};TouchScroll.prototype={refresh:function(){this.node.style.webkitTransformStyle="flat";this.node.style.webkitTransformStyle="preserve-3d"},scrollTo:function(A,C,B){this.set_matrix({e:A,f:C},(B||0))},onscroll:function(A,B){},handleEvent:function(A){return this["ev_"+A.type](A)},get_matrix:function(A){return new WebKitCSSMatrix(window.getComputedStyle(A||this.area).webkitTransform)},set_matrix:function(C,B,A){(A||this.area).style.webkitTransform="translate("+Math.round(C.e)+"px,"+Math.round(C.f)+"px)";(A||this.area).style.webkitTransitionDuration=B},ev_touchstart:function(A){this.ev_mousedown(A.touches[0]);A.preventDefault();return false},ev_mousedown:function(B){var C=B;this.x=C.pageX;this.y=C.pageY;this.dx=this.node.offsetWidth;this.dy=this.node.offsetHeight;this.mx=this.area.scrollWidth;this.my=this.area.scrollHeight;this.target=C.target;if(!this.rough){var A=this.get_matrix();this.target_x=A.e;this.target_y=A.f;if(!this.scroll&&this.compat){A.e=this.node.scrollLeft*-1;A.f=this.node.scrollTop*-1;this.node.scrollTop=this.node.scrollLeft=0}this.set_matrix(A,0);this._correct_scroll(this.target_x,this.target_y)}this.scroll_x=this.scroll_y=this.scroll=false;this._init_events()},ev_touchend:function(){return this.ev_mouseup()},ev_mouseup:function(){this._deinit_events();if(!this.scroll){this._remove_scroll();var A=document.createEvent("MouseEvent");A.initMouseEvent("click",true,true);this.target.dispatchEvent(A)}this.target=null},ev_webkitTransitionEnd:function(){if(this.target||!this.scroll){return }this._remove_scroll();var B=this.get_matrix();this.node.firstChild._scrollTop=-1*B.f;if(this.compat&&(B.e||B.f)){var C=B.f;var A=B.e;B.e=B.f=0;this.set_matrix(B,0);this.node.scrollTop=-1*C;this.node.scrollLeft=-1*A}this.scroll=false},ev_touchmove:function(A){return this.ev_mousemove(A.touches[0])},ev_mousemove:function(E){if(!this.target){return }var G=E;var D=(G.pageX-this.x)*(this.axisX?5:0);var A=(G.pageY-this.y)*(this.axisY?5:0);if(Math.abs(D)<10&&Math.abs(A)<10){return }if(Math.abs(D)>50){this.scroll_x=true}if(Math.abs(A)>50){this.scroll_y=true}if(this.scroll_x||this.scroll_y){this.x=G.pageX;this.y=G.pageY;this.scroll=true;var C=this.get_matrix();D=D+(this.target_x-C.e);A=A+(this.target_y-C.f);var F="2000ms";var B="500ms";this.target_x=D+C.e;this.target_y=A+C.f;if(this.target_x>0){this.target_x=0;F=B}if(this.target_y>0){this.target_y=0;F=B}if(this.mx-this.dx+this.target_x<0){this.target_x=-this.mx+this.dx;F=B}if(this.my-this.dy+this.target_y<0){this.target_y=-this.my+this.dy;F=B}this.set_matrix({e:this.target_x,f:this.target_y},F);this._add_scroll(C.e,C.f);this._correct_scroll(this.target_x,this.target_y,F);this.onscroll(this.target_x,this.target_y)}return false},_correct_scroll:function(A,F,B){if(this.scrolls.x){var E=this.get_matrix(this.scrolls.x);var D=this.dx*A/this.mx;this.set_matrix({e:-1*D,f:0},B,this.scrolls.x)}if(this.scrolls.y){var E=this.get_matrix(this.scrolls.y);var C=this.dy*F/this.my;this.set_matrix({e:0,f:-1*C},B,this.scrolls.y)}},_remove_scroll:function(){if(this.scrolls.x){this.scrolls.x.parentNode.removeChild(this.scrolls.x)}if(this.scrolls.y){this.scrolls.y.parentNode.removeChild(this.scrolls.y)}this.scrolls={}},_add_scroll:function(){if(this.scrolls.ready){return }var C;if(this.my>5&&this.axisY){var B=this.dy*this.dy/this.my-1;this.scrolls.y=C=document.createElement("DIV");C.className="dhx_scroll_y";C.style.height=B+"px";this.node.appendChild(C)}if(this.mx>5&&this.axisX){var B=this.dx*this.dx/this.mx;this.scrolls.x=C=document.createElement("DIV");C.className="dhx_scroll_x";C.style.width=B+"px";this.node.appendChild(C)}var A=this.get_matrix();this._correct_scroll(A.e,A.f,0);this.scrolls.ready=true},_init_events:function(){document.addEventListener("touchmove",this,false);document.addEventListener("touchend",this,false);if(this.debug){document.addEventListener("mousemove",this,false);document.addEventListener("mouseup",this,false)}},_deinit_events:function(){document.removeEventListener("touchmove",this,false);document.removeEventListener("touchend",this,false);if(this.debug){document.removeEventListener("mousemove",this,false);document.removeEventListener("mouseup",this,false)}},_init:function(){document.styleSheets[0].insertRule(".dhx_scroll_x { width:50px;height:4px;background:rgba(0, 0, 0, 0.4);position:absolute; left:0px; bottom:3px; border:1px solid transparent; -webkit-border-radius:4px;-webkit-transition: -webkit-transform;}",0);document.styleSheets[0].insertRule(".dhx_scroll_y { width:4px;height:50px;background:rgba(0, 0, 0, 0.4);position:absolute; top:0px; right:3px; border:1px solid transparent; -webkit-border-radius:4px;-webkit-transition: -webkit-transform;}",0);this._init=function(){}}};scheduler._ipad_before_init=function(){scheduler._ipad_before_init=function(){};scheduler.xy.scroll_width=0;var C=scheduler._els.dhx_cal_tab;var B=42;for(var A=C.length-1;A>=0;A--){C[A].style.cssText+="top:4px;";C[A].style.left="auto";C[A].style.right=B+"px";if(A==0){C[A].style.cssText+=";-webkit-border-top-left-radius: 5px; -webkit-border-bottom-left-radius: 5px;"}if(A==C.length-1){C[A].style.cssText+=";-webkit-border-top-right-radius: 5px; -webkit-border-bottom-right-radius: 5px;"}B+=100}scheduler._els.dhx_cal_prev_button[0].innerHTML="&lt;";scheduler._els.dhx_cal_next_button[0].innerHTML="&gt;";var F=document.createElement("div");F.className="dhx_cal_add_button";F.innerHTML="+ ";F.onclick=function(){var G=new Date();if(G>scheduler._min_date&&G<scheduler._max_date){scheduler.addEventNow()}else{scheduler.addEventNow(scheduler._min_date.valueOf())}};scheduler._els.dhx_cal_navline[0].appendChild(F);this._obj.onmousedown=this._obj.onmouseup=this._obj.onmousemove=function(){};var D=null;var E=[];this._obj.ontouchmove=function(I){if(D){var H=Math.abs(I.touches[0].pageX-E[0]);var G=Math.abs(I.touches[0].pageY-E[1]);if(H>50||G>50){D=window.clearTimeout(D)}}if(scheduler.config.touch_actions){scheduler._on_mouse_move(I.touches[0])}};this._obj.ontouchstart=function(G){if(scheduler._lightbox_id){return }D=window.setTimeout(function(){scheduler._on_dbl_click(G.touches[0],(G.target.className?G.target:G.target.parentNode))},400);E=[G.touches[0].pageX,G.touches[0].pageY];if(scheduler.config.touch_actions){scheduler._on_mouse_down(G.touches[0])}};this._obj.ontouchend=function(G){if(D){D=window.clearTimeout(D)}if(scheduler.config.touch_actions){scheduler._on_mouse_up(G.touches[0])}}};scheduler._ipad_init=function(){var C=document.createElement("DIV");var B=scheduler._els.dhx_cal_data[0];C.appendChild(B);C.style.cssText="overflow:hidden; width:100%; overflow:hidden;position:relative;";this._obj.appendChild(C);B.style.overflowY="hidden";var A=new TouchScroll(C);A.axisX=false;scheduler._ipad_init=function(){B.parentNode.style.height=B.style.height;B.parentNode.style.top=B.style.top;B.style.height=B.scrollHeight+"px";B.style.top="0px";if(Math.abs(B.parentNode.offsetHeight-B.offsetHeight)<5){A.axisY=false;A.scrollTo(0,0,0)}else{A.axisY=true}A.refresh()};scheduler.attachEvent("onSchedulerResize",function(){setTimeout(function(){scheduler._ipad_init()});return true});scheduler._ipad_init()};scheduler.attachEvent("onViewChange",function(){scheduler._ipad_init()});scheduler.attachEvent("onBeforeViewChange",function(){scheduler._ipad_before_init();return true});scheduler.showCover=function(B){this.show_cover();if(B){B.style.display="block";var C=getOffset(this._obj);B.style.top=B.offsetHeight*-1+"px";B.style.left=Math.round(C.left+(this._obj.offsetWidth-B.offsetWidth)/2)+"px"}var A=this._get_lightbox();A.style.webkitTransform="translate(0px,"+(B.offsetHeight+41)+"px)";A.style.webkitTransitionDuration="500ms"};scheduler.hideCover=function(A){if(A){A.style.webkitTransform="translate(0px,"+(A.offsetHeight+41)*-1+"px)";A.style.webkitTransitionDuration="500ms"}this.hide_cover()};scheduler.config.lightbox.sections[0].height=100;if(scheduler.form_blocks.calendar_time){scheduler.config.lightbox.sections[1].type="calendar_time";scheduler._mini_cal_arrows=["&lt;","&gt;"]}scheduler.xy.menu_width=0;scheduler.attachEvent("onClick",function(){return false});scheduler.locale.labels.new_event="";scheduler._mouse_coords=function(C){var F;var A=document.body;var E=document.documentElement;if(C.pageX||C.pageY){F={x:C.pageX,y:C.pageY}}else{F={x:C.clientX+(A.scrollLeft||E.scrollLeft||0)-A.clientLeft,y:C.clientY+(A.scrollTop||E.scrollTop||0)-A.clientTop}}F.x-=getAbsoluteLeft(this._obj)+(this._table_view?0:this.xy.scale_width);var D=F.y-=getAbsoluteTop(this._obj)+this.xy.nav_height+this._dy_shift+this.xy.scale_height-(this._els.dhx_cal_data[0]._scrollTop||0);if(!this._table_view){F.x=Math.max(0,Math.ceil(F.x/this._cols[0])-1);F.y=Math.max(0,Math.ceil(F.y*60/(this.config.time_step*this.config.hour_size_px))-1)+this.config.first_hour*(60/this.config.time_step)}else{var B=0;for(B=1;B<this._colsS.heights.length;B++){if(this._colsS.heights[B]>F.y){break}}F.y=(Math.max(0,Math.ceil(F.x/this._cols[0])-1)+Math.max(0,B-1)*7)*24*60/this.config.time_step;F.x=0}return F};
Note: See TracBrowser for help on using the repository browser.