From 41e2a9591fd4a73c64630cbf46843513d3fb33a2 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Mon, 11 Mar 2013 13:09:23 +0800 Subject: [PATCH 1/2] MDL-30438 Lesson Module: improve password field to disabled when password protect is set to no. --- lib/form/passwordunmask.php | 5 ++++- lib/form/yui/passwordunmask/passwordunmask.js | 7 ++++--- mod/lesson/mod_form.php | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/form/passwordunmask.php b/lib/form/passwordunmask.php index bd256fcf123..15bd4bc35d2 100644 --- a/lib/form/passwordunmask.php +++ b/lib/form/passwordunmask.php @@ -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() . '_getAttrString($this->_attributes) . ' />'; } } diff --git a/lib/form/yui/passwordunmask/passwordunmask.js b/lib/form/yui/passwordunmask/passwordunmask.js index dfe4de4b472..1bbefccdc8c 100644 --- a/lib/form/yui/passwordunmask/passwordunmask.js +++ b/lib/form/yui/passwordunmask/passwordunmask.js @@ -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('
'); //Add checkbox for unmasking to unmaskdiv - var unmaskchb = Y.Node.create(''); + var unmaskchb = Y.Node.create(''); unmaskdiv.appendChild(unmaskchb); //Attach event using static javascript function for unmasking password. unmaskchb.on('click', function() {unmaskPassword(elementid);}); diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index 9e88c584d69..7f82372b8fd 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -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(); From 3bd18935d7201334c3986e03109fe861b1739587 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Mon, 25 Mar 2013 11:47:05 +0800 Subject: [PATCH 2/2] MDL-30438 Lesson Module: fixed input text editable capability after checking/unchecking unmask option --- lib/javascript-static.js | 64 ++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 3930b79ebf3..c225d96a52a 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -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(''); - } else { - var newpw = document.createElement(''); + // 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(''); + } else { + var newpw = document.createElement(''); + } + 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) {