mod-glossary MDL-23026 Changed method glossary auto linking was generating popup events in JS

Now rather than adding a click event for EVERY possible glossary entry it adds a single event that delegates
clicks against anchor elements with the classes glossary and autolink.
This commit is contained in:
Sam Hemelryk 2010-07-20 08:44:09 +00:00
parent 4df5322391
commit 673cc1e888
2 changed files with 89 additions and 7 deletions

View File

@ -3,13 +3,13 @@
/**
*
* @global moodle_database $DB
* @global core_renderer $OUTPUT
* @global moodle_page $PAGE
* @param int $courseid
* @param string $text
* @return string
*/
function glossary_filter($courseid, $text) {
global $CFG, $DB, $OUTPUT, $GLOSSARY_EXCLUDECONCEPTS;
global $CFG, $DB, $GLOSSARY_EXCLUDECONCEPTS, $PAGE;
// Trivial-cache - keyed on $cachedcourseid
static $nothingtodo;
@ -121,7 +121,7 @@ function glossary_filter($courseid, $text) {
foreach ($concepts as $concept) {
$glossaryname = $glossaries[$concept->glossaryid];
$glossaryname = str_replace(':', '-', $glossaries[$concept->glossaryid]);
if ($concept->category) { // Link to a category
$title = strip_tags($glossaryname.': '.$strcategory.' '.$concept->concept);
$href_tag_begin = '<a class="glossary autolink glossaryid'.$concept->glossaryid.'" title="'.$title.'" '.
@ -135,21 +135,18 @@ function glossary_filter($courseid, $text) {
$encodedconcept = urlencode($concept->concept);
$title = str_replace('"', "'", strip_tags($glossaryname.': '.$concept->concept));
}
$randid = html_writer::random_id('glossary');
$link = new moodle_url('/mod/glossary/showentry.php', array('courseid'=>$courseid, 'concept'=>$encodedconcept));
$href_tag_begin = html_writer::start_tag('a', array(
'href'=>$link,
'id'=>$randid,
'title'=>$title,
'class'=>'glossary autolink glossaryid'.$concept->glossaryid));
//attach the onclick events
$OUTPUT->add_action_handler(new popup_action('click', new moodle_url($link, array('popup'=>'1')), 'entry', array('height'=>600,'width'=>450)), $randid);
}
$conceptlist[] = new filterobject($concept->concept, $href_tag_begin, '</a>',
$concept->casesensitive, $concept->fullmatch);
}
$conceptlist = filter_remove_duplicates($conceptlist);
$PAGE->requires->yui_module('moodle-mod_glossary-autolinker', 'M.mod_glossary.init_filter_autolinking', array(array('courseid'=>$courseid)));
}
if(!empty($GLOSSARY_EXCLUDECONCEPTS)) {

View File

@ -0,0 +1,85 @@
YUI.add('moodle-mod_glossary-autolinker', function(Y) {
var AUTOLINKERNAME = 'Glossary autolinker',
URL = 'url',
POPUPNAME = 'name',
POPUPOPTIONS = 'options',
TITLE = 'title',
COURSEID = 'courseid',
WIDTH = 'width',
HEIGHT = 'height',
MENUBAR = 'menubar',
LOCATION = 'location',
SCROLLBARS = 'scrollbars',
RESIZEABLE = 'resizable',
TOOLBAR = 'toolbar',
STATUS = 'status',
DIRECTORIES = 'directories',
FULLSCREEN = 'fullscreen',
DEPENDENT = 'dependent';
var AUTOLINKER = function() {
AUTOLINKER.superclass.constructor.apply(this, arguments);
}
Y.extend(AUTOLINKER, Y.Base, {
initializer : function(config) {
var popupname = this.get(POPUPNAME),
popupoptions = this.get(POPUPOPTIONS);
Y.delegate('click', function(e){
openpopup(e, {
url : this.getAttribute('href')+'&popup=1',
name : popupname,
options : build_querystring(popupoptions)
})
}, Y.one(document.body), 'a.glossary.autolink');
}
}, {
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(val) {
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 : 450},
height : {value : 600},
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},
courseid : {value : 1}
}
});
M.mod_glossary = M.mod_glossary || {};
M.mod_glossary.init_filter_autolinking = function(config) {
return new AUTOLINKER(config);
}
}, '@VERSION@', {requires:['base','node','event-delegate']});