Skip to content

Commit

Permalink
lib-form MDL-16706 Changed inline JS to use PAGE methods
Browse files Browse the repository at this point in the history
  • Loading branch information
samhemelryk committed Jul 7, 2009
1 parent f77fcb5 commit e4e7044
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 61 deletions.
20 changes: 20 additions & 0 deletions lib/form/filepicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function updatefile(client_id, obj) {
document.getElementById('repo_info_'+client_id).innerHTML = obj['file'];
}
function callpicker(client_id, id) {
var picker = document.createElement('DIV');
picker.id = 'file-picker-'+client_id;
picker.className = 'file-picker';
document.body.appendChild(picker);
var el=document.getElementById(id);
var params = {};
params.env = 'filepicker';
params.itemid = itemid;
params.maxbytes = filepicker.maxbytes;
params.maxfiles = filepicker.maxfiles;
params.target = el;
params.callback = updatefile;
open_filepicker(client_id, params);
return false;
}
alert('here');
25 changes: 3 additions & 22 deletions lib/form/filepicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function getElementTemplateType() {
}

function toHtml() {
global $CFG, $COURSE, $USER;
global $CFG, $COURSE, $USER, $PAGE;

if ($this->_flagFrozen) {
return $this->getFrozenHtml();
Expand Down Expand Up @@ -96,30 +96,11 @@ function toHtml() {
$str .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" '.$draftvalue.' />';
$str .= $repojs;

$str .= $PAGE->requires->data_for_js('filepicker', Array('maxbytes'=>$this->_options['maxbytes'],'maxfiles'=>$this->_options['maxfiles']))->asap();
$str .= $PAGE->requires->js('lib/form/filepicker.js')->asap();
$str .= <<<EOD
<a href="#nonjsfp" class="btnaddfile" onclick="return callpicker('$client_id', '$id', '$draftvalue')">$straddfile</a>
<span id="repo_info_{$client_id}" class="notifysuccess">$currentfile</span>
<script type="text/javascript">
function updatefile(client_id, obj) {
document.getElementById('repo_info_'+client_id).innerHTML = obj['file'];
}
function callpicker(client_id, id) {
var picker = document.createElement('DIV');
picker.id = 'file-picker-'+client_id;
picker.className = 'file-picker';
document.body.appendChild(picker);
var el=document.getElementById(id);
var params = {};
params.env = 'filepicker';
params.itemid = itemid;
params.maxbytes = $this->_options['maxbytes'];
params.maxfiles = $this->_options['maxfiles'];
params.target = el;
params.callback = updatefile;
open_filepicker(client_id, params);
return false;
}
</script>
<noscript>
<a name="nonjsfp"></a>
<object type="text/html" data="{$CFG->httpswwwroot}/repository/filepicker.php?action=embedded&itemid={$draftitemid}&ctx_id=$context->id" height="300" width="800" style="border:1px solid #000">Error</object>
Expand Down
26 changes: 26 additions & 0 deletions lib/form/passwordunmask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var is_ie = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);

document.getElementById(punmask.id).setAttribute("autocomplete", "off");

var unmaskdiv = document.getElementById(punmask.id+"unmaskdiv");

var unmaskchb = document.createElement("input");
unmaskchb.setAttribute("type", "checkbox");
unmaskchb.setAttribute("id", punmask.id+"unmask");
unmaskchb.onchange = function() {unmaskPassword(punmask.id);};
unmaskdiv.appendChild(unmaskchb);

var unmasklbl = document.createElement("label");
unmasklbl.innerHTML = punmask.unmaskstr;
if (is_ie) {
unmasklbl.setAttribute("htmlFor", punmask.id+"unmask");
} else {
unmasklbl.setAttribute("for", punmask.id+"unmask");
}
unmaskdiv.appendChild(unmasklbl);

if (is_ie) {
// ugly hack to work around the famous onchange IE bug
unmaskchb.onclick = function() {this.blur();};
unmaskdiv.onclick = function() {this.blur();};
}
34 changes: 3 additions & 31 deletions lib/form/passwordunmask.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,14 @@ function MoodleQuickForm_passwordunmask($elementName=null, $elementLabel=null, $
}

function toHtml() {
global $PAGE;
if ($this->_flagFrozen) {
return $this->getFrozenHtml();
} else {
$id = $this->getAttribute('id');
$unmask = get_string('unmaskpassword', 'form');
$unmaskjs = '<script type="text/javascript">
//<![CDATA[
var is_ie = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
document.getElementById("'.$id.'").setAttribute("autocomplete", "off");
var unmaskdiv = document.getElementById("'.$id.'unmaskdiv");
var unmaskchb = document.createElement("input");
unmaskchb.setAttribute("type", "checkbox");
unmaskchb.setAttribute("id", "'.$id.'unmask");
unmaskchb.onchange = function() {unmaskPassword("'.$id.'");};
unmaskdiv.appendChild(unmaskchb);
var unmasklbl = document.createElement("label");
unmasklbl.innerHTML = "'.addslashes_js($unmask).'";
if (is_ie) {
unmasklbl.setAttribute("htmlFor", "'.$id.'unmask");
} else {
unmasklbl.setAttribute("for", "'.$id.'unmask");
}
unmaskdiv.appendChild(unmasklbl);
if (is_ie) {
// ugly hack to work around the famous onchange IE bug
unmaskchb.onclick = function() {this.blur();};
unmaskdiv.onclick = function() {this.blur();};
}
//]]>
</script>';
$unmaskjs = $PAGE->requires->data_for_js('punmask',Array('id'=>$id, 'unmaskstr'=>$unmask))->asap();
$unmaskjs .= $PAGE->requires->js('lib/form/passwordunmask.js')->asap();
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' /><div class="unmask" id="'.$id.'unmaskdiv"></div>'.$unmaskjs;
}
} //end func toHtml
Expand Down
11 changes: 3 additions & 8 deletions lib/form/recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ function MoodleQuickForm_recaptcha($elementName = null, $elementLabel = null, $a
* @return string
*/
function toHtml() {
global $CFG;
global $CFG, $PAGE;
require_once $CFG->libdir . '/recaptchalib.php';

$html = '<script type="text/javascript">
var RecaptchaOptions = {
theme : \'custom\',
tabindex : 2,
custom_theme_widget : \'recaptcha_widget\'
};
</script>' . "\n";
$recaptureoptions = Array('theme'=>'custom', 'tabindex'=>2, 'custom_theme_widget'=>'recaptcha_widget');
$html = $PAGE->requires->data_for_js('RecaptchaOptions', $recaptureoptions)->asap();

$attributes = $this->getAttributes();
if (empty($attributes['error_message'])) {
Expand Down

0 comments on commit e4e7044

Please sign in to comment.