2
* JavaScript functionalitiy for the media management popup
4
* @author Andreas Gohr <andi@splitbrain.org>
11
* Attach event handlers to all "folders" below the given element
13
* @author Andreas Gohr <andi@splitbrain.org>
15
treeattach: function(obj){
18
var items = obj.getElementsByTagName('li');
19
for(var i=0; i<items.length; i++){
22
// attach action to make the +/- clickable
23
var clicky = elem.getElementsByTagName('img')[0];
24
clicky.style.cursor = 'pointer';
25
addEvent(clicky,'click',function(event){ return media.toggle(event,this); });
27
// attach action load folder list via AJAX
28
var link = elem.getElementsByTagName('a')[0];
29
link.style.cursor = 'pointer';
30
addEvent(link,'click',function(event){ return media.list(event,this); });
35
* Attach the image selector action to all links below the given element
36
* also add the action to autofill the "upload as" field
38
* @author Andreas Gohr <andi@splitbrain.org>
40
selectorattach: function(obj){
43
var items = getElementsByClass('select',obj,'a');
44
for(var i=0; i<items.length; i++){
46
elem.style.cursor = 'pointer';
47
addEvent(elem,'click',function(event){ return media.select(event,this); });
50
// hide syntax example
51
items = getElementsByClass('example',obj,'div');
52
for(var i=0; i<items.length; i++){
54
elem.style.display = 'none';
57
var file = $('upload__file');
59
addEvent(file,'change',media.suggest);
63
* Creates checkboxes for additional options
65
* @author Andreas Gohr <andi@splitbrain.org>
67
attachoptions: function(obj){
72
var kobox = document.createElement('input');
73
kobox.type = 'checkbox';
74
kobox.id = 'media__keepopen';
75
if(DokuCookie.getValue('keepopen')){
77
kobox.defaultChecked = true; //IE wants this
78
media.keepopen = true;
80
addEvent(kobox,'click',function(event){ return media.togglekeepopen(event,this); });
82
var kolbl = document.createElement('label');
83
kolbl.htmlFor = 'media__keepopen';
84
kolbl.innerHTML = LANG['keepopen'];
86
var kobr = document.createElement('br');
88
obj.appendChild(kobox);
89
obj.appendChild(kolbl);
90
obj.appendChild(kobr);
94
var hdbox = document.createElement('input');
95
hdbox.type = 'checkbox';
96
hdbox.id = 'media__hide';
97
if(DokuCookie.getValue('hide')){
99
hdbox.defaultChecked = true; //IE wants this
102
addEvent(hdbox,'click',function(event){ return media.togglehide(event,this); });
104
var hdlbl = document.createElement('label');
105
hdlbl.htmlFor = 'media__hide';
106
hdlbl.innerHTML = LANG['hidedetails'];
108
var hdbr = document.createElement('br');
110
obj.appendChild(hdbox);
111
obj.appendChild(hdlbl);
112
obj.appendChild(hdbr);
117
* Toggles the keep open state
119
* @author Andreas Gohr <andi@splitbrain.org>
121
togglekeepopen: function(event,cb){
123
DokuCookie.setValue('keepopen',1);
124
media.keepopen = true;
126
DokuCookie.setValue('keepopen','');
127
media.keepopen = false;
132
* Toggles the hide details state
134
* @author Andreas Gohr <andi@splitbrain.org>
136
togglehide: function(event,cb){
138
DokuCookie.setValue('hide',1);
141
DokuCookie.setValue('hide','');
148
* Sets the visibility of the image details accordingly to the
151
* @author Andreas Gohr <andi@splitbrain.org>
153
updatehide: function(){
154
var obj = $('media__content');
156
var details = getElementsByClass('detail',obj,'div');
157
for(var i=0; i<details.length; i++){
159
details[i].style.display = 'none';
161
details[i].style.display = '';
167
* Insert the clicked image into the opener's textarea
169
* @author Andreas Gohr <andi@splitbrain.org>
171
select: function(event,link){
172
var id = link.name.substr(2);
175
// if we don't run in popup display example
176
var ex = $('ex_'+id);
177
if(ex.style.display == ''){
178
ex.style.display = 'none';
180
ex.style.display = '';
184
opener.insertTags('wiki__text','{{'+id+'|','}}','');
186
if(!media.keepopen) window.close();
192
* list the content of a namespace using AJAX
194
* @author Andreas Gohr <andi@splitbrain.org>
196
list: function(event,link){
197
// prepare an AJAX call to fetch the subtree
198
var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php');
199
ajax.AjaxFailedAlert = '';
200
ajax.encodeURIString = false;
201
if(ajax.failed) return true;
205
var content = $('media__content');
206
content.innerHTML = '<img src="'+DOKU_BASE+'lib/images/loading.gif" alt="..." class="load" />';
208
ajax.elementObj = content;
209
ajax.afterCompletion = function(){
210
media.selectorattach(content);
213
ajax.runAJAX(link.search.substr(1)+'&call=medialist');
219
* Open or close a subtree using AJAX
221
* @author Andreas Gohr <andi@splitbrain.org>
223
toggle: function(event,clicky){
224
var listitem = clicky.parentNode;
226
// if already open, close by removing the sublist
227
var sublists = listitem.getElementsByTagName('ul');
229
listitem.removeChild(sublists[0]);
230
clicky.src = DOKU_BASE+'lib/images/plus.gif';
234
// get the enclosed link (is always the first one)
235
var link = listitem.getElementsByTagName('a')[0];
237
// prepare an AJAX call to fetch the subtree
238
var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php');
239
ajax.AjaxFailedAlert = '';
240
ajax.encodeURIString = false;
241
if(ajax.failed) return true;
244
var ul = document.createElement('ul');
245
//fixme add classname here
246
listitem.appendChild(ul);
247
ajax.elementObj = ul;
248
ajax.afterCompletion = function(){ media.treeattach(ul); };
249
ajax.runAJAX(link.search.substr(1)+'&call=medians');
250
clicky.src = DOKU_BASE+'lib/images/minus.gif';
255
* Prefills the wikiname.
257
* @author Andreas Gohr <andi@splitbrain.org>
260
var file = $('upload__file');
261
var name = $('upload__name');
262
if(!file || !name) return;
264
var text = file.value;
265
text = text.substr(text.lastIndexOf('/')+1);
266
text = text.substr(text.lastIndexOf('\\')+1);
272
addInitEvent(function(){
273
media.treeattach($('media__tree'));
274
media.selectorattach($('media__content'));
275
media.attachoptions($('media__opts'));