-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs_controller.coffee
140 lines (120 loc) · 5.01 KB
/
docs_controller.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
class @DocsController
constructor: (params={}) ->
# Containing Element.
@container = params.container || $("#docsContainer")
# Loading GUI
@loadingPanel = params.loadingPanel || @container.find("#loadingPanel")
@spinnerRadius = params.spinnerRadius || 10
# Content Container
@docItems = params.docItems || @container.find("#docItems")
@selectedItemDetails = params.selectedItemDetails || @container.find("#selectedItemDetails")
@externalFrameACF = params.externalFrameACF || @container.find('#externalFrameACF')
@externalFrameRailo = params.externalFrameRailo || @container.find('#externalFrameRailo')
@sideBarContentArea = params.sideBarContentArea || @container.find('#sideBarMiddle')
@searchInput = params.searchInput || @container.find('#searchInput')
# Configurable CSS Classes
@loadingClass = params.loadingClass || "loading"
@errorClass = params.errorClass || "error"
# Errors
@errorPanel = params.errorFlash || @container.find("#errorPanel")
@errorMessage = params.errorMessage || @container.find("#message")
@errorMessageOnXML = params.errorMessageOnXML || "Sorry! We cannot load the configuration XML."
#Non-configurable attributes
@acfConfigLoaded = false
@railoConfigLoaded = false
@acfConfigXML = ""
@acfBasePath = "/data/cfml/docs/"
@railoBasePath = "http://assets.coldfusiondocs.com/html/railo/"
@fixHeight()
@showSpinner()
@searchInput.bind 'keyup change', ( =>
@filterResults() if @acfConfigLoaded && @searchInput.val().length > 2
false
)
$(window).resize( =>
@fixHeight()
)
fixHeight: ->
@sideBarContentArea.css('height', $(document).height() - 200)
showSpinner: ->
# Configure and position spinner.
@spinner = new Spinner(
lines: 12 # The number of lines to draw
length: 7 # The length of each line
width: 3 # The line thickness
radius: @spinnerRadius # The radius of the inner circle
color: '#000' # #rgb or #rrggbb
speed: 1.1 # Rounds per second
trail: 60 # Afterglow percentage
shadow: true # Whether to render a shadow
).spin()
spinnerElement = $(@spinner.el)
spinnerElement.attr("id","spinner")
spinnerElement.css("margin-top", "#{-@spinnerRadius*4}px")
spinnerElement.css("margin-left", "#{-@spinnerRadius}px")
spinnerElement.css("position", "absolute")
@loadingPanel.append(@spinner.el)
removeSpinner: ->
@container.removeClass(@loadingClass)
$(@spinner.el).remove()
filterResults: ->
@parseXML(@searchInput.val())
@searchImput.focus()
false
# Loads XML data for a supplied URL.
loadConfig: (url, docset = 'acf') ->
@container.addClass(@loadingClass)
@url = url
$.ajax({
url: url
dataType: "xml"
timeout: 3000
cache: false
complete: (jqXHR, textStatus) =>
@removeSpinner()
error: (jqXHR, textStatus, errorThrown) =>
@errorMessage.html(@errorMessageOnXML)
@container.addClass(@errorClass)
success: (data) =>
@acfConfigLoaded = true
@acfConfigXML = data
@parseXML()
})
false
parseXML: (criteria = "") ->
@config_xml = $(@acfConfigXML)
@topics = @config_xml.find("topic")
@docItems.find('li').remove()
@docItems.find("a").unbind('click')
index = 0
for topic in @topics
current = $(topic)
topicLabel = current.attr("label")
topicUrl = current.attr("href")
if criteria == "" || topicLabel.indexOf(criteria) != -1
listItem = $('<li/>')
listItem.attr("data-index", index)
listItem.attr("data-name", topicLabel)
listItem.attr("data-url", topicUrl)
href = $('<a/>')
href.attr('class', 'docItem').attr('href','#')
href.append(topicLabel)
listItem.append(href)
@docItems.append(listItem)
index += 1
@docItems.find("a").click( (event) =>
@handleItemClick($(event.target).parent())
)
#force select first item
@handleItemClick(@docItems.find('li:first')) if criteria == ""
handleItemClick: (obj = null) ->
@showSpinner()
@docItems.find('li').removeClass("selected")
clickedListItem = $(obj)
objectUrl = clickedListItem.attr("data-url").split("/")
objectLabel = clickedListItem.attr("data-name")
fileName = objectUrl[objectUrl.length - 1]
@externalFrameACF.attr("src", @acfBasePath + fileName)
@externalFrameRailo.attr("src", @railoBasePath + 'tag_' + objectLabel + '.html')
clickedListItem.addClass("selected")
@removeSpinner()