]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9239 New fromslib password element with reveal option; merged from MOODLE_18_STABLE
authorskodak <skodak>
Fri, 6 Apr 2007 14:18:02 +0000 (14:18 +0000)
committerskodak <skodak>
Fri, 6 Apr 2007 14:18:02 +0000 (14:18 +0000)
lang/en_utf8/form.php
lib/form/passwordreveal.php [new file with mode: 0644]
lib/formslib.php
lib/javascript-static.js
theme/standard/styles_layout.css

index 1263808b5702e032a093976a66451df657cacbc0..d90fab05de0e347dfdd13a71e4e0bfbdd6f7d1a4 100644 (file)
@@ -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 (file)
index 0000000..dcdda8f
--- /dev/null
@@ -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
+
+}
+?>
\ No newline at end of file
index 32604fa8e0da7c5fbcf61096ad24d1faa7536a03..baf928c86310c378c811f35c860f8ada5d398474 100644 (file)
@@ -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');
index 81d323d734a2bf5d4c7dc9c9365030d1f7272ef7..65874080ce266f6d0fac6bf7fc4e4679b4441e42 100644 (file)
@@ -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('<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)
 
index f76b50f7145efe580591c32cb5802a2e2fcc9d35..39b1537e70ad726f72a09aa2ea1d43f287bf0b5e 100644 (file)
@@ -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;