forked from damiengarbarino/dojo-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewBase.js
executable file
·3024 lines (2501 loc) · 79.3 KB
/
ViewBase.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
define([
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/_base/array",
"dojo/_base/window",
"dojo/_base/event",
"dojo/_base/html",
"dojo/sniff",
"dojo/query",
"dojo/dom",
"dojo/dom-style",
"dojo/dom-class",
"dojo/dom-construct",
"dojo/dom-geometry",
"dojo/on",
"dojo/date",
"dojo/date/locale",
"dojo/when",
"dijit/_WidgetBase",
"dojox/widget/_Invalidating",
"dojox/widget/Selection",
"./time",
"./StoreMixin",
"./StoreManager",
"./RendererManager"],
function(
declare,
lang,
arr,
win,
event,
html,
has,
query,
dom,
domStyle,
domClass,
domConstruct,
domGeometry,
on,
date,
locale,
when,
_WidgetBase,
_Invalidating,
Selection,
timeUtil,
StoreMixin,
StoreManager,
RendererManager){
/*=====
var __GridClickEventArgs = {
// summary:
// The event dispatched when the grid is clicked or double-clicked.
// date: Date
// The start of the previously displayed time interval, if any.
// triggerEvent: Event
// The event at the origin of this event.
};
=====*/
/*=====
var __ItemMouseEventArgs = {
// summary:
// The event dispatched when an item is clicked, double-clicked or context-clicked.
// item: Object
// The item clicked.
// renderer: dojox/calendar/_RendererMixin
// The item renderer clicked.
// triggerEvent: Event
// The event at the origin of this event.
};
=====*/
/*=====
var __itemEditingEventArgs = {
// summary:
// An item editing event.
// item: Object
// The render item that is being edited. Set/get the startTime and/or endTime properties to customize editing behavior.
// storeItem: Object
// The real data from the store. DO NOT change properties, but you may use properties of this item in the editing behavior logic.
// editKind: String
// Kind of edit: "resizeBoth", "resizeStart", "resizeEnd" or "move".
// dates: Date[]
// The computed date/time of the during the event editing. One entry per edited date (touch use case).
// startTime: Date?
// The start time of data item.
// endTime: Date?
// The end time of data item.
// sheet: String
// For views with several sheets (columns view for example), the sheet when the event occurred.
// source: dojox/calendar/ViewBase
// The view where the event occurred.
// eventSource: String
// The device that triggered the event. This property can take the following values:
//
// - "mouse",
// - "keyboard",
// - "touch"
// triggerEvent: Event
// The event at the origin of this event.
};
=====*/
/*=====
var __rendererLifecycleEventArgs = {
// summary:
// An renderer lifecycle event.
// renderer: Object
// The renderer.
// source: dojox/calendar/ViewBase
// The view where the event occurred.
// item:Object?
// The item that will be displayed by the renderer for the "rendererCreated" and "rendererReused" events.
};
=====*/
return declare("dojox.calendar.ViewBase", [_WidgetBase, StoreMixin, _Invalidating, Selection], {
// summary:
// The dojox.calendar.ViewBase widget is the base of calendar view widgets
// datePackage: Object
// JavaScript namespace to find Calendar routines. Uses Gregorian Calendar routines at dojo.date by default.
datePackage: date,
_calendar: "gregorian",
// viewKind: String
// Kind of the view. Used by the calendar widget to determine how to configure the view.
viewKind: null,
// _layoutStep: [protected] Integer
// The number of units displayed by a visual layout unit (i.e. a column or a row)
_layoutStep: 1,
// _layoutStep: [protected] Integer
// The unit displayed by a visual layout unit (i.e. a column or a row)
_layoutUnit: "day",
// resizeCursor: String
// CSS value to apply to the cursor while resizing an item renderer.
resizeCursor: "n-resize",
// formatItemTimeFunc: Function
// Optional function to format the time of day of the item renderers.
// The function takes the date, the render data object, the view and the data item as arguments and returns a String.
formatItemTimeFunc: null,
_cssDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
_getFormatItemTimeFuncAttr: function(){
if(this.formatItemTimeFunc){
return this.formatItemTimeFunc;
}
if(this.owner != null){
return this.owner.get("formatItemTimeFunc");
}
},
// The listeners added by the view itself.
_viewHandles: null,
constructor: function(/*Object*/ args){
args = args || {};
this._calendar = args.datePackage ? args.datePackage.substr(args.datePackage.lastIndexOf(".")+1) : this._calendar;
this.dateModule = args.datePackage ? lang.getObject(args.datePackage, false) : date;
this.dateClassObj = this.dateModule.Date || Date;
this.dateLocaleModule = args.datePackage ? lang.getObject(args.datePackage+".locale", false) : locale;
this._viewHandles = [];
this.storeManager = new StoreManager({owner: this, _ownerItemsProperty: "items"});
this.storeManager.on("layoutInvalidated", lang.hitch(this, this._refreshItemsRendering));
this.storeManager.on("dataLoaded", lang.hitch(this, function(items){
this.set("items", items);
}));
this.storeManager.on("renderersInvalidated", lang.hitch(this, function(item){
this.updateRenderers(item);
}));
this.rendererManager = new RendererManager({owner: this});
this.rendererManager.on("rendererCreated", lang.hitch(this, this._onRendererCreated));
this.rendererManager.on("rendererReused", lang.hitch(this, this._onRendererReused));
this.rendererManager.on("rendererRecycled", lang.hitch(this, this._onRendererRecycled));
this.rendererManager.on("rendererDestroyed", lang.hitch(this, this._onRendererDestroyed));
this.decorationStoreManager = new StoreManager({owner: this, _ownerItemsProperty: "decorationItems"});
this.decorationStoreManager.on("layoutInvalidated", lang.hitch(this, this._refreshDecorationItemsRendering));
this.decorationStoreManager.on("dataLoaded", lang.hitch(this, function(items){
this.set("decorationItems", items);
}));
this.decorationRendererManager = new RendererManager({owner: this});
this._setupDayRefresh();
},
destroy: function(preserveDom){
this.rendererManager.destroy();
this.decorationRendererManager.destroy();
while(this._viewHandles.length > 0){
this._viewHandles.pop().remove();
}
this.inherited(arguments);
},
_setupDayRefresh: function(){
// Refresh the view when the current day changes.
var now = this.newDate(new Date());
var d = timeUtil.floor(now, "day", 1, this.dateClassObj);
var d = this.dateModule.add(d, "day", 1);
// manages DST at 24h
if(d.getHours() == 23){
d = this.dateModule.add(d, "hour", 2); // go to 1am
}else{
d = timeUtil.floorToDay(d, true, this.dateClassObj);
}
setTimeout(lang.hitch(this, function(){
if(!this._isEditing){
this.refreshRendering(true); // recursive refresh
}
this._setupDayRefresh();
}), d.getTime()-now.getTime() + 5000);
// add 5 seconds to be sure to be tomorrow
},
resize: function(changeSize){
// summary:
// Function to call when the view is resized.
// If the view is in a Dijit container or in a Dojo mobile container, it will be automatically called.
// On other use cases, this method must called when the window is resized and/or when the orientation has changed.
if(changeSize){
domGeometry.setMarginBox(this.domNode, changeSize);
}
},
// view lifecycle methods
beforeActivate: function(){
// summary:
// Function invoked just before the view is displayed by the calendar.
// tags:
// protected
},
afterActivate: function(){
// summary:
// Function invoked just after the view is displayed by the calendar.
// tags:
// protected
},
beforeDeactivate: function(){
// summary:
// Function invoked just before the view is hidden or removed by the calendar.
// tags:
// protected
},
afterDeactivate: function(){
// summary:
// Function invoked just after the view is the view is hidden or removed by the calendar.
// tags:
// protected
},
_getTopOwner: function(){
// summary:
// Returns the top owner: the calendar or the parent view.
var p = this;
while(p.owner != undefined){
p = p.owner;
}
return p;
},
_createRenderData: function(){
// summary:
// Creates the object that contains all the data needed to render this widget.
// tags:
// protected
},
_validateProperties: function(){
// summary:
// Validates the widget properties before the rendering pass.
// tags:
// protected
},
_setText: function(node, text, allowHTML){
// summary:
// Creates a text node under the parent node after having removed children nodes if any.
// node: Node
// The node that will contain the text node.
// text: String
// The text to set to the text node.
if(text != null){
if(!allowHTML && node.hasChildNodes()){
// span > textNode
node.childNodes[0].childNodes[0].nodeValue = text;
}else{
while(node.hasChildNodes()){
node.removeChild(node.lastChild);
}
var tNode = win.doc.createElement("span");
if(has("dojo-bidi")){
this.applyTextDir(tNode, text);
}
if(allowHTML){
tNode.innerHTML = text;
}else{
tNode.appendChild(win.doc.createTextNode(text));
}
node.appendChild(tNode);
}
}
},
isAscendantHasClass: function(node, ancestor, className){
// summary:
// Determines if a node has an ascendant node that has the css class specified.
// node: Node
// The DOM node.
// ancestor: Node
// The ancestor node used to limit the search in hierarchy.
// className: String
// The css class name.
// returns: Boolean
while(node != ancestor && node != document){
if(domClass.contains(node, className)){
return true;
}
node = node.parentNode;
}
return false;
},
isWeekEnd: function(date){
// summary:
// Determines whether the specified date is a week-end.
// This method is using dojo.date.locale.isWeekend() method as
// dojox.date.XXXX calendars are not supporting this method.
// date: Date
// The date to test.
return this.dateLocaleModule.isWeekend(date);
},
getWeekNumberLabel: function(date){
// summary:
// Returns the week number string from dojo.date.locale.format() method as
// dojox.date.XXXX calendar are not supporting the "w" pattern.
// date: Date
// The date to format.
if(date.toGregorian){
date = date.toGregorian();
}
return this.dateLocaleModule.format(date, {
selector: "date",
datePattern: "w"});
},
addAndFloor: function(date, unit, steps){
// date must be floored!!
// unit >= day
var d = this.dateModule.add(date, unit, steps);
if(d.getHours() == 23){
d = this.dateModule.add(d, "hour", 2); // go to 1am
}else{
d = timeUtil.floorToDay(d, true, this.dateClassObj);
}
return d;
},
floorToDay: function(date, reuse){
// summary:
// Floors the specified date to the start of day.
// date: Date
// The date to floor.
// reuse: Boolean
// Whether use the specified instance or create a new one. Default is false.
// returns: Date
return timeUtil.floorToDay(date, reuse, this.dateClassObj);
},
floorToMonth: function(date, reuse){
// summary:
// Floors the specified date to the start of the date's month.
// date: Date
// The date to floor.
// reuse: Boolean
// Whether use the specified instance or create a new one. Default is false.
// returns: Date
return timeUtil.floorToMonth(date, reuse, this.dateClassObj);
},
floorDate: function(date, unit, steps, reuse){
// summary:
// floors the date to the unit.
// date: Date
// The date/time to floor.
// unit: String
// The unit. Valid values are "minute", "hour", "day".
// steps: Integer
// For "day" only 1 is valid.
// reuse: Boolean
// Whether use the specified instance or create a new one. Default is false.
// returns: Date
return timeUtil.floor(date, unit, steps, reuse, this.dateClassObj);
},
isToday: function(date){
// summary:
// Returns whether the specified date is in the current day.
// date: Date
// The date to test.
// renderData: Object
// The current renderData
// returns: Boolean
return timeUtil.isToday(date, this.dateClassObj);
},
isStartOfDay: function(d){
// summary:
// Tests if the specified date represents the starts of day.
// d:Date
// The date to test.
// returns: Boolean
return timeUtil.isStartOfDay(d, this.dateClassObj, this.dateModule);
},
isOverlapping: function(renderData, start1, end1, start2, end2, includeLimits){
// summary:
// Computes if the first time range defined by the start1 and end1 parameters
// is overlapping the second time range defined by the start2 and end2 parameters.
// renderData: Object
// The render data.
// start1: Date
// The start time of the first time range.
// end1: Date
// The end time of the first time range.
// start2: Date
// The start time of the second time range.
// end2: Date
// The end time of the second time range.
// includeLimits: Boolean
// Whether include the end time or not.
// returns: Boolean
return timeUtil.isOverlapping(renderData, start1, end1, start2, end2, includeLimits);
},
computeRangeOverlap: function(renderData, start1, end1, start2, end2, includeLimits){
// summary:
// Computes the overlap time range of the time ranges.
// Returns a vector of Date with at index 0 the start time and at index 1 the end time.
// renderData: Object.
// The render data.
// start1: Date
// The start time of the first time range.
// end1: Date
// The end time of the first time range.
// start2: Date
// The start time of the second time range.
// end2: Date
// The end time of the second time range.
// includeLimits: Boolean
// Whether include the end time or not.
// returns: Date[]
var cal = renderData.dateModule;
if(start1 == null || start2 == null || end1 == null || end2 == null){
return null;
}
var comp1 = cal.compare(start1, end2);
var comp2 = cal.compare(start2, end1);
if(includeLimits){
if(comp1 == 0 || comp1 == 1 || comp2 == 0 || comp2 == 1){
return null;
}
} else if(comp1 == 1 || comp2 == 1){
return null;
}
return [
this.newDate(cal.compare(start1, start2)>0 ? start1: start2, renderData),
this.newDate(cal.compare(end1, end2)>0 ? end2: end1, renderData)
];
},
isSameDay : function(date1, date2){
// summary:
// Tests if the specified dates are in the same day.
// date1: Date
// The first date.
// date2: Date
// The second date.
// returns: Boolean
if(date1 == null || date2 == null){
return false;
}
return date1.getFullYear() == date2.getFullYear() &&
date1.getMonth() == date2.getMonth() &&
date1.getDate() == date2.getDate();
},
computeProjectionOnDate: function(renderData, refDate, date, max){
// summary:
// Computes the time to pixel projection in a day.
// renderData: Object
// The render data.
// refDate: Date
// The reference date that defines the destination date.
// date: Date
// The date to project.
// max: Integer
// The size in pixels of the representation of a day.
// tags:
// protected
// returns: Number
var cal = renderData.dateModule;
var minH = renderData.minHours;
var maxH = renderData.maxHours;
if(max <= 0 || cal.compare(date, refDate) == -1){
return 0;
}
var gt = function(d){
return d.getHours() * 3600 + d.getMinutes() * 60 + d.getSeconds();
};
var referenceDate = this.floorToDay(refDate, false, renderData);
if(date.getDate() != referenceDate.getDate()){
if(date.getMonth() == referenceDate.getMonth()){
if(date.getDate() < referenceDate.getDate()){
return 0;
} else if(date.getDate() > referenceDate.getDate() && maxH < 24){
return max;
}
}else{
if(date.getFullYear() == referenceDate.getFullYear()){
if(date.getMonth() < referenceDate.getMonth()){
return 0;
} else if(date.getMonth() > referenceDate.getMonth()){
return max;
}
}else{
if(date.getFullYear() < referenceDate.getFullYear()){
return 0;
} else if(date.getFullYear() > referenceDate.getFullYear()){
return max;
}
}
}
}
var res;
var ONE_DAY = 86400; // 24h x 60m x 60s
if(this.isSameDay(refDate, date) || maxH > 24){
var d = lang.clone(refDate);
var minTime = 0;
if(minH != null && minH != 0){
d.setHours(minH);
minTime = gt(d);
}
d = lang.clone(refDate);
d.setHours(maxH);
var maxTime;
if(maxH == null || maxH == 24){
maxTime = ONE_DAY;
}else if(maxH > 24){
maxTime = ONE_DAY + gt(d);
}else{
maxTime = gt(d);
}
//precision is the second
//use this API for daylight time issues.
var delta = 0;
if(maxH > 24 && refDate.getDate() != date.getDate()){
delta = ONE_DAY + gt(date);
}else{
delta = gt(date);
}
if(delta < minTime){
return 0;
}
if(delta > maxTime){
return max;
}
delta -= minTime;
res = (max * delta)/(maxTime - minTime);
}else{
if(date.getDate() < refDate.getDate() &&
date.getMonth() == refDate.getMonth()){
return 0;
}
var d2 = this.floorToDay(date);
var dp1 = renderData.dateModule.add(refDate, "day", 1);
dp1 = this.floorToDay(dp1, false, renderData);
if(cal.compare(d2, refDate) == 1 && cal.compare(d2, dp1) == 0 || cal.compare(d2, dp1) == 1){
res = max;
}else{
res = 0;
}
}
return res;
},
getTime: function(e, x, y, touchIndex){
// summary:
// Returns the time displayed at the specified point by this component.
// e: Event
// Optional mouse event.
// x: Number
// Position along the x-axis with respect to the sheet container used if event is not defined.
// y: Number
// Position along the y-axis with respect to the sheet container (scroll included) used if event is not defined.
// touchIndex: Integer
// If parameter 'e' is not null and a touch event, the index of the touch to use.
// returns: Date
return null;
},
getSubColumn: function(e, x, y, touchIndex){
// summary:
// Returns the sub column at the specified point by this component.
// e: Event
// Optional mouse event.
// x: Number
// Position along the x-axis with respect to the sheet container used if event is not defined.
// y: Number
// Position along the y-axis with respect to the sheet container (scroll included) used if event is not defined.
// touchIndex: Integer
// If parameter 'e' is not null and a touch event, the index of the touch to use.
// returns: Object
return null;
},
getSubColumnIndex: function(value){
// summary:
// Returns the sub column index that has the specified value, if any. -1 otherwise.
// value: String
// The sub column index.
if(this.subColumns){
for(var i=0; i<this.subColumns.length; i++){
if(this.subColumns[i] == value){
return i;
}
}
}
return -1;
},
newDate: function(obj){
// summary:
// Creates a new Date object.
// obj: Object
// This object can have several values:
//
// - the time in milliseconds since gregorian epoch.
// - a Date instance
// returns: Date
return timeUtil.newDate(obj, this.dateClassObj);
},
_isItemInView: function(item){
// summary:
// Computes whether the specified item is entirely in the view or not.
// item: Object
// The item to test
// returns: Boolean
var rd = this.renderData;
var cal = rd.dateModule;
if(cal.compare(item.startTime, rd.startTime) == -1){
return false;
}
return cal.compare(item.endTime, rd.endTime) != 1;
},
_ensureItemInView: function(item){
// summary:
// If needed, moves the item to be entirely in view.
// item: Object
// The item to test
// returns: Boolean
// Whether the item has been moved to be in view or not.
// tags:
// protected
var rd = this.renderData;
var cal = rd.dateModule;
var duration = Math.abs(cal.difference(item.startTime, item.endTime, "millisecond"));
var fixed = false;
if(cal.compare(item.startTime, rd.startTime) == -1){
item.startTime = rd.startTime;
item.endTime = cal.add(item.startTime, "millisecond", duration);
fixed = true;
}else if(cal.compare(item.endTime, rd.endTime) == 1){
item.endTime = rd.endTime;
item.startTime = cal.add(item.endTime, "millisecond", -duration);
fixed = true;
}
return fixed;
},
/////////////////////////////////////////////////////////
//
// Scrollable
//
/////////////////////////////////////////////////////////
// scrollable: Boolean
// Indicates whether the view can be scrolled or not.
scrollable: true,
// autoScroll: Boolean
// Indicates whether the view can be scrolled automatically.
// Auto scrolling is used when moving focus to a non visible renderer using keyboard
// and while editing an item.
autoScroll: true,
_autoScroll: function(gx, gy, orientation){
// summary:
// Starts or stops the auto scroll according to the mouse cursor position during an item editing.
// gx: Integer
// The position of the mouse cursor along the x-axis.
// gy: Integer
// The position of the mouse cursor along the y-axis.
// tags:
// extension
return false;
},
// scrollMethod: String
// Method used to scroll the view, for example the scroll of column view.
// Valid value are:
//
// - "auto": let the view decide (default),
// - "css": use css 3d transform,
// - "dom": use the scrollTop property.
scrollMethod: "auto",
_setScrollMethodAttr: function(value){
if(this.scrollMethod != value){
this.scrollMethod = value;
// reset
if(this._domScroll !== undefined){
if(this._domScroll){
domStyle.set(this.sheetContainer, this._cssPrefix+"transform", "translateY(0px)");
}else{
this.scrollContainer.scrollTop = 0;
}
}
delete this._domScroll;
var pos = this._getScrollPosition();
delete this._scrollPos;
this._setScrollPosition(pos);
}
},
_startAutoScroll: function(step){
// summary:
// Starts the auto scroll of the view (if it's scrollable). Used only during editing.
// tags:
// protected
var sp = this._scrollProps;
if(!sp){
sp = this._scrollProps = {};
}
sp.scrollStep = step;
if (!sp.isScrolling){
sp.isScrolling = true;
sp.scrollTimer = setInterval(lang.hitch(this, this._onScrollTimer_tick), 10);
}
},
_stopAutoScroll: function(){
// summary:
// Stops the auto scroll of the view (if it's scrollable). Used only during editing.
// tags:
// protected
var sp = this._scrollProps;
if (sp && sp.isScrolling) {
clearInterval(sp.scrollTimer);
sp.scrollTimer = null;
}
this._scrollProps = null;
},
_onScrollTimer_tick: function(pos){
},
_scrollPos: 0,
_hscrollPos: 0,
getCSSPrefix: function(){
// summary:
// Utility method that return the specific CSS prefix
// for non standard CSS properties. Ex: -moz-border-radius.
if(has("ie")){
return "-ms-";
}
if(has("webkit")){
return "-webkit-";
}
if(has("mozilla")){
return "-moz-";
}
if(has("opera")){
return "-o-";
}
return "";
},
// _hScrollNodes: DOMNodes[]
// Array of nodes that will be scrolled horizontally.
// Must be set by sub class on buildRendering.
_hScrollNodes: null,
_setScrollPositionBase: function(pos, vertical){
// summary:
// Sets the scroll position (if the view is scrollable), using the scroll method defined.
// tags:
// protected
if(vertical && this._scrollPos == pos ||
!vertical && this._hScrollPos == pos){
return;
}
// determine scroll method once.
if(this._domScroll === undefined){
var sm = this.get("scrollMethod");
if(sm === "auto"){
this._domScroll = !has("ios") && !has("android") && !has("webkit");
}else{
this._domScroll = sm === "dom";
}
}
var max = 0;
if(vertical){
var containerSize = domGeometry.getMarginBox(this.scrollContainer);
var sheetSize = domGeometry.getMarginBox(this.sheetContainer);
max = sheetSize.h - containerSize.h;
}else{
var gridSize = domGeometry.getMarginBox(this.grid);
var gridTableSize = domGeometry.getMarginBox(this.gridTable);
max = gridTableSize.w - gridSize.w;
}
if(pos < 0){
pos = 0;
}else if(pos > max){
pos = max;
}
if(vertical){
this._scrollPos = pos;
}else{
this._hScrollPos = pos;
}
var rtl = !this.isLeftToRight();
if(this._domScroll){
if(vertical){
this.scrollContainer.scrollTop = pos;
}else{
arr.forEach(this._hScrollNodes, function(elt){
domStyle.set(elt, "left", ((rtl?1:-1) * pos) + "px");
}, this);
}
}else{
if(!this._cssPrefix){
this._cssPrefix = this.getCSSPrefix();
}
var cssProp = this._cssPrefix+"transform";
if(vertical){
domStyle.set(this.sheetContainer, cssProp, "translateY(-"+pos+"px)");
}else{
var css = "translateX("+(rtl?"":"-")+pos+"px)";
arr.forEach(this._hScrollNodes, function(elt){
domStyle.set(elt, cssProp, css);
}, this);
}
}
},
_setScrollPosition: function(pos){
// summary:
// Sets the verical scroll position (if the view is scrollable), using the scroll method defined.
// tags:
// protected
this._setScrollPositionBase(pos, true);
},
_getScrollPosition: function(){
// summary:
// Returns the vertical scroll position (if the view is scrollable), using the scroll method defined.
// tags:
// protected
return this._scrollPos;
},
_setHScrollPosition: function(pos){
// summary:
// Sets the horizontal scroll position (if the view is scrollable), using the scroll method defined.
// tags:
// protected
this._setScrollPositionBase(pos, false);
},
_setHScrollPositionImpl: function(pos, useDom, cssProperty){
// summary:
// Sets the horizontal scroll position on sub elements (if the view is scrollable), using the scroll method defined.
// Important: must be implemented by sub classes and not called directly. Use _setHScrollPosition() method instead.
// tags:
// private
var css = useDom ? null : "translateX(-"+pos+"px)";
arr.forEach(this._hScrollNodes, function(elt){
if(useDom){
elt.scrollLeft = pos;
domStyle.set(elt, "left", (-pos) + "px");
}else{
domStyle.set(elt, cssProp, css);
}
}, this);
},
_hScrollPos: 0,
_getHScrollPosition: function(){
// summary:
// Returns the horizontal scroll position (if the view is scrollable), using the scroll method defined.
// tags:
// protected
return this._hScrollPos;
},
scrollView: function(dir){