@@ -308,6 +308,22 @@ define([
308308
309309_bindEvent ( ) {
310310var that = this ;
311+ // Popup click / focus event
312+ $ ( this . wrapSelector ( ) ) . on ( 'click focus' , function ( evt ) {
313+ // Close on blur
314+ if ( $ ( that . wrapSelector ( '.vp-popup-button' ) ) . find ( evt . target ) . length == 0 ) {
315+ if ( ! $ ( evt . target ) . hasClass ( 'vp-popup-codeview-box' )
316+ && $ ( that . wrapSelector ( '.vp-popup-codeview-box' ) ) . find ( evt . target ) . length == 0 ) {
317+ that . closeView ( 'code' ) ;
318+ }
319+ }
320+ if ( $ ( that . wrapSelector ( '.vp-popup-button' ) ) . find ( evt . target ) . length == 0 ) {
321+ if ( ! $ ( evt . target ) . hasClass ( 'vp-popup-dataview-box' )
322+ && $ ( that . wrapSelector ( '.vp-popup-dataview-box' ) ) . find ( evt . target ) . length == 0 ) {
323+ that . closeView ( 'data' ) ;
324+ }
325+ }
326+ } ) ;
311327// Close popup event
312328$ ( this . wrapSelector ( '.vp-popup-close' ) ) . on ( 'click' , function ( evt ) {
313329if ( that . getTaskType ( ) === 'task' ) {
@@ -514,6 +530,14 @@ define([
514530}
515531} ) ;
516532
533+ // blur on code, dataview
534+ $ ( this . wrapSelector ( '.vp-popup-codeview-box' ) ) . on ( 'hide' , function ( ) {
535+ that . closeView ( 'code' ) ;
536+ } ) ;
537+ $ ( this . wrapSelector ( '.vp-popup-dataview-box' ) ) . on ( 'hide' , function ( ) {
538+ that . closeView ( 'data' ) ;
539+ } ) ;
540+
517541// focus on data selector input
518542$ ( this . wrapSelector ( '.vp-data-selector' ) ) . on ( 'focus' , function ( evt ) {
519543
@@ -1154,20 +1178,36 @@ define([
11541178setTimeout ( function ( ) {
11551179that . cmCodeview . refresh ( ) ;
11561180} , 1 ) ;
1157- $ ( this . wrapSelector ( '.vp-popup-dataview-box' ) ) . hide ( ) ;
1181+ this . closeView ( 'data' ) ;
11581182$ ( this . wrapSelector ( '.vp-popup-codeview-box' ) ) . show ( ) ;
11591183} else if ( viewType === 'data' ) {
11601184this . renderDataView ( ) ;
1161- $ ( this . wrapSelector ( '.vp-popup-codeview-box' ) ) . hide ( ) ;
1185+ this . closeView ( 'code' ) ;
11621186$ ( this . wrapSelector ( '.vp-popup-dataview-box' ) ) . show ( ) ;
11631187} else if ( viewType === 'help' ) {
1164- $ ( this . wrapSelector ( '.vp-popup-codeview-box' ) ) . hide ( ) ;
1165- $ ( this . wrapSelector ( '.vp-popup-dataview-box' ) ) . hide ( ) ;
1188+ this . closeView ( 'code' ) ;
1189+ this . closeView ( 'data' ) ;
11661190this . openHelpView ( ) ;
11671191}
11681192}
11691193
11701194closeView ( viewType ) {
1195+ if ( viewType === 'code' ) {
1196+ // reset codeview
1197+ if ( this . cmCodeview ) {
1198+ this . cmCodeview . setValue ( '' ) ;
1199+ this . cmCodeview . save ( ) ;
1200+
1201+ var that = this ;
1202+ setTimeout ( function ( ) {
1203+ that . cmCodeview . refresh ( ) ;
1204+ } , 1 ) ;
1205+ }
1206+ } else if ( viewType === 'data' ) {
1207+ // reset dataview
1208+ $ ( this . wrapSelector ( '.vp-popup-dataview-box' ) ) . html ( '' ) ;
1209+ }
1210+ // hide view
11711211$ ( this . wrapSelector ( '.vp-popup-' + viewType + 'view-box' ) ) . hide ( ) ;
11721212}
11731213