Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"display.min.js","sources":["../src/display.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 * This module adds ajax display functions to the template library page.\n *\n * @module     tool_templatelibrary/display\n * @copyright  2015 Damyon Wiese <damyon@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates', 'core/config', 'core/str'],\n       function($, ajax, log, notification, templates, config, str) {\n\n    /**\n     * Search through a template for a template docs comment.\n     *\n     * @param {String} templateSource The raw template\n     * @param {String} templateName The name of the template used to search for docs tag\n     * @return {String|boolean} the correct comment or false\n     */\n    var findDocsSection = function(templateSource, templateName) {\n\n        if (!templateSource) {\n            return false;\n        }\n        // Find the comment section marked with @template component/template.\n        var marker = \"@template \" + templateName,\n            i = 0,\n            sections = [];\n\n        sections = templateSource.match(/{{!([\\s\\S]*?)}}/g);\n\n        // If no sections match - show the entire file.\n        if (sections !== null) {\n            for (i = 0; i < sections.length; i++) {\n                var section = sections[i];\n                var start = section.indexOf(marker);\n                if (start !== -1) {\n                    // Remove {{! and }} from start and end.\n                    var offset = start + marker.length + 1;\n                    section = section.substr(offset, section.length - 2 - offset);\n                    return section;\n                }\n            }\n        }\n        // No matching comment.\n        return false;\n    };\n\n    /**\n     * Handle a template loaded response.\n     *\n     * @param {String} templateName The template name\n     * @param {String} source The template source\n     * @param {String} originalSource The original template source (not theme overridden)\n     */\n    var templateLoaded = function(templateName, source, originalSource) {\n        str.get_string('templateselected', 'tool_templatelibrary', templateName).done(function(s) {\n            $('[data-region=\"displaytemplateheader\"]').text(s);\n        }).fail(notification.exception);\n\n        // Find the comment section marked with @template component/template.\n        var docs = findDocsSection(source, templateName);\n\n        if (docs === false) {\n            // Docs was not in theme template, try original.\n            docs = findDocsSection(originalSource, templateName);\n        }\n\n        // If we found a docs section, limit the template library to showing this section.\n        if (docs) {\n            source = docs;\n        }\n\n        $('[data-region=\"displaytemplatesource\"]').text(source);\n\n        // Now search the text for a json example.\n\n        var example = source.match(/Example context \\(json\\):([\\s\\S]*)/);\n        var context = false;\n        if (example) {\n            var rawJSON = example[1].trim();\n            try {\n                context = $.parseJSON(rawJSON);\n            } catch (e) {\n                log.debug('Could not parse json example context for template.');\n                log.debug(e);\n            }\n        }\n        if (context) {\n            templates.render(templateName, context).done(function(html, js) {\n                templates.replaceNodeContents($('[data-region=\"displaytemplateexample\"]'), html, js);\n            }).fail(notification.exception);\n        } else {\n            str.get_string('templatehasnoexample', 'tool_templatelibrary').done(function(s) {\n                $('[data-region=\"displaytemplateexample\"]').text(s);\n            }).fail(notification.exception);\n        }\n    };\n\n    /**\n     * Load the a template source from Moodle.\n     *\n     * @param {String} templateName\n     */\n    var loadTemplate = function(templateName) {\n        var parts = templateName.split('/');\n        var component = parts.shift();\n        var name = parts.join('/');\n\n        var promises = ajax.call([{\n            methodname: 'core_output_load_template',\n            args: {\n                    component: component,\n                    template: name,\n                    themename: config.theme,\n                    includecomments: true\n            }\n        }, {\n            methodname: 'tool_templatelibrary_load_canonical_template',\n            args: {\n                    component: component,\n                    template: name\n            }\n        }], true, false);\n\n        // When returns a new promise that is resolved when all the passed in promises are resolved.\n        // The arguments to the done become the values of each resolved promise.\n        $.when.apply($, promises)\n            .done(function(source, originalSource) {\n              templateLoaded(templateName, source, originalSource);\n            })\n            .fail(notification.exception);\n    };\n\n    // Add the event listeners.\n    $('[data-region=\"list-templates\"]').on('click', '[data-templatename]', function(e) {\n        var templatename = $(this).data('templatename');\n        e.preventDefault();\n        loadTemplate(templatename);\n    });\n\n    // This module does not expose anything.\n    return {};\n});\n"],"names":["define","$","ajax","log","notification","templates","config","str","findDocsSection","templateSource","templateName","sections","marker","i","match","length","section","start","indexOf","offset","substr","loadTemplate","parts","split","component","shift","name","join","promises","call","methodname","args","template","themename","theme","includecomments","when","apply","done","source","originalSource","get_string","s","text","fail","exception","docs","example","context","rawJSON","trim","parseJSON","e","debug","render","html","js","replaceNodeContents","templateLoaded","on","templatename","this","data","preventDefault"],"mappings":";;;;;;;AAsBAA,sCAAO,CAAC,SAAU,YAAa,WAAY,oBAAqB,iBAAkB,cAAe,aAC1F,SAASC,EAAGC,KAAMC,IAAKC,aAAcC,UAAWC,OAAQC,SASvDC,gBAAkB,SAASC,eAAgBC,kBAEtCD,sBACM,MAKPE,SAFAC,OAAS,aAAeF,aACxBG,EAAI,KAMS,QAHjBF,SAAWF,eAAeK,MAAM,yBAIvBD,EAAI,EAAGA,EAAIF,SAASI,OAAQF,IAAK,KAC9BG,QAAUL,SAASE,GACnBI,MAAQD,QAAQE,QAAQN,YACb,IAAXK,MAAc,KAEVE,OAASF,MAAQL,OAAOG,OAAS,SACrCC,QAAUA,QAAQI,OAAOD,OAAQH,QAAQD,OAAS,EAAII,gBAM3D,GA2DPE,aAAe,SAASX,kBACpBY,MAAQZ,aAAaa,MAAM,KAC3BC,UAAYF,MAAMG,QAClBC,KAAOJ,MAAMK,KAAK,KAElBC,SAAW1B,KAAK2B,KAAK,CAAC,CACtBC,WAAY,4BACZC,KAAM,CACEP,UAAWA,UACXQ,SAAUN,KACVO,UAAW3B,OAAO4B,MAClBC,iBAAiB,IAE1B,CACCL,WAAY,+CACZC,KAAM,CACEP,UAAWA,UACXQ,SAAUN,SAElB,GAAM,GAIVzB,EAAEmC,KAAKC,MAAMpC,EAAG2B,UACXU,MAAK,SAASC,OAAQC,iBAzEV,SAAS9B,aAAc6B,OAAQC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