merged fix for MDL-6968
[moodle.git] / lib / ajax / ajaxlib.php
CommitLineData
4488daf7 1<?php // Library functions for using AJAX with Moodle
9bb74178 2
3/**
35b974da 4 * Print require statements for javascript libraries
5 * Takes in an array of either full paths or shortnames and it will translate them to full paths
9bb74178 6 **/
9bb74178 7function print_require_js($list) {
8 global $CFG;
9
10 //list of shortname to filepath translations
11 $translatelist = array(
12 'yui_yahoo' => '/lib/yui/yahoo/yahoo.js',
13 'yui_dom' => '/lib/yui/dom/dom.js',
14 'yui_event' => '/lib/yui/event/event.js',
15 'yui_dragdrop' => '/lib/yui/dragdrop/dragdrop.js',
16 'yui_logger' => '/lib/yui/logger/logger.js',
17 'yui_connection' => '/lib/yui/connection/connection.js',
3e1e2b69 18 'ajaxcourse_blocks' => '/lib/ajax/block_classes.js',
19 'ajaxcourse_sections' => '/lib/ajax/section_classes.js',
9bb74178 20 'ajaxcourse' => '/lib/ajax/ajaxcourse.js'
21 );
22
23
35b974da 24 for ($i=0; $i<count($list); $i++) {
9bb74178 25 if ($translatelist[$list[$i]]) {
35b974da 26 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist[$list[$i]]."'></script>\n";
9bb74178 27 } else {
35b974da 28 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$list[$i]."'></script>\n";
9bb74178 29 }
30 }
31}
32
35b974da 33
34/**
35 * Used to create view of document to be passed to javascript on pageload.
36 */
9bb74178 37class jsportal{
38
0a0bb380 39 var $currentblocksection = null;
9bb74178 40 var $blocks = array();
d4df8fdc 41 var $blocksoutput = '';
42 var $output = '';
0a0bb380 43
9bb74178 44
35b974da 45 /**
46 * Takes id of block and adds it
47 */
48 function block_add($id, $hidden=false){
0a0bb380 49 $hidden_binary = 0;
9bb74178 50
51 if ($hidden) {
52 $hidden_binary = 1;
53 }
54
35b974da 55 $this->blocks[count($this->blocks)] = array($this->currentblocksection, $id, $hidden_binary);
0a0bb380 56 }
9bb74178 57
58
d4df8fdc 59 function print_javascript($id){
9bb74178 60 global $CFG;
61
d4df8fdc 62 $blocksoutput = $output = '';
35b974da 63 for ($i=0; $i<count($this->blocks); $i++) {
64 $blocksoutput .= "['".$this->blocks[$i][0]."','".$this->blocks[$i][1]."','".$this->blocks[$i][2]."']";
9bb74178 65 if ($i != (count($this->blocks)-1)) {
35b974da 66 $blocksoutput .= ',';
9bb74178 67 }
68 }
69
35b974da 70 $output .= "<script language='javascript'>\n";
71 $output .= " main.portal.id = ".$id.";\n";
72 $output .= " main.portal.blocks = new Array(".$blocksoutput.");\n";
73 $output .= " main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
3287cb4c 74 $output .= " main.portal.strings['update']='".get_string('update')."';\n";
75 $output .= " main.portal.strings['deletecheck']='".get_string('deletecheck','','_var_')."';\n";
76 $output .= " main.portal.strings['resource']='".get_string('resource')."';\n";
77 $output .= " main.portal.strings['activity']='".get_string('activity')."';\n";
35b974da 78 $output .= " onload.load();\n";
79 $output .= " main.process_blocks();\n";
80 $output .= "</script>";
0a0bb380 81 echo $output;
82 }
9bb74178 83}
84
479eea41 85?>