From 239ade458cef29e32a0bfed738fdfd452aaa07cd Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 6 Apr 2007 14:18:02 +0000 Subject: [PATCH] MDL-9239 New fromslib password element with reveal option; merged from MOODLE_18_STABLE --- lang/en_utf8/form.php | 1 + lib/form/passwordreveal.php | 33 ++++++++++++++++++++++++++++++++ lib/formslib.php | 1 + lib/javascript-static.js | 28 +++++++++++++++++++++++++++ theme/standard/styles_layout.css | 8 ++++++++ 5 files changed, 71 insertions(+) create mode 100644 lib/form/passwordreveal.php diff --git a/lang/en_utf8/form.php b/lang/en_utf8/form.php index 1263808b57..d90fab05de 100644 --- a/lang/en_utf8/form.php +++ b/lang/en_utf8/form.php @@ -16,6 +16,7 @@ $string['nonexistentformelements'] = 'Trying to add help buttons to nonexistent $string['requiredelement'] = 'Required field'; $string['general'] = 'General'; $string['optional'] = 'Optional'; +$string['revealpassword'] = 'Reveal'; $string['modstandardels']='Common Module Settings'; $string['miscellaneoussettings']='Miscellaneous Settings'; $string['addfields']='Add $a fields to form'; diff --git a/lib/form/passwordreveal.php b/lib/form/passwordreveal.php new file mode 100644 index 0000000000..dcdda8f2cd --- /dev/null +++ b/lib/form/passwordreveal.php @@ -0,0 +1,33 @@ +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 = ''; + return $this->_getTabs() . '_getAttrString($this->_attributes) . ' />'.$revealjs; + } + } //end func toHtml + +} +?> \ No newline at end of file diff --git a/lib/formslib.php b/lib/formslib.php index 32604fa8e0..baf928c863 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -1585,6 +1585,7 @@ MoodleQuickForm::registerElementType('checkbox', "$CFG->libdir/form/checkbox.php MoodleQuickForm::registerElementType('file', "$CFG->libdir/form/file.php", 'MoodleQuickForm_file'); MoodleQuickForm::registerElementType('group', "$CFG->libdir/form/group.php", 'MoodleQuickForm_group'); 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('select', "$CFG->libdir/form/select.php", 'MoodleQuickForm_select'); MoodleQuickForm::registerElementType('text', "$CFG->libdir/form/text.php", 'MoodleQuickForm_text'); diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 81d323d734..65874080ce 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -280,6 +280,34 @@ function showAdvancedOnClick(button, hidetext, showtext){ 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(''); + } else { + var newpw = document.createElement(''); + } + } 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) diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index f76b50f714..39b1537e70 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -553,6 +553,14 @@ form.mform div.error,form.mform fieldset.error { form.mform .fcheckbox input { margin-left: 0px; } +form.mform .fpassword .reveal { + display:inline; +} +form.mform .fpassword .reveal input { + margin-left:5px; + margin-right:3px; +} + form#adminsettings div.htmlarea { clear: left; padding-top: 5px; -- 2.39.5