Last active
December 22, 2015 07:39
-
-
Save knownasilya/6439916 to your computer and use it in GitHub Desktop.
GMap InfoWindow for Ember
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.MapView = Ember.View.extend({ | |
// Other methods here | |
openPopup: function (options) { | |
var popup = this.get('popup'), | |
hiddenPopup = this.get('lastPopupView'), | |
controller = this.get('controller'); | |
// close last popup | |
if (popup) { | |
popup.close(); | |
} | |
if (hiddenPopup) { | |
hiddenPopup.destroy(); | |
} | |
popup = new google.maps.InfoWindow({ | |
content: '<div id=\'single-popup\'></div>', | |
position: options.position | |
}); | |
hiddenPopup = this.container.lookup('view:popup'); | |
hiddenPopup.set('controller', controller); | |
hiddenPopup.set('building', options.data); | |
popup.open(options.map); | |
hiddenPopup.appendTo('body'); | |
Ember.run.scheduleOnce('afterRender', hiddenPopup, function () { | |
var $detached = hiddenPopup.$().detach(); | |
popup.setContent($detached.get(0)); | |
hiddenPopup.toggleProperty('isVisible'); | |
}); | |
this.set('popup', popup); | |
this.set('lastPopupView', hiddenPopup); | |
this.handlePopupClose(popup, hiddenPopup); | |
}, | |
handlePopupClose: function (popup, popupView) { | |
if (popup && popupView) { | |
google.maps.event.addListener(popup, 'closeclick', function () { | |
popupView.destroy(); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for a single popup at a time. To get multiple popups to work, i'd take the auto generated id of the
hiddenPopup
and prepend it withcontainer-
, socontainer-ember323
and add that as a blank div to the popup just opened, then you can find that element, and append to it.