Permalink
Browse files

Merge branch 'MDL-30438_b_m24' of git://github.com/rwijaya/moodle int…

…o MOODLE_24_STABLE
  • Loading branch information...
2 parents a9cb8b7 + 4ee9853 commit 06b3c7e96135ac5bb3357c37431f7e802a7b4e2c @damyon damyon committed Mar 26, 2013
Showing with 49 additions and 32 deletions.
  1. +4 −1 lib/form/passwordunmask.php
  2. +4 −3 lib/form/yui/passwordunmask/passwordunmask.js
  3. +40 −28 lib/javascript-static.js
  4. +1 −0 mod/lesson/mod_form.php
@@ -80,8 +80,11 @@ function toHtml() {
} else {
$unmask = get_string('unmaskpassword', 'form');
//Pass id of the element, so that unmask checkbox can be attached.
+ $attributes = array('formid' => $this->getAttribute('id'),
+ 'checkboxlabel' => $unmask,
+ 'checkboxname' => $this->getAttribute('name'));
$PAGE->requires->yui_module('moodle-form-passwordunmask', 'M.form.passwordunmask',
- array(array('formid' => $this->getAttribute('id'), 'checkboxname' => $unmask)));
+ array($attributes));
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
}
}
@@ -7,18 +7,19 @@ YUI.add('moodle-form-passwordunmask', function(Y) {
//Initialize checkbox if id is passed
initializer : function(params) {
if (params && params.formid) {
- this.add_checkbox(params.formid, params.checkboxname);
+ this.add_checkbox(params.formid, params.checkboxlabel, params.checkboxname);
}
},
//Create checkbox for unmasking password
- add_checkbox : function(elementid, checkboxlabel) {
+ add_checkbox : function(elementid, checkboxlabel, checkboxname) {
var node = Y.one('#'+elementid);
//retaining unmask div from previous implementation.
var unmaskdiv = Y.Node.create('<div id="'+elementid+'unmaskdiv" class="unmask"></div>');
//Add checkbox for unmasking to unmaskdiv
- var unmaskchb = Y.Node.create('<input id="'+elementid+'unmask" type="checkbox">');
+ var unmaskchb = Y.Node.create('<input id="'+elementid+'unmask" type="checkbox" name="'+
+ checkboxname+'unmask">');
unmaskdiv.appendChild(unmaskchb);
//Attach event using static javascript function for unmasking password.
unmaskchb.on('click', function() {unmaskPassword(elementid);});
@@ -1063,34 +1063,46 @@ function findChildNodes(start, tagName, elementClass, elementID, elementName) {
}
function unmaskPassword(id) {
- var pw = document.getElementById(id);
- var chb = document.getElementById(id+'unmask');
-
- try {
- // first try IE way - it can not set name attribute later
- if (chb.checked) {
- var newpw = document.createElement('<input type="text" autocomplete="off" name="'+pw.name+'">');
- } else {
- var newpw = document.createElement('<input type="password" autocomplete="off" name="'+pw.name+'">');
- }
- newpw.attributes['class'].nodeValue = pw.attributes['class'].nodeValue;
- } catch (e) {
- var newpw = document.createElement('input');
- newpw.setAttribute('autocomplete', 'off');
- newpw.setAttribute('name', pw.name);
- if (chb.checked) {
- newpw.setAttribute('type', 'text');
- } else {
- newpw.setAttribute('type', 'password');
- }
- newpw.setAttribute('class', pw.getAttribute('class'));
- }
- 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);
+ var pw = document.getElementById(id);
+ var chb = document.getElementById(id+'unmask');
+
+ // MDL-30438 - The capability to changing the value of input type is not supported by IE8 or lower.
+ // Replacing existing child with a new one, removed all yui properties for the node. Therefore, this
+ // functionality won't work in IE8 or lower.
+ // This is a temporary fixed for 2.4 or lower branches to allow other browsers to function properly.
+ if (Y.UA.ie == 0 || Y.UA.ie >= 9) {
+ if (chb.checked) {
+ pw.type = "text";
+ } else {
+ pw.type = "password";
+ }
+ } else { //IE Browser version 8 or lower
+ try {
+ // first try IE way - it can not set name attribute later
+ if (chb.checked) {
+ var newpw = document.createElement('<input type="text" autocomplete="off" name="'+pw.name+'">');
+ } else {
+ var newpw = document.createElement('<input type="password" autocomplete="off" name="'+pw.name+'">');
+ }
+ newpw.attributes['class'].nodeValue = pw.attributes['class'].nodeValue;
+ } catch (e) {
+ var newpw = document.createElement('input');
+ newpw.setAttribute('autocomplete', 'off');
+ newpw.setAttribute('name', pw.name);
+ if (chb.checked) {
+ newpw.setAttribute('type', 'text');
+ } else {
+ newpw.setAttribute('type', 'password');
+ }
+ newpw.setAttribute('class', pw.getAttribute('class'));
+ }
+ 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);
+ }
}
function filterByParent(elCollection, parentFinder) {
@@ -133,6 +133,7 @@ function definition() {
$mform->setType('password', PARAM_RAW);
$mform->setAdvanced('password');
$mform->disabledIf('password', 'usepassword', 'eq', 0);
+ $mform->disabledIf('passwordunmask', 'usepassword', 'eq', 0);
$this->standard_grading_coursemodule_elements();

0 comments on commit 06b3c7e

Please sign in to comment.