glossary MDL-23423 converted glossary autolinker to use an overlay rather than a popup

This commit is contained in:
Andrew Davis
2010-07-27 01:32:51 +00:00
parent 0a9a33b55c
commit 7ee9d9c881
3 changed files with 74 additions and 8 deletions
+15
View File
@@ -8,6 +8,11 @@ $courseid = optional_param('courseid', 0, PARAM_INT);
$eid = optional_param('eid', 0, PARAM_INT); // glossary entry id
$displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR);
$popup = optional_param('popup',0, PARAM_INT);
$ajax = optional_param('ajax',0, PARAM_INT);
if ($ajax && !defined('AJAX_SCRIPT')) {
define('AJAX_SCRIPT', true);
}
$url = new moodle_url('/mod/glossary/showentry.php');
$url->param('concept', $concept);
@@ -42,6 +47,8 @@ if ($eid) {
if ($popup) {
$PAGE->set_pagelayout('popup');
} else if (!$ajax) {
$PAGE->set_pagelayout('course');
}
if ($entries) {
@@ -70,6 +77,14 @@ if ($entries) {
}
}
if ($ajax) {
$result = new stdClass;
$result->success = true;
$result->entries = $entries;
echo json_encode($result);
die();
}
if (!empty($courseid)) {
$strglossaries = get_string('modulenameplural', 'glossary');
$strsearch = get_string('search');
+3 -1
View File
@@ -26,4 +26,6 @@
#page-mod-glossary-view table.glossarycategoryheader {margin-bottom:0em;}
#page-mod-glossary-view table.glossarycategoryheader th {padding:0px;}
#page-mod-glossary-showentry #page-content {min-width:600px;}
#page-mod-glossary-showentry #page-content {min-width:600px;}
#glossaryoverlayprogress {position:fixed;top:50%;width:100%;text-align:center;}
+56 -7
View File
@@ -22,16 +22,65 @@ YUI.add('moodle-mod_glossary-autolinker', function(Y) {
AUTOLINKER.superclass.constructor.apply(this, arguments);
}
Y.extend(AUTOLINKER, Y.Base, {
overlay : null,
initializer : function(config) {
var popupname = this.get(POPUPNAME),
popupoptions = this.get(POPUPOPTIONS);
popupoptions = this.get(POPUPOPTIONS),
self = this;
Y.delegate('click', function(e){
openpopup(e, {
url : this.getAttribute('href')+'&popup=1',
name : popupname,
options : build_windowoptionsstring(popupoptions)
})
e.preventDefault();
//display a progress indicator
var title = '';
var content = Y.Node.create('<div id="glossaryoverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" /></div>');
var o = new Y.Overlay({
headerContent : title,
bodyContent : content
});
self.overlay = o;
o.render(Y.one(document.body));
//fetch the glossary item
var fullurl = this.getAttribute('href')+'&ajax=1';
var cfg = {
method: 'get',
context : self,
on: {
success: function(id, o, node) {
this.display_callback(o.responseText);
},
failure: function(id, o, node) {
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');
},
display_callback : function(content) {
try {
var data = Y.JSON.parse(content);
if (data.success){
this.overlay.hide(); //hide progress indicator
for (key in data.entries) {
new M.core.alert({title:data.entries[key].concept, message:data.entries[key].definition, lightbox:false});
}
return true;
} else if (data.error) {
alert(data.error);
}
}catch(ex) {
alert(ex.message+" "+content);
}
return false;
}
}, {
NAME : AUTOLINKERNAME,
@@ -82,4 +131,4 @@ YUI.add('moodle-mod_glossary-autolinker', function(Y) {
return new AUTOLINKER(config);
}
}, '@VERSION@', {requires:['base','node','event-delegate']});
}, '@VERSION@', {requires:['base','node','event-delegate','overlay','moodle-enrol-notification']});