@@ -597,21 +597,9 @@ Code.loadSimulator = function () {
597597 var frame = document . getElementById ( 'simulator-frame' ) ;
598598 var btn = document . getElementById ( 'simulatorButton' ) ;
599599 var closeBtn = document . querySelector ( '#simulator-area .close-btn' ) ;
600+ var enlargeBtn = document . querySelector ( '#simulator-area .icon-enlarge' ) ;
601+ var shrinkBtn = document . querySelector ( '#simulator-area .icon-shrink' )
600602 var resizeBar = document . getElementById ( 'simulator-resize-bar' ) ;
601- var updateHeight = function ( ) {
602- var contentHeight = document . getElementById ( 'content_blocks' ) . offsetHeight ;
603- area . style . height = ( contentHeight - 110 ) + 'px' ;
604- } ;
605- var frameReady = function ( ) {
606- if ( storage . config ) {
607- frame . contentWindow . blockly . config ( storage . config ) ;
608- }
609-
610- if ( storage . opened ) {
611- area . classList . add ( 'show' ) ;
612- btn . classList . add ( 'opened' ) ;
613- }
614- } ;
615603 var storage = { } ;
616604
617605 if ( localStorage . simulator ) {
@@ -622,24 +610,19 @@ Code.loadSimulator = function () {
622610 }
623611 }
624612
625- if ( storage . width ) {
626- area . style . width = storage . width ;
627- }
628-
629613 if ( frame . contentWindow . blockly ) {
630614 frameReady ( ) ;
631615 } else {
632616 frame . contentWindow . addEventListener ( 'load' , frameReady ) ;
633617 }
634618
635- updateHeight ( ) ;
636-
637619 window . addEventListener ( 'resize' , updateHeight ) ;
638620
639621 window . addEventListener ( 'unload' , function ( ) {
640622 storage . config = frame . contentWindow . blockly . config ( ) ;
641623 storage . opened = area . classList . contains ( 'show' ) ;
642- storage . width = area . style . width ;
624+ storage . isFull = area . classList . contains ( 'full' ) ;
625+ storage . width = area . dataset . width ;
643626 localStorage . simulator = JSON . stringify ( storage ) ;
644627 } ) ;
645628
@@ -648,11 +631,30 @@ Code.loadSimulator = function () {
648631 } ) ;
649632
650633 Code . bindClick ( closeBtn , function ( ) {
651- area . classList . remove ( 'show' ) ;
634+ area . classList . remove ( 'show' , 'full' ) ;
652635 btn . classList . remove ( 'opened' ) ;
636+ updateWidth ( ) ;
637+ updateHeight ( ) ;
638+ } ) ;
639+
640+ Code . bindClick ( enlargeBtn , function ( ) {
641+ area . classList . add ( 'full' ) ;
642+ updateWidth ( ) ;
643+ updateHeight ( ) ;
644+ } ) ;
645+
646+ Code . bindClick ( shrinkBtn , function ( ) {
647+ area . classList . remove ( 'full' ) ;
648+ updateWidth ( ) ;
649+ updateHeight ( ) ;
653650 } ) ;
654651
655652 resizeBar . addEventListener ( 'mousedown' , function ( e ) {
653+
654+ if ( area . classList . contains ( 'full' ) ) {
655+ return ;
656+ }
657+
656658 var cover = document . createElement ( 'div' ) ;
657659 var ox = e . pageX ;
658660 var dw = area . offsetWidth ;
@@ -676,12 +678,61 @@ Code.loadSimulator = function () {
676678 cover . removeEventListener ( 'mousemove' , move ) ;
677679 cover . removeEventListener ( 'mouseup' , up ) ;
678680 cover . remove ( ) ;
681+ area . dataset . width = area . style . width ;
679682 } ;
680683
681684 cover . addEventListener ( 'mousemove' , move ) ;
682685 cover . addEventListener ( 'mouseup' , up ) ;
686+
683687 } ) ;
684688
689+ function updateHeight ( ) {
690+ if ( area . classList . contains ( 'full' ) ) {
691+ area . style . height = '' ;
692+ return ;
693+ }
694+
695+ var contentHeight = document . getElementById ( 'content_blocks' ) . offsetHeight ;
696+ area . style . height = ( contentHeight - 110 ) + 'px' ;
697+ }
698+
699+ function updateWidth ( ) {
700+ if ( area . classList . contains ( 'full' ) ) {
701+ area . style . width = '' ;
702+ return ;
703+ }
704+
705+ area . style . width = area . dataset . width || '' ;
706+ }
707+
708+ function frameReady ( ) {
709+ var api = frame . contentWindow . blockly ;
710+
711+ // 寬度的儲存
712+ storage . width && ( area . dataset . width = storage . width ) ;
713+
714+ // 語系
715+ api . lang ( Code . getLang ( ) ) ;
716+
717+ // 之前存檔的回復
718+ if ( storage . config ) {
719+ api . config ( storage . config ) ;
720+ }
721+
722+ if ( storage . isFull ) {
723+ area . classList . add ( 'full' ) ;
724+ }
725+
726+ updateWidth ( ) ;
727+ updateHeight ( ) ;
728+
729+ if ( storage . opened ) {
730+ area . classList . add ( 'show' ) ;
731+ btn . classList . add ( 'opened' ) ;
732+ }
733+
734+ }
735+
685736} ;
686737
687738/**
0 commit comments