mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
moodle-filter_glossary-autolinker.js
146 lines (136 loc) · 4.65 KB
/
moodle-filter_glossary-autolinker.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
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
141
142
143
144
145
146
YUI.add('moodle-filter_glossary-autolinker', function (Y, NAME) {
var AUTOLINKERNAME = 'Glossary filter autolinker',
WIDTH = 'width',
HEIGHT = 'height',
MENUBAR = 'menubar',
LOCATION = 'location',
SCROLLBARS = 'scrollbars',
RESIZEABLE = 'resizable',
TOOLBAR = 'toolbar',
STATUS = 'status',
DIRECTORIES = 'directories',
FULLSCREEN = 'fullscreen',
DEPENDENT = 'dependent',
AUTOLINKER;
AUTOLINKER = function() {
AUTOLINKER.superclass.constructor.apply(this, arguments);
};
Y.extend(AUTOLINKER, Y.Base, {
overlay : null,
initializer : function() {
var self = this;
Y.delegate('click', function(e){
e.preventDefault();
//display a progress indicator
var title = '',
content = Y.Node.create('<div id="glossaryfilteroverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" /></div>'),
o = new Y.Overlay({
headerContent : title,
bodyContent : content
}),
fullurl,
cfg;
self.overlay = o;
o.render(Y.one(document.body));
//Switch over to the ajax url and fetch the glossary item
fullurl = this.getAttribute('href').replace('showentry.php','showentry_ajax.php');
cfg = {
method: 'get',
context : self,
on: {
success: function(id, o) {
this.display_callback(o.responseText);
},
failure: function(id, o) {
var debuginfo = o.statusText;
if (M.cfg.developerdebug) {
o.statusText += ' (' + fullurl + ')';
}
this.display_callback('bodyContent',debuginfo);
}
}
};
Y.io(fullurl, cfg);
}, Y.one(document.body), 'a.glossary.autolink.concept');
},
display_callback : function(content) {
var data,
key,
alertpanel;
try {
data = Y.JSON.parse(content);
if (data.success){
this.overlay.hide(); //hide progress indicator
for (key in data.entries) {
definition = data.entries[key].definition + data.entries[key].attachments;
alertpanel = new M.core.alert({title:data.entries[key].concept,
message:definition, lightbox:false, yesLabel: M.util.get_string('ok', 'moodle')});
alertpanel.show();
Y.Node.one('#id_yuialertconfirm-' + alertpanel.get('COUNT')).focus();
}
return true;
} else if (data.error) {
new M.core.ajaxException(data);
}
} catch(e) {
new M.core.exception(e);
}
return false;
}
}, {
NAME : AUTOLINKERNAME,
ATTRS : {
url : {
validator : Y.Lang.isString,
value : M.cfg.wwwroot+'/mod/glossary/showentry.php'
},
name : {
validator : Y.Lang.isString,
value : 'glossaryconcept'
},
options : {
getter : function() {
return {
width : this.get(WIDTH),
height : this.get(HEIGHT),
menubar : this.get(MENUBAR),
location : this.get(LOCATION),
scrollbars : this.get(SCROLLBARS),
resizable : this.get(RESIZEABLE),
toolbar : this.get(TOOLBAR),
status : this.get(STATUS),
directories : this.get(DIRECTORIES),
fullscreen : this.get(FULLSCREEN),
dependent : this.get(DEPENDENT)
};
},
readOnly : true
},
width : {value : 600},
height : {value : 450},
menubar : {value : false},
location : {value : false},
scrollbars : {value : true},
resizable : {value : true},
toolbar : {value : true},
status : {value : true},
directories : {value : false},
fullscreen : {value : false},
dependent : {value : true}
}
});
M.filter_glossary = M.filter_glossary || {};
M.filter_glossary.init_filter_autolinking = function(config) {
return new AUTOLINKER(config);
};
}, '@VERSION@', {
"requires": [
"base",
"node",
"io-base",
"json-parse",
"event-delegate",
"overlay",
"moodle-core-notification-alert"
]
});