@@ -59,6 +59,10 @@ function addSvgs(size, rows, cols) {
5959 shape . translation . set ( two . width / 2 , two . height / 2 ) ;
6060 two . add ( shape ) ;
6161 two . update ( ) ;
62+
63+ $ ( o ) . on ( "click" , function ( ) {
64+ toggleSVG ( $ ( o ) , two , shape ) ;
65+ } ) ;
6266 } ) ;
6367}
6468
@@ -113,23 +117,64 @@ function pickFlower(flowers) {
113117 flower . cap = 'round' ;
114118 return flower ;
115119}
116- //
117- // function getHeight(element)
118- // {
119- // element.style.visibility = "hidden";
120- // document.body.appendChild(element);
121- // var height = element.offsetHeight + 0;
122- // document.body.removeChild(element);
123- // element.style.visibility = "visible";
124- // return height;
125- // }
126- //
127- // function getWidth(element)
128- // {
129- // element.style.visibility = "hidden";
130- // document.body.appendChild(element);
131- // var width = element.offsetWidth + 0;
132- // document.body.removeChild(element);
133- // element.style.visibility = "visible";
134- // return width;
135- // }
120+
121+
122+ function toggleSVG ( cell , two , shape ) {
123+ var isEnlarged = cell . data ( "isEnlarged" ) ;
124+
125+ if ( isEnlarged ) {
126+ // Shrink back to original size
127+ cell . css ( {
128+ position : "absolute" ,
129+ width : two . width ,
130+ height : two . height ,
131+ zIndex : 1
132+ } ) ;
133+
134+ shape . translation . set ( two . width / 2 , two . height / 2 ) ;
135+ shape . scale = 1 ;
136+ // Remove text if it exists
137+ var text = shape . children . find ( child => child instanceof Two . Text ) ;
138+ if ( text ) {
139+ shape . remove ( text ) ;
140+ }
141+ two . update ( ) ;
142+ } else {
143+ // Enlarge to cover the entire screen
144+ var newWidth = $ ( window ) . width ( ) ;
145+ var newHeight = $ ( window ) . height ( ) ;
146+ var newCenterX = newWidth / 2 ;
147+ var newCenterY = newHeight / 2 ;
148+ var scaleFactor = Math . max ( newWidth / two . width , newHeight / two . height ) ;
149+
150+ cell . css ( {
151+ position : "fixed" ,
152+ top : 0 ,
153+ left : 0 ,
154+ width : "100vw" ,
155+ height : "100vh" ,
156+ zIndex : 9999 ,
157+ transition : "width 1s, height 1s"
158+ } ) ;
159+
160+ two . width = newWidth ;
161+ two . height = newHeight ;
162+ two . update ( ) ;
163+
164+
165+
166+ two . bind ( "update" , function ( ) {
167+ shape . scale += ( scaleFactor - shape . scale ) * 0.1 ;
168+ shape . translation . set ( newCenterX , newCenterY ) ;
169+
170+ if ( Math . abs ( shape . scale - scaleFactor ) < 0.01 ) {
171+ shape . scale = scaleFactor ;
172+ two . unbind ( "update" ) ;
173+ }
174+ } ) ;
175+
176+ two . play ( ) ;
177+ }
178+
179+ cell . data ( "isEnlarged" , ! isEnlarged ) ;
180+ }
0 commit comments