-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathatc.coffee
74 lines (64 loc) · 2.4 KB
/
atc.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# # Application Root
# This is the start of the application. Steps:
#
# 1. Load dependencies (JS/CSS/JSON)
# 2. Register client-side routes
#
# **TODO:** Load any HTML/JSON sent from the server that is sprinkled in the HTML file.
#
# For example, if the user goes to a piece of content we already send
# the content inside a `div` tag.
# The same can be done with metadata/roles (as a JSON object sent in the HTML)
define [
'jquery'
'underscore'
'backbone'
'marionette'
'aloha'
'atc/auth'
'atc/controller'
'css!atc'
], (jQuery, _, Backbone, Marionette, Aloha, Auth, Controller) ->
# # Application Code
# ## Authenticated User
# Find out whether the user is authenticated
#
# Auth.fetch()
# Begin listening to route changes
# and load the initial views based on the URL.
Controller.start()
# # Various HACKS
# These cross over many modules and do not have a better home than here.
# ## Global Variables like jQuery
# **HACK:** discourage people from using the global jQuery
# and instead use the `requirejs` version.
# This helps ensure plugins that extend jQuery (like bootstrap)
# are properly listed as dependencies in requirejs' `define`
@jQuery = @$ = ->
console.warn 'You should add "jquery" to your dependencies in define() instead of using the global jQuery!'
jQuery.apply @, arguments
jQuery.extend(@jQuery, jQuery)
# jQueryUI in Aloha relies on a very old function.
# Used for re-ordering Authors and copyright holders
# in the Select2 widget
jQuery.curCSS = jQuery.css
# # Hash tags in links
# Code should use the `Controller` module to change the page
# instead of relying on the URL
#
# For now, I trust that the programmer knows what they are doing and:
#
# 1. warn them
# 2. trigger the route change
# 3. hope a router matches that URL
jQuery(document).on 'click', 'a:not([data-bypass])', (evt) ->
evt.preventDefault()
href = $(@).attr('href')
console.warn "User clicked on an internal link. Use the atc/controller module instead of the URL #{href}"
# `Backbone.history.navigate` is sufficient for all Routers and will
# trigger the correct events. The Router's internal `navigate` method
# calls this anyways.
#
# Added the `javascript:` test because Select2 generates anchor links
# but we should not change the URL.
Backbone.history.navigate(href, true) if href? and not /^javascript:/.test(href)