MDL-23930 fixed javascript insert into tinymce
[moodle.git] / mod / data / data.js
CommitLineData
9d0cffa5 1/**
2 * Javascript to insert the field tags into the textarea.
3 * Used when editing a data template
4 */
5function insert_field_tags(selectlist) {
b83f54f8
DC
6 var value = selectlist.options[selectlist.selectedIndex].value;
7 var editorname = 'template';
8 if (typeof tinyMCE == 'undefined') {
9 var element = document.getElementsByName(editorname)[0];
10 // For inserting when in normal textareas
11 insertAtCursor(element, value);
12 } else {
13 tinyMCE.execInstanceCommand(editorname, 'mceInsertContent', false, value);
14 }
9d0cffa5 15}
16
17/**
18 * javascript for hiding/displaying advanced search form when viewing
19 */
20function showHideAdvSearch(checked) {
21 var divs = document.getElementsByTagName('div');
22 for(i=0;i<divs.length;i++) {
23 if(divs[i].id.match('data_adv_form')) {
24 if(checked) {
25 divs[i].style.display = 'inline';
26 }
27 else {
28 divs[i].style.display = 'none';
29 }
30 }
31 else if (divs[i].id.match('reg_search')) {
32 if (!checked) {
33 divs[i].style.display = 'inline';
34 }
35 else {
36 divs[i].style.display = 'none';
37 }
38 }
39 }
26032c2d
DC
40}
41
42M.data_filepicker = {};
43
e4256380
DC
44
45M.data_filepicker.callback = function(params) {
46 var html = '<a href="'+params['url']+'">'+params['file']+'</a>';
47 document.getElementById('file_info_'+params['client_id']).innerHTML = html;
48};
49
50/**
51 * This fucntion is called for each file picker on page.
52 */
26032c2d
DC
53M.data_filepicker.init = function(Y, options) {
54 options.formcallback = M.data_filepicker.callback;
55 if (!M.core_filepicker.instances[options.client_id]) {
9d8de346 56 M.core_filepicker.init(Y, options);
26032c2d
DC
57 }
58 Y.on('click', function(e, client_id) {
59 e.preventDefault();
60 M.core_filepicker.instances[client_id].show();
61 }, '#filepicker-button-'+options.client_id, null, options.client_id);
62
e4256380
DC
63 var item = document.getElementById('nonjs-filepicker-'+options.client_id);
64 if (item) {
65 item.parentNode.removeChild(item);
66 }
67 item = document.getElementById('filepicker-wrapper-'+options.client_id);
68 if (item) {
69 item.style.display = '';
70 }
26032c2d
DC
71};
72
e4256380
DC
73M.data_urlpicker = {};
74
75M.data_urlpicker.init = function(Y, options) {
e4256380
DC
76 options.formcallback = M.data_urlpicker.callback;
77 if (!M.core_filepicker.instances[options.client_id]) {
9d8de346 78 M.core_filepicker.init(Y, options);
e4256380
DC
79 }
80 Y.on('click', function(e, client_id) {
81 e.preventDefault();
82 M.core_filepicker.instances[client_id].show();
83 }, '#filepicker-button-'+options.client_id, null, options.client_id);
84
85};
86
87M.data_urlpicker.callback = function (params) {
cd4a1897 88 document.getElementById('field_url_'+params.client_id).value = params.url;
9d8de346 89};
e4256380
DC
90
91M.data_imagepicker = {};
92
e4256380
DC
93M.data_imagepicker.callback = function(params) {
94 var html = '<a href="'+params['url']+'"><img src="'+params['url']+'" /> '+params['file']+'</a>';
95 document.getElementById('file_info_'+params['client_id']).innerHTML = html;
96};
97
98/**
99 * This fucntion is called for each file picker on page.
100 */
101M.data_imagepicker.init = function(Y, options) {
102 options.formcallback = M.data_imagepicker.callback;
103 if (!M.core_filepicker.instances[options.client_id]) {
9d8de346 104 M.core_filepicker.init(Y, options);
e4256380
DC
105 }
106 Y.on('click', function(e, client_id) {
107 e.preventDefault();
108 M.core_filepicker.instances[client_id].show();
109 }, '#filepicker-button-'+options.client_id, null, options.client_id);
110
111 var item = document.getElementById('nonjs-filepicker-'+options.client_id);
112 if (item) {
113 item.parentNode.removeChild(item);
114 }
115 item = document.getElementById('filepicker-wrapper-'+options.client_id);
116 if (item) {
117 item.style.display = '';
118 }
119};