-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
155 lines (136 loc) · 4.34 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* DOKUWIKI:include_once vendor/pnotify/jquery.pnotify.js */
/**
* DokuWiki Plugin ajaxedit (JavaScript Component)
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author lisps
*/
var LASTMOD = JSINFO?JSINFO['lastmod']:null;
jQuery.pnotify.defaults.styling = "jqueryui";
jQuery.pnotify.defaults.delay = 2000;
jQuery.pnotify.defaults.history = false;
var ajaxedit_queue_ = [];
var ajaxedit_queue_working = false;
function ajaxedit_queue(callback) {
ajaxedit_queue_.push(callback);
if(!ajaxedit_queue_working) {
ajaxedit_queue_working = true;
ajaexedit_queue_next();
}
}
function ajaexedit_queue_next(){
var c = ajaxedit_queue_.pop();
if(c) c();
else ajaxedit_queue_working = false;
}
function ajaxedit_send_(url,data,fcnSuccess) {
data['lastmod']=LASTMOD;
jQuery.post(
url,
data,
function(data) {
fcnSuccess(data);
ajaexedit_queue_next();
}
);
}
/**
* ajaxedit_send is a wrapper for jQuery's post function
* it automatically adds the current pageid, lastmod and the security token
*
* @param string plugin plugin name
* @param int idx_tag the id counter
* @param function fcnSuccess callback function
* @param hash data additional data
*/
function ajaxedit_send(plugin,idx_tag,fcnSuccess,data){
data['pageid']=data['pageid']?data['pageid']:JSINFO['id'];
data['sectok']=JSINFO['sectok'];
data['id']=idx_tag;
data['index']=idx_tag;
var url = DOKU_BASE+'lib/plugins/'+plugin+'/ajax.php';
ajaxedit_queue(function(){ajaxedit_send_(url,data,fcnSuccess)});
}
/**
* ajaxedit_send is a wrapper for jQuery's post function
* it automatically adds the current pageid, lastmod and the security token
*
* @param string plugin plugin name
* @param int idx_tag the id counter
* @param function fcnSuccess callback function
* @param hash data additional data
*/
function ajaxedit_send2(plugin,idx_tag,fcnSuccess,data){
data['pageid']=data['pageid']?data['pageid']:JSINFO['id'];
data['sectok']=JSINFO['sectok'];
data['id']=idx_tag;
data['index']=idx_tag;
data['call']='plugin_'+plugin;
var url = DOKU_BASE+'lib/exe/ajax.php';
ajaxedit_queue(function(){ajaxedit_send_(url,data,fcnSuccess)});
}
/**
* ajaxedit_parse simply parses the json response using JSON.parse()
*
* @param json data
* @return mixed false if there is no data/ the response
*/
function ajaxedit_parse(data){
if(!data) return false;
return JSON.parse(data);
}
/**
* ajaxedit_checkResponse checks if the server error flag is set and displays a jQuery Dialog, with the Message
*
* @param hash response the parsed @see ajaxedit_parse server response
* @return boolean false on error
*/
function ajaxedit_checkResponse(response){
if(response.error != 0) {
if(jQuery('#ajaxedit__dialog')){
jQuery('body').append('<div id="ajaxedit__dialog" position="absolute" border=1 ><div id="ajaxedit__dialog_div"></div></div>');
jQuery( "#ajaxedit__dialog" ).dialog({title:'Error',height:300,width:400,autoOpen:true,modal:true});
}
jQuery('#ajaxedit__dialog_div').html(response.msg);
return false;
} else if(response.msg){
jQuery.pnotify({
title: false,
text: response.msg?response.msg:'gespeichert',
type: 'success',
icon: false,
delay: response.notifyDelay?response.notifyDelay*1000:2000,
animate_speed: 100,
animation: {
effect_in:'bounce',
effect_out:'drop',
}
});
}
if(response.pageid === JSINFO['id']) LASTMOD = response.lastmod; //refresh LASTMOD
return true;
}
function ajaxedit_getIdxByIdClass(id,classname) {
var tag_type = jQuery("#"+id).prop('tagName');
id = jQuery("#"+id).attr('id');
var $els = jQuery(tag_type+"."+classname);
for(var ii=0, kk=0; ii < $els.length; ii++){
if($els[ii].id == id) return kk;
kk++;
}
}
function ajaxedit_getIdxByIdClassNodeid(id,classname,nodeid) {
var tag_type = jQuery("#"+id).prop('tagName');
id = jQuery("#"+id).attr('id');
var $els = jQuery('#'+nodeid +" > "+tag_type+"."+classname);
for(var ii=0; ii<$els.length; ii++){
if($els[ii].id == id) {
return ii;
}
}
}
jQuery(window).on('beforeunload',function(e){
if(ajaxedit_queue_working) {
return LANG.plugins.ajaxedit.tasks_left.replace('{0}',(ajaxedit_queue_.length *1 +1)) ;
}
});