@@ -45,7 +45,7 @@ module.exports = baseVw.extend({
4545 'click .js-buyWizardWalletNext' : 'walletNowClick' ,
4646 'click .js-buyWizardHasWallet' : 'hasWalletClick' ,
4747 'click .js-buyWizardDoesntHaveWallet' : 'doesntHaveWallet' ,
48- 'click .js-buyWizardNewAddressCancel' : 'hideNewAddress ' ,
48+ 'click .js-buyWizardNewAddressCancel' : 'onAddressCancel ' ,
4949 'click .js-buyWizardNewAddressSave' : 'saveNewAddress' ,
5050 'click .js-buyWizardSendPurchase' : 'sendPurchase' ,
5151 'click .js-buyWizardPurchaseBack' : 'backPurchase' ,
@@ -56,7 +56,6 @@ module.exports = baseVw.extend({
5656 'click .js-buyWizardPayCheck' : 'checkPayment' ,
5757 'click .js-buyWizardCloseSummary' : 'closeWizard' ,
5858 'click input[name="radioPaymentType"]' : 'changePaymentType' ,
59- 'blur .js-buyWizardPostalInput' : 'updateMap' ,
6059 'click #BuyWizardQRDetailsInput' : 'toggleQRDetails' ,
6160 'blur input' : 'validateInput'
6261 } ,
@@ -181,6 +180,8 @@ module.exports = baseVw.extend({
181180
182181 self . listenTo ( self . buyAddressesView , 'setAddress' , self . addressSelected ) ;
183182
183+ self . $buyWizardMap = self . $ ( '.js-buyWizardMap' ) ;
184+
184185 //init the accordion
185186 self . initAccordion ( '.js-buyWizardAccordion' ) ;
186187
@@ -226,37 +227,37 @@ module.exports = baseVw.extend({
226227 } ,
227228
228229 showMaps : function ( ) {
229- "use strict" ;
230230 this . $el . find ( '.js-buyWizardMap' ) . removeClass ( 'hide' ) ;
231- this . $el . find ( '.js-buyWizardMapPlaceHolder' ) . removeClass ( 'hide' ) ;
232- this . hideMap = false ;
233231 } ,
234232
235233 hideMaps : function ( ) {
236- "use strict" ;
237234 this . $el . find ( '.js-buyWizardMap' ) . addClass ( 'hide' ) ;
238- this . $el . find ( '.js-buyWizardMapPlaceHolder' ) . addClass ( 'hide' ) ;
239- this . hideMap = true ;
240235 } ,
241236
242237 createNewAddress : function ( ) {
243- "use strict" ;
244238 var self = this ;
245239 this . $el . find ( '.js-buyWizardAddress' ) . addClass ( 'hide' ) ;
246240 this . $el . find ( '.js-buyWizardNewAddress' ) . removeClass ( 'hide' ) ;
247241 this . $el . find ( '#buyWizardNameInput' ) . focus ( ) ;
242+ this . $el . addClass ( 'addressFormOpened' ) ;
243+ this . $buyWizardMap . find ( 'iframe' ) . addClass ( 'blurMore' ) ;
244+
248245 //set chosen inputs
249246 $ ( '.chosen' ) . chosen ( { search_contains : true } ) ;
250247 } ,
251248
252- hideNewAddress : function ( ) {
253- "use strict" ;
249+ onAddressCancel : function ( e ) {
250+ this . $buyWizardMap . find ( 'iframe' ) . removeClass ( 'blurMore' ) ;
251+ this . hideNewAddress ( ) ;
252+ } ,
253+
254+ hideNewAddress : function ( e ) {
254255 this . $el . find ( '.js-buyWizardAddress' ) . removeClass ( 'hide' ) ;
255256 this . $el . find ( '.js-buyWizardNewAddress' ) . addClass ( 'hide' ) ;
257+ this . $el . removeClass ( 'addressFormOpened' ) ;
256258 } ,
257259
258260 addressSelected : function ( selectedAddress ) {
259- "use strict" ;
260261 this . model . set ( 'selectedAddress' , selectedAddress ) ;
261262 this . displayMap ( selectedAddress ) ;
262263 this . $el . find ( '.js-buyWizardAddressNext' ) . removeClass ( 'disabled' ) ;
@@ -374,28 +375,46 @@ module.exports = baseVw.extend({
374375 } ,
375376
376377 displayMap : function ( address ) {
377- "use strict" ;
378- var addressString = "" ;
379- //only create new map if address is valid
378+ var addressString = "" ,
379+ $currentIframe ;
380+
381+ this . $buyWizardMap . find ( '.js-iframe-pending, .js-iframe-leaving' )
382+ . remove ( ) ;
383+ $currentIframe = this . $buyWizardMap . find ( 'iframe' ) ;
384+ $currentIframe . addClass ( 'blurMore' ) ;
385+
380386 if ( address && address . street && address . city && address . state && address . postal_code ) {
381387 addressString = address . street + ", " + address . city + ", " + address . state + " " + address . postal_code + " " + address . displayCountry ;
382- addressString = encodeURIComponent ( addressString ) ;
383- var hideClass = this . hideMap ? "hide" : "" ;
384- var newMap = '<div class="flexContainer"><iframe class="' + hideClass + ' js-buyWizardMap"' +
385- 'width="525" height="350" frameborder="0" style="border:0; margin-top: 0"' +
386- 'src="https://www.google.com/maps/embed/v1/place?key=AIzaSyBoWGMeVZpy9qc7H418Jk2Sq2NWedJgp_4&q=' + addressString + '"></iframe></div>' ;
387- this . $el . find ( '.js-buyWizardMap' ) . html ( newMap ) ;
388+ } else {
389+ // if address is invalid, we'll create a dummy address for which google maps will show a map of the world
390+ addressString = "123 Street" + ", " + "City" + ", " + "State" + " " + "12345" + " " + "Country" ;
388391 }
389- } ,
390392
391- updateMap : function ( ) {
392- var address = [ ] ;
393- address . street = $ ( '#buyWizardStreetInput' ) . val ( ) ;
394- address . city = $ ( '#buyWizardCityInput' ) . val ( ) ;
395- address . state = $ ( '#buyWizardStateInput' ) . val ( ) ;
396- address . postal_code = $ ( '#buyWizardPostalInput' ) . val ( ) ;
393+ addressString = encodeURIComponent ( addressString ) ;
394+ $iFrame = $ ( '<iframe class="js-iframe-pending positionTop" width="525" height="350" frameborder="0" style="border:0; margin-top: 0; height: 262px" />' ) ;
395+
396+ if ( $currentIframe . length ) {
397+ this . $buyWizardMap . find ( '.js-mapSpinner' ) . removeClass ( 'hide' ) ;
398+ $iFrame . insertBefore ( $currentIframe ) ;
399+ } else {
400+ this . $buyWizardMap . find ( '.mapWrap' )
401+ . prepend ( $iFrame ) ;
402+ }
403+
404+ $iFrame . on ( 'load' , ( ) => {
405+ this . $buyWizardMap . find ( '.js-mapSpinner' ) . addClass ( 'hide' ) ;
406+
407+ $currentIframe . addClass ( 'js-iframe-leaving' )
408+ . fadeOut ( {
409+ duration : 'slow' ,
410+ complete : ( ) => {
411+ $currentIframe . remove ( ) ;
412+ }
413+ } ) ;
414+ $iFrame . removeClass ( 'js-iframe-pending' ) ;
415+ } ) ;
397416
398- this . displayMap ( address ) ;
417+ $iFrame . attr ( 'src' , 'https://www.google.com/maps/embed/v1/place?key=AIzaSyBoWGMeVZpy9qc7H418Jk2Sq2NWedJgp_4&q=' + addressString ) ;
399418 } ,
400419
401420 returnNext : function ( ) {
0 commit comments