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

148 lines
3.8 KiB
JavaScript
Raw Normal View History

/* global $ */
2016-09-30 00:20:16 +08:00
import Create from '../Create'
2017-09-22 18:38:38 -04:00
import Notifications from './Notifications'
react-router and rebuild app structure in react (#1091) * initial restructuring * stuff * lock version number * just keep using current mapinfobox * fix map upperRightUI layout * make mapsWidth work and add mobile * remove filterBoxOpen for now * redo the mobile menu in react * get account menu and invite lightbox working * fixed maps scrolling * make other routes work * fix signed out home page * fix accountbox toggling * add metacode edit routes * lots of fixes * fix map chat layout and tab bug * improve topic card readability and fix dragging bug * fixup mapchat stuff * fix up navigation to use react-router * jquery no longer handling access requests * handle case where user hasn't loaded yet * this shouldn't have been removed * add frame for topic view * rewrite map instructions * fix toast (and sign out bug) * fix apps pages and missing routes * made our request invite page look nice * filter box in react * forgot to add one proptype * remove extra comments * handle page title and mobile title updates * reenable google analytics * make filterbox use onclickoutside * reenable topic view in react * fix csrf auth token * fix little homepage styling issue * try putting preparevizdata in a timeout * installing render log to count * little fixes * fixup filters * make filter map function names more readable * eslint helps * renaming for clarity * use onclickoutside for account/sign in box * add some logging to see whether this is source of many renders * turns out chatview was heavily hogging memory * tiimeout not needed
2017-03-16 17:58:56 -04:00
import ReactApp from './ReactApp'
2016-09-30 00:20:16 +08:00
import Search from './Search'
import CreateMap from './CreateMap'
import ImportDialog from './ImportDialog'
2016-09-22 18:31:56 +08:00
const GlobalUI = {
2016-09-22 18:31:56 +08:00
notifyTimeout: null,
notifyQueue: [],
notifying: false,
2016-09-22 18:31:56 +08:00
lightbox: null,
2016-11-07 15:25:08 -05:00
init: function(serverData) {
const self = GlobalUI
2016-09-22 14:25:49 +08:00
2017-09-25 15:21:04 -04:00
self.Notifications.init(serverData)
react-router and rebuild app structure in react (#1091) * initial restructuring * stuff * lock version number * just keep using current mapinfobox * fix map upperRightUI layout * make mapsWidth work and add mobile * remove filterBoxOpen for now * redo the mobile menu in react * get account menu and invite lightbox working * fixed maps scrolling * make other routes work * fix signed out home page * fix accountbox toggling * add metacode edit routes * lots of fixes * fix map chat layout and tab bug * improve topic card readability and fix dragging bug * fixup mapchat stuff * fix up navigation to use react-router * jquery no longer handling access requests * handle case where user hasn't loaded yet * this shouldn't have been removed * add frame for topic view * rewrite map instructions * fix toast (and sign out bug) * fix apps pages and missing routes * made our request invite page look nice * filter box in react * forgot to add one proptype * remove extra comments * handle page title and mobile title updates * reenable google analytics * make filterbox use onclickoutside * reenable topic view in react * fix csrf auth token * fix little homepage styling issue * try putting preparevizdata in a timeout * installing render log to count * little fixes * fixup filters * make filter map function names more readable * eslint helps * renaming for clarity * use onclickoutside for account/sign in box * add some logging to see whether this is source of many renders * turns out chatview was heavily hogging memory * tiimeout not needed
2017-03-16 17:58:56 -04:00
self.ReactApp.init(serverData, self.openLightbox)
2016-10-03 08:32:37 +08:00
self.CreateMap.init(serverData)
self.ImportDialog.init(serverData, self.openLightbox, self.closeLightbox)
react-router and rebuild app structure in react (#1091) * initial restructuring * stuff * lock version number * just keep using current mapinfobox * fix map upperRightUI layout * make mapsWidth work and add mobile * remove filterBoxOpen for now * redo the mobile menu in react * get account menu and invite lightbox working * fixed maps scrolling * make other routes work * fix signed out home page * fix accountbox toggling * add metacode edit routes * lots of fixes * fix map chat layout and tab bug * improve topic card readability and fix dragging bug * fixup mapchat stuff * fix up navigation to use react-router * jquery no longer handling access requests * handle case where user hasn't loaded yet * this shouldn't have been removed * add frame for topic view * rewrite map instructions * fix toast (and sign out bug) * fix apps pages and missing routes * made our request invite page look nice * filter box in react * forgot to add one proptype * remove extra comments * handle page title and mobile title updates * reenable google analytics * make filterbox use onclickoutside * reenable topic view in react * fix csrf auth token * fix little homepage styling issue * try putting preparevizdata in a timeout * installing render log to count * little fixes * fixup filters * make filter map function names more readable * eslint helps * renaming for clarity * use onclickoutside for account/sign in box * add some logging to see whether this is source of many renders * turns out chatview was heavily hogging memory * tiimeout not needed
2017-03-16 17:58:56 -04:00
self.Search.init(serverData)
2016-09-22 18:31:56 +08:00
react-router and rebuild app structure in react (#1091) * initial restructuring * stuff * lock version number * just keep using current mapinfobox * fix map upperRightUI layout * make mapsWidth work and add mobile * remove filterBoxOpen for now * redo the mobile menu in react * get account menu and invite lightbox working * fixed maps scrolling * make other routes work * fix signed out home page * fix accountbox toggling * add metacode edit routes * lots of fixes * fix map chat layout and tab bug * improve topic card readability and fix dragging bug * fixup mapchat stuff * fix up navigation to use react-router * jquery no longer handling access requests * handle case where user hasn't loaded yet * this shouldn't have been removed * add frame for topic view * rewrite map instructions * fix toast (and sign out bug) * fix apps pages and missing routes * made our request invite page look nice * filter box in react * forgot to add one proptype * remove extra comments * handle page title and mobile title updates * reenable google analytics * make filterbox use onclickoutside * reenable topic view in react * fix csrf auth token * fix little homepage styling issue * try putting preparevizdata in a timeout * installing render log to count * little fixes * fixup filters * make filter map function names more readable * eslint helps * renaming for clarity * use onclickoutside for account/sign in box * add some logging to see whether this is source of many renders * turns out chatview was heavily hogging memory * tiimeout not needed
2017-03-16 17:58:56 -04:00
if (serverData.toast) self.notifyUser(serverData.toast)
2016-09-22 18:31:56 +08:00
2016-09-30 00:05:49 +08:00
// bind lightbox clicks
2016-11-07 15:25:08 -05:00
$('.openLightbox').click(function(event) {
2016-09-30 00:05:49 +08:00
self.openLightbox($(this).attr('data-open'))
event.preventDefault()
return false
})
2016-09-22 18:31:56 +08:00
2016-09-30 00:05:49 +08:00
$('#lightbox_screen, #lightbox_close').click(self.closeLightbox)
2018-03-08 10:22:11 -05:00
// tab the cheatsheet
$('#cheatSheet').tabs()
$('#quickReference').tabs().addClass('ui-tabs-vertical ui-helper-clearfix')
$('#quickReference .ui-tabs-nav li').removeClass('ui-corner-top').addClass('ui-corner-left')
2016-09-22 18:31:56 +08:00
},
2016-11-07 15:25:08 -05:00
showDiv: function(selector) {
2016-09-22 18:31:56 +08:00
$(selector).show()
$(selector).animate({
opacity: 1
}, 200, 'easeOutCubic')
},
2016-11-07 15:25:08 -05:00
hideDiv: function(selector) {
2016-09-22 18:31:56 +08:00
$(selector).animate({
opacity: 0
2016-11-07 15:25:08 -05:00
}, 200, 'easeInCubic', function() { $(this).hide() })
2016-09-22 18:31:56 +08:00
},
2016-11-07 15:25:08 -05:00
openLightbox: function(which) {
const self = GlobalUI
2016-09-22 18:31:56 +08:00
2016-09-30 00:05:49 +08:00
$('.lightboxContent').hide()
$('#' + which).show()
2016-09-22 18:31:56 +08:00
2016-09-30 00:05:49 +08:00
self.lightbox = which
2016-09-22 18:31:56 +08:00
2016-09-30 00:05:49 +08:00
$('#lightbox_overlay').show()
2016-09-22 18:31:56 +08:00
2016-09-30 00:05:49 +08:00
var heightOfContent = '-' + ($('#lightbox_main').height() / 2) + 'px'
2016-09-22 18:31:56 +08:00
// animate the content in from the bottom
$('#lightbox_main').animate({
'top': '50%',
'margin-top': heightOfContent
2016-09-30 00:05:49 +08:00
}, 200, 'easeOutCubic')
2016-09-22 18:31:56 +08:00
// fade the black overlay in
$('#lightbox_screen').animate({
'opacity': '0.42'
2016-09-30 00:05:49 +08:00
}, 200)
2016-09-22 18:31:56 +08:00
2016-09-30 00:05:49 +08:00
if (which === 'switchMetacodes') {
Create.isSwitchingSet = true
2016-09-22 18:31:56 +08:00
}
},
2016-09-22 14:25:49 +08:00
2016-11-07 15:25:08 -05:00
closeLightbox: function(event) {
const self = GlobalUI
2016-09-22 18:31:56 +08:00
2016-09-30 00:05:49 +08:00
if (event) event.preventDefault()
2016-09-22 18:31:56 +08:00
// animate the lightbox content offscreen
$('#lightbox_main').animate({
'top': '100%',
'margin-top': '0'
2016-09-30 00:05:49 +08:00
}, 200, 'easeInCubic')
2016-09-22 18:31:56 +08:00
// fade the black overlay out
$('#lightbox_screen').animate({
'opacity': '0.0'
2016-11-07 15:25:08 -05:00
}, 200, function() {
2016-09-30 00:05:49 +08:00
$('#lightbox_overlay').hide()
})
2016-09-22 18:31:56 +08:00
2016-09-30 00:05:49 +08:00
if (self.lightbox === 'forkmap') GlobalUI.CreateMap.reset('fork_map')
if (self.lightbox === 'newmap') GlobalUI.CreateMap.reset('new_map')
2016-09-22 18:31:56 +08:00
if (Create && Create.isSwitchingSet) {
2016-09-30 00:05:49 +08:00
Create.cancelMetacodeSetSwitch()
2016-09-22 18:31:56 +08:00
}
2016-09-30 00:05:49 +08:00
self.lightbox = null
2016-09-22 18:31:56 +08:00
},
notifyUser: function(message, opts = {}) {
const self = GlobalUI
if (self.notifying) {
self.notifyQueue.push({ message, opts })
return
} else {
self._notifyUser(message, opts)
}
},
// note: use the wrapper function notifyUser instead of this one
_notifyUser: function(message, opts = {}) {
const self = GlobalUI
react-router and rebuild app structure in react (#1091) * initial restructuring * stuff * lock version number * just keep using current mapinfobox * fix map upperRightUI layout * make mapsWidth work and add mobile * remove filterBoxOpen for now * redo the mobile menu in react * get account menu and invite lightbox working * fixed maps scrolling * make other routes work * fix signed out home page * fix accountbox toggling * add metacode edit routes * lots of fixes * fix map chat layout and tab bug * improve topic card readability and fix dragging bug * fixup mapchat stuff * fix up navigation to use react-router * jquery no longer handling access requests * handle case where user hasn't loaded yet * this shouldn't have been removed * add frame for topic view * rewrite map instructions * fix toast (and sign out bug) * fix apps pages and missing routes * made our request invite page look nice * filter box in react * forgot to add one proptype * remove extra comments * handle page title and mobile title updates * reenable google analytics * make filterbox use onclickoutside * reenable topic view in react * fix csrf auth token * fix little homepage styling issue * try putting preparevizdata in a timeout * installing render log to count * little fixes * fixup filters * make filter map function names more readable * eslint helps * renaming for clarity * use onclickoutside for account/sign in box * add some logging to see whether this is source of many renders * turns out chatview was heavily hogging memory * tiimeout not needed
2017-03-16 17:58:56 -04:00
const { leaveOpen = false, timeOut = 5000 } = opts
ReactApp.toast = message
ReactApp.render()
2016-09-30 00:05:49 +08:00
clearTimeout(self.notifyTimeOut)
2016-09-22 18:31:56 +08:00
if (!leaveOpen) {
2016-11-07 15:25:08 -05:00
self.notifyTimeOut = setTimeout(function() {
GlobalUI.clearNotify()
}, timeOut)
2016-09-22 14:25:49 +08:00
}
self.notifying = true
2016-09-22 18:31:56 +08:00
},
2016-11-07 15:25:08 -05:00
clearNotify: function() {
const self = GlobalUI
// if there are messages remaining, display them
if (self.notifyQueue.length > 0) {
const { message, opts } = self.notifyQueue.shift()
self._notifyUser(message, opts)
} else {
react-router and rebuild app structure in react (#1091) * initial restructuring * stuff * lock version number * just keep using current mapinfobox * fix map upperRightUI layout * make mapsWidth work and add mobile * remove filterBoxOpen for now * redo the mobile menu in react * get account menu and invite lightbox working * fixed maps scrolling * make other routes work * fix signed out home page * fix accountbox toggling * add metacode edit routes * lots of fixes * fix map chat layout and tab bug * improve topic card readability and fix dragging bug * fixup mapchat stuff * fix up navigation to use react-router * jquery no longer handling access requests * handle case where user hasn't loaded yet * this shouldn't have been removed * add frame for topic view * rewrite map instructions * fix toast (and sign out bug) * fix apps pages and missing routes * made our request invite page look nice * filter box in react * forgot to add one proptype * remove extra comments * handle page title and mobile title updates * reenable google analytics * make filterbox use onclickoutside * reenable topic view in react * fix csrf auth token * fix little homepage styling issue * try putting preparevizdata in a timeout * installing render log to count * little fixes * fixup filters * make filter map function names more readable * eslint helps * renaming for clarity * use onclickoutside for account/sign in box * add some logging to see whether this is source of many renders * turns out chatview was heavily hogging memory * tiimeout not needed
2017-03-16 17:58:56 -04:00
ReactApp.toast = null
ReactApp.render()
self.notifying = false
}
2016-09-22 18:31:56 +08:00
}
}
2016-09-22 14:25:49 +08:00
2017-09-22 18:38:38 -04:00
export { Notifications, ReactApp, Search, CreateMap, ImportDialog }
export default GlobalUI