1 | TouchScroll=function(node, nontouch, scroll, compat){
|
---|
2 | this.debug = !!nontouch;
|
---|
3 | this.compat = !!compat;
|
---|
4 | this.rough = !!scroll;
|
---|
5 |
|
---|
6 |
|
---|
7 | this.axisX = this.axisY = true;
|
---|
8 |
|
---|
9 | if (typeof node!= "object")
|
---|
10 | node = document.getElementById(node);
|
---|
11 |
|
---|
12 | this._init();
|
---|
13 | node.addEventListener("touchstart",this,false);
|
---|
14 | node.addEventListener("webkitTransitionEnd",this,false);
|
---|
15 | if (this.debug)
|
---|
16 | node.addEventListener("mousedown",this,false);
|
---|
17 |
|
---|
18 |
|
---|
19 | this.node = node;
|
---|
20 | for (var i=0; i < node.childNodes.length; i++)
|
---|
21 | if (node.childNodes[i].nodeType == 1){
|
---|
22 | this.area = node.childNodes[i];
|
---|
23 | break;
|
---|
24 | }
|
---|
25 |
|
---|
26 | if (window.getComputedStyle(this.node).position == "static")
|
---|
27 | this.node.style.position = "relative"
|
---|
28 | this.area.style.cssText += "-webkit-transition: -webkit-transform; -webkit-user-select:none; -webkit-transform-style:preserve-3d;";
|
---|
29 | this.scrolls={};
|
---|
30 | };
|
---|
31 |
|
---|
32 | TouchScroll.prototype = {
|
---|
33 | refresh:function(){
|
---|
34 | this.node.style.webkitTransformStyle="flat";
|
---|
35 | this.node.style.webkitTransformStyle="preserve-3d";
|
---|
36 | },
|
---|
37 | scrollTo:function(x,y,speed){
|
---|
38 | this.set_matrix({e:x,f:y}, (speed||0));
|
---|
39 | },
|
---|
40 | onscroll:function(x,y){},
|
---|
41 | handleEvent:function(ev){
|
---|
42 | return this["ev_"+ev.type](ev);
|
---|
43 | },
|
---|
44 | get_matrix:function(node){
|
---|
45 | return new WebKitCSSMatrix(window.getComputedStyle(node||this.area).webkitTransform);
|
---|
46 | },
|
---|
47 | set_matrix:function(value,speed,node){
|
---|
48 | (node||this.area).style.webkitTransform = "translate("+Math.round(value.e)+"px,"+Math.round(value.f)+"px)";
|
---|
49 | (node||this.area).style.webkitTransitionDuration= speed;
|
---|
50 | },
|
---|
51 | ev_touchstart:function(ev){
|
---|
52 | this.ev_mousedown(ev.touches[0]);
|
---|
53 | ev.preventDefault();
|
---|
54 | return false;
|
---|
55 | },
|
---|
56 | ev_mousedown:function(ev){
|
---|
57 | var touch = ev;
|
---|
58 |
|
---|
59 | this.x = touch.pageX;
|
---|
60 | this.y = touch.pageY;
|
---|
61 | this.dx = this.node.offsetWidth;
|
---|
62 | this.dy = this.node.offsetHeight;
|
---|
63 | this.mx = this.area.scrollWidth;
|
---|
64 | this.my = this.area.scrollHeight;
|
---|
65 | this.target = touch.target;
|
---|
66 |
|
---|
67 | if (!this.rough){
|
---|
68 | var temp = this.get_matrix();
|
---|
69 | this.target_x = temp.e;
|
---|
70 | this.target_y = temp.f;
|
---|
71 | if (!this.scroll && this.compat){
|
---|
72 | temp.e = this.node.scrollLeft*-1;
|
---|
73 | temp.f = this.node.scrollTop*-1;
|
---|
74 | this.node.scrollTop = this.node.scrollLeft = 0;
|
---|
75 | }
|
---|
76 |
|
---|
77 | this.set_matrix(temp,0);
|
---|
78 | this._correct_scroll(this.target_x, this.target_y);
|
---|
79 | }
|
---|
80 | this.scroll_x = this.scroll_y = this.scroll = false;
|
---|
81 |
|
---|
82 |
|
---|
83 | this._init_events();
|
---|
84 | },
|
---|
85 | ev_touchend:function(){
|
---|
86 | return this.ev_mouseup();
|
---|
87 | },
|
---|
88 | ev_mouseup:function(){
|
---|
89 | this._deinit_events();
|
---|
90 | if (!this.scroll){
|
---|
91 | this._remove_scroll();
|
---|
92 | var ev = document.createEvent("MouseEvent");
|
---|
93 | ev.initMouseEvent("click",true, true);
|
---|
94 | this.target.dispatchEvent(ev);
|
---|
95 | }
|
---|
96 | this.target = null;
|
---|
97 | },
|
---|
98 | ev_webkitTransitionEnd:function(){
|
---|
99 | if (this.target || !this.scroll) return;
|
---|
100 |
|
---|
101 | this._remove_scroll();
|
---|
102 | var temp = this.get_matrix();
|
---|
103 | this.node.firstChild._scrollTop = -1*temp.f;
|
---|
104 |
|
---|
105 | if (this.compat && (temp.e||temp.f)){
|
---|
106 | var y = temp.f; var x = temp.e;
|
---|
107 | temp.e = temp.f = 0;
|
---|
108 | this.set_matrix(temp,0);
|
---|
109 |
|
---|
110 | this.node.scrollTop = -1*y;
|
---|
111 | this.node.scrollLeft = -1*x;
|
---|
112 | }
|
---|
113 |
|
---|
114 | this.scroll = false;
|
---|
115 | },
|
---|
116 | ev_touchmove:function(ev){
|
---|
117 | return this.ev_mousemove(ev.touches[0]);
|
---|
118 | },
|
---|
119 | ev_mousemove:function(ev){
|
---|
120 | if (!this.target) return;
|
---|
121 | var touch = ev;
|
---|
122 |
|
---|
123 | var dx = (touch.pageX - this.x)*(this.axisX?5:0);//Math.min(3,this.mx/this.dx);
|
---|
124 | var dy = (touch.pageY - this.y)*(this.axisY?5:0);//Math.min(3,this.my/this.dy);
|
---|
125 |
|
---|
126 | if (Math.abs(dx)<10 && Math.abs(dy)<10) return;
|
---|
127 |
|
---|
128 | if (Math.abs(dx)>50)
|
---|
129 | this.scroll_x=true;
|
---|
130 | if (Math.abs(dy)>50)
|
---|
131 | this.scroll_y=true;
|
---|
132 |
|
---|
133 |
|
---|
134 | if (this.scroll_x || this.scroll_y){
|
---|
135 | this.x = touch.pageX; this.y = touch.pageY;
|
---|
136 | this.scroll = true;
|
---|
137 | var temp = this.get_matrix();
|
---|
138 | dx = dx + (this.target_x - temp.e);
|
---|
139 | dy = dy + (this.target_y - temp.f);
|
---|
140 |
|
---|
141 | var speed = "2000ms";
|
---|
142 | var fast = "500ms";
|
---|
143 | this.target_x = dx+temp.e;
|
---|
144 | this.target_y = dy+temp.f;
|
---|
145 |
|
---|
146 | if (this.target_x > 0) {
|
---|
147 | this.target_x = 0;
|
---|
148 | speed = fast;
|
---|
149 | }
|
---|
150 | if (this.target_y > 0) {
|
---|
151 | this.target_y = 0;
|
---|
152 | speed = fast;
|
---|
153 | }
|
---|
154 | if (this.mx - this.dx + this.target_x < 0){
|
---|
155 | this.target_x = - this.mx + this.dx;
|
---|
156 | speed = fast;
|
---|
157 | }
|
---|
158 | if (this.my - this.dy + this.target_y < 0){
|
---|
159 | this.target_y = - this.my + this.dy;
|
---|
160 | speed = fast;
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | this.set_matrix({e:this.target_x,f:this.target_y},speed);
|
---|
165 | this._add_scroll(temp.e, temp.f);
|
---|
166 | this._correct_scroll(this.target_x, this.target_y, speed);
|
---|
167 | this.onscroll(this.target_x, this.target_y);
|
---|
168 | }
|
---|
169 | return false;
|
---|
170 | },
|
---|
171 | _correct_scroll:function(x,y,speed){
|
---|
172 | if (this.scrolls.x){
|
---|
173 | var stemp = this.get_matrix(this.scrolls.x);
|
---|
174 | var sx = this.dx*x/this.mx;
|
---|
175 | this.set_matrix({e:-1*sx,f:0}, speed, this.scrolls.x);
|
---|
176 | }
|
---|
177 | if (this.scrolls.y){
|
---|
178 | var stemp = this.get_matrix(this.scrolls.y);
|
---|
179 | var sy = this.dy*y/this.my;
|
---|
180 | this.set_matrix({e:0,f:-1*sy}, speed, this.scrolls.y);
|
---|
181 | }
|
---|
182 | },
|
---|
183 | _remove_scroll:function(){
|
---|
184 | if (this.scrolls.x)
|
---|
185 | this.scrolls.x.parentNode.removeChild(this.scrolls.x);
|
---|
186 | if (this.scrolls.y)
|
---|
187 | this.scrolls.y.parentNode.removeChild(this.scrolls.y);
|
---|
188 | this.scrolls = {};
|
---|
189 | },
|
---|
190 | _add_scroll:function(){
|
---|
191 | if (this.scrolls.ready) return;
|
---|
192 |
|
---|
193 | var d;
|
---|
194 | if (this.my>5 && this.axisY){
|
---|
195 | var h = this.dy*this.dy/this.my-1;
|
---|
196 | this.scrolls.y = d = document.createElement("DIV");
|
---|
197 | d.className="dhx_scroll_y";
|
---|
198 | d.style.height = h +"px";
|
---|
199 | this.node.appendChild(d);
|
---|
200 | }
|
---|
201 | if (this.mx>5 && this.axisX){
|
---|
202 | var h = this.dx*this.dx/this.mx;
|
---|
203 | this.scrolls.x = d = document.createElement("DIV");
|
---|
204 | d.className="dhx_scroll_x";
|
---|
205 | d.style.width = h +"px";
|
---|
206 | this.node.appendChild(d);
|
---|
207 | }
|
---|
208 |
|
---|
209 | var temp = this.get_matrix();
|
---|
210 | this._correct_scroll(temp.e, temp.f, 0);
|
---|
211 | this.scrolls.ready = true;
|
---|
212 | },
|
---|
213 | _init_events:function(){
|
---|
214 | document.addEventListener("touchmove",this,false);
|
---|
215 | document.addEventListener("touchend",this,false);
|
---|
216 | if (this.debug){
|
---|
217 | document.addEventListener("mousemove",this,false);
|
---|
218 | document.addEventListener("mouseup",this,false);
|
---|
219 | }
|
---|
220 | },
|
---|
221 | _deinit_events:function(){
|
---|
222 | document.removeEventListener("touchmove",this,false);
|
---|
223 | document.removeEventListener("touchend",this,false);
|
---|
224 | if (this.debug){
|
---|
225 | document.removeEventListener("mousemove",this,false);
|
---|
226 | document.removeEventListener("mouseup",this,false);
|
---|
227 | }
|
---|
228 | },
|
---|
229 | _init:function(){
|
---|
230 | 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);
|
---|
231 | 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);
|
---|
232 | this._init = function(){};
|
---|
233 | }
|
---|
234 | };
|
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 |
|
---|
240 | scheduler._ipad_before_init=function(){
|
---|
241 | scheduler._ipad_before_init=function(){};
|
---|
242 | scheduler.xy.scroll_width = 0;
|
---|
243 |
|
---|
244 | var tabs = scheduler._els["dhx_cal_tab"];
|
---|
245 | var right = 42;
|
---|
246 | for (var i=tabs.length-1; i >=0; i--) {
|
---|
247 | tabs[i].style.cssText+="top:4px;";
|
---|
248 | tabs[i].style.left="auto";
|
---|
249 | tabs[i].style.right = right+"px";
|
---|
250 | if (i==0)
|
---|
251 | tabs[i].style.cssText+=";-webkit-border-top-left-radius: 5px; -webkit-border-bottom-left-radius: 5px;";
|
---|
252 | if (i==tabs.length-1)
|
---|
253 | tabs[i].style.cssText+=";-webkit-border-top-right-radius: 5px; -webkit-border-bottom-right-radius: 5px;";
|
---|
254 |
|
---|
255 | right+=100;
|
---|
256 | };
|
---|
257 |
|
---|
258 | scheduler._els["dhx_cal_prev_button"][0].innerHTML = "<";
|
---|
259 | scheduler._els["dhx_cal_next_button"][0].innerHTML = ">";
|
---|
260 | var d = document.createElement("div");
|
---|
261 | d.className = "dhx_cal_add_button";
|
---|
262 | d.innerHTML = "+ ";
|
---|
263 | d.onclick = function(){
|
---|
264 | var now = new Date();
|
---|
265 | if (now > scheduler._min_date && now < scheduler._max_date)
|
---|
266 | scheduler.addEventNow();
|
---|
267 | else
|
---|
268 | scheduler.addEventNow(scheduler._min_date.valueOf());
|
---|
269 | }
|
---|
270 | scheduler._els["dhx_cal_navline"][0].appendChild(d);
|
---|
271 |
|
---|
272 |
|
---|
273 | this._obj.onmousedown = this._obj.onmouseup = this._obj.onmousemove = function(){};
|
---|
274 |
|
---|
275 | var long_tap = null;
|
---|
276 | var long_tap_pos = [];
|
---|
277 | this._obj.ontouchmove=function(e){
|
---|
278 | if (long_tap){
|
---|
279 | var dx = Math.abs(e.touches[0].pageX - long_tap_pos[0]);
|
---|
280 | var dy = Math.abs(e.touches[0].pageY - long_tap_pos[1]);
|
---|
281 | if (dx>50 || dy>50)
|
---|
282 | long_tap = window.clearTimeout(long_tap);
|
---|
283 | }
|
---|
284 | if (scheduler.config.touch_actions)
|
---|
285 | scheduler._on_mouse_move(e.touches[0]);
|
---|
286 | }
|
---|
287 | this._obj.ontouchstart = function(e){
|
---|
288 | if (scheduler._lightbox_id) return;
|
---|
289 |
|
---|
290 | long_tap = window.setTimeout(function(){
|
---|
291 | scheduler._on_dbl_click(e.touches[0],(e.target.className?e.target:e.target.parentNode));
|
---|
292 | },400);
|
---|
293 | long_tap_pos = [e.touches[0].pageX, e.touches[0].pageY];
|
---|
294 | if (scheduler.config.touch_actions)
|
---|
295 | scheduler._on_mouse_down(e.touches[0]);
|
---|
296 | }
|
---|
297 | this._obj.ontouchend = function(e){
|
---|
298 | if (long_tap)
|
---|
299 | long_tap = window.clearTimeout(long_tap);
|
---|
300 | if (scheduler.config.touch_actions)
|
---|
301 | scheduler._on_mouse_up(e.touches[0]);
|
---|
302 | }
|
---|
303 | }
|
---|
304 | scheduler._ipad_init=function(){
|
---|
305 | var d = document.createElement("DIV");
|
---|
306 | var data = scheduler._els["dhx_cal_data"][0];
|
---|
307 | d.appendChild(data);
|
---|
308 | d.style.cssText = "overflow:hidden; width:100%; overflow:hidden;position:relative;";
|
---|
309 | this._obj.appendChild(d);
|
---|
310 |
|
---|
311 | data.style.overflowY = "hidden";
|
---|
312 |
|
---|
313 | var scroll = new TouchScroll(d);
|
---|
314 | scroll.axisX = false;
|
---|
315 | scheduler._ipad_init = function(){
|
---|
316 | data.parentNode.style.height = data.style.height;
|
---|
317 | data.parentNode.style.top = data.style.top;
|
---|
318 | data.style.height = data.scrollHeight+"px";
|
---|
319 | data.style.top = "0px";
|
---|
320 |
|
---|
321 | if (Math.abs(data.parentNode.offsetHeight - data.offsetHeight)<5){
|
---|
322 | scroll.axisY=false;
|
---|
323 | scroll.scrollTo(0,0,0);
|
---|
324 | } else
|
---|
325 | scroll.axisY=true;
|
---|
326 |
|
---|
327 | scroll.refresh();
|
---|
328 | };
|
---|
329 |
|
---|
330 | scheduler.attachEvent("onSchedulerResize", function(){
|
---|
331 | setTimeout(function(){
|
---|
332 | scheduler._ipad_init();
|
---|
333 | });
|
---|
334 | return true;
|
---|
335 | })
|
---|
336 |
|
---|
337 | scheduler._ipad_init();
|
---|
338 | };
|
---|
339 |
|
---|
340 | scheduler.attachEvent("onViewChange",function(){
|
---|
341 | scheduler._ipad_init();
|
---|
342 | });
|
---|
343 | scheduler.attachEvent("onBeforeViewChange",function(){
|
---|
344 | scheduler._ipad_before_init();
|
---|
345 | return true;
|
---|
346 | });
|
---|
347 |
|
---|
348 | scheduler.showCover=function(box){
|
---|
349 | this.show_cover();
|
---|
350 | if (box){
|
---|
351 | box.style.display="block";
|
---|
352 | var pos = getOffset(this._obj);
|
---|
353 | box.style.top = box.offsetHeight*-1+"px";
|
---|
354 | box.style.left = Math.round(pos.left+(this._obj.offsetWidth-box.offsetWidth)/2)+"px";
|
---|
355 | }
|
---|
356 |
|
---|
357 | var node =this._get_lightbox();
|
---|
358 | node.style.webkitTransform = "translate(0px,"+(box.offsetHeight+41)+"px)";
|
---|
359 | node.style.webkitTransitionDuration = "500ms";
|
---|
360 | };
|
---|
361 |
|
---|
362 | scheduler.hideCover=function(box){
|
---|
363 | if (box){
|
---|
364 | box.style.webkitTransform = "translate(0px,"+(box.offsetHeight+41)*-1+"px)";
|
---|
365 | box.style.webkitTransitionDuration = "500ms";
|
---|
366 | }
|
---|
367 | this.hide_cover();
|
---|
368 | }
|
---|
369 |
|
---|
370 | scheduler.config.lightbox.sections[0].height = 100;
|
---|
371 | if (scheduler.form_blocks.calendar_time){
|
---|
372 | scheduler.config.lightbox.sections[1].type = "calendar_time";
|
---|
373 | scheduler._mini_cal_arrows = ["<", ">"];
|
---|
374 | }
|
---|
375 |
|
---|
376 | scheduler.xy.menu_width = 0;
|
---|
377 | scheduler.attachEvent("onClick", function(){
|
---|
378 | return false;
|
---|
379 | });
|
---|
380 |
|
---|
381 | scheduler.locale.labels.new_event="";
|
---|
382 |
|
---|
383 | scheduler._mouse_coords=function(ev){
|
---|
384 | var pos;
|
---|
385 | var b=document.body;
|
---|
386 | var d = document.documentElement;
|
---|
387 | if(ev.pageX || ev.pageY)
|
---|
388 | pos={x:ev.pageX, y:ev.pageY};
|
---|
389 | else pos={
|
---|
390 | x:ev.clientX + (b.scrollLeft||d.scrollLeft||0) - b.clientLeft,
|
---|
391 | y:ev.clientY + (b.scrollTop||d.scrollTop||0) - b.clientTop
|
---|
392 | }
|
---|
393 |
|
---|
394 | //apply layout
|
---|
395 | pos.x-=getAbsoluteLeft(this._obj)+(this._table_view?0:this.xy.scale_width);
|
---|
396 | var top =
|
---|
397 | pos.y-=getAbsoluteTop(this._obj)+this.xy.nav_height+this._dy_shift+this.xy.scale_height-(this._els["dhx_cal_data"][0]._scrollTop||0);
|
---|
398 | //transform to date
|
---|
399 | if (!this._table_view){
|
---|
400 | pos.x=Math.max(0,Math.ceil(pos.x/this._cols[0])-1);
|
---|
401 | pos.y=Math.max(0,Math.ceil(pos.y*60/(this.config.time_step*this.config.hour_size_px))-1)+this.config.first_hour*(60/this.config.time_step);
|
---|
402 | } else {
|
---|
403 | var dy=0;
|
---|
404 | for (dy=1; dy < this._colsS.heights.length; dy++)
|
---|
405 | if (this._colsS.heights[dy]>pos.y) break;
|
---|
406 |
|
---|
407 | pos.y=(Math.max(0,Math.ceil(pos.x/this._cols[0])-1)+Math.max(0,dy-1)*7)*24*60/this.config.time_step;
|
---|
408 | pos.x=0;
|
---|
409 | }
|
---|
410 | return pos;
|
---|
411 | }
|
---|