text: tinymce.PluginManager.add("link",function(t){function e(e){return function(){var n=t.settings.link_list;"string"==typeof n?tinymce.util.XHR.send({url:n,success:function(t){e(tinymce.util.JSON.parse(t))}}):e(n)}}function n(e){function n(t){var e=d.find("#text");(!e.value()||t.lastControl&&e.value()==t.lastControl.text())&&e.value(t.control.text()),d.find("#href").value(t.control.value())}function l(){var t=[{text:"None",value:""}];return tinymce.each(e,function(e){t.push({text:e.text||e.title,value:e.value||e.url,menu:e.menu})}),t}function i(e){var n=[{text:"None",value:""}];return tinymce.each(t.settings.rel_list,function(t){n.push({text:t.text||t.title,value:t.value,selected:e===t.value})}),n}function a(e){var n=[{text:"None",value:""}];return t.settings.target_list||n.push({text:"New window",value:"_blank"}),tinymce.each(t.settings.target_list,function(t){n.push({text:t.text||t.title,value:t.value,selected:e===t.value})}),n}function r(e){var l=[];return tinymce.each(t.dom.select("a:not([href])"),function(t){var n=t.name||t.id;n&&l.push({text:n,value:"#"+n,selected:-1!=e.indexOf("#"+n)})}),l.length?(l.unshift({text:"None",value:""}),{name:"anchor",type:"listbox",label:"Anchors",values:l,onselect:n}):void 0}function o(){c||0!==v.text.length||this.parent().parent().find("#text")[0].value(this.value())}var u,s,c,d,f,h,x,v={},g=t.selection,m=t.dom;u=g.getNode(),s=m.getParent(u,"a[href]"),s&&g.select(s),v.text=c=g.getContent({format:"text"}),v.href=s?m.getAttrib(s,"href"):"",v.target=s?m.getAttrib(s,"target"):"",v.rel=s?m.getAttrib(s,"rel"):"","IMG"==u.nodeName&&(v.text=c=" "),e&&(f={type:"listbox",label:"Link list",values:l(),onselect:n}),t.settings.target_list!==!1&&(x={name:"target",type:"listbox",label:"Target",values:a(v.target)}),t.settings.rel_list&&(h={name:"rel",type:"listbox",label:"Rel",values:i(v.rel)}),d=t.windowManager.open({title:"Insert link",data:v,body:[{name:"href",type:"filepicker",filetype:"file",size:40,autofocus:!0,label:"Url",onchange:o,onkeyup:o},{name:"text",type:"textbox",size:40,label:"Text to display",onchange:function(){v.text=this.value()}},r(v.href),f,h,x],onSubmit:function(e){function n(e,n){window.setTimeout(function(){t.windowManager.confirm(e,n)},0)}function l(){i.text!=c?s?(t.focus(),s.innerHTML=i.text,m.setAttribs(s,{href:a,target:i.target?i.target:null,rel:i.rel?i.rel:null}),g.select(s)):t.insertContent(m.createHTML("a",{href:a,target:i.target?i.target:null,rel:i.rel?i.rel:null},i.text)):t.execCommand("mceInsertLink",!1,{href:a,target:i.target,rel:i.rel?i.rel:null})}var i=e.data,a=i.href;return a?a.indexOf("@")>0&&-1==a.indexOf("//")&&-1==a.indexOf("mailto:")?(n("The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?",function(t){t&&(a="mailto:"+a),l()}),void 0):/^\s*www\./i.test(a)?(n("The URL you entered seems to be an external link. Do you want to add the required http:// prefix?",function(t){t&&(a="http://"+a),l()}),void 0):(l(),void 0):(t.execCommand("unlink"),void 0)}})}t.addButton("link",{icon:"link",tooltip:"Insert/edit link",shortcut:"Ctrl+K",onclick:e(n),stateSelector:"a[href]"}),t.addButton("unlink",{icon:"unlink",tooltip:"Remove link",cmd:"unlink",stateSelector:"a[href]"}),t.addShortcut("Ctrl+K","",e(n)),this.showDialog=n,t.addMenuItem("link",{icon:"link",text:"Insert link",shortcut:"Ctrl+K",onclick:e(n),stateSelector:"a[href]",context:"insert",prependToContext:!0})});