<commit_before>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, {
        overlay : null,
        initializer : function(config) {
            var popupname = this.get(POPUPNAME),
                popupoptions = this.get(POPUPOPTIONS),
                self = this;
            Y.delegate('click', function(e){

                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));

                //Switch over to the ajax url and fetch the glossary item
                var fullurl = this.getAttribute('href').replace('showentry.php','showentry_ajax.php');
                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,
        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),<commit_msg>glossary MDL-23423 improved ajax error display<commit_after>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, {
        overlay : null,
        initializer : function(config) {
            var popupname = this.get(POPUPNAME),
                popupoptions = this.get(POPUPOPTIONS),
                self = this;
            Y.delegate('click', function(e){

                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));

                //Switch over to the ajax url and fetch the glossary item
                var fullurl = this.getAttribute('href').replace('showentry.php','showentry_ajax.php');
                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) {
                    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(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),
{'fraction_non_alphanumeric': 0.10920719198745023, 'fraction_numerical': 0.0006033546518643658, 'mean_word_length': 1.1427094105480868, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4428579', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2061, 'n_words': 391}