/** * JavaScript functionalitiy for the media management popup * * @author Andreas Gohr * @author Otto Vainio */ linkpage = { keepopen: false, hide: false, /** * Attach event handlers to all "folders" below the given element * * @author Andreas Gohr * @author Otto Vainio */ treeattach: function(obj){ if(!obj) return; var items = obj.getElementsByTagName('li'); for(var i=0; i * @author Otto Vainio */ selectorattach: function(obj){ if(!obj) return; var items = getElementsByClass('select',obj,'a'); for(var i=0; i * @author Otto Vainio */ attachoptions: function(obj){ if(!obj) return; // keep open if(opener){ var kobox = document.createElement('input'); kobox.type = 'checkbox'; kobox.id = 'linkpage__keepopen'; if(DokuCookie.getValue('keepopen')){ kobox.checked = true; kobox.defaultChecked = true; //IE wants this linkpage.keepopen = true; } addEvent(kobox,'click',function(event){ return linkpage.togglekeepopen(event,this); }); var kolbl = document.createElement('label'); kolbl.htmlFor = 'linkpage__keepopen'; kolbl.innerHTML = LANG['keepopen']; var kobr = document.createElement('br'); obj.appendChild(kobox); obj.appendChild(kolbl); obj.appendChild(kobr); } }, /** * Toggles the keep open state * * @author Andreas Gohr */ togglekeepopen: function(event,cb){ if(cb.checked){ DokuCookie.setValue('keepopen',1); linkpage.keepopen = true; }else{ DokuCookie.setValue('keepopen',''); linkpage.keepopen = false; } }, /** * Toggles the hide details state * * @author Andreas Gohr */ togglehide: function(event,cb){ if(cb.checked){ DokuCookie.setValue('hide',1); linkpage.hide = true; }else{ DokuCookie.setValue('hide',''); linkpage.hide = false; } linkpage.updatehide(); }, /** * Sets the visibility of the image details accordingly to the * chosen hide state * * @author Andreas Gohr */ updatehide: function(){ var obj = $('linkpage__content'); if(!obj) return; var details = getElementsByClass('detail',obj,'div'); for(var i=0; i */ select: function(event,link){ var id = link.name.substr(2); var confusesepafield = $('conf__use_sepa'); var confusesepa = confusesepafield.value; var sepa = ''; if (confusesepa==1) { sepa='|'; } if (confusesepa==0) { sepa=''; } if(!opener){ // if we don't run in popup display example var ex = $('ex_'+id); if(ex.style.display == ''){ ex.style.display = 'none'; }else{ ex.style.display = ''; } return false; } opener.insertTags('wiki__text','[[:'+id+sepa,']]',''); if(!linkpage.keepopen) window.close(); opener.focus(); return false; }, selectnew: function(event,link){ // var id = link.value; var submit = $('newpage__name'); var id = submit.value; var nsfield = $('newpage__ns'); var confusesepafield = $('conf__use_sepa'); var confusesepa = confusesepafield.value; var sepa = ''; if (confusesepa==1) { sepa='|'; } if (confusesepa==0) { sepa=''; } var ns = nsfield.value; if (ns) { ns = ns + ':'; } if(!opener){ // if we don't run in popup display example var ex = $('ex_'+id); if(ex.style.display == ''){ ex.style.display = 'none'; }else{ ex.style.display = ''; } return false; } opener.insertTags('wiki__text','[[:'+ns+id+sepa,']]',''); if(!linkpage.keepopen) window.close(); opener.focus(); return false; }, /** * list the content of a namespace using AJAX * * @author Andreas Gohr */ list: function(event,link){ // prepare an AJAX call to fetch the subtree var ajax = new sack(DOKU_BASE + 'lib/plugins/linkmanager/exe/ajax.php'); ajax.AjaxFailedAlert = ''; ajax.encodeURIString = false; if(ajax.failed) return true; cleanMsgArea(); var content = $('linkpage__content'); content.innerHTML = '...'; ajax.elementObj = content; ajax.afterCompletion = function(){ linkpage.selectorattach(content); linkpage.updatehide(); reinitsort(); }; ajax.runAJAX(link.search.substr(1)+'&call=linkpagelist'); return false; }, /** * Open or close a subtree using AJAX * * @author Andreas Gohr */ toggle: function(event,clicky){ var listitem = clicky.parentNode; // if already open, close by removing the sublist var sublists = listitem.getElementsByTagName('ul'); if(sublists.length){ listitem.removeChild(sublists[0]); clicky.src = DOKU_BASE+'lib/images/plus.gif'; return false; } // get the enclosed link (is always the first one) var link = listitem.getElementsByTagName('a')[0]; // prepare an AJAX call to fetch the subtree var ajax = new sack(DOKU_BASE + 'lib/plugins/linkmanager/exe/ajax.php'); ajax.AjaxFailedAlert = ''; ajax.encodeURIString = false; if(ajax.failed) return true; //prepare the new ul var ul = document.createElement('ul'); //fixme add classname here listitem.appendChild(ul); ajax.elementObj = ul; ajax.afterCompletion = function(){ linkpage.treeattach(ul); }; ajax.runAJAX(link.search.substr(1)+'&call=linkpagens'); clicky.src = DOKU_BASE+'lib/images/minus.gif'; return false; } }; addInitEvent(function(){ linkpage.treeattach($('linkpage__tree')); linkpage.selectorattach($('linkpage__content')); linkpage.attachoptions($('linkpage__opts')); }); //if(toolbar){ if(window.toolbar!=undefined){ toolbar[toolbar.length] = {"type":"mediapopup", "title":"links", "icon":"../../plugins/linkmanager/images/page_link.png", "key":"", "name":"linknameselect", "url":DOKU_BASE+"lib/plugins/linkmanager/exe/filemanager.php?ns=", "options":"width=750,height=500,left=20,top=20,scrollbars=yes,resizable=yes" }; } function reinitsort() { sorttable.reinit(); }