mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-9239 New fromslib password element with reveal option
This commit is contained in:
parent
da586c3430
commit
0d4f86ce4b
5 changed files with 71 additions and 0 deletions
|
@ -16,6 +16,7 @@ $string['nonexistentformelements'] = 'Trying to add help buttons to nonexistent
|
||||||
$string['requiredelement'] = 'Required field';
|
$string['requiredelement'] = 'Required field';
|
||||||
$string['general'] = 'General';
|
$string['general'] = 'General';
|
||||||
$string['optional'] = 'Optional';
|
$string['optional'] = 'Optional';
|
||||||
|
$string['revealpassword'] = 'Reveal';
|
||||||
$string['modstandardels']='Common Module Settings';
|
$string['modstandardels']='Common Module Settings';
|
||||||
$string['miscellaneoussettings']='Miscellaneous Settings';
|
$string['miscellaneoussettings']='Miscellaneous Settings';
|
||||||
$string['addfields']='Add $a fields to form';
|
$string['addfields']='Add $a fields to form';
|
||||||
|
|
33
lib/form/passwordreveal.php
Normal file
33
lib/form/passwordreveal.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
if (!defined('MOODLE_INTERNAL')) {
|
||||||
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
||||||
|
}
|
||||||
|
|
||||||
|
global $CFG;
|
||||||
|
require_once($CFG->libdir.'/form/password.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML class for a password type element with reveal option
|
||||||
|
*
|
||||||
|
* @author Petr Skoda
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
class MoodleQuickForm_passwordreveal extends MoodleQuickForm_password {
|
||||||
|
|
||||||
|
function toHtml() {
|
||||||
|
if ($this->_flagFrozen) {
|
||||||
|
return $this->getFrozenHtml();
|
||||||
|
} else {
|
||||||
|
$id = $this->getAttribute('id');
|
||||||
|
$reveal = get_string('revealpassword', 'form');
|
||||||
|
$revealjs = '<script type="text/javascript">
|
||||||
|
//<![CDATA[
|
||||||
|
document.write(\'<div class="reveal"><input id="'.$id.'reveal" value="1" type="checkbox" onclick="revealPassword(\\\''.$id.'\\\')"/><label for="'.$id.'reveal">'.addslashes_js($reveal).'<\/label><\/div>\');
|
||||||
|
//]]>
|
||||||
|
</script>';
|
||||||
|
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />'.$revealjs;
|
||||||
|
}
|
||||||
|
} //end func toHtml
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
|
@ -1585,6 +1585,7 @@ MoodleQuickForm::registerElementType('checkbox', "$CFG->libdir/form/checkbox.php
|
||||||
MoodleQuickForm::registerElementType('file', "$CFG->libdir/form/file.php", 'MoodleQuickForm_file');
|
MoodleQuickForm::registerElementType('file', "$CFG->libdir/form/file.php", 'MoodleQuickForm_file');
|
||||||
MoodleQuickForm::registerElementType('group', "$CFG->libdir/form/group.php", 'MoodleQuickForm_group');
|
MoodleQuickForm::registerElementType('group', "$CFG->libdir/form/group.php", 'MoodleQuickForm_group');
|
||||||
MoodleQuickForm::registerElementType('password', "$CFG->libdir/form/password.php", 'MoodleQuickForm_password');
|
MoodleQuickForm::registerElementType('password', "$CFG->libdir/form/password.php", 'MoodleQuickForm_password');
|
||||||
|
MoodleQuickForm::registerElementType('passwordreveal', "$CFG->libdir/form/passwordreveal.php", 'MoodleQuickForm_passwordreveal');
|
||||||
MoodleQuickForm::registerElementType('radio', "$CFG->libdir/form/radio.php", 'MoodleQuickForm_radio');
|
MoodleQuickForm::registerElementType('radio', "$CFG->libdir/form/radio.php", 'MoodleQuickForm_radio');
|
||||||
MoodleQuickForm::registerElementType('select', "$CFG->libdir/form/select.php", 'MoodleQuickForm_select');
|
MoodleQuickForm::registerElementType('select', "$CFG->libdir/form/select.php", 'MoodleQuickForm_select');
|
||||||
MoodleQuickForm::registerElementType('text', "$CFG->libdir/form/text.php", 'MoodleQuickForm_text');
|
MoodleQuickForm::registerElementType('text', "$CFG->libdir/form/text.php", 'MoodleQuickForm_text');
|
||||||
|
|
|
@ -280,6 +280,34 @@ function showAdvancedOnClick(button, hidetext, showtext){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function revealPassword(id) {
|
||||||
|
var pw = document.getElementById(id);
|
||||||
|
var chb = document.getElementById(id+'reveal');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// first try IE way - it can not set name attribute later
|
||||||
|
if (chb.checked) {
|
||||||
|
var newpw = document.createElement('<input type="text" name="'+pw.name+'">');
|
||||||
|
} else {
|
||||||
|
var newpw = document.createElement('<input type="password" name="'+pw.name+'">');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
var newpw = document.createElement('input');
|
||||||
|
newpw.setAttribute('name', pw.name);
|
||||||
|
if (chb.checked) {
|
||||||
|
newpw.setAttribute('type', 'text');
|
||||||
|
} else {
|
||||||
|
newpw.setAttribute('type', 'password');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newpw.id = pw.id;
|
||||||
|
newpw.size = pw.size;
|
||||||
|
newpw.onblur = pw.onblur;
|
||||||
|
newpw.onchange = pw.onchange;
|
||||||
|
newpw.value = pw.value;
|
||||||
|
pw.parentNode.replaceChild(newpw, pw);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
elementToggleHide (element, elementFinder)
|
elementToggleHide (element, elementFinder)
|
||||||
|
|
||||||
|
|
|
@ -553,6 +553,14 @@ form.mform div.error,form.mform fieldset.error {
|
||||||
form.mform .fcheckbox input {
|
form.mform .fcheckbox input {
|
||||||
margin-left: 0px;
|
margin-left: 0px;
|
||||||
}
|
}
|
||||||
|
form.mform .fpassword .reveal {
|
||||||
|
display:inline;
|
||||||
|
}
|
||||||
|
form.mform .fpassword .reveal input {
|
||||||
|
margin-left:5px;
|
||||||
|
margin-right:3px;
|
||||||
|
}
|
||||||
|
|
||||||
form#adminsettings div.htmlarea {
|
form#adminsettings div.htmlarea {
|
||||||
clear: left;
|
clear: left;
|
||||||
padding-top: 5px;
|
padding-top: 5px;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue