From: tjhunt Date: Mon, 15 Jun 2009 05:37:57 +0000 (+0000) Subject: javascript: MDL-19475 replace require_js calls with $PAGE->requires->js. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c28bf5c9f8c2ca58bea55d36514e85b95a2ff4b4;p=moodle.git javascript: MDL-19475 replace require_js calls with $PAGE->requires->js. Also, some related JavaScript cleanup. More to follow. --- diff --git a/course/report/progress/index.php b/course/report/progress/index.php index 566e0d3aa6..cc592383f9 100644 --- a/course/report/progress/index.php +++ b/course/report/progress/index.php @@ -86,12 +86,10 @@ if($csv) { $navlinks = array(); $navlinks[] = array('name' => $strreports, 'link' => "../../report.php?id=$course->id", 'type' => 'misc'); $navlinks[] = array('name' => $strcompletion, 'link' => null, 'type' => 'misc'); - if($svgcleverness) { - require_js(array('yui_yahoo','yui_event','yui_dom')); - } print_header($strcompletion,$course->fullname,build_navigation($navlinks)); if($svgcleverness) { - require_js('course/report/progress/textrotate.js'); + $PAGE->requires->yui_lib('event'); + $PAGE->requires->js('course/report/progress/textrotate.js'); } // Handle groups (if enabled) diff --git a/course/view.php b/course/view.php index 54dae4d017..15edd623cc 100644 --- a/course/view.php +++ b/course/view.php @@ -249,7 +249,7 @@ // At the bottom because we want to process sections and activities // after the relevant html has been generated. We're forced to do this // because of the way in which lib/ajax/ajaxcourse.js is written. - require_js('lib/ajax/ajaxcourse.js'); + $PAGE->requires->js('lib/ajax/ajaxcourse.js'); $COURSE->javascriptportal->print_javascript($course->id); } diff --git a/grade/edit/tree/index.php b/grade/edit/tree/index.php index a957474faa..646b93ac93 100644 --- a/grade/edit/tree/index.php +++ b/grade/edit/tree/index.php @@ -28,8 +28,14 @@ require_once $CFG->dirroot.'/grade/lib.php'; require_once $CFG->dirroot.'/grade/report/lib.php'; // for preferences require_once $CFG->dirroot.'/grade/edit/tree/lib.php'; -require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_json', 'yui_connection', 'yui_dragdrop', 'yui_treeview', 'yui_element', 'yui_container','yui_animation', - $CFG->wwwroot.'/grade/edit/tree/functions.js')); +$PAGE->requires->yui_lib('event'); +$PAGE->requires->yui_lib('json'); +$PAGE->requires->yui_lib('connection'); +$PAGE->requires->yui_lib('dragdrop'); +$PAGE->requires->yui_lib('element'); +$PAGE->requires->yui_lib('container'); +$PAGE->requires->yui_lib('animation'); +$PAGE->requires->js('grade/edit/tree/functions.js'); $courseid = required_param('id', PARAM_INT); $action = optional_param('action', 0, PARAM_ALPHA); diff --git a/group/index.php b/group/index.php index 168817470a..42868277db 100644 --- a/group/index.php +++ b/group/index.php @@ -13,8 +13,8 @@ require_once('lib.php'); ini_set('include_path', $CFG->libdir.'/pear'.PATH_SEPARATOR.ini_get('include_path')); -require_js(array('yui_yahoo', 'yui_dom', 'yui_utilities', 'yui_connection')); -require_js('group/clientlib.js'); +$PAGE->requires->yui_lib('connection'); +$PAGE->requires->js('group/clientlib.js'); $courseid = required_param('id', PARAM_INT); $groupid = optional_param('group', false, PARAM_INT); @@ -24,14 +24,7 @@ $action = groups_param_action(); if ($groupid) { $groupids=array($groupid); } else { - $groupids=array(); - if (isset($_REQUEST['groups'])) { - foreach ($_REQUEST['groups'] as $groupid) { - if ($groupid = clean_param($groupid, PARAM_INT)) { - $groupids[]=$groupid; - } - } - } + $groupids = optional_param('groups', array(), PARAM_INT); } $singlegroup=count($groupids) == 1; @@ -259,12 +252,10 @@ echo ''."\n"; echo ''."\n"; if (ajaxenabled()) { - echo ''."\n"; + $PAGE->requires->js_function_call('var groupsCombo = new UpdatableGroupsCombo', + array($CFG->httpswwwroot, $course->id)); + $PAGE->requires->js_function_call('var membersCombo = new UpdatableMembersCombo', + array($CFG->httpswwwroot, $course->id)); } print_footer($course); diff --git a/lib/editor/tinymce/extra/tinymce.js.php b/lib/editor/tinymce/extra/tinymce.js.php index 231cac4a20..4eced7890a 100644 --- a/lib/editor/tinymce/extra/tinymce.js.php +++ b/lib/editor/tinymce/extra/tinymce.js.php @@ -154,7 +154,6 @@ function mce_saveOnSubmit(id) { function mce_moodlefilemanager(field_name, url, type, win) { var client_id = id2clientid[tinyMCE.selectedInstance.editorId]; - document.body.className += ' yui-skin-sam'; var picker = document.createElement('DIV'); picker.className = "file-picker"; picker.id = 'file-picker-'+client_id; diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 1de9c8201b..25340ead1e 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -206,7 +206,6 @@ function fp_callback(obj) { list.innerHTML += html; } function callpicker(el_id, client_id, itemid) { - document.body.className += ' yui-skin-sam'; var picker = document.createElement('DIV'); picker.id = 'file-picker-'+client_id; picker.className = 'file-picker'; diff --git a/lib/form/filepicker.php b/lib/form/filepicker.php index 167262f70f..a2d7d94014 100644 --- a/lib/form/filepicker.php +++ b/lib/form/filepicker.php @@ -97,7 +97,6 @@ function updatefile(client_id, obj) { document.getElementById('repo_info_'+client_id).innerHTML = obj['file']; } function callpicker(client_id, id) { - document.body.className += ' yui-skin-sam'; var picker = document.createElement('DIV'); picker.id = 'file-picker-'+client_id; picker.className = 'file-picker'; diff --git a/lib/formslib.php b/lib/formslib.php index ef5352cb0f..72d39f5672 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -2111,7 +2111,8 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ * @access public * @return void */ - function renderHeader(&$header) { + function renderHeader(&$header) { + global $PAGE; $name = $header->getName(); $id = empty($name) ? '' : ' id="' . $name . '"'; @@ -2137,7 +2138,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ } if (isset($this->_advancedElements[$name])){ - require_js(array('yui_yahoo', 'yui_event')); + $PAGE->requires->yui_lib('event'); // this is tricky - the first submit button on form is "clicked" if user presses enter // we do not want to "submit" using advanced button if javascript active $button_nojs = ''; diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 6dd02ff958..641ef08dcc 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -410,7 +410,6 @@ function unmaskPassword(id) { * elements, and add date_selector_calendar instance to each. */ function init_date_selectors(firstdayofweek) { - YAHOO.util.Dom.addClass(document.body, 'yui-skin-sam'); var els = YAHOO.util.Dom.getElementsByClassName('fdate_time_selector', 'fieldset'); for (var i = 0; i < els.length; i++) { new date_selector_calendar(els[i], firstdayofweek); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 4286a86195..8708db492a 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1210,10 +1210,10 @@ function get_user_preferences($name=NULL, $default=NULL, $otheruserid=NULL) { * submitted values before set_user_preference is called. */ function user_preference_allow_ajax_update($name, $paramtype) { - global $USER; + global $USER, $PAGE; // Make sure that the required JavaScript libraries are loaded. - require_js(array('yui_yahoo', 'yui_connection')); + $PAGE->requires->yui_lib('connection'); // Record in the session that this user_preference is allowed to updated remotely. $USER->ajax_updatable_user_prefs[$name] = $paramtype; diff --git a/lib/questionlib.php b/lib/questionlib.php index a83d09bc86..f5ee6e35a0 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -2126,11 +2126,11 @@ function question_init_qenginejs_script() { * @return string some HTML code that can go inside the head tag. */ function get_html_head_contributions($questionlist, &$questions, &$states) { - global $CFG, $QTYPES; + global $CFG, $PAGE, $QTYPES; // The question engine's own JavaScript. - require_js(array('yui_yahoo','yui_event', 'yui_connection')); - require_js('question/qengine.js'); + $PAGE->requires->yui_lib('connection'); + $PAGE->requires->js('question/qengine.js'); // An inline script to record various lang strings, etc. that qengine.js needs. $contributions = array(question_init_qenginejs_script()); diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index ac944967fa..b5b53f9d52 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -31,8 +31,10 @@ require_course_login($course, true, $cm); /// Add ajax-related libs - require_js(array('yui_yahoo', 'yui_event', 'yui_dom', 'yui_connection', 'yui_json')); - require_js('mod/forum/rate_ajax.js'); + $PAGE->requires->yui_lib('event'); + $PAGE->requires->yui_lib('connection'); + $PAGE->requires->yui_lib('json'); + $PAGE->requires->js('mod/forum/rate_ajax.js'); // move this down fix for MDL-6926 require_once('lib.php'); diff --git a/repository/repository.js b/repository/repository.js index 363cca3037..28f3ebd943 100644 --- a/repository/repository.js +++ b/repository/repository.js @@ -1 +1 @@ -var repository_listing={};var cached_client_id={};var file_extensions={};var new_filename="";var cached_id;var cached_repo_id;var repository_client=(function(){var a="2.0";var d=(10*2);function b(){alert(a)}function c(h,f){if(YAHOO.env.ua.ie==6){var g=document.getElementById("file-picker-"+h);g.style.width=f}}function e(){this.create_filepicker=function(o){var m=(YAHOO.env.ua.ie&&document.compatMode=="BackCompat");var j=(YAHOO.env.ua.ie==6||(YAHOO.env.ua.ie==7&&m));var n={label:fp_lang.listview,value:"l",onclick:{fn:repository_client.view_as_list,obj:o}};var f={label:fp_lang.thumbview,value:"t",onclick:{fn:repository_client.view_as_icons,obj:o}};document.body.className+=" yui-skin-sam";var h=document.createElement("DIV");h.id="file-picker-"+o;h.className="file-picker";this.client_id=o;document.body.appendChild(h);this.filepicker=new YAHOO.widget.Panel("file-picker-"+o,{draggable:true,close:true,underlay:"none",zindex:666666,xy:[50,YAHOO.util.Dom.getDocumentScrollTop()+20]});var l="";this.filepicker.client_id=o;this.filepicker.setHeader(fp_lang.title);this.filepicker.setBody('
');this.filepicker.beforeRenderEvent.subscribe(function(){YAHOO.util.Event.onAvailable("layout-"+o,function(){l=new YAHOO.widget.Layout("layout-"+o,{height:480,width:700,units:[{position:"top",height:32,resize:false,body:'
',gutter:"2"},{position:"left",width:200,resize:true,scroll:true,body:'',gutter:"0 5 0 2",minWidth:150,maxWidth:300},{position:"center",body:'
',scroll:true,gutter:"0 2 0 0"}]});l.render()})});var g=new YAHOO.util.Resize("file-picker-"+o,{handles:["br"],autoRatio:true,status:true,minWidth:680,minHeight:400});c(o,"680px");g.on("resize",function(q){var r=q.height;var p=this.header.offsetHeight;var t=(r-p);var s=(m)?t:t-d;YAHOO.util.Dom.setStyle(this.body,"height",s+"px");c(this.client_id,"680px");if(j){this.sizeUnderlay();this.syncIframe()}l.set("height",s);l.set("width",(q.width-d));l.resize()},this.filepicker,true);repository_client.fp[o].viewbar=new YAHOO.widget.ButtonGroup({id:"btngroup-"+o,name:"buttons",disabled:true,container:"repo-viewbar-"+o});repository_client.fp[o].viewbar.addButtons([f,n]);this.print_listing();this.filepicker.render()};this.init_search=function(){var f=document.getElementById("search-div-"+this.client_id);f.innerHTML='";var g=new YAHOO.util.Element("search-btn-"+this.client_id);g.client_id=this.client_id;var h=new YAHOO.util.Element("search-input-"+this.client_id);h.client_id=this.client_id;g.fnSearch=function(o){var m=new YAHOO.util.Element("search-input-"+this.client_id);var j=m.get("value");var n=repository_client.fp[this.client_id];var p=[];p.s=j;p.env=n.env;p.accepted_types=n.accepted_types;p.sesskey=moodle_cfg.sesskey;p.ctx_id=fp_config.contextid;p.client_id=this.client_id;repository_client.loading(this.client_id,"load");var l=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=gsearch",this.search_cb,repository_client.postdata(p))};g.on("contentReady",function(){g.on("click",this.fnSearch,this.input_keyword)});g.search_cb={success:function(p){var n=repository_client.parse_json(p.responseText,"global_search_cb");var j=new YAHOO.util.Element("panel-"+n.client_id);if(!n.list||n.list.length<1){j.get("element").innerHTML=fp_lang.noresult;return}var m=repository_client.fp[n.client_id];m.view_staus=0;m.fs=n.list;if(n.gsearch){m.gsearch=true}if(m.view_staus){repository_client.view_as_list(n.client_id,n.list)}else{repository_client.view_as_icons(n.client_id,n.list)}var l=new YAHOO.util.Element("search-input-"+n.client_id);l.set("value","")}};h.on("contentReady",function(){var j=document.getElementById("search-input-"+this.client_id);var l=new YAHOO.util.KeyListener(j,{keys:13},{fn:function(){this.fnSearch()},scope:g,correctScope:true});l.enable()})};this.print_listing=function(){var f=new YAHOO.util.Element("repo-list-"+this.client_id);f.set("innerHTML","");f.on("contentReady",function(){this.init_search();for(var m in repository_listing[this.client_id]){var l=repository_listing[this.client_id][m];var o=false;if(this.env=="editor"&&this.accepted_types!="*"){if(l.supported_types!="*"){for(var h in l.supported_types){if(mdl_in_array(l.supported_types[h],this.accepted_types)){o=true}}}}else{o=true}if(l.supported_types=="*"||o){var g=document.createElement("li");g.id="repo-"+this.client_id+"-"+l.id;var n=document.createElement("img");n.src=l.icon;n.width="16";n.height="16";var p=document.createElement("a");p.href="###";p.id="repo-call-"+this.client_id+"-"+l.id;p.appendChild(n);p.className="fp-repo-name";p.innerHTML+=" "+l.name;p.onclick=function(){var s=new RegExp("repo-call-(\\w+)-(\\d+)","i");var j=this.id.match(s);var v=j[1];var r=j[2];for(var u in repository_listing[v]){var t="repo-call-"+v+"-"+u;var q=document.getElementById(t);if(q){q.style.background="transparent"}}this.style.background="#CCC";repository_client.req(v,r,"")};g.appendChild(p);f.appendChild(g);l=null}}},this,true)};this.show=function(){this.print_listing();var f=new YAHOO.util.Element("panel-"+this.filepicker.client_id);f.get("element").innerHTML="";this.filepicker.show()};this.hide=function(){this.filepicker.hide()}}e.fp={};return e})();repository_client.req=function(g,f,d,c){repository_client.loading(g,"load");this.fp[g].viewbar.set("disabled",false);var b=repository_client.fp[g];var e=[];e.p=d;e.env=b.env;e.sesskey=moodle_cfg.sesskey;e.ctx_id=fp_config.contextid;e.client_id=g;e.repo_id=f;if(!!c){e.page=c}e.accepted_types=b.accepted_types;var a=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=list",this.req_cb,this.postdata(e))};repository_client.req_cb={success:function(d){var c=repository_client.parse_json(d.responseText,"req_cb");var b=repository_client.fp[c.client_id];b.viewbar.set("disabled",false);var a=new YAHOO.util.Element("panel-"+c.client_id);if(c&&c.e){a.get("element").innerHTML=c.e;return}b.fs=c;if(!c){return}else{if(c.msg){repository_client.print_msg(c.msg)}else{if(c.iframe){repository_client.view_iframe(c.client_id)}else{if(c.login){b.viewbar.set("disabled",true);repository_client.print_login(c.client_id,c)}else{if(c.list){if(b.view_status){repository_client.view_as_list(c.client_id,c.list)}else{repository_client.view_as_icons(c.client_id,c.list)}}}}}}}};repository_client.view_iframe=function(c){var a=repository_client.fp[c].fs;var b=new YAHOO.util.Element("panel-"+c);b.get("element").innerHTML='