1
+ var EQ = require ( '../src/ElementQueries' ) ;
2
+ var ResizeSensor = require ( '../src/ResizeSensor' ) ;
3
+
4
+ EQ . listen ( ) ;
5
+
6
+ var ResizerDemo = new Class ( {
7
+ y : null ,
8
+ initialize : function ( container ) {
9
+ this . container = container ;
10
+ this . setupLayout ( ) ;
11
+ } ,
12
+
13
+ setupLayout : function ( ) {
14
+ this . handler = new Element ( 'div' , {
15
+ 'class' : 'resizerDemo-handler'
16
+ } ) . inject ( this . container ) ;
17
+
18
+ this . container . makeResizable ( {
19
+ snap : 0 ,
20
+ handle : this . handler ,
21
+ modifiers : {
22
+ 'x' : 'width' ,
23
+ 'y' : this . y
24
+ }
25
+ } ) ;
26
+ }
27
+ } ) ;
28
+
29
+ var ResizeDemoXY = new Class ( {
30
+ Extends : ResizerDemo ,
31
+ y : 'height'
32
+ } ) ;
33
+
34
+ window . addEvent ( 'domready' , function ( ) {
35
+ $$ ( '.examplesResizerDemos' ) . each ( function ( resizer ) {
36
+ new ResizerDemo ( resizer ) ;
37
+ } ) ;
38
+ $$ ( '.examplesResizerDemosXY' ) . each ( function ( resizer ) {
39
+ new ResizeDemoXY ( resizer ) ;
40
+ } ) ;
41
+
42
+
43
+ perfTest ( ) ;
44
+ example3 ( ) ;
45
+ example4 ( ) ;
46
+ example5 ( ) ;
47
+ } ) ;
48
+
49
+ function perfTest ( ) {
50
+ var container = $ ( 'dynamicContainer' ) ;
51
+ var dynamicCount = $ ( 'dynamicCount' ) ;
52
+ var dynamicCounter = $ ( 'dynamicCounter' ) ;
53
+
54
+ window . detachDynamic = function ( ) {
55
+ container . getChildren ( ) . each ( function ( element ) {
56
+ ResizeSensor . detach ( element ) ;
57
+ } ) ;
58
+ } ;
59
+
60
+ window . removeDynamic = function ( ) {
61
+ container . empty ( ) ;
62
+ } ;
63
+
64
+ window . addDynamic = function ( ) {
65
+ container . empty ( ) ;
66
+ var i = 0 , to = dynamicCount . value , div , counter = 0 ;
67
+ for ( ; i < to ; i ++ ) {
68
+ div = new Element ( 'div' , {
69
+ 'class' : 'dynamicElement' ,
70
+ text : '#' + i
71
+ } ) . inject ( container ) ;
72
+
73
+ new ResizeSensor ( div , function ( ) {
74
+ counter ++ ;
75
+ dynamicCounter . set ( 'text' , counter + ' changes.' ) ;
76
+ } ) ;
77
+ }
78
+ }
79
+ }
80
+
81
+ function example3 ( ) {
82
+
83
+ var logger = document . id ( 'example-3-log' ) ;
84
+ var box = document . id ( 'example-3-box' ) ;
85
+ document . id ( 'startStop3' ) . addEvent ( 'click' , function ( ) {
86
+ if ( box . hasClass ( 'example-3-box-start' ) ) {
87
+ box . removeClass ( 'example-3-box-start' ) ;
88
+ } else {
89
+ box . addClass ( 'example-3-box-start' ) ;
90
+ }
91
+ } ) ;
92
+ new ResizeSensor ( box , function ( el ) {
93
+ logger . set ( 'html' , 'Changed to ' + box . getSize ( ) . x + 'px width.' ) ;
94
+ } ) ;
95
+
96
+ }
97
+
98
+ function example4 ( ) {
99
+ var logger = document . id ( 'example-4-log' ) ;
100
+ var box = document . id ( 'example-4-box' ) ;
101
+ document . id ( 'startStop4' ) . addEvent ( 'click' , function ( ) {
102
+ if ( box . hasClass ( 'example-4-box-start' ) ) {
103
+ box . removeClass ( 'example-4-box-start' ) ;
104
+ } else {
105
+ box . addClass ( 'example-4-box-start' ) ;
106
+ }
107
+ } ) ;
108
+ new ResizeSensor ( box , function ( ) {
109
+ logger . set ( 'html' , 'Changed to ' + box . getSize ( ) . y + 'px height.' ) ;
110
+ } ) ;
111
+ }
112
+
113
+ function example5 ( ) {
114
+ var box = document . id ( 'example-5' ) ;
115
+ var changed = 0 ;
116
+ new ResizeSensor ( box . getParent ( ) , function ( ) {
117
+ box . innerHTML = ( ++ changed ) + ' changes. ' + box . getParent ( ) . getSize ( ) . x + 'px/' + box . getParent ( ) . getSize ( ) . y + 'px' ;
118
+ } ) ;
119
+ }
0 commit comments