{"version":3,"sources":["https:\/\/flodev.flinders.edu.au\/lib\/amd\/src\/fragment.js"],"names":["define","$","ajax","loadFragment","component","callback","contextid","params","formattedparams","index","push","name","value","call","methodname","args","processCollectedJavascript","js","jsNodes","allScript","each","scriptNode","tagName","prop","toLowerCase","attr","exists","s","encodeURI","text","promise","Deferred","then","data","resolve","html","javascript","fail","ex","reject"],"mappings":"AAuBAA,OAAM,iBAAC,CAAC,QAAD,CAAW,WAAX,CAAD,CAA0B,SAASC,CAAT,CAAYC,CAAZ,CAAkB,IAY1CC,CAAAA,CAAY,CAAG,QAAfA,CAAAA,YAAe,CAASC,CAAT,CAAoBC,CAApB,CAA8BC,CAA9B,CAAyCC,CAAzC,CAAiD,CAEhE,GAAIC,CAAAA,CAAe,CAAG,EAAtB,CACA,IAAK,GAAIC,CAAAA,CAAT,GAAkBF,CAAAA,CAAlB,CAA0B,CACtBC,CAAe,CAACE,IAAhB,CAAqB,CACjBC,IAAI,CAAEF,CADW,CAEjBG,KAAK,CAAEL,CAAM,CAACE,CAAD,CAFI,CAArB,CAIH,CAED,MAAOP,CAAAA,CAAI,CAACW,IAAL,CAAU,CAAC,CACdC,UAAU,CAAE,mBADE,CAEdC,IAAI,CAAE,CACFX,SAAS,CAAEA,CADT,CAEFC,QAAQ,CAAEA,CAFR,CAGFC,SAAS,CAAEA,CAHT,CAIFS,IAAI,CAAEP,CAJJ,CAFQ,CAAD,CAAV,EAQH,CARG,CASV,CA\/B6C,CAuC1CQ,CAA0B,CAAG,QAA7BA,CAAAA,0BAA6B,CAASC,CAAT,CAAa,IACtCC,CAAAA,CAAO,CAAGjB,CAAC,CAACgB,CAAD,CAD2B,CAEtCE,CAAS,CAAG,EAF0B,CAG1CD,CAAO,CAACE,IAAR,CAAa,SAASX,CAAT,CAAgBY,CAAhB,CAA4B,CACrCA,CAAU,CAAGpB,CAAC,CAACoB,CAAD,CAAd,CACA,GAAIC,CAAAA,CAAO,CAAGD,CAAU,CAACE,IAAX,CAAgB,SAAh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,CAAa,CACjBR,CAAO,CAACS,MAAR,CAAeD,CAAf,CACH,CAJD,EAKA,MAAOR,CAAAA,CAAO,CAACA,OAAR,EACV,CArBE,CA6BHd,0BAA0B,CAAE,oCAASC,CAAT,CAAa,CACrC,MAAOD,CAAAA,CAA0B,CAACC,CAAD,CACpC,CA\/BE,CAiCV,CAxGK,CAAN","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 .\n\n\/**\n * A way to call HTML fragments to be inserted as required via JavaScript.\n *\n * @module core\/fragment\n * @copyright 2016 Adrian Greeve \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n * @since 3.1\n *\/\ndefine(['jquery', 'core\/ajax'], function($, ajax) {\n\n \/**\n * Loads an HTML fragment through a callback.\n *\n * @method loadFragment\n * @param {string} component Component where callback is located.\n * @param {string} callback Callback function name.\n * @param {integer} contextid Context ID of the fragment.\n * @param {object} params Parameters for the callback.\n * @return {Promise} JQuery promise object resolved when the fragment has been loaded.\n *\/\n var loadFragment = function(component, callback, contextid, params) {\n \/\/ Change params into required webservice format.\n var formattedparams = [];\n for (var index in params) {\n formattedparams.push({\n name: index,\n value: params[index]\n });\n }\n\n return ajax.call([{\n methodname: 'core_get_fragment',\n args: {\n component: component,\n callback: callback,\n contextid: contextid,\n args: formattedparams\n }\n }])[0];\n };\n\n \/**\n * Converts the JS that was received from collecting JS requirements on the $PAGE so it can be added to the existing page\n *\n * @param {string} js\n * @return {string}\n *\/\n var processCollectedJavascript = function(js) {\n var jsNodes = $(js);\n var allScript = '';\n jsNodes.each(function(index, scriptNode) {\n scriptNode = $(scriptNode);\n var tagName = scriptNode.prop('tagName');\n if (tagName && (tagName.toLowerCase() == 'script')) {\n if (scriptNode.attr('src')) {\n \/\/ We only reload the script if it was not loaded already.\n var exists = false;\n $('script').each(function(index, s) {\n if ($(s).attr('src') == scriptNode.attr('src')) {\n exists = true;\n }\n return !exists;\n });\n if (!exists) {\n allScript += ' { ';\n allScript += ' node = document.createElement(\"script\"); ';\n allScript += ' node.type = \"text\/javascript\"; ';\n allScript += ' node.src = decodeURI(\"' + encodeURI(scriptNode.attr('src')) + '\"); ';\n allScript += ' document.getElementsByTagName(\"head\")[0].appendChild(node); ';\n allScript += ' } ';\n }\n } else {\n allScript += ' ' + scriptNode.text();\n }\n }\n });\n return allScript;\n };\n\n return {\n \/**\n * Appends HTML and JavaScript fragments to specified nodes.\n * Callbacks called by this AMD module are responsible for doing the appropriate security checks\n * to access the information that is returned. This only does minimal validation on the context.\n *\n * @method fragmentAppend\n * @param {string} component Component where callback is located.\n * @param {string} callback Callback function name.\n * @param {integer} contextid Context ID of the fragment.\n * @param {object} params Parameters for the callback.\n * @return {Deferred} new promise that is resolved with the html and js.\n *\/\n loadFragment: function(component, callback, contextid, params) {\n var promise = $.Deferred();\n loadFragment(component, callback, contextid, params).then(function(data) {\n promise.resolve(data.html, processCollectedJavascript(data.javascript));\n }).fail(function(ex) {\n promise.reject(ex);\n });\n return promise.promise();\n },\n\n \/**\n * Converts the JS that was received from collecting JS requirements on the $PAGE so it can be added to the existing page\n *\n * @param {string} js\n * @return {string}\n *\/\n processCollectedJavascript: function(js) {\n return processCollectedJavascript(js);\n }\n };\n});\n"],"file":"fragment.min.js"}