Merge branch 'MDL-30438_b' of git://github.com/rwijaya/moodle
This commit is contained in:
@@ -80,8 +80,11 @@ class MoodleQuickForm_passwordunmask extends MoodleQuickForm_password {
|
||||
} 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) . ' />';
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -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);});
|
||||
|
||||
+38
-26
@@ -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');
|
||||
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+'">');
|
||||
// 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 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);
|
||||
}
|
||||
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 @@ class mod_lesson_mod_form extends moodleform_mod {
|
||||
$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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user