forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (74 loc) · 2.4 KB
/
index.js
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
/*
* Copyright (C) 2013 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import I18n from 'i18n!catalog'
import $ from 'jquery'
import ready from '@instructure/ready'
import 'jqueryui/dialog'
const startupHost = window.location.host
function fetchCourses() {
// Defense-in-depth... it's hard to see how this could happen given
// the places in which this function is given control, but let's just
// make absolutely sure that we never load off-application HTML into
// the #catalog_content div.
if (window.location.host !== startupHost) return
$('#catalog_content').load(window.location.href)
}
function handleNav(e) {
let url
if (!window.history.pushState) {
return
}
if (this.href) {
url = this.href
} else {
url = `${this.action}?${$(this).serialize()}`
}
window.history.pushState(null, '', url)
fetchCourses()
e.preventDefault()
}
function handleCourseClick(e) {
const link = $(e.target).closest('.course_enrollment_link')[0]
if (!link) {
const $course = $(e.target).closest('.course_summary')
if ($course.length && !$(e.target).is('a')) {
$course.find('h3 a')[0].click()
}
return
}
const $dialog = $('<div>')
const $iframe = $('<iframe>', {
style: 'position:absolute;top:0;left:0;width:100%;height:100%;border:none',
src: `${link.href}?embedded=1&no_headers=1`,
title: I18n.t('Course Catalog')
})
$dialog.append($iframe)
$dialog.dialog({
width: 550,
height: 500,
resizable: false
})
e.preventDefault()
}
ready(() => {
$('#course_filter').submit(handleNav)
$('#catalog_content').on('click', '#previous-link', handleNav)
$('#catalog_content').on('click', '#next-link', handleNav)
$('#catalog_content').on('click', '#course_summaries', handleCourseClick)
window.addEventListener('popstate', fetchCourses)
})