init
This commit is contained in:
303
public/tinymce/plugins/link/plugin.js
Normal file
303
public/tinymce/plugins/link/plugin.js
Normal file
@ -0,0 +1,303 @@
|
||||
/**
|
||||
* plugin.js
|
||||
*
|
||||
* Copyright, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/*global tinymce:true */
|
||||
|
||||
tinymce.PluginManager.add('link', function(editor) {
|
||||
function createLinkList(callback) {
|
||||
return function() {
|
||||
var linkList = editor.settings.link_list;
|
||||
|
||||
if (typeof(linkList) == "string") {
|
||||
tinymce.util.XHR.send({
|
||||
url: linkList,
|
||||
success: function(text) {
|
||||
callback(tinymce.util.JSON.parse(text));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback(linkList);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function showDialog(linkList) {
|
||||
var data = {}, selection = editor.selection, dom = editor.dom, selectedElm, anchorElm, initialText;
|
||||
var win, linkListCtrl, relListCtrl, targetListCtrl;
|
||||
|
||||
function linkListChangeHandler(e) {
|
||||
var textCtrl = win.find('#text');
|
||||
|
||||
if (!textCtrl.value() || (e.lastControl && textCtrl.value() == e.lastControl.text())) {
|
||||
textCtrl.value(e.control.text());
|
||||
}
|
||||
|
||||
win.find('#href').value(e.control.value());
|
||||
}
|
||||
|
||||
function buildLinkList() {
|
||||
var linkListItems = [{text: 'None', value: ''}];
|
||||
|
||||
tinymce.each(linkList, function(link) {
|
||||
linkListItems.push({
|
||||
text: link.text || link.title,
|
||||
value: editor.convertURL(link.value || link.url, 'href'),
|
||||
menu: link.menu
|
||||
});
|
||||
});
|
||||
|
||||
return linkListItems;
|
||||
}
|
||||
|
||||
function buildRelList(relValue) {
|
||||
var relListItems = [{text: 'None', value: ''}];
|
||||
|
||||
tinymce.each(editor.settings.rel_list, function(rel) {
|
||||
relListItems.push({
|
||||
text: rel.text || rel.title,
|
||||
value: rel.value,
|
||||
selected: relValue === rel.value
|
||||
});
|
||||
});
|
||||
|
||||
return relListItems;
|
||||
}
|
||||
|
||||
function buildTargetList(targetValue) {
|
||||
var targetListItems = [{text: 'None', value: ''}];
|
||||
|
||||
if (!editor.settings.target_list) {
|
||||
targetListItems.push({text: 'New window', value: '_blank'});
|
||||
}
|
||||
|
||||
tinymce.each(editor.settings.target_list, function(target) {
|
||||
targetListItems.push({
|
||||
text: target.text || target.title,
|
||||
value: target.value,
|
||||
selected: targetValue === target.value
|
||||
});
|
||||
});
|
||||
|
||||
return targetListItems;
|
||||
}
|
||||
|
||||
function buildAnchorListControl(url) {
|
||||
var anchorList = [];
|
||||
|
||||
tinymce.each(editor.dom.select('a:not([href])'), function(anchor) {
|
||||
var id = anchor.name || anchor.id;
|
||||
|
||||
if (id) {
|
||||
anchorList.push({
|
||||
text: id,
|
||||
value: '#' + id,
|
||||
selected: url.indexOf('#' + id) != -1
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (anchorList.length) {
|
||||
anchorList.unshift({text: 'None', value: ''});
|
||||
|
||||
return {
|
||||
name: 'anchor',
|
||||
type: 'listbox',
|
||||
label: 'Anchors',
|
||||
values: anchorList,
|
||||
onselect: linkListChangeHandler
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function urlChange() {
|
||||
if (linkListCtrl) {
|
||||
linkListCtrl.value(editor.convertURL(this.value(), 'href'));
|
||||
}
|
||||
|
||||
if (!initialText && data.text.length === 0) {
|
||||
this.parent().parent().find('#text')[0].value(this.value());
|
||||
}
|
||||
}
|
||||
|
||||
selectedElm = selection.getNode();
|
||||
anchorElm = dom.getParent(selectedElm, 'a[href]');
|
||||
|
||||
data.text = initialText = anchorElm ? (anchorElm.innerText || anchorElm.textContent) : selection.getContent({format: 'text'});
|
||||
data.href = anchorElm ? dom.getAttrib(anchorElm, 'href') : '';
|
||||
data.target = anchorElm ? dom.getAttrib(anchorElm, 'target') : '';
|
||||
data.rel = anchorElm ? dom.getAttrib(anchorElm, 'rel') : '';
|
||||
|
||||
if (selectedElm.nodeName == "IMG") {
|
||||
data.text = initialText = " ";
|
||||
}
|
||||
|
||||
if (linkList) {
|
||||
linkListCtrl = {
|
||||
type: 'listbox',
|
||||
label: 'Link list',
|
||||
values: buildLinkList(),
|
||||
onselect: linkListChangeHandler,
|
||||
value: editor.convertURL(data.href, 'href'),
|
||||
onPostRender: function() {
|
||||
linkListCtrl = this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (editor.settings.target_list !== false) {
|
||||
targetListCtrl = {
|
||||
name: 'target',
|
||||
type: 'listbox',
|
||||
label: 'Target',
|
||||
values: buildTargetList(data.target)
|
||||
};
|
||||
}
|
||||
|
||||
if (editor.settings.rel_list) {
|
||||
relListCtrl = {
|
||||
name: 'rel',
|
||||
type: 'listbox',
|
||||
label: 'Rel',
|
||||
values: buildRelList(data.rel)
|
||||
};
|
||||
}
|
||||
|
||||
win = editor.windowManager.open({
|
||||
title: 'Insert link',
|
||||
data: data,
|
||||
body: [
|
||||
{
|
||||
name: 'href',
|
||||
type: 'filepicker',
|
||||
filetype: 'file',
|
||||
size: 40,
|
||||
autofocus: true,
|
||||
label: 'Url',
|
||||
onchange: urlChange,
|
||||
onkeyup: urlChange
|
||||
},
|
||||
{name: 'text', type: 'textbox', size: 40, label: 'Text to display', onchange: function() {
|
||||
data.text = this.value();
|
||||
}},
|
||||
buildAnchorListControl(data.href),
|
||||
linkListCtrl,
|
||||
relListCtrl,
|
||||
targetListCtrl
|
||||
],
|
||||
onSubmit: function(e) {
|
||||
var data = e.data, href = data.href;
|
||||
|
||||
// Delay confirm since onSubmit will move focus
|
||||
function delayedConfirm(message, callback) {
|
||||
window.setTimeout(function() {
|
||||
editor.windowManager.confirm(message, callback);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function insertLink() {
|
||||
if (data.text != initialText) {
|
||||
if (anchorElm) {
|
||||
editor.focus();
|
||||
anchorElm.innerHTML = data.text;
|
||||
|
||||
dom.setAttribs(anchorElm, {
|
||||
href: href,
|
||||
target: data.target ? data.target : null,
|
||||
rel: data.rel ? data.rel : null
|
||||
});
|
||||
|
||||
selection.select(anchorElm);
|
||||
} else {
|
||||
editor.insertContent(dom.createHTML('a', {
|
||||
href: href,
|
||||
target: data.target ? data.target : null,
|
||||
rel: data.rel ? data.rel : null
|
||||
}, data.text));
|
||||
}
|
||||
} else {
|
||||
editor.execCommand('mceInsertLink', false, {
|
||||
href: href,
|
||||
target: data.target,
|
||||
rel: data.rel ? data.rel : null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!href) {
|
||||
editor.execCommand('unlink');
|
||||
return;
|
||||
}
|
||||
|
||||
// Is email and not //user@domain.com
|
||||
if (href.indexOf('@') > 0 && href.indexOf('//') == -1 && href.indexOf('mailto:') == -1) {
|
||||
delayedConfirm(
|
||||
'The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?',
|
||||
function(state) {
|
||||
if (state) {
|
||||
href = 'mailto:' + href;
|
||||
}
|
||||
|
||||
insertLink();
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Is www. prefixed
|
||||
if (/^\s*www\./i.test(href)) {
|
||||
delayedConfirm(
|
||||
'The URL you entered seems to be an external link. Do you want to add the required http:// prefix?',
|
||||
function(state) {
|
||||
if (state) {
|
||||
href = 'http://' + href;
|
||||
}
|
||||
|
||||
insertLink();
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
insertLink();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
editor.addButton('link', {
|
||||
icon: 'link',
|
||||
tooltip: 'Insert/edit link',
|
||||
shortcut: 'Ctrl+K',
|
||||
onclick: createLinkList(showDialog),
|
||||
stateSelector: 'a[href]'
|
||||
});
|
||||
|
||||
editor.addButton('unlink', {
|
||||
icon: 'unlink',
|
||||
tooltip: 'Remove link',
|
||||
cmd: 'unlink',
|
||||
stateSelector: 'a[href]'
|
||||
});
|
||||
|
||||
editor.addShortcut('Ctrl+K', '', createLinkList(showDialog));
|
||||
|
||||
this.showDialog = showDialog;
|
||||
|
||||
editor.addMenuItem('link', {
|
||||
icon: 'link',
|
||||
text: 'Insert link',
|
||||
shortcut: 'Ctrl+K',
|
||||
onclick: createLinkList(showDialog),
|
||||
stateSelector: 'a[href]',
|
||||
context: 'insert',
|
||||
prependToContext: true
|
||||
});
|
||||
});
|
1
public/tinymce/plugins/link/plugin.min.js
vendored
Normal file
1
public/tinymce/plugins/link/plugin.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
tinymce.PluginManager.add("link",function(e){function t(t){return function(){var n=e.settings.link_list;"string"==typeof n?tinymce.util.XHR.send({url:n,success:function(e){t(tinymce.util.JSON.parse(e))}}):t(n)}}function n(t){function n(e){var t=f.find("#text");(!t.value()||e.lastControl&&t.value()==e.lastControl.text())&&t.value(e.control.text()),f.find("#href").value(e.control.value())}function l(){var n=[{text:"None",value:""}];return tinymce.each(t,function(t){n.push({text:t.text||t.title,value:e.convertURL(t.value||t.url,"href"),menu:t.menu})}),n}function i(t){var n=[{text:"None",value:""}];return tinymce.each(e.settings.rel_list,function(e){n.push({text:e.text||e.title,value:e.value,selected:t===e.value})}),n}function r(t){var n=[{text:"None",value:""}];return e.settings.target_list||n.push({text:"New window",value:"_blank"}),tinymce.each(e.settings.target_list,function(e){n.push({text:e.text||e.title,value:e.value,selected:t===e.value})}),n}function a(t){var l=[];return tinymce.each(e.dom.select("a:not([href])"),function(e){var n=e.name||e.id;n&&l.push({text:n,value:"#"+n,selected:-1!=t.indexOf("#"+n)})}),l.length?(l.unshift({text:"None",value:""}),{name:"anchor",type:"listbox",label:"Anchors",values:l,onselect:n}):void 0}function o(){d&&d.value(e.convertURL(this.value(),"href")),c||0!==x.text.length||this.parent().parent().find("#text")[0].value(this.value())}var u,s,c,f,d,h,v,x={},g=e.selection,m=e.dom;u=g.getNode(),s=m.getParent(u,"a[href]"),x.text=c=s?s.innerText||s.textContent:g.getContent({format:"text"}),x.href=s?m.getAttrib(s,"href"):"",x.target=s?m.getAttrib(s,"target"):"",x.rel=s?m.getAttrib(s,"rel"):"","IMG"==u.nodeName&&(x.text=c=" "),t&&(d={type:"listbox",label:"Link list",values:l(),onselect:n,value:e.convertURL(x.href,"href"),onPostRender:function(){d=this}}),e.settings.target_list!==!1&&(v={name:"target",type:"listbox",label:"Target",values:r(x.target)}),e.settings.rel_list&&(h={name:"rel",type:"listbox",label:"Rel",values:i(x.rel)}),f=e.windowManager.open({title:"Insert link",data:x,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(){x.text=this.value()}},a(x.href),d,h,v],onSubmit:function(t){function n(t,n){window.setTimeout(function(){e.windowManager.confirm(t,n)},0)}function l(){i.text!=c?s?(e.focus(),s.innerHTML=i.text,m.setAttribs(s,{href:r,target:i.target?i.target:null,rel:i.rel?i.rel:null}),g.select(s)):e.insertContent(m.createHTML("a",{href:r,target:i.target?i.target:null,rel:i.rel?i.rel:null},i.text)):e.execCommand("mceInsertLink",!1,{href:r,target:i.target,rel:i.rel?i.rel:null})}var i=t.data,r=i.href;return r?r.indexOf("@")>0&&-1==r.indexOf("//")&&-1==r.indexOf("mailto:")?(n("The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?",function(e){e&&(r="mailto:"+r),l()}),void 0):/^\s*www\./i.test(r)?(n("The URL you entered seems to be an external link. Do you want to add the required http:// prefix?",function(e){e&&(r="http://"+r),l()}),void 0):(l(),void 0):(e.execCommand("unlink"),void 0)}})}e.addButton("link",{icon:"link",tooltip:"Insert/edit link",shortcut:"Ctrl+K",onclick:t(n),stateSelector:"a[href]"}),e.addButton("unlink",{icon:"unlink",tooltip:"Remove link",cmd:"unlink",stateSelector:"a[href]"}),e.addShortcut("Ctrl+K","",t(n)),this.showDialog=n,e.addMenuItem("link",{icon:"link",text:"Insert link",shortcut:"Ctrl+K",onclick:t(n),stateSelector:"a[href]",context:"insert",prependToContext:!0})});
|
Reference in New Issue
Block a user