
/**************************************
    Webutler V3.0 - www.webutler.de
    Copyright (c) 2008 - 2014
    Autor: Sven Zinke
    Free for any use
    Lizenz: GPL
**************************************/

CKEDITOR.dialog.add('sortmenu',function(editor)
{function loadTreeMenu(list){if(!String.prototype.trim){String.prototype.trim=function(){return this.replace(/^\s*|\s*$/g,"");};}
var LIs=list.getElementsByTagName('li');var ulid=0;for(var i=0;i<LIs.length;i++){var text='';var newDiv=document.createElement('div');var divContent;if(LIs[i].parentNode.id.substring(0,8)!='savedUL_'){divContent=document.getElementById('treemenu_newMenu').appendChild(newDiv);}
else{divContent=document.getElementById(LIs[i].parentNode.id+'_D').appendChild(newDiv);}
var uDiv=document.createElement('div');var uCont=document.getElementById('treemenu_subDiv').appendChild(uDiv);var elms=LIs[i].cloneNode(true);if(LIs[i].getElementsByTagName('ul').length>0){var docorfolder='folder';for(var k=0;k<elms.getElementsByTagName('ul').length;k++){ulid=parseInt(ulid+1);LIs[i].getElementsByTagName('ul')[k].id='savedUL_'+ulid;divContent.id='savedUL_'+ulid+'_D';elms.getElementsByTagName('ul')[k].innerHTML='';}}
else{var docorfolder='doc';}
uCont.appendChild(elms);divContent.setAttribute('class',docorfolder);divContent.setAttribute('savedtags',escape(uCont.innerHTML));document.getElementById('treemenu_subDiv').innerHTML='';if(LIs[i].hasChildNodes()){text=getTextNode(LIs[i]);}
divContent.innerHTML=text;}};function getTextNode(node){var res='';if(node.nodeType==3){res+=node.nodeValue.trim();}
if(node.hasChildNodes()){for(var i=0;i<node.childNodes.length;i++){newnode=node.childNodes[i];if(newnode.nodeName!='LI'){res+=getTextNode(newnode);}}}
return res;};function loadTreeElements(loadMenu)
{if(CKEDITOR.env.ie){ckeMenu=loadMenu.getOuterHtml().replace(/href=["']([^"']*)["']/g,'href="dynamictree://dynamictree/$1"');}
else{ckeMenu=loadMenu.getOuterHtml();}
document.getElementById('treemenu_savedMenu').innerHTML=ckeMenu;orgMenu=document.getElementById('treemenu_savedMenu');if(orgMenu.getElementsByTagName('ul')[0])
loadTreeMenu(orgMenu.getElementsByTagName('ul')[0]);else
return;var divarray=document.getElementById('treemenu_newMenu').getElementsByTagName('div');for(var d=0;d<divarray.length;d++){if(divarray[d].id!=''){divarray[d].removeAttribute('id');}}};function reset_treemenu()
{document.getElementById('treemenu_savedMenu').innerHTML='';document.getElementById('treemenu_newMenu').innerHTML='';document.getElementById('treemenubuilder').innerHTML='';treemenubuilder=null;};var loadMenu;var ckeMenu;var orgMenu;var imgpath=CKEDITOR.plugins.getPath('sortmenu')+'dialogs/images/';return{title:editor.lang.sortmenu.title,minWidth:300,minHeight:300,onShow:function()
{loadMenu='';orgMenu='';treemenubuilder=new DynamicTreeBuilder('treemenubuilder',imgpath);treemenubuilder.init();DynamicTreePlugins.call(treemenubuilder);var startelement=editor.getSelection().getStartElement();var rootlist=startelement.getParents();for(var i=0;i<rootlist.length;i++){if(rootlist[i].getName()=='ul'){loadMenu=rootlist[i];editor.getSelection().fake(rootlist[i]);break;}}
if(loadMenu!=''){loadTreeElements(loadMenu);treemenubuilder.importFromHtml(document.getElementById('treemenu_newMenu').innerHTML);}},onCancel:function()
{reset_treemenu();},onOk:function()
{orgMenu.getElementsByTagName('ul')[0].innerHTML=treemenubuilder.exportToHtml();if(CKEDITOR.env.ie){var aTags=orgMenu.getElementsByTagName('a');for(var i=0;i<aTags.length;i++){var str=aTags[i].parentNode.innerHTML.match(/href=["'](dynamictree:\/\/dynamictree\/)?([^"']*)["']/i);if(str)
aTags[i].href=str[2];}}
var newMenu=orgMenu.innerHTML.replace(/<!--\?/gi,'<\?').replace(/\?-->/gi,'\?>');editor.insertHtml(newMenu);reset_treemenu();},contents:[{id:'tab1',label:'',title:'',elements:[{type:'html',html:loadTreeHTML(imgpath,editor)}]}]}});