Merge branch 'MDL-23872_m19' of git://github.com/nebgor/moodle into MOODLE_19_STABLE
[moodle.git] / lib / javascript.php
blobe13192273e773668c8d72e88f397dfc639251a38
1 <?php /// $Id$
2 /// Load up any required Javascript libraries
4 if (!defined('MOODLE_INTERNAL')) {
5 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
8 if (!empty($CFG->aspellpath)) { // Enable global access to spelling feature.
9 echo '<script type="text/javascript" src="'.$CFG->httpswwwroot.'/lib/speller/spellChecker.js"></script>'."\n";
12 if (!empty($CFG->editorsrc) ) {
13 foreach ( $CFG->editorsrc as $scriptsource ) {
14 echo '<script type="text/javascript" src="'. $scriptsource .'"></script>'."\n";
19 <!--<style type="text/css">/*<![CDATA[*/ body{behavior:url(<?php echo $CFG->httpswwwroot ?>/lib/csshover.htc);} /*]]>*/</style>-->
21 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/javascript-static.js"></script>
22 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/javascript-mod.php"></script>
23 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/overlib/overlib.js"></script>
24 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/overlib/overlib_cssstyle.js"></script>
25 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/cookies.js"></script>
26 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/ufo.js"></script>
27 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/dropdown.js"></script>
29 <script type="text/javascript" defer="defer">
30 //<![CDATA[
31 setTimeout('fix_column_widths()', 20);
32 //]]>
33 </script>
34 <script type="text/javascript">
35 //<![CDATA[
36 function openpopup(url, name, options, fullscreen) {
37 var fullurl = "<?php echo $CFG->httpswwwroot ?>" + url;
38 <?php
39 //code to add session id to url params if necessary for cookieless sessions
40 if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])){
41 $sessionparams = session_name() .'='. session_id();
42 echo <<<EOF
43 if (-1 == fullurl.indexOf('?')){
44 fullurl = fullurl+'?$sessionparams';
45 } else {
46 fullurl = fullurl+'&$sessionparams';
48 EOF;
51 var windowobj = window.open(fullurl, name, options);
52 if (!windowobj) {
53 return true;
55 if (fullscreen) {
56 windowobj.moveTo(0, 0);
57 windowobj.resizeTo(screen.availWidth, screen.availHeight);
59 windowobj.focus();
60 return false;
63 function uncheckall() {
64 var inputs = document.getElementsByTagName('input');
65 for(var i = 0; i < inputs.length; i++) {
66 inputs[i].checked = false;
70 function checkall() {
71 var inputs = document.getElementsByTagName('input');
72 for(var i = 0; i < inputs.length; i++) {
73 inputs[i].checked = true;
77 function inserttext(text) {
78 <?php
79 if (!empty($SESSION->inserttextform)) {
80 $insertfield = "opener.document.forms['$SESSION->inserttextform'].$SESSION->inserttextfield";
81 } else {
82 $insertfield = "opener.document.forms['theform'].message";
84 echo " text = ' ' + text + ' ';\n";
85 echo " if ( $insertfield.createTextRange && $insertfield.caretPos) {\n";
86 echo " var caretPos = $insertfield.caretPos;\n";
87 echo " caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;\n";
88 echo " } else {\n";
89 echo " $insertfield.value += text;\n";
90 echo " }\n";
91 echo " $insertfield.focus();\n";
94 <?php if (!empty($focus)) {
95 if(($pos = strpos($focus, '.')) !== false) {
96 //old style focus using form name - no allowed inXHTML Strict
97 $topelement = substr($focus, 0, $pos);
98 echo "addonload(function() { if(document.$topelement) document.$focus.focus(); });\n";
99 } else {
100 //focus element with given id
101 echo "addonload(function() { if(el = document.getElementById('$focus')) el.focus(); });\n";
103 $focus=false; // Prevent themes from adding it to body tag which breaks addonload(), MDL-10249
104 } ?>
106 function getElementsByClassName(oElm, strTagName, oClassNames){
107 var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
108 var arrReturnElements = new Array();
109 var arrRegExpClassNames = new Array();
110 if(typeof oClassNames == "object"){
111 for(var i=0; i<oClassNames.length; i++){
112 arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
115 else{
116 arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
118 var oElement;
119 var bMatchesAll;
120 for(var j=0; j<arrElements.length; j++){
121 oElement = arrElements[j];
122 bMatchesAll = true;
123 for(var k=0; k<arrRegExpClassNames.length; k++){
124 if(!arrRegExpClassNames[k].test(oElement.className)){
125 bMatchesAll = false;
126 break;
129 if(bMatchesAll){
130 arrReturnElements.push(oElement);
133 return (arrReturnElements)
135 //]]>
136 </script>