1 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 * Javascript helper function for wiki
20 * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 M.mod_wiki.init = function(Y, args) {
27 var WikiHelper = function(args) {
28 WikiHelper.superclass.constructor.apply(this, arguments);
30 WikiHelper.NAME = "WIKI";
35 Y.extend(WikiHelper, Y.Base, {
36 initializer: function(args) {
41 M.mod_wiki.renew_lock = function() {
43 sesskey: M.cfg.sesskey,
47 args.section = wiki.section;
49 YUI().use('io', function(Y) {
50 function renewLock() {
51 Y.io('lock.php?' + build_querystring(args), {
55 setInterval(renewLock, wiki.renew_lock_timeout * 1000);
58 M.mod_wiki.history = function(Y, args) {
60 var comparewith = false;
61 var radio = document.getElementsByName('compare');
62 var radio2 = document.getElementsByName('comparewith');
63 for(var i=0; i<radio.length;i++){
68 radio[i].disabled=true;
69 radio2[i].disabled=false;
70 } else if(!compare && comparewith){
71 radio[i].disabled=false;
72 radio2[i].disabled=false;
74 radio[i].disabled=false;
75 radio2[i].disabled=true;
78 if(radio2[i].checked){
84 M.mod_wiki.deleteversion = function(Y, args) {
85 var fromversion = false;
86 var toversion = false;
87 var radio = document.getElementsByName('fromversion');
88 var radio2 = document.getElementsByName('toversion');
89 var length = radio.length;
90 //version to should be more then version from
91 for (var i = 0; i < radio.length; i++) {
92 //if from-version is selected then disable all to-version options after that.
94 radio2[i].disabled = true;
96 radio2[i].disabled = false;
98 //check when to-version option is selected
99 if (radio2[i].checked) {
102 //make sure to-version should be >= from-version
103 if (radio[i].checked) {
106 radio2[i].checked = true;
110 //avoid selecting first and last version
111 if (radio[0].checked && radio2[length-1].checked) {
112 radio2[length - 2].checked = true;
113 } else if(radio[length - 1].checked && radio2[0].checked) {
114 radio2[1].checked = true;
115 radio2[0].disabled = true;
120 M.mod_wiki.init_tree = function(Y, expand_all, htmlid) {
121 Y.use('yui2-treeview', 'node-event-simulate', function(Y) {
122 var tree = new Y.YUI2.widget.TreeView(htmlid);
124 tree.subscribe("clickEvent", function(node, event) {
125 // we want normal clicking which redirects to url
129 tree.subscribe("enterKeyPressed", function(node) {
130 // We want keyboard activation to trigger a click on the first link.
131 Y.one(node.getContentEl()).one('a').simulate('click');