FCKCommands.RegisterCommand('Wikilink',new FCKDialogCommand('Wikilink',FCKLang.WikilinkDlgTitle,FCKPlugins.Items['wikilink'].Path+'fck_wikilink.html',350,250));var oPlaceholderItem=new FCKToolbarButton('Wikilink',FCKLang.WikilinkBtn);oPlaceholderItem.IconPath=FCKPlugins.Items['wikilink'].Path+'wikilink.gif';FCKToolbarItems.RegisterItem('Wikilink',oPlaceholderItem);var FCKPlaceholders={};FCKPlaceholders.Add=function(A){var B=FCK.InsertElement('span');this.SetupSpan(B,A);};FCKPlaceholders.SetupSpan=function(A,B){A.innerHTML='[[ '+B+' ]]';A.style.backgroundColor='#ffff00';A.style.color='#000000';if (FCKBrowserInfo.IsGecko) A.style.cursor='default';A._fckplaceholder=B;A.contentEditable=false;A.onresizestart=function(){FCK.EditorWindow.event.returnValue=false;return false;}};FCKPlaceholders._SetupClickListener=function(){FCKPlaceholders._ClickListener=function(e){if (e.target.tagName=='SPAN'&&e.target._fckplaceholder) FCKSelection.SelectNode(e.target);};FCK.EditorDocument.addEventListener('click',FCKPlaceholders._ClickListener,true);};FCK.ContextMenu.RegisterListener({AddItems:function (A,B,C){if (!B){return;};if (B.nodeName.IEquals('span')&&B._fckplaceholder){A.AddSeparator();A.AddItem('Wikilink',FCKLang.WikilinkDlgTitle,FCKConfig.PluginsPath+'wikilink/wikilink.gif');}} });FCKPlaceholders.OnDoubleClick=function(A){if (A.tagName=='SPAN'&&A._fckplaceholder) FCKCommands.GetCommand('Wikilink').Execute();};FCK.RegisterDoubleClickHandler(FCKPlaceholders.OnDoubleClick,'SPAN');FCKPlaceholders.Exist=function(A){var B=FCK.EditorDocument.getElementsByTagName('SPAN');for (var i=0;i<B.length;i++){if (B[i]._fckplaceholder==A) return true;};return false;};if (FCKBrowserInfo.IsIE){FCKPlaceholders.Redraw=function(){if (FCK.EditMode!=FCK_EDITMODE_WYSIWYG) return;var A=FCK.EditorDocument.body.innerText.match(/\[\[[^\[\]]+\]\]/g);if (!A) return;var B=FCK.EditorDocument.body.createTextRange();for (var i=0;i<A.length;i++){if (B.findText(A[i])){var C=A[i].match(/\[\[\s*([^\]]*?)\s*\]\]/)[1];B.pasteHTML('<span style="color: #000000; background-color: #ffff00" contenteditable="false" _fckplaceholder="'+C+'">'+A[i]+'</span>');}}}}else{FCKPlaceholders.Redraw=function(){if (FCK.EditMode!=FCK_EDITMODE_WYSIWYG) return;var A=FCK.EditorDocument.createTreeWalker(FCK.EditorDocument.body,NodeFilter.SHOW_TEXT,FCKPlaceholders._AcceptNode,true);var	B=[];while ((oNode=A.nextNode())){B[B.length]=oNode;};for (var n=0;n<B.length;n++){var C=B[n].nodeValue.split(/(\[\[[^\[\]]+\]\])/g);for (var i=0;i<C.length;i++){if (C[i].length>0){if (C[i].indexOf('[[')==0){var D=C[i].match(/\[\[\s*([^\]]*?)\s*\]\]/)[1];var E=FCK.EditorDocument.createElement('span');FCKPlaceholders.SetupSpan(E,D);B[n].parentNode.insertBefore(E,B[n]);}else B[n].parentNode.insertBefore(FCK.EditorDocument.createTextNode(C[i]),B[n]);}};B[n].parentNode.removeChild(B[n]);};FCKPlaceholders._SetupClickListener();};FCKPlaceholders._AcceptNode=function(A){if (/\[\[[^\[\]]+\]\]/.test(A.nodeValue)) return NodeFilter.FILTER_ACCEPT;else return NodeFilter.FILTER_SKIP;}};FCK.Events.AttachEvent('OnAfterSetHTML',FCKPlaceholders.Redraw);FCKXHtml.TagProcessors['span']=function(A,B){if (B._fckplaceholder) A=FCKXHtml.XML.createTextNode('[['+B._fckplaceholder+']]');else FCKXHtml._AppendChildNodes(A,B,false);return A;};
