metamaps--metamaps/frontend/src/Metamaps/GlobalUI/index.js

132 lines
3.4 KiB
JavaScript
Raw Normal View History

/* global $ */
2016-09-29 16:20:16 +00:00
import clipboard from 'clipboard-js'
2016-09-29 16:20:16 +00:00
import Create from '../Create'
import Search from './Search'
import CreateMap from './CreateMap'
import Account from './Account'
import ImportDialog from './ImportDialog'
2016-09-22 10:31:56 +00:00
const GlobalUI = {
2016-09-22 10:31:56 +00:00
notifyTimeout: null,
lightbox: null,
2016-11-07 20:25:08 +00:00
init: function(serverData) {
2016-09-29 16:05:49 +00:00
var self = GlobalUI
2016-09-22 06:25:49 +00:00
2016-10-03 00:32:37 +00:00
self.Search.init(serverData)
self.CreateMap.init(serverData)
self.Account.init(serverData)
self.ImportDialog.init(serverData, self.openLightbox, self.closeLightbox)
2016-09-22 10:31:56 +00:00
if ($('#toast').html().trim()) self.notifyUser($('#toast').html())
2016-09-29 16:05:49 +00:00
// bind lightbox clicks
2016-11-07 20:25:08 +00:00
$('.openLightbox').click(function(event) {
2016-09-29 16:05:49 +00:00
self.openLightbox($(this).attr('data-open'))
event.preventDefault()
return false
})
2016-09-22 10:31:56 +00:00
2016-09-29 16:05:49 +00:00
$('#lightbox_screen, #lightbox_close').click(self.closeLightbox)
2016-09-22 10:31:56 +00:00
},
2016-11-07 20:25:08 +00:00
showDiv: function(selector) {
2016-09-22 10:31:56 +00:00
$(selector).show()
$(selector).animate({
opacity: 1
}, 200, 'easeOutCubic')
},
2016-11-07 20:25:08 +00:00
hideDiv: function(selector) {
2016-09-22 10:31:56 +00:00
$(selector).animate({
opacity: 0
2016-11-07 20:25:08 +00:00
}, 200, 'easeInCubic', function() { $(this).hide() })
2016-09-22 10:31:56 +00:00
},
2016-11-07 20:25:08 +00:00
openLightbox: function(which) {
2016-09-29 16:05:49 +00:00
var self = GlobalUI
2016-09-22 10:31:56 +00:00
2016-09-29 16:05:49 +00:00
$('.lightboxContent').hide()
$('#' + which).show()
2016-09-22 10:31:56 +00:00
2016-09-29 16:05:49 +00:00
self.lightbox = which
2016-09-22 10:31:56 +00:00
2016-09-29 16:05:49 +00:00
$('#lightbox_overlay').show()
2016-09-22 10:31:56 +00:00
2016-09-29 16:05:49 +00:00
var heightOfContent = '-' + ($('#lightbox_main').height() / 2) + 'px'
2016-09-22 10:31:56 +00:00
// animate the content in from the bottom
$('#lightbox_main').animate({
'top': '50%',
'margin-top': heightOfContent
2016-09-29 16:05:49 +00:00
}, 200, 'easeOutCubic')
2016-09-22 10:31:56 +00:00
// fade the black overlay in
$('#lightbox_screen').animate({
'opacity': '0.42'
2016-09-29 16:05:49 +00:00
}, 200)
2016-09-22 10:31:56 +00:00
2016-09-29 16:05:49 +00:00
if (which === 'switchMetacodes') {
Create.isSwitchingSet = true
2016-09-22 10:31:56 +00:00
}
},
2016-09-22 06:25:49 +00:00
2016-11-07 20:25:08 +00:00
closeLightbox: function(event) {
2016-09-29 16:05:49 +00:00
var self = GlobalUI
2016-09-22 10:31:56 +00:00
2016-09-29 16:05:49 +00:00
if (event) event.preventDefault()
2016-09-22 10:31:56 +00:00
// animate the lightbox content offscreen
$('#lightbox_main').animate({
'top': '100%',
'margin-top': '0'
2016-09-29 16:05:49 +00:00
}, 200, 'easeInCubic')
2016-09-22 10:31:56 +00:00
// fade the black overlay out
$('#lightbox_screen').animate({
'opacity': '0.0'
2016-11-07 20:25:08 +00:00
}, 200, function() {
2016-09-29 16:05:49 +00:00
$('#lightbox_overlay').hide()
})
2016-09-22 10:31:56 +00:00
2016-09-29 16:05:49 +00:00
if (self.lightbox === 'forkmap') GlobalUI.CreateMap.reset('fork_map')
if (self.lightbox === 'newmap') GlobalUI.CreateMap.reset('new_map')
2016-09-22 10:31:56 +00:00
if (Create && Create.isSwitchingSet) {
2016-09-29 16:05:49 +00:00
Create.cancelMetacodeSetSwitch()
2016-09-22 10:31:56 +00:00
}
2016-09-29 16:05:49 +00:00
self.lightbox = null
2016-09-22 10:31:56 +00:00
},
2016-11-07 20:25:08 +00:00
notifyUser: function(message, leaveOpen) {
2016-09-29 16:05:49 +00:00
var self = GlobalUI
2016-09-22 10:31:56 +00:00
$('#toast').html(message)
self.showDiv('#toast')
2016-09-29 16:05:49 +00:00
clearTimeout(self.notifyTimeOut)
2016-09-22 10:31:56 +00:00
if (!leaveOpen) {
2016-11-07 20:25:08 +00:00
self.notifyTimeOut = setTimeout(function() {
2016-09-22 06:25:49 +00:00
self.hideDiv('#toast')
2016-09-29 16:05:49 +00:00
}, 8000)
2016-09-22 06:25:49 +00:00
}
2016-09-22 10:31:56 +00:00
},
2016-11-07 20:25:08 +00:00
clearNotify: function() {
2016-09-29 16:05:49 +00:00
var self = GlobalUI
2016-09-22 10:31:56 +00:00
2016-09-29 16:05:49 +00:00
clearTimeout(self.notifyTimeOut)
2016-09-22 10:31:56 +00:00
self.hideDiv('#toast')
},
2016-11-07 20:25:08 +00:00
shareInvite: function(inviteLink) {
clipboard.copy({
'text/plain': inviteLink
}).then(() => {
$('#joinCodesBox .popup').remove()
$('#joinCodesBox').append('<p class="popup" style="text-align: center">Copied!</p>')
window.setTimeout(() => $('#joinCodesBox .popup').remove(), 1500)
}, () => {
$('#joinCodesBox .popup').remove()
$('#joinCodesBox').append(`<p class="popup" style="text-align: center">Your browser doesn't support copying, please copy manually.</p>`)
window.setTimeout(() => $('#joinCodesBox .popup').remove(), 1500)
})
2016-09-22 10:31:56 +00:00
}
}
2016-09-22 06:25:49 +00:00
export { Search, CreateMap, Account, ImportDialog }
export default GlobalUI