]> git.mjollnir.org Git - moodle.git/commitdiff
moddata MDL-16706 Removed inline scripts in mod data and added data.js
authorsamhemelryk <samhemelryk>
Mon, 22 Jun 2009 03:16:25 +0000 (03:16 +0000)
committersamhemelryk <samhemelryk>
Mon, 22 Jun 2009 03:16:25 +0000 (03:16 +0000)
mod/data/data.js [new file with mode: 0644]
mod/data/edit.php
mod/data/lib.php
mod/data/templates.php
mod/data/view.php

diff --git a/mod/data/data.js b/mod/data/data.js
new file mode 100644 (file)
index 0000000..f66c8a8
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * Javascript to insert the field tags into the textarea.
+ * Used when editing a data template
+ */
+function insert_field_tags(selectlist) {
+  if (typeof(currEditor) != 'undefined' && currEditor._editMode == 'wysiwyg') {
+    // HTMLArea-specific
+     currEditor.insertHTML(selectlist.options[selectlist.selectedIndex].value);
+  } else {
+    // For inserting when in HTMLArea code view or for normal textareas
+     insertAtCursor(currTextarea, selectlist.options[selectlist.selectedIndex].value);
+  }
+}
+
+/**
+ * javascript for hiding/displaying advanced search form when viewing
+ */
+function showHideAdvSearch(checked) {
+    var divs = document.getElementsByTagName('div');
+    for(i=0;i<divs.length;i++) {
+        if(divs[i].id.match('data_adv_form')) {
+            if(checked) {
+                divs[i].style.display = 'inline';
+            }
+            else {
+                divs[i].style.display = 'none';
+            }
+        }
+        else if (divs[i].id.match('reg_search')) {
+            if (!checked) {
+                divs[i].style.display = 'inline';
+            }
+            else {
+                divs[i].style.display = 'none';
+            }
+        }
+    }
+}
\ No newline at end of file
index eb8262ec8f842b8963707c2e287de135b450e101..0bef0b6d9a83b96115bafc13274254a2eb00351d 100755 (executable)
         $meta .= '<link rel="stylesheet" type="text/css" href="'.$CFG->wwwroot.'/mod/data/css.php?d='.$data->id.'" /> ';
     }
     if ($data->jstemplate) {
-        $meta .= '<script type="text/javascript" src="'.$CFG->wwwroot.'/mod/data/js.php?d='.$data->id.'"></script>';
+        $PAGE->requires->js('mod/data/js.php?d='.$data->id)->in_head();
     }
 
 
index 89eb2a3198ccd1b3e9a9e5dbb5c9ca3f018cee73..9a9328beb44b2135ea38262bb9fd38a31a59ad15 100755 (executable)
@@ -1305,7 +1305,7 @@ function data_print_template($template, $records, $data, $search='', $page=0, $r
  * @return void
  */
 function data_print_preference_form($data, $perpage, $search, $sort='', $order='ASC', $search_array = '', $advanced = 0, $mode= ''){
-    global $CFG, $DB;
+    global $CFG, $DB, $PAGE;
 
     $cm = get_coursemodule_from_instance('data', $data->id);
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -1381,37 +1381,7 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
     else {
         $checked = '';
     }
-    print '
-
-        <script type="text/javascript">
-        //<![CDATA[
-        <!-- Start
-        // javascript for hiding/displaying advanced search form
-
-        function showHideAdvSearch(checked) {
-            var divs = document.getElementsByTagName(\'div\');
-            for(i=0;i<divs.length;i++) {
-                if(divs[i].id.match(\'data_adv_form\')) {
-                    if(checked) {
-                        divs[i].style.display = \'inline\';
-                    }
-                    else {
-                        divs[i].style.display = \'none\';
-                    }
-                }
-                else if (divs[i].id.match(\'reg_search\')) {
-                    if (!checked) {
-                        divs[i].style.display = \'inline\';
-                    }
-                    else {
-                        divs[i].style.display = \'none\';
-                    }
-                }
-            }
-        }
-        //  End -->
-        //]]>
-        </script>';
+    $PAGE->requires->js('mod/data/data.js');
     echo '&nbsp;<input type="hidden" name="advanced" value="0" />';
     echo '&nbsp;<input type="hidden" name="filter" value="1" />';
     echo '&nbsp;<input type="checkbox" id="advancedcheckbox" name="advanced" value="1" '.$checked.' onchange="showHideAdvSearch(this.checked);" /><label for="advancedcheckbox">'.get_string('advancedsearch', 'data').'</label>';
index afe0945d2cd07403dc554fa96154ec7ae7b689a4..a8591808316bb8586741588cdbdd831f3b34c71c 100755 (executable)
     $bodytag .= 'currTextarea = document.getElementById(\'tempform\').template;';
     $bodytag .= '" ';
 
-    // Javascript to insert the field tags into the textarea.
-    $meta = '<script type="text/javascript">'."\n";
-    $meta .= '//<![CDATA['."\n";
-    $meta .= 'function insert_field_tags(selectlist) {';
-    $meta .= '  if (typeof(currEditor) != \'undefined\' && currEditor._editMode == \'wysiwyg\') {';
-        // HTMLArea-specific
-    $meta .= '     currEditor.insertHTML(selectlist.options[selectlist.selectedIndex].value); '; 
-    $meta .= '  } else {';
-        // For inserting when in HTMLArea code view or for normal textareas
-    $meta .= '     insertAtCursor(currTextarea, selectlist.options[selectlist.selectedIndex].value);';   
-    $meta .= '  }'."\n";
-    $meta .= '}'."\n";
-    $meta .= '//]]>'."\n";
-    $meta .= '</script>'."\n";
-    
+    $PAGE->requires->js('mod/data/data.js');
     $navigation = build_navigation('', $cm);
     print_header_simple($data->name, '', $navigation,
-                        '', $meta, true, update_module_button($cm->id, $course->id, get_string('modulename', 'data')),
+                        '', '', true, update_module_button($cm->id, $course->id, get_string('modulename', 'data')),
                         navmenu($course, $cm), '', $bodytag);
 
     print_heading(format_string($data->name));
index 347f2c0e43011640a155c1ab6c5fe7c3015d537f..181e7ac98d654a6a2e69a33f1aaaf9778db7004d 100755 (executable)
         $meta .= '<link rel="stylesheet" type="text/css" href="'.$CFG->wwwroot.'/mod/data/css.php?d='.$data->id.'" /> ';
     }
     if ($data->jstemplate) {
-        $meta .= '<script type="text/javascript" src="'.$CFG->wwwroot.'/mod/data/js.php?d='.$data->id.'"></script>';
+        $PAGE->requires->js('mod/data/js.php?d='.$data->id)->in_head();
     }
 
 /// Print the page header