[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 /** 2 * @author Dongsheng Cai <[email protected]> 3 */ 4 5 // No need to require lang packs in moodle plugins. 6 7 var ed, url; 8 9 if (url = tinyMCEPopup.getParam("media_external_list_url")) { 10 document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>'); 11 } 12 13 function init() { 14 ed = tinyMCEPopup.editor; 15 document.getElementById('filebrowsercontainer').innerHTML = getFileBrowserHTML('filebrowser','src','media','media'); 16 } 17 18 function insertMedia() { 19 var f = document.forms[0]; 20 var url = f.filename.value; 21 var linkname = url.substring(url.lastIndexOf('/')+1); 22 var h = '<a href="'+f.src.value+'">'+linkname+'</a>'; 23 ed.execCommand('mceInsertContent', false, h); 24 tinyMCEPopup.close(); 25 } 26 27 function serializeParameters() { 28 var d = document, s = ''; 29 s += getStr(null, 'src'); 30 31 // delete the tail comma 32 s = s.length > 0 ? s.substring(0, s.length - 1) : s; 33 34 return s; 35 } 36 37 function getStr(p, n, d) { 38 var e = document.forms[0].elements[(p != null ? p + "_" : "") + n]; 39 var v = e.type == "hidden" ? e.value : e.options[e.selectedIndex].value; 40 41 if (n == 'src') 42 v = tinyMCEPopup.editor.convertURL(v, 'src', null); 43 44 return ((n == d || v == '') ? '' : n + ":'" + jsEncode(v) + "',"); 45 } 46 47 function jsEncode(s) { 48 s = s.replace(new RegExp('\\\\', 'g'), '\\\\'); 49 s = s.replace(new RegExp('"', 'g'), '\\"'); 50 s = s.replace(new RegExp("'", 'g'), "\\'"); 51 52 return s; 53 } 54 55 function generatePreview(c) { 56 var f = document.forms[0], p = document.getElementById('prev'); 57 58 p.innerHTML = '<!-- x --->'; 59 var re = new RegExp("(.+)\#(.+)", "i"); 60 var result = f.src.value.match(re); 61 if (result) { 62 f.src.value = result[1]; 63 f.filename.value = result[2]; 64 } else { 65 f.src.value = f.src.value; 66 f.filename.value = f.src.value; 67 } 68 69 // After constrain 70 var pl = serializeParameters(); 71 if (pl == '') { 72 p.innerHTML = ''; 73 return; 74 } 75 pl = tinyMCEPopup.editor.plugins.moodlemedia._parse(pl); 76 77 if (!pl.src) { 78 p.innerHTML = ''; 79 return; 80 } 81 82 pl.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(pl.src); 83 84 // NOTE: Do not try to prevent https security popups here - users would get them later on real page anyway! 85 86 // We can not include URL directly in parameters because some security filters might block it. 87 p.innerHTML = '<iframe src="' + tinyMCEPopup.editor.getParam("moodle_plugin_base") + 'moodlemedia/preview.php' 88 + '?media=' + encodeURIComponent(encode64(pl.src.toString())) 89 + '&sesskey=' + encodeURIComponent(parent.M.cfg.sesskey) 90 + '" width="100%" height="100%"></iframe>'; 91 } 92 93 function encode64(input) { 94 /* 95 CryptoMX Tools 96 Copyright (C) 2004 - 2006 Derek Buitenhuis 97 98 This program is free software; you can redistribute it and/or 99 modify it under the terms of the GNU General Public License 100 as published by the Free Software Foundation; either version 2 101 of the License, or (at your option) any later version. 102 103 This program is distributed in the hope that it will be useful, 104 but WITHOUT ANY WARRANTY; without even the implied warranty of 105 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 106 GNU General Public License for more details. 107 108 You should have received a copy of the GNU General Public License 109 along with this program; if not, write to the Free Software 110 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 111 */ 112 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 113 var output = ""; 114 var chr1, chr2, chr3 = ""; 115 var enc1, enc2, enc3, enc4 = ""; 116 var i = 0; 117 118 do { 119 chr1 = input.charCodeAt(i++); 120 chr2 = input.charCodeAt(i++); 121 chr3 = input.charCodeAt(i++); 122 123 enc1 = chr1 >> 2; 124 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 125 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 126 enc4 = chr3 & 63; 127 128 if (isNaN(chr2)) { 129 enc3 = enc4 = 64; 130 } else if (isNaN(chr3)) { 131 enc4 = 64; 132 } 133 134 output = output + 135 keyStr.charAt(enc1) + 136 keyStr.charAt(enc2) + 137 keyStr.charAt(enc3) + 138 keyStr.charAt(enc4); 139 chr1 = chr2 = chr3 = ""; 140 enc1 = enc2 = enc3 = enc4 = ""; 141 } while (i < input.length); 142 143 return output; 144 } 145 146 tinyMCEPopup.onInit.add(init);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |