[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 // This file is part of Moodle - http://moodle.org/ 2 // 3 // Moodle is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // Moodle is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 15 16 /** 17 * URL utility functions. 18 * 19 * @module core/url 20 * @package core 21 * @class url 22 * @copyright 2015 Damyon Wiese <damyon@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 * @since 2.9 25 */ 26 define(['core/config'], function(config) { 27 28 29 return /** @alias module:core/url */ { 30 // Public variables and functions. 31 /** 32 * Construct a file url 33 * 34 * @method fileUrl 35 * @param {string} relativeScript 36 * @param {string} slashArg 37 * @return {string} 38 */ 39 fileUrl: function(relativeScript, slashArg) { 40 41 var url = config.wwwroot + relativeScript; 42 43 // Force a / 44 if (slashArg.charAt(0) != '/') { 45 slashArg = '/' + slashArg; 46 } 47 if (config.slasharguments) { 48 url += slashArg; 49 } else { 50 url += '?file=' + encodeURIComponent(slashArg); 51 } 52 return url; 53 }, 54 55 /** 56 * Take a path relative to the moodle basedir and do some fixing (see class moodle_url in php). 57 * 58 * @method relativeUrl 59 * @param {string} relativePath The path relative to the moodle basedir. 60 * @return {string} 61 */ 62 relativeUrl: function(relativePath) { 63 64 if (relativePath.indexOf('http:') === 0 || relativePath.indexOf('https:') === 0 || relativePath.indexOf('://') >= 0) { 65 throw new Error('relativeUrl function does not accept absolute urls'); 66 } 67 68 // Fix non-relative paths; 69 if (relativePath.charAt(0) != '/') { 70 relativePath = '/' + relativePath; 71 } 72 73 // Fix admin urls. 74 if (config.admin !== 'admin') { 75 relativePath = relativePath.replace(/^\/admin\//, '/' + config.admin + '/'); 76 } 77 return config.wwwroot + relativePath; 78 }, 79 80 /** 81 * Wrapper for image_url function. 82 * 83 * @method imageUrl 84 * @param {string} imagename The image name (e.g. t/edit). 85 * @param {string} component The component (e.g. mod_feedback). 86 * @return {string} 87 */ 88 imageUrl: function(imagename, component) { 89 return M.util.image_url(imagename, component); 90 } 91 }; 92 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |