Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"contentloader.min.js","sources":["../src/contentloader.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n\n/**\n * @author     Andreas Grabs <moodle@grabs-edv.de>\n * @copyright  2024 Andreas Grabs\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'core/fragment', 'core/templates', 'core/notification'], function(\n    $, fragment, templates, notification) {\n\n    /**\n     * Class constructor\n     * @param {string} contentcontainerselector\n     * @param {string} fragmentcall\n     * @param {object} serviceparams\n     * @param {int} contextid\n     */\n    var ContentLoader = function(contentcontainerselector, fragmentcall, serviceparams, contextid) {\n        this.contentcontainerselector = contentcontainerselector;\n        this.fragmentcall = fragmentcall;\n        if (serviceparams === undefined) {\n            this.serviceparams = { };\n        } else {\n            this.serviceparams = serviceparams;\n        }\n        this.contextid = contextid;\n        this.isshown = false;\n    };\n\n    /**\n     * Load content by the fragment api\n     * @param {string} adjacentPosition Can be on of the following values: afterbegin, afterend, beforebegin, beforeend.\n     * @returns {Promise}\n     */\n    ContentLoader.prototype.loadContent = function(adjacentPosition) {\n        var _this = this; // We have to save this because the context in the promise is another.\n        // Show a spinner while loading the table if not disabled.\n        if (_this.disablespinner === undefined) {\n            $(_this.contentcontainerselector).html('');\n            var spinnerhtml = '<div class=\"text-center\" id=\"myspinner\"><i class=\"fa fa-spinner fa-2x fa-spin\"></i></div>';\n            $(_this.contentcontainerselector).prepend(spinnerhtml);\n        }\n        var fragmentpromise = fragment.loadFragment('mod_unilabel', _this.fragmentcall, _this.contextid, _this.serviceparams);\n        return fragmentpromise.then(function(html, js) {\n            var container = document.querySelector(_this.contentcontainerselector);\n            container.insertAdjacentHTML(adjacentPosition, html);\n            if (js) {\n                templates.runTemplateJS(js);\n            }\n            _this.isshown = true;\n            $('#myspinner').remove();\n            return true;\n        }).fail(notification.exception);\n    };\n\n    /**\n     * Load html content on the given event.\n     * @param {string} triggerselector\n     * @param {string} triggerevent\n     * @param {string} adjacentPosition Can be on of the following values: afterbegin, afterend, beforebegin, beforeend.\n     */\n    ContentLoader.prototype.autoload = function(triggerselector, triggerevent, adjacentPosition) {\n        var _this = this;\n        $(triggerselector).on(triggerevent, function() {\n            if (_this.isshown == false) {\n                _this.loadContent(adjacentPosition);\n                _this.isshown = true;\n            }\n        });\n    };\n\n    return ContentLoader;\n\n});\n"],"names":["define","$","fragment","templates","notification","ContentLoader","contentcontainerselector","fragmentcall","serviceparams","contextid","undefined","isshown","prototype","loadContent","adjacentPosition","_this","this","disablespinner","html","prepend","loadFragment","then","js","document","querySelector","insertAdjacentHTML","runTemplateJS","remove","fail","exception","autoload","triggerselector","triggerevent","on"],"mappings":";;;;;AAsBAA,oCAAO,CAAC,SAAU,gBAAiB,iBAAkB,sBAAsB,SACvEC,EAAGC,SAAUC,UAAWC,kBASpBC,cAAgB,SAASC,yBAA0BC,aAAcC,cAAeC,gBAC3EH,yBAA2BA,8BAC3BC,aAAeA,kBAEXC,mBADaE,IAAlBF,cACqB,GAEAA,mBAEpBC,UAAYA,eACZE,SAAU,UAQnBN,cAAcO,UAAUC,YAAc,SAASC,sBACvCC,MAAQC,aAEiBN,IAAzBK,MAAME,eAA8B,CACpChB,EAAEc,MAAMT,0BAA0BY,KAAK,IAEvCjB,EAAEc,MAAMT,0BAA0Ba,QADhB,oGAGAjB,SAASkB,aAAa,eAAgBL,MAAMR,aAAcQ,MAAMN,UAAWM,MAAMP,eAChFa,MAAK,SAASH,KAAMI,WACvBC,SAASC,cAAcT,MAAMT,0BACnCmB,mBAAmBX,iBAAkBI,MAC3CI,IACAnB,UAAUuB,cAAcJ,IAE5BP,MAAMJ,SAAU,EAChBV,EAAE,cAAc0B,UACT,KACRC,KAAKxB,aAAayB,YASzBxB,cAAcO,UAAUkB,SAAW,SAASC,gBAAiBC,aAAclB,sBACnEC,MAAQC,KACZf,EAAE8B,iBAAiBE,GAAGD,cAAc,WACX,GAAjBjB,MAAMJ,UACNI,MAAMF,YAAYC,kBAClBC,MAAMJ,SAAU,OAKrBN"}