MDL-20204 the ultimate fix for our frames (theyare not accessbile, but anyway); instead of adding the target to each element when creating html we use yui to set the target from page footer via JS - this fixes the links and forms in all elements in pages with frametop layout

This commit is contained in:
Petr Skoda
2010-02-11 13:27:02 +00:00
parent ae6b463442
commit 4aea3cc7cd
24 changed files with 59 additions and 100 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ $user_fields = $authplugin->userfields;
admin_externalpage_print_header();
// choose an authentication method
echo "<form $CFG->frametarget id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
echo "<form id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
echo "<div>\n";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n";
echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
+2 -2
View File
@@ -60,7 +60,7 @@
echo $OUTPUT->box(get_string('configenrolmentplugins', 'admin'));
echo "<form $CFG->frametarget id=\"enrolmenu\" method=\"post\" action=\"enrol.php\">";
echo "<form id=\"enrolmenu\" method=\"post\" action=\"enrol.php\">";
echo "<div>";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
@@ -113,7 +113,7 @@
$yesnooptions = array(0=>get_string('no'), 1=>get_string('yes'));
echo '<form '.$CFG->frametarget.' id="adminsettings" method="post" action="enrol.php">';
echo '<form id="adminsettings" method="post" action="enrol.php">';
echo '<div class="settingsform clearfix">';
echo $OUTPUT->heading(get_string('commonsettings', 'admin'));
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+1 -1
View File
@@ -42,7 +42,7 @@
admin_externalpage_print_header();
echo "<form $CFG->frametarget id=\"enrolmenu\" method=\"post\" action=\"enrol_config.php\">";
echo "<form id=\"enrolmenu\" method=\"post\" action=\"enrol_config.php\">";
echo "<div>";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
echo "<input type=\"hidden\" name=\"enrol\" value=\"".$enrol."\" />";
-2
View File
@@ -33,8 +33,6 @@ die;die;die;
$CFG->release = $real_cfg->release;
$CFG->version = $real_cfg->version;
$CFG->config_php_settings = $real_cfg->config_php_settings;
$CFG->frametarget = $real_cfg->frametarget;
$CFG->framename = $real_cfg->framename;
$CFG->debug = 0;
$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
+1 -1
View File
@@ -1445,7 +1445,7 @@ function calendar_preferences_button() {
return '';
}
return "<form $CFG->frametarget method=\"get\" ".
return "<form method=\"get\" ".
" action=\"$CFG->wwwroot/calendar/preferences.php\">".
"<div><input type=\"submit\" value=\"".get_string("preferences", "calendar")." ...\" /></div></form>";
}
+1 -1
View File
@@ -54,7 +54,7 @@ class activitynames_filter extends moodle_text_filter {
$entitisedname = s($currentname);
/// Avoid empty or unlinkable activity names
if (!empty($title)) {
$href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\" $CFG->frametarget>";
$href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\">";
$this->activitylist[] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
if ($currentname != $entitisedname) { /// If name has some entity (&amp; &quot; &lt; &gt;) add that filter too. MDL-17545
$this->activitylist[] = new filterobject($entitisedname, $href_tag_begin, '</a>', false, true);
+28 -16
View File
@@ -385,28 +385,40 @@ M.util.init_maximised_embed = function(Y, id) {
* Attach handler to single_select
*/
M.util.init_select_autosubmit = function(Y, formid, selectid, nothing) {
YUI(M.yui.loader).use('node', function(Y) {
Y.on('change', function() {
if ((nothing == false && Y.Lang.isBoolean(nothing)) || Y.one('#'+selectid).get('value') != nothing) {
Y.one('#'+formid).submit();
}
},
'#'+selectid);
});
YUI(M.yui.loader).use('node', function(Y) {
Y.on('change', function() {
if ((nothing == false && Y.Lang.isBoolean(nothing)) || Y.one('#'+selectid).get('value') != nothing) {
Y.one('#'+formid).submit();
}
},
'#'+selectid);
});
};
/**
* Attach handler to url_select
*/
M.util.init_url_select = function(Y, formid, selectid, nothing) {
YUI(M.yui.loader).use('node', function(Y) {
Y.on('change', function() {
if ((nothing == false && Y.Lang.isBoolean(nothing)) || Y.one('#'+selectid).get('value') != nothing) {
window.location = M.cfg.wwwroot+Y.one('#'+selectid).get('value');
}
},
'#'+selectid);
});
YUI(M.yui.loader).use('node', function(Y) {
Y.on('change', function() {
if ((nothing == false && Y.Lang.isBoolean(nothing)) || Y.one('#'+selectid).get('value') != nothing) {
window.location = M.cfg.wwwroot+Y.one('#'+selectid).get('value');
}
},
'#'+selectid);
});
};
/**
* Breaks out all links to the top frame - used in frametop page layout.
*/
M.util.init_frametop = function(Y) {
Y.all('a').each(function(node) {
node.set('target', '_top');
});
Y.all('form').each(function(node) {
node.set('target', '_top');
});
};
//=== old legacy JS code, hopefully to be replaced soon by M.xx.yy and YUI3 code ===
+2 -6
View File
@@ -432,13 +432,8 @@ class navigation_node {
if ($this->hidden) {
$link->add_class('dimmed');
}
if (!empty($CFG->framename) && ($PAGE->pagelayout=='frametop' || $CFG->framename!='_top')) {
$breakoutaction = new breakout_of_frame_action();
$link->add_action($breakoutaction);
}
$content = $OUTPUT->link($link);
} else {
$span = new html_span();
$span->contents = $content;
@@ -450,6 +445,7 @@ class navigation_node {
}
$content = $OUTPUT->span($span);
}
return $content;
}
-17
View File
@@ -158,20 +158,3 @@ class popup_action extends component_action {
}
}
/**
* Component action for a breaking out of a frameset for a redirection.
*
* This function simply sets a `onclick="this.target='framename'` for the link when
* it is clicked causing the page to be directed to the target rather than the just
* the frame.
*/
class breakout_of_frame_action extends component_action {
/**
* Constructor to set up the action
* Relies on parent::__construct
*/
public function __construct() {
global $CFG;
parent::__construct('click', 'frame_breakout', array('framename'=>$CFG->framename));
}
}
+7 -21
View File
@@ -423,8 +423,7 @@ class core_renderer extends renderer_base {
if (session_is_loggedinas()) {
$realuser = session_get_realuser();
$fullname = fullname($realuser, true);
$realuserinfo = " [<a $CFG->frametarget
href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;return=1&amp;sesskey=".sesskey()."\">$fullname</a>] ";
$realuserinfo = " [<a href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;return=1&amp;sesskey=".sesskey()."\">$fullname</a>] ";
} else {
$realuserinfo = '';
}
@@ -438,28 +437,27 @@ class core_renderer extends renderer_base {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$fullname = fullname($USER, true);
$username = "<a $CFG->frametarget href=\"$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id\">$fullname</a>";
$username = "<a href=\"$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id\">$fullname</a>";
if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) {
$username .= " from <a $CFG->frametarget href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
$username .= " from <a href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
}
if (isset($USER->username) && $USER->username == 'guest') {
$loggedinas = $realuserinfo.get_string('loggedinasguest').
" (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
" (<a href=\"$loginurl\">".get_string('login').'</a>)';
} else if (!empty($USER->access['rsw'][$context->path])) {
$rolename = '';
if ($role = $DB->get_record('role', array('id'=>$USER->access['rsw'][$context->path]))) {
$rolename = ': '.format_string($role->name);
}
$loggedinas = get_string('loggedinas', 'moodle', $username).$rolename.
" (<a $CFG->frametarget
href=\"$CFG->wwwroot/course/view.php?id=$course->id&amp;switchrole=0&amp;sesskey=".sesskey()."\">".get_string('switchrolereturn').'</a>)';
" (<a href=\"$CFG->wwwroot/course/view.php?id=$course->id&amp;switchrole=0&amp;sesskey=".sesskey()."\">".get_string('switchrolereturn').'</a>)';
} else {
$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).' '.
" (<a $CFG->frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';
" (<a href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';
}
} else {
$loggedinas = get_string('loggedinnot', 'moodle').
" (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
" (<a href=\"$loginurl\">".get_string('login').'</a>)';
}
$loggedinas = '<div class="logininfo">'.$loggedinas.'</div>';
@@ -905,11 +903,6 @@ class core_renderer extends renderer_base {
'style' => $link->style,
'id' => $link->id);
if (!empty($CFG->frametarget)) {
//TODO: this seems wrong, we have to use onclick hack in order to be xhtml strict...
$attributes['target'] = $CFG->framename;
}
return html_writer::tag('a', $attributes, $link->text);
}
@@ -961,13 +954,6 @@ class core_renderer extends renderer_base {
}
}
if (!empty($CFG->frametarget)) {
//TODO: this seems wrong, we have to use onclick hack in order to be xhtml strict,
// we should instead use YUI and alter all links in frame-top layout,
// that is officially the only place where we have the "breaking out of frame" problems.
$attributes['target'] = $CFG->framename;
}
return html_writer::tag('a', $attributes, $link->text);
}
+5 -1
View File
@@ -226,7 +226,7 @@ class page_requirements_manager {
// JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot.
// Otherwise, in some situations, users will get warnings about insecure content
// on sercure pages from their web browser.
// on secure pages from their web browser.
$this->M_cfg = array(
'wwwroot' => $CFG->httpswwwroot, // Yes, really. See above.
@@ -250,6 +250,10 @@ class page_requirements_manager {
$this->string_for_js('cancel', 'moodle');
$this->string_for_js('yes', 'moodle');
$this->js_init_call('M.util.init_help_icons');
if ($page->pagelayout === 'frametop') {
$this->js_init_call('M.util.init_frametop');
}
}
/**
+1 -1
View File
@@ -1673,7 +1673,7 @@ class page_generic_activity extends page_base {
$buttons = '<table><tr><td>'.$OUTPUT->update_module_button($this->modulerecord->id, $this->activityname).'</td>';
if ($this->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
$buttons .= '<td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
$buttons .= '<td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
'<input type="hidden" name="edit" value="'.($this->user_is_editing()?'off':'on').'" />'.
'<input type="submit" value="'.get_string($this->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td>';
-3
View File
@@ -461,9 +461,6 @@ if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
}
$CFG->os = PHP_OS;
// Set up default frame target string, based on $CFG->framename
$CFG->frametarget = frametarget();
// Setup cache dir for Smarty and others
if (!file_exists($CFG->dataroot .'/cache')) {
make_upload_directory('cache');
-16
View File
@@ -2989,22 +2989,6 @@ function debugging($message = '', $level = DEBUG_NORMAL, $backtrace = null) {
return true;
}
/**
* Returns string to add a frame attribute, if required
*
* @global object
* @return bool
*/
function frametarget() {
global $CFG;
if (empty($CFG->framename) or ($CFG->framename == '_top')) {
return '';
} else {
return ' target="'.$CFG->framename.'" ';
}
}
/**
* Outputs a HTML comment to the browser. This is used for those hard-to-debug
* pages that use bits from many different files in very confusing ways (e.g. blocks).
+2 -1
View File
@@ -111,13 +111,14 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
}
$mform->display();
/* TODO: frames are a nono, this has to be redesigned
echo $OUTPUT->box_start('noframesjslink');
$accesslink = new html_link();
$accesslink->url = new moodle_url('/message/discussion.php', array('id'=>$userid, 'noframesjs'=>1));
$accesslink->text = get_string('noframesjs', 'message');
$accesslink->add_action(new breakout_of_frame_action());
echo $OUTPUT->link($accesslink);
echo $OUTPUT->box_end();
*/
$PAGE->requires->js_init_call('M.core_message.init_focus', array('id_message_editor'));
+1 -1
View File
@@ -73,7 +73,7 @@
$title = $course->shortname . ': ' . format_string($chat->name);
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
$buttons = '<table><tr><td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'.
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>';
+1 -1
View File
@@ -57,7 +57,7 @@
'<a class="data autolink" title="'.
$strippedcontent.'" href="'.
$CFG->wwwroot.'/mod/data/view.php?d='. $datacontent->dataid .
'&amp;rid='. $datacontent->recordid .'" '.$CFG->frametarget.'>',
'&amp;rid='. $datacontent->recordid .'">',
'</a>', false, true);
}
} // End foreach
+1 -1
View File
@@ -283,7 +283,7 @@
$title = $course->shortname.': ' . format_string($data->name);
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
$buttons = '<table><tr><td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'.
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>';
+1 -1
View File
@@ -6248,7 +6248,7 @@ function forum_update_subscriptions_button($courseid, $forumid) {
$edit = "on";
}
return "<form $CFG->frametarget method=\"get\" action=\"$CFG->wwwroot/mod/forum/subscribers.php\">".
return "<form method=\"get\" action=\"$CFG->wwwroot/mod/forum/subscribers.php\">".
"<input type=\"hidden\" name=\"id\" value=\"$forumid\" />".
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
"<input type=\"submit\" value=\"$string\" /></form>";
+1 -1
View File
@@ -364,7 +364,7 @@
if (has_capability('moodle/course:manageactivities', $coursecontext)) {
$updatebutton = ''
. '<form '.$CFG->frametarget.' method="get" action="'.$CFG->wwwroot.'/course/mod.php">'
. '<form method="get" action="'.$CFG->wwwroot.'/course/mod.php">'
. '<input type="hidden" name="update" value="'.$hotpot->coursemodule.'" />'
. $sesskey
. '<input type="submit" value="'.$strupdate.'" />'
-2
View File
@@ -2155,8 +2155,6 @@ class hotpot_xml_quiz extends hotpot_xml_tree {
$frametarget = ' onsubmit="'."this.target='$targetframe';".'"';
} else if (! empty($CFG->framename)) {
$frametarget = ' onsubmit="'."this.target='$CFG->framename';".'"';
} else if (! empty($CFG->frametarget)) {
$frametarget = $CFG->frametarget;
} else {
$frametarget = '';
}
+1 -1
View File
@@ -73,7 +73,7 @@
$title = $course->shortname . ': ' . format_string($quiz->name);
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
$buttons = '<table><tr><td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'.
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>';
+1 -1
View File
@@ -686,7 +686,7 @@ function scorm_course_format_display($user,$course) {
$trackedusers = $DB->get_record('scorm_scoes_track', array('scormid'=>$scorm->id), 'count(distinct(userid)) as c');
if ($trackedusers->c > 0) {
$headertext .= '<td class="reportlink">'.
'<a '.$CFG->frametarget.'" href="'.$CFG->wwwroot.'/mod/scorm/report.php?id='.$cm->id.'">'.
'<a href="'.$CFG->wwwroot.'/mod/scorm/report.php?id='.$cm->id.'">'.
get_string('viewallreports','scorm',$trackedusers->c).'</a>';
} else {
$headertext .= '<td class="reportlink">'.get_string('noreports','scorm');
+1 -1
View File
@@ -67,7 +67,7 @@
$trackedusers = scorm_get_count_users($scorm->id, $cm->groupingid);
if ($trackedusers > 0) {
echo "<div class=\"reportlink\"><a $CFG->frametarget href=\"report.php?id=$cm->id\"> ".get_string('viewalluserreports','scorm',$trackedusers).'</a></div>';
echo "<div class=\"reportlink\"><a href=\"report.php?id=$cm->id\"> ".get_string('viewalluserreports','scorm',$trackedusers).'</a></div>';
} else {
echo '<div class="reportlink">'.get_string('noreports','scorm').'</div>';
}