MDL-41030 Behat: Add support for waiting for javascript
[moodle.git] / mod / wiki / module.js
CommitLineData
00710f4c
DC
1// This file is part of Moodle - http://moodle.org/
2//
3// Moodle is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// Moodle is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15
16/**
17 * Javascript helper function for wiki
18 *
19 * @package mod-wiki
20 * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23
24M.mod_wiki = {};
25
26M.mod_wiki.init = function(Y, args) {
27 var WikiHelper = function(args) {
28 WikiHelper.superclass.constructor.apply(this, arguments);
29 }
30 WikiHelper.NAME = "WIKI";
31 WikiHelper.ATTRS = {
32 options: {},
33 lang: {}
34 };
35 Y.extend(WikiHelper, Y.Base, {
36 initializer: function(args) {
37 }
38 });
39 new WikiHelper(args);
40};
41M.mod_wiki.renew_lock = function(Y, args) {
42 function renewLock() {
d2807da8
DC
43 var args = {};
44 args['sesskey'] = M.cfg.sesskey;
45 args['pageid'] = wiki.pageid;
00710f4c 46 if (wiki.section) {
d2807da8 47 args['section'] = wiki.section;
00710f4c
DC
48 }
49 var callback = {};
5f573e8e
PS
50 Y.use('yui2-connection', function(Y) {
51 Y.YUI2.util.Connect.asyncRequest('GET', 'lock.php?' + build_querystring(args), callback);
52 });
00710f4c
DC
53 }
54 setInterval(renewLock, wiki.renew_lock_timeout * 1000);
55}
56M.mod_wiki.history = function(Y, args) {
57 var compare = false;
58 var comparewith = false;
59 var radio = document.getElementsByName('compare');
60 var radio2 = document.getElementsByName('comparewith');
61 for(var i=0; i<radio.length;i++){
62 if(radio[i].checked){
63 compare = true;
64 }
65 if(!comparewith){
66 radio[i].disabled=true;
67 radio2[i].disabled=false;
68 } else if(!compare && comparewith){
69 radio[i].disabled=false;
70 radio2[i].disabled=false;
71 } else {
72 radio[i].disabled=false;
73 radio2[i].disabled=true;
74 }
75
76 if(radio2[i].checked){
77 comparewith = true;
78 }
79 }
80}
12c9bbbd 81
ac0a82cf
RT
82M.mod_wiki.deleteversion = function(Y, args) {
83 var fromversion = false;
84 var toversion = false;
85 var radio = document.getElementsByName('fromversion');
86 var radio2 = document.getElementsByName('toversion');
87 var length = radio.length;
88 //version to should be more then version from
89 for (var i = 0; i < radio.length; i++) {
90 //if from-version is selected then disable all to-version options after that.
91 if (fromversion) {
92 radio2[i].disabled = true;
93 } else {
94 radio2[i].disabled = false;
95 }
96 //check when to-version option is selected
97 if (radio2[i].checked) {
98 toversion = true;
99 }
100 //make sure to-version should be >= from-version
101 if (radio[i].checked) {
102 fromversion = true;
103 if (!toversion) {
104 radio2[i].checked = true;
105 }
106 }
107 }
108 //avoid selecting first and last version
109 if (radio[0].checked && radio2[length-1].checked) {
110 radio2[length - 2].checked = true;
111 } else if(radio[length - 1].checked && radio2[0].checked) {
112 radio2[1].checked = true;
113 radio2[0].disabled = true;
114 toversion = true;
115 }
116}
117
12c9bbbd
DC
118M.mod_wiki.init_tree = function(Y, expand_all, htmlid) {
119 Y.use('yui2-treeview', function(Y) {
5f573e8e 120 var tree = new Y.YUI2.widget.TreeView(htmlid);
12c9bbbd
DC
121
122 tree.subscribe("clickEvent", function(node, event) {
123 // we want normal clicking which redirects to url
124 return false;
125 });
126
127 if (expand_all) {
128 tree.expandAll();
129 }
130
131 tree.render();
132 });
133};