mod-resource-file MDL-16706 Removed inline JS and replaced with new PAGE methods

This commit is contained in:
samhemelryk 2009-06-26 05:12:43 +00:00
parent 1d6b319b11
commit cafe98f394
4 changed files with 83 additions and 87 deletions

View file

@ -0,0 +1,44 @@
function local_file_set_value(choose, localpath) {
var txt = document.getElementById('myform').myfile.value;
if (txt.indexOf('/') > -1) {
var mpath = txt.substring(txt.indexOf('/'),txt.length);
} else if (txt.indexOf('\\') > -1) {
var mpath = txt.substring(txt.indexOf('\\'),txt.length);
} else {
window.close();
return;
}
opener.document.getElementById('<?php echo $choose ?>').value = localpath+mpath;
window.close();
}
function local_path_set_value(txt) {
if (txt.indexOf('/') > -1) {
txt = txt.substring(0,txt.lastIndexOf('/'));
} else if (txt.indexOf('\\') > -1) {
txt = txt.substring(0,txt.lastIndexOf('\\'));
}
document.getElementById('myform').pathname.value = txt;
document.getElementById('myform').submit();
}
function resizeEmbeddedHtml(viewportheight) {
//calculate new embedded html height size
objectheight = YAHOO.util.Dom.getViewportHeight() - viewportheight;
if (objectheight < 200) {
objectheight = 200;
}
//resize the embedded html object
YAHOO.util.Dom.setStyle("embeddedhtml", "height", objectheight+"px");
YAHOO.util.Dom.setStyle("embeddedhtml", "width", "100%");
}
function file_resource_init(viewportheight) {
resizeEmbeddedHtml();
YAHOO.widget.Overlay.windowResizeEvent.subscribe(resizeEmbeddedHtml);
}
function create_UFO_object(id) {
UFO.create(FO, id);
}

View file

@ -15,30 +15,15 @@
print_simple_box(get_string('localfileinfo', 'resource'), 'center'); print_simple_box(get_string('localfileinfo', 'resource'), 'center');
$PAGE->requires->js('mod/resource/type/file/file.js');
?> ?>
<script type="text/javascript">
//<![CDATA[
function set_value(txt) {
if (txt.indexOf('/') > -1) {
path = txt.substring(txt.indexOf('/'),txt.length);
} else if (txt.indexOf('\\') > -1) {
path = txt.substring(txt.indexOf('\\'),txt.length);
} else {
window.close();
}
opener.document.getElementById('<?php echo $choose ?>').value = '<?php p(RESOURCE_LOCALPATH) ?>'+path;
window.close();
}
//]]>
</script>
<br /> <br />
<div class="mdl-align form"> <div class="mdl-align form">
<form id="myform"> <form id="myform">
<fieldset class="invisiblefieldset"> <fieldset class="invisiblefieldset">
<input type="file" size="60" name="myfile" /><br /> <input type="file" size="60" name="myfile" /><br />
<input type="button" value="<?php print_string('localfileselect','resource') ?>" <input type="button" value="<?php print_string('localfileselect','resource') ?>"
onClick="return set_value(getElementById('myform').myfile.value)"> onClick="return local_file_set_value('<?php echo $choose?>', '<?php echo p(RESOURCE_LOCALPATH);?>')">
<input type="button" value="<?php print_string('cancel') ?>" <input type="button" value="<?php print_string('cancel') ?>"
onClick="window.close()"> onClick="window.close()">
</fieldset> </fieldset>

View file

@ -9,35 +9,16 @@
if (confirm_sesskey()) { if (confirm_sesskey()) {
set_user_preference('resource_localpath', $pathname); set_user_preference('resource_localpath', $pathname);
} }
?> echo $PAGE->requires->js_function_call('window.close')->asap();
<script type="text/javascript">
//<![CDATA[
window.close();
//]]>
</script>
<?php
exit; exit;
} }
print_header(get_string('localfilechoose', 'resource')); print_header(get_string('localfilechoose', 'resource'));
print_simple_box(get_string('localfilepath', 'resource', $CFG->wwwroot.'/user/edit.php?course='.SITEID), 'center'); print_simple_box(get_string('localfilepath', 'resource', $CFG->wwwroot.'/user/edit.php?course='.SITEID), 'center');
$PAGE->requires->js('mod/resource/type/file/file.js');
?> ?>
<script type="text/javascript">
//<![CDATA[
function set_value(txt) {
if (txt.indexOf('/') > -1) {
txt = txt.substring(0,txt.lastIndexOf('/'));
} else if (txt.indexOf('\\') > -1) {
txt = txt.substring(0,txt.lastIndexOf('\\'));
}
getElementById('myform').pathname.value = txt;
getElementById('myform').submit();
}
//]]>
</script>
<br /> <br />
<div class="mdl-align form"> <div class="mdl-align form">
<form id="myform" action="localpath.php" method="post"> <form id="myform" action="localpath.php" method="post">
@ -46,7 +27,7 @@
<input type="hidden" name="pathname" value="" /> <input type="hidden" name="pathname" value="" />
<input type="file" size="60" name="myfile" /><br /> <input type="file" size="60" name="myfile" /><br />
<input type="button" value="<?php print_string('localfileselect','resource') ?>" <input type="button" value="<?php print_string('localfileselect','resource') ?>"
onClick="return set_value(getElementById('myform').myfile.value)"> onClick="return local_path_set_value(document.getElementById('myform').myfile.value)">
<input type="button" value="<?php print_string('cancel') ?>" <input type="button" value="<?php print_string('cancel') ?>"
onClick="window.close()"> onClick="window.close()">
</fieldset> </fieldset>

View file

@ -357,11 +357,7 @@ class resource_file extends resource_base {
print_header($pagetitle, $course->fullname, $navigation, print_header($pagetitle, $course->fullname, $navigation,
"", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm));
echo "\n<script type=\"text/javascript\">"; $PAGE->requires->js_function_call('openpopup', Array("/mod/resource/view.php?inpopup=true&id={$cm->id}","resource{$resource->id}",$resource->popup));
echo "\n<!--\n";
echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";
echo "\n-->\n";
echo '</script>';
if (trim(strip_tags($resource->intro))) { if (trim(strip_tags($resource->intro))) {
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center"); print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
@ -415,39 +411,21 @@ class resource_file extends resource_base {
alt : <a href="' . $fullurl . '">' . $fullurl . '</a> alt : <a href="' . $fullurl . '">' . $fullurl . '</a>
</object></p>'; </object></p>';
} }
///add some javascript in order to fit this object tag into the browser window
echo '<script type="text/javascript">
//<![CDATA[
function resizeEmbeddedHtml() {
//calculate new embedded html height size
';
if (!empty($resource->intro)) { if (!empty($resource->intro)) {
echo' objectheight = YAHOO.util.Dom.getViewportHeight() - 230; $viewportheight = 230;
'; } else {
$viewportheight = 120;
} }
else { ///add some javascript in order to fit this object tag into the browser window
echo' objectheight = YAHOO.util.Dom.getViewportHeight() - 120; $PAGE->requires->js('mod/resource/type/file/file.js');
'; $PAGE->requires->js_function_call('file_resource_init', Array($viewportheight));
}
echo ' //the object tag cannot be smaller than a human readable size
if (objectheight < 200) {
objectheight = 200;
}
//resize the embedded html object
YAHOO.util.Dom.setStyle("embeddedhtml", "height", objectheight+"px");
YAHOO.util.Dom.setStyle("embeddedhtml", "width", "100%");
}
resizeEmbeddedHtml();
YAHOO.widget.Overlay.windowResizeEvent.subscribe(resizeEmbeddedHtml);
//]]>
</script>
';
///print the intro ///print the intro
if (!empty($resource->intro)) { if (!empty($resource->intro)) {
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center"); print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
} }
echo "</body></html>"; print_footer();
exit; exit;
} else { } else {
/// display the resource into a frame tag /// display the resource into a frame tag
@ -522,7 +500,6 @@ class resource_file extends resource_base {
'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes'; 'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes';
} }
$c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource'); $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
$c = htmlentities($c);
$id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache $id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache
$cleanurl = addslashes_js($fullurl); $cleanurl = addslashes_js($fullurl);
@ -531,14 +508,18 @@ class resource_file extends resource_base {
echo '<div class="resourcecontent resourcemp3">'; echo '<div class="resourcecontent resourcemp3">';
echo '<span class="mediaplugin mediaplugin_mp3" id="'.$id.'"></span>'. echo '<span class="mediaplugin mediaplugin_mp3" id="'.$id.'"></span>';
'<script type="text/javascript">'."\n". $args = Array();
'//<![CDATA['."\n". $args['movie'] = $CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.$cleanurl;
'var FO = { movie:"'.$CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.$cleanurl.'",'."\n". $args['width'] = 600;
'width:"600", height:"70", majorversion:"6", build:"40", flashvars:"'.$c.'", quality: "high" };'."\n". $args['height'] = 70;
'UFO.create(FO, "'.$id.'");'."\n". $args['majorversion'] = 6;
'//]]>'."\n". $args['build'] = 40;
'</script>'."\n"; $args['flashvars'] = $c;
$args['quality'] = 'high';
echo $PAGE->requires->js('mod/resource/type/file/file.js')->asap();
echo $PAGE->requires->data_for_js('FO', $args)->asap();
echo $PAGE->requires->js_function_call('create_UFO_object', Array($id))->asap();
echo '<noscript>'; echo '<noscript>';
@ -562,14 +543,19 @@ class resource_file extends resource_base {
echo '<div class="resourcecontent resourceflv">'; echo '<div class="resourcecontent resourceflv">';
echo '<span class="mediaplugin mediaplugin_flv" id="'.$id.'"></span>'. echo '<span class="mediaplugin mediaplugin_flv" id="'.$id.'"></span>';
'<script type="text/javascript">'."\n". $args = Array();
'//<![CDATA['."\n". $args['movie'] = $CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file='.$cleanurl;
'var FO = { movie:"'.$CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file='.$cleanurl.'",'."\n". $args['width'] = 600;
'width:"600", height:"400", majorversion:"6", build:"40", allowscriptaccess:"never", allowfullscreen:"true", quality: "high" };'."\n". $args['height'] = 400;
'UFO.create(FO, "'.$id.'");'."\n". $args['majorversion'] = 6;
'//]]>'."\n". $args['build'] = 40;
'</script>'."\n"; $args['allowscriptaccess'] = 'never';
$args['allowfullscreen'] = 'true';
$args['quality'] = 'high';
echo $PAGE->requires->js('mod/resource/type/file/file.js')->asap();
echo $PAGE->requires->data_for_js('FO', $args)->asap();
echo $PAGE->requires->js_function_call('create_UFO_object', Array($id))->asap();
echo '<noscript>'; echo '<noscript>';