]> git.mjollnir.org Git - moodle.git/commitdiff
lib-form MDL-16706 Changed inline JS to use PAGE methods
authorsamhemelryk <samhemelryk>
Tue, 7 Jul 2009 08:49:00 +0000 (08:49 +0000)
committersamhemelryk <samhemelryk>
Tue, 7 Jul 2009 08:49:00 +0000 (08:49 +0000)
lib/form/filepicker.js [new file with mode: 0644]
lib/form/filepicker.php
lib/form/passwordunmask.js [new file with mode: 0644]
lib/form/passwordunmask.php
lib/form/recaptcha.php

diff --git a/lib/form/filepicker.js b/lib/form/filepicker.js
new file mode 100644 (file)
index 0000000..6ab7fdb
--- /dev/null
@@ -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');
\ No newline at end of file
index cd667c8d83fe249f6685cf9b7da3efabea176e11..427683829d53be40dbf8d0f7662f12c926934c74 100644 (file)
@@ -62,7 +62,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
     }
 
     function toHtml() {
-        global $CFG, $COURSE, $USER;
+        global $CFG, $COURSE, $USER, $PAGE;
 
         if ($this->_flagFrozen) {
             return $this->getFrozenHtml();
@@ -96,30 +96,11 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
         $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>
diff --git a/lib/form/passwordunmask.js b/lib/form/passwordunmask.js
new file mode 100644 (file)
index 0000000..cb2582d
--- /dev/null
@@ -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();};
+}
\ No newline at end of file
index ea9148787bb8723b2307722abd9228f7231a630a..59dad0acdde903f2a4de0e03e5f97f5edfe206a3 100644 (file)
@@ -19,42 +19,14 @@ class MoodleQuickForm_passwordunmask extends MoodleQuickForm_password {
     }
     
     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
index 3b509f32660ea1872e053287880c63a4b7aa81f7..48c529d3e28ac3d528b2f6f016f4762f81534f3a 100644 (file)
@@ -48,16 +48,11 @@ class MoodleQuickForm_recaptcha extends HTML_QuickForm_input {
      * @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'])) {