2014-06-30 22:16:26 -04:00
|
|
|
gplusClientID = '800329290710-j9sivplv2gpcdgkrsis9rff3o417mlfa.apps.googleusercontent.com'
|
2014-07-18 20:06:20 -04:00
|
|
|
# TODO: Move to GPlusHandler
|
|
|
|
|
|
|
|
NotFoundView = require('views/NotFoundView')
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-17 20:42:41 -05:00
|
|
|
go = (path) -> -> @routeDirectly path, arguments
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
module.exports = class CocoRouter extends Backbone.Router
|
2014-07-23 10:02:45 -04:00
|
|
|
|
|
|
|
initialize: ->
|
|
|
|
# http://nerds.airbnb.com/how-to-add-google-analytics-page-tracking-to-57536
|
|
|
|
@bind 'route', @_trackPageView
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.subscribe 'auth:gplus-api-loaded', @onGPlusAPILoaded, @
|
2014-01-03 13:32:13 -05:00
|
|
|
Backbone.Mediator.subscribe 'router:navigate', @onNavigate, @
|
2014-10-15 16:43:26 -04:00
|
|
|
@initializeSocialMediaServices = _.once @initializeSocialMediaServices
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
routes:
|
2014-09-17 21:56:08 -04:00
|
|
|
'': go('HomeView') # This will go somewhere deprecated when FrontView is done.
|
|
|
|
'front': go('FrontView') # This will become '' when it is done.
|
2014-07-18 20:06:20 -04:00
|
|
|
|
2014-07-17 20:16:32 -04:00
|
|
|
'about': go('AboutView')
|
2014-08-13 22:17:26 -04:00
|
|
|
|
2014-07-29 11:28:13 -04:00
|
|
|
'account': go('account/MainAccountView')
|
2014-07-23 10:02:45 -04:00
|
|
|
'account/settings': go('account/AccountSettingsView')
|
|
|
|
'account/unsubscribe': go('account/UnsubscribeView')
|
2014-08-13 22:17:26 -04:00
|
|
|
'account/profile': go('user/JobProfileView') # legacy URL, sent in emails
|
2014-07-29 11:28:13 -04:00
|
|
|
#'account/payment'
|
2014-08-13 22:17:26 -04:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
'admin': go('admin/MainAdminView')
|
|
|
|
'admin/candidates': go('admin/CandidatesView')
|
|
|
|
'admin/clas': go('admin/CLAsView')
|
|
|
|
'admin/employers': go('admin/EmployersListView')
|
|
|
|
'admin/files': go('admin/FilesView')
|
2014-11-05 01:17:49 -05:00
|
|
|
'admin/growth': go('admin/GrowthView')
|
2014-07-23 10:02:45 -04:00
|
|
|
'admin/level-sessions': go('admin/LevelSessionsView')
|
|
|
|
'admin/users': go('admin/UsersView')
|
2014-08-30 23:27:58 -04:00
|
|
|
'admin/base': go('admin/BaseView')
|
2014-10-24 18:11:55 -04:00
|
|
|
'admin/user-code-problems': go('admin/UserCodeProblemsView')
|
2014-07-18 20:06:20 -04:00
|
|
|
|
|
|
|
'beta': go('HomeView')
|
|
|
|
|
2014-07-17 20:16:32 -04:00
|
|
|
'cla': go('CLAView')
|
|
|
|
'community': go('CommunityView')
|
2014-08-13 22:17:26 -04:00
|
|
|
|
2014-07-17 20:16:32 -04:00
|
|
|
'contribute': go('contribute/MainContributeView')
|
|
|
|
'contribute/adventurer': go('contribute/AdventurerView')
|
|
|
|
'contribute/ambassador': go('contribute/AmbassadorView')
|
|
|
|
'contribute/archmage': go('contribute/ArchmageView')
|
|
|
|
'contribute/artisan': go('contribute/ArtisanView')
|
|
|
|
'contribute/diplomat': go('contribute/DiplomatView')
|
|
|
|
'contribute/scribe': go('contribute/ScribeView')
|
2014-07-18 20:06:20 -04:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
'db/*path': 'routeToServer'
|
2014-07-18 20:06:20 -04:00
|
|
|
'demo(/*subpath)': go('DemoView')
|
2014-08-29 01:32:55 -04:00
|
|
|
'docs/components': go('docs/ComponentsDocumentationView')
|
|
|
|
'docs/systems': go('docs/SystemsDocumentationView')
|
2014-08-13 22:17:26 -04:00
|
|
|
|
2014-08-26 20:34:00 -04:00
|
|
|
'editor': go('CommunityView')
|
2014-07-23 10:02:45 -04:00
|
|
|
|
|
|
|
'editor/achievement': go('editor/achievement/AchievementSearchView')
|
2014-08-03 17:58:51 -04:00
|
|
|
'editor/achievement/:articleID': go('editor/achievement/AchievementEditView')
|
2014-07-23 10:02:45 -04:00
|
|
|
'editor/article': go('editor/article/ArticleSearchView')
|
|
|
|
'editor/article/preview': go('editor/article/ArticlePreviewView')
|
|
|
|
'editor/article/:articleID': go('editor/article/ArticleEditView')
|
|
|
|
'editor/level': go('editor/level/LevelSearchView')
|
|
|
|
'editor/level/:levelID': go('editor/level/LevelEditView')
|
|
|
|
'editor/thang': go('editor/thang/ThangTypeSearchView')
|
|
|
|
'editor/thang/:thangID': go('editor/thang/ThangTypeEditView')
|
2014-08-13 22:17:26 -04:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
'employers': go('EmployersView')
|
|
|
|
|
|
|
|
'file/*path': 'routeToServer'
|
|
|
|
|
2014-08-15 10:20:45 -04:00
|
|
|
'github/*path': 'routeToServer'
|
|
|
|
|
2014-10-27 20:11:48 -04:00
|
|
|
'i18n': go('i18n/I18NHomeView')
|
|
|
|
'i18n/thang/:handle': go('i18n/I18NEditThangTypeView')
|
|
|
|
'i18n/component/:handle': go('i18n/I18NEditComponentView')
|
|
|
|
'i18n/level/:handle': go('i18n/I18NEditLevelView')
|
|
|
|
'i18n/achievement/:handle': go('i18n/I18NEditAchievementView')
|
|
|
|
|
2014-07-18 20:06:20 -04:00
|
|
|
'legal': go('LegalView')
|
2014-08-13 22:17:26 -04:00
|
|
|
|
2014-07-18 20:06:20 -04:00
|
|
|
'multiplayer': go('MultiplayerView')
|
|
|
|
|
2014-09-25 18:32:33 -04:00
|
|
|
'play-old': go('play/MainPlayView') # This used to be 'play'.
|
|
|
|
'play': go('play/WorldMapView')
|
|
|
|
'play-hero': go('play/WorldMapView') # Legacy URL for /play; leave up until start of 2015, I guess.
|
2014-07-23 10:02:45 -04:00
|
|
|
'play/ladder/:levelID': go('play/ladder/LadderView')
|
|
|
|
'play/ladder': go('play/ladder/MainLadderView')
|
|
|
|
'play/level/:levelID': go('play/level/PlayLevelView')
|
|
|
|
'play/spectate/:levelID': go('play/SpectateView')
|
2014-10-29 12:47:00 -04:00
|
|
|
'play/:map': go('play/WorldMapView')
|
2014-07-23 10:02:45 -04:00
|
|
|
|
2014-07-18 20:06:20 -04:00
|
|
|
'preview': go('HomeView')
|
|
|
|
|
|
|
|
'teachers': go('TeachersView')
|
2014-08-13 22:17:26 -04:00
|
|
|
|
2014-07-18 20:06:20 -04:00
|
|
|
'test(/*subpath)': go('TestView')
|
|
|
|
|
2014-07-21 13:49:16 -04:00
|
|
|
'user/:slugOrID': go('user/MainUserView')
|
|
|
|
'user/:slugOrID/profile': go('user/JobProfileView')
|
2014-07-06 14:45:27 -04:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
'*name': 'showNotFoundView'
|
2014-07-13 16:34:32 -04:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
routeToServer: (e) ->
|
|
|
|
window.location.href = window.location.href
|
2014-07-10 14:50:16 -04:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
routeDirectly: (path, args) ->
|
|
|
|
path = "views/#{path}"
|
|
|
|
ViewClass = @tryToLoadModule path
|
|
|
|
return @openView @notFoundView() if not ViewClass
|
|
|
|
view = new ViewClass({}, args...) # options, then any path fragment args
|
|
|
|
view.render()
|
|
|
|
@openView(view)
|
2014-07-10 14:50:16 -04:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
tryToLoadModule: (path) ->
|
|
|
|
try
|
|
|
|
return require(path)
|
|
|
|
catch error
|
|
|
|
if error.toString().search('Cannot find module "' + path + '" from') is -1
|
|
|
|
throw error
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
showNotFoundView: ->
|
|
|
|
@openView @notFoundView()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
notFoundView: ->
|
|
|
|
view = new NotFoundView()
|
2014-01-03 13:32:13 -05:00
|
|
|
view.render()
|
|
|
|
|
|
|
|
openView: (view) ->
|
|
|
|
@closeCurrentView()
|
|
|
|
$('#page-container').empty().append view.el
|
|
|
|
window.currentView = view
|
|
|
|
@activateTab()
|
2014-10-15 16:43:26 -04:00
|
|
|
@renderLoginButtons() if view.usesSocialMedia
|
2014-01-03 13:32:13 -05:00
|
|
|
view.afterInsert()
|
2014-07-23 10:02:45 -04:00
|
|
|
view.didReappear()
|
|
|
|
|
|
|
|
closeCurrentView: ->
|
|
|
|
if window.currentView?.reloadOnClose
|
|
|
|
return document.location.reload()
|
|
|
|
window.currentModal?.hide?()
|
|
|
|
return unless window.currentView?
|
|
|
|
window.currentView.destroy()
|
2014-10-06 21:09:27 -04:00
|
|
|
$('.popover').popover 'hide'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onGPlusAPILoaded: =>
|
|
|
|
@renderLoginButtons()
|
2014-11-02 21:36:43 -05:00
|
|
|
|
2014-10-15 16:43:26 -04:00
|
|
|
initializeSocialMediaServices: ->
|
|
|
|
return if application.testing or application.demoing
|
|
|
|
services = [
|
|
|
|
'./lib/services/facebook'
|
|
|
|
'./lib/services/google'
|
|
|
|
'./lib/services/twitter'
|
|
|
|
]
|
|
|
|
|
|
|
|
for service in services
|
|
|
|
service = require service
|
|
|
|
service()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-11-02 21:36:43 -05:00
|
|
|
renderLoginButtons: =>
|
2014-10-15 16:43:26 -04:00
|
|
|
@initializeSocialMediaServices()
|
2014-01-07 02:45:33 -05:00
|
|
|
$('.share-buttons, .partner-badges').addClass('fade-in').delay(10000).removeClass('fade-in', 5000)
|
2014-01-09 13:48:51 -05:00
|
|
|
setTimeout(FB.XFBML.parse, 10) if FB?.XFBML?.parse # Handles FB login and Like
|
|
|
|
twttr?.widgets?.load?()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
return unless gapi?.plusone?
|
2014-01-09 13:48:51 -05:00
|
|
|
gapi.plusone.go?() # Handles +1 button
|
2014-01-03 13:32:13 -05:00
|
|
|
for gplusButton in $('.gplus-login-button')
|
|
|
|
params = {
|
2014-06-30 22:16:26 -04:00
|
|
|
callback: 'signinCallback',
|
|
|
|
clientid: gplusClientID,
|
|
|
|
cookiepolicy: 'single_host_origin',
|
|
|
|
scope: 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email',
|
|
|
|
height: 'short',
|
2014-01-03 13:32:13 -05:00
|
|
|
}
|
2014-01-09 13:48:51 -05:00
|
|
|
if gapi.signin?.render
|
2014-01-03 13:32:13 -05:00
|
|
|
gapi.signin.render(gplusButton, params)
|
|
|
|
else
|
2014-06-30 22:16:26 -04:00
|
|
|
console.warn 'Didn\'t have gapi.signin to render G+ login button. (DoNotTrackMe extension?)'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
activateTab: ->
|
|
|
|
base = _.string.words(document.location.pathname[1..], '/')[0]
|
|
|
|
$("ul.nav li.#{base}").addClass('active')
|
|
|
|
|
|
|
|
_trackPageView: ->
|
|
|
|
window.tracker?.trackPageView()
|
|
|
|
|
|
|
|
onNavigate: (e) ->
|
|
|
|
manualView = e.view or e.viewClass
|
2014-11-07 11:54:22 -05:00
|
|
|
if (e.route is document.location.pathname) and not manualView
|
|
|
|
return document.location.reload()
|
2014-03-17 00:33:46 -04:00
|
|
|
@navigate e.route, {trigger: not manualView}
|
2014-01-03 13:32:13 -05:00
|
|
|
return unless manualView
|
|
|
|
if e.viewClass
|
|
|
|
args = e.viewArgs or []
|
|
|
|
view = new e.viewClass(args...)
|
|
|
|
view.render()
|
|
|
|
@openView view
|
|
|
|
else
|
|
|
|
@openView e.view
|
2014-10-01 13:58:19 -04:00
|
|
|
|
|
|
|
navigate: (fragment, options) ->
|
|
|
|
super fragment, options
|
|
|
|
Backbone.Mediator.publish 'router:navigated', route: fragment
|