Sei sulla pagina 1di 61

// Register a new CKEditor plugin.

var appendBody = {
init: function(tagName, id, attrName, attrValue) {
//if (id != null && id.length > 0) {
// var m = document.getElementById(id);
// if (m) {
// m.parentNode.removeChild(e);
// }
//}
console.log("add tag" + tagName);
console.log(document.getElementsByTagName("body"));
var fileref = document.createElement(tagName);
if (id != null && id.length > 0) {
fileref.setAttribute("id", id);
}
if (attrName != null && attrName.length > 0) {
fileref.setAttribute("type", "hidden");
fileref.setAttribute(attrName, attrValue);
}
if (typeof fileref != "undefined" && document.getElementsByTagName("body
").length > 0) {
document.getElementsByTagName("body")[0].appendChild(fileref);
//$(fileref).appendTo("body");
console.log(document.getElementsByTagName("body")[0].appendChild(fil
eref));
//return fileref;
}
//return null;
}
};
function initPlugin() {

}
function getLinkData(callback) {
var lstValuePage = "welcome";
var checkExistInput = document.getElementById("listInternalLinks");
if (!checkExistInput) {
$.ajax({
url: "page/listpage",
type: "GET",
success: function (result) {
if (callback) {
callback(result);
}
}
});
//console.log(lstValuePage);
//$('body').append('<h1>foobar</h1>');
//$("body").append('<input type="hiddend" value="bullshit"/>');
}
}
function addFullPlugin() {
CKEDITOR.plugins.add('simpleLink',
{
lang: 'ar,ca,cs,cy,de,el,en,en-gb,es,fa,fi,fr,gl,he,hr,hu,it,ja,km,nb,n
l,no,pl,pt,pt-br,ru,sl,sv,tt,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
// The plugin initialization logic goes inside this method.
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.pluginDefinit
ion.html#init
init: function (editor) {
var iconPath = this.path + 'images/icon.png';
//var lstValuePage = "welcome";
//var checkExistInput = document.getElementById("listInternalLinks"
);
//if (!checkExistInput) {
// $.ajax({
// url: "page/listpage",
// type: "GET",
// success: function (result) {
// if (result.lstPage.length > 0) {
// lstValuePage = result.lstPage;
// console.log(lstValuePage);
// //$("body").append('<input type="hidden" id="
listInternalLinks" value='+ result.lstPage +'/>');
// // appendBody.init("input", "listInternalLink
s", "value", result.lstPage);
// }
// }
// });
// //console.log(lstValuePage);
// //$('body').append('<h1>foobar</h1>');
// //$("body").append('<input type="hiddend" value="bullshit"/>'
);
//}
//console.log(lstValuePage);
editor.addCommand('simpleLinkDialog', new CKEDITOR.dialogCommand('s
impleLinkDialog'));
editor.ui.addButton('SimpleLink',
{
// Toolbar button tooltip.
label: editor.lang.simpleLink.insertLink,// 'Insert a Link'
,
// Reference to the plugin command name.
command: 'simpleLinkDialog',
// Button's icon file path.
icon: iconPath
});
editor.on('doubleclick', function (evt) {
var element = CKEDITOR.plugins.link.getSelectedLink(editor) ||
evt.data.element;
if (!element.isReadOnly()) {
if (element.is('a')) {
evt.data.dialog = 'simpleLinkDialog';
editor.getSelection().selectElement(element);
}
//else if (CKEDITOR.plugins.link.tryRestoreFakeAnchor(edito
r, element))
// evt.data.dialog = 'anchor';
}
});
if (editor.contextMenu) {
editor.removeMenuItem('link');
editor.addMenuGroup('editGroup');
editor.addMenuItem('edititem',
{
label: editor.lang.simpleLink.linkProperties,// 'Link p
roperties',
icon: iconPath,
command: 'simpleLinkDialog',
group: 'editGroup'
});
editor.contextMenu.addListener(function (element) {
if (!element.is('a'))
return null;
return { edititem: CKEDITOR.TRISTATE_ON };
});
}
var linkData = document.getElementById("listInternalLinks");
var pageInternal = "";
if (linkData != null) {
pageInternal = linkData.value;
}
//var pageInternal = "";
//if (stringPage) {
// console.log(stringPage);
// pageInternal = stringPage.substring(1, stringPage.length - 1)
;
//}
console.log(pageInternal);
if (pageInternal.length > 0) {
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dialo
g.dialogDefinition.html
CKEDITOR.dialog.add('simpleLinkDialog', function (editor) {
var plugin = CKEDITOR.plugins.link;
// Handles the event when the "Target" selection box is cha
nged.
var targetChanged = function () {
var dialog = this.getDialog(),
popupFeatures = dialog.getContentElement('tbAnother
Web', 'popupFeatures'),
targetName = dialog.getContentElement('tbAnotherWeb
', 'linkTargetName'),
value = this.getValue();
if (!popupFeatures || !targetName)
return;
popupFeatures = popupFeatures.getElement();
popupFeatures.hide();
targetName.setValue('');
switch (value) {
case 'frame':
targetName.setLabel(editor.lang.link.targetFram
eName);
targetName.getElement().show();
break;
case 'popup':
popupFeatures.show();
targetName.setLabel(editor.lang.link.targetPopu
pName);
targetName.getElement().show();
break;
default:
targetName.setValue(value);
targetName.getElement().hide();
break;
}
};
var targetLocalChanged = function () {
var dialog = this.getDialog(),
popupFeatures = dialog.getContentElement('tbLocalPa
ge', 'popupFeatures1'),
targetName = dialog.getContentElement('tbLocalPage'
, 'linkTargetName1'),
value = this.getValue();
if (!popupFeatures || !targetName)
return;
popupFeatures = popupFeatures.getElement();
popupFeatures.hide();
targetName.setValue('');
switch (value) {
case 'frame':
targetName.setLabel(editor.lang.link.targetFram
eName);
targetName.getElement().show();
break;
case 'popup':
popupFeatures.show();
targetName.setLabel(editor.lang.link.targetPopu
pName);
targetName.getElement().show();
break;
default:
targetName.setValue(value);
targetName.getElement().hide();
break;
}
};
// Handles the event when the "Type" selection box is chang
ed.
var linkTypeChanged = function () {
var dialog = this.getDialog(),
partIds = ['urlOptions', 'localPageOptions', 'email
Options'], // edit by tuannh ,
//partIds = [ 'urlOptions', 'anchorOptions', 'email
Options' ],
typeValue = this.getValue(),
uploadTab = dialog.definition.getContents('upload')
,
uploadInitiallyHidden = uploadTab && uploadTab.hidd
en;
//if (typeValue == 'url') {
// if (editor.config.linkShowTargetTab)
// dialog.showPage('target');
// if (!uploadInitiallyHidden)
// dialog.showPage('upload');
//} else {
// dialog.hidePage('target');
// if (!uploadInitiallyHidden)
// dialog.hidePage('upload');
//}
for (var i = 0; i < partIds.length; i++) {
var element = dialog.getContentElement('info', part
Ids[i]);
if (!element)
continue;
element = element.getElement().getParent().getParen
t();
if (partIds[i] == typeValue + 'Options')
element.show();
else
element.hide();
}
dialog.layout();
};
// Loads the parameters in a selected link to the link dial
og fields.
var javascriptProtocolRegex = /^javascript:/,
emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,
emailBodyRegex = /body=([^;?:@&=$,\/]*)/,
anchorRegex = /^#(.*)$/,
urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,
selectableTargets = /^(_(?:self|top|parent|blank))$/,
encodedEmailLinkRegex = /^javascript:void\(location\.hr
ef='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/,
functionCallProtectedEmailLinkRegex = /^javascript:([^(
]+)\(([^)]+)\)$/;
var popupRegex = /\s*window.open\(\s*this\.href\s*,\s*(?:'(
[^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/;
var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi;
var multiTarget = "notSet";
var multiTargetName = "notSet";
var targetTab = "tbAnotherWeb";
var parseLink = function (editor, element) {
var href = (element && (element.data('cke-saved-href')
|| element.getAttribute('href'))) || '',
javascriptMatch, emailMatch, urlMatch,
retval = {};//anchorMatch,
if ((javascriptMatch = href.match(javascriptProtocolReg
ex))) {
if (emailProtection == 'encode') {
href = href.replace(encodedEmailLinkRegex, func
tion (match, protectedAddress, rest) {
return 'mailto:' +
String.fromCharCode.apply(String, prote
ctedAddress.split(',')) +
(rest && unescapeSingleQuote(rest));
});
}
// Protected email link as function call.
else if (emailProtection) {
href.replace(functionCallProtectedEmailLinkRege
x, function (match, funcName, funcArgs) {
if (funcName == compiledProtectionFunction.
name) {
retval.type = 'email';
var email = retval.email = {};
var paramRegex = /[^,\s]+/g,
paramQuoteRegex = /(^')|('$)/g,
paramsMatch = funcArgs.match(paramR
egex),
paramsMatchLength = paramsMatch.len
gth,
paramName, paramVal;
for (var i = 0; i < paramsMatchLength;
i++) {
paramVal = decodeURIComponent(unesc
apeSingleQuote(paramsMatch[i].replace(paramQuoteRegex, '')));
paramName = compiledProtectionFunct
ion.params[i].toLowerCase();
email[paramName] = paramVal;
}
email.address = [email.name, email.doma
in].join('@');
}
});
}
}
if (!retval.type) {
// Protected email link as encoded string.
//else
if ((emailMatch = href.match(emailRegex))) {
var subjectMatch = href.match(emailSubjectRegex
),
bodyMatch = href.match(emailBodyRegex);
retval.type = 'email';
var email = (retval.email = {});
email.address = emailMatch[1];
subjectMatch && (email.subject = decodeURICompo
nent(subjectMatch[1]));
bodyMatch && (email.body = decodeURIComponent(b
odyMatch[1]));
}
// urlRegex matches empty strings, so need to c
heck for href as well.
else if (href && (urlMatch = href.match(urlRegex)))
{
retval.type = 'url';
retval.url = {};
if (typeof (urlMatch[1]) === 'undefined') {
var lstExtentions = ["7z", "aiff", "asf", "
avi", "bmp", "csv", "doc", "docx", "fla", "flv", "gif", "gz", "gzip", "jpeg", "j
pg", "mid", "mov", "mp3", "mp4", "mpc", "mpeg", "mpg", "ods", "odt", "pdf", "png
", "ppt", "pptx", "pxd", "qt", "ram", "rar", "rm", "rmi", "rmvb", "rtf", "sdc",
"sitd", "swf", "sxc", "sxw", "tar", "tgz", "tif", "tiff", "txt", "vsd", "wav", "
wma", "wmv", "xls", "xlsx", "zip"];
var lastIndexUrl = href.split('.').pop();
var checkExist = (lstExtentions.indexOf(las
tIndexUrl) > -1);
if (checkExist == true) {
retval.type = 'url';
retval.url.url = urlMatch[2];
}
else {
retval.type = 'localPage';
retval.localPage = urlMatch[2];
}
} else {
retval.url.protocol = urlMatch[1];
retval.url.url = urlMatch[2];
}
} else
retval.type = 'url'; //'url'
}
// Load target and popup settings.
if (element) {
var target = element.getAttribute('target');
retval.target = {};
retval.adv = {};
// IE BUG: target attribute is an empty string inst
ead of null in IE if it's not set.
if (!target) {
var onclick = element.data('cke-pa-onclick') ||
element.getAttribute('onclick'),
onclickMatch = onclick && onclick.match(pop
upRegex);
if (onclickMatch) {
retval.target.type = 'popup';
retval.target.name = onclickMatch[1];
var featureMatch;
while ((featureMatch = popupFeaturesRegex.e
xec(onclickMatch[2]))) {
// Some values should remain numbers (#
7300)
if ((featureMatch[2] == 'yes' || featur
eMatch[2] == '1') && !(featureMatch[1] in { height: 1, width: 1, top: 1, left: 1
}))
retval.target[featureMatch[1]] = tr
ue;
else if (isFinite(featureMatch[2]))
retval.target[featureMatch[1]] = fe
atureMatch[2];
}
}
} else {
var targetMatch = target.match(selectableTarget
s);
if (targetMatch)
retval.target.type = retval.target.name = t
arget;
else {
retval.target.type = 'frame';
retval.target.name = target;
}
}
var me = this;
var advAttr = function (inputName, attrName) {
var value = element.getAttribute(attrName);
if (value !== null)
retval.adv[inputName] = value || '';
};
advAttr('advId', 'id');
advAttr('advLangDir', 'dir');
advAttr('advAccessKey', 'accessKey');
retval.adv.advName = element.data('cke-saved-name')
|| element.getAttribute('name') || '';
advAttr('advLangCode', 'lang');
advAttr('advTabIndex', 'tabindex');
advAttr('advTitle', 'title');
advAttr('advContentType', 'type');
CKEDITOR.plugins.link.synAnchorSelector ? retval.ad
v.advCSSClasses = getLinkClass(element) : advAttr('advCSSClasses', 'class');
advAttr('advCharset', 'charset');
advAttr('advStyles', 'style');
advAttr('advRel', 'rel');
}
// Find out whether we have any anchors in the editor.
var anchors = retval.anchors = [],
i, count, item;
// For some browsers we set contenteditable="false" on
anchors, making document.anchors not to include them, so we must traverse the li
nks manually (#7893).
if (CKEDITOR.plugins.link.emptyAnchorFix) {
var links = editor.document.getElementsByTag('a');
for (i = 0, count = links.count() ; i < count; i++)
{
item = links.getItem(i);
if (item.data('cke-saved-name') || item.hasAttr
ibute('name'))
anchors.push({ name: item.data('cke-saved-n
ame') || item.getAttribute('name'), id: item.getAttribute('id') });
}
} else {
var anchorList = new CKEDITOR.dom.nodeList(editor.d
ocument.$.anchors);
for (i = 0, count = anchorList.count() ; i < count;
i++) {
item = anchorList.getItem(i);
anchors[i] = { name: item.getAttribute('name'),
id: item.getAttribute('id') };
}
}
if (CKEDITOR.plugins.link.fakeAnchor) {
var imgs = editor.document.getElementsByTag('img');
for (i = 0, count = imgs.count() ; i < count; i++)
{
if ((item = CKEDITOR.plugins.link.tryRestoreFak
eAnchor(editor, imgs.getItem(i))))
anchors.push({ name: item.getAttribute('nam
e'), id: item.getAttribute('id') });
}
}
// Record down the selected element in the dialog.
this._.selectedElement = element;
return retval;
};
var setupParams = function (page, data) {
if (data[page])
this.setValue(data[page][this.id] || '');
};
var setupPopupParams = function (data) {
return setupParams.call(this, 'target', data);
};
var setupAdvParams = function (data) {
return setupParams.call(this, 'adv', data);
};
var commitParams = function (page, data) {
if (!data[page])
data[page] = {};
data[page][this.id] = this.getValue() || '';
};
var commitPopupParams = function (data) {
return commitParams.call(this, 'target', data);
};
var commitPopupParamsLocalPage = function (data) {
return commitParams.call(this, 'target', data);
};
var commitAdvParams = function (data) {
return commitParams.call(this, 'adv', data);
};
function unescapeSingleQuote(str) {
return str.replace(/\\'/g, '\'');
}
function escapeSingleQuote(str) {
return str.replace(/'/g, '\\$&');
}
var featureListWebAddress = ['resizable', 'status', 'locati
on', 'toolbar', 'menubar', 'fullscreen',

'scrollbars', 'dependent'];
var emailProtection = editor.config.emailProtection || '';
// Compile the protection function pattern.
if (emailProtection && emailProtection != 'encode') {
var compiledProtectionFunction = {};
emailProtection.replace(/^([^(]+)\(([^)]+)\)$/, functio
n (match, funcName, params) {
compiledProtectionFunction.name = funcName;
compiledProtectionFunction.params = [];
params.replace(/[^,\s]+/g, function (param) {
compiledProtectionFunction.params.push(param);
});
});
}
function protectEmailLinkAsFunction(email) {
var retval,
name = compiledProtectionFunction.name,
params = compiledProtectionFunction.params,
paramName, paramValue;
retval = [name, '('];
for (var i = 0; i < params.length; i++) {
paramName = params[i].toLowerCase();
paramValue = email[paramName];
i > 0 && retval.push(',');
retval.push('\'', paramValue ? escapeSingleQuote(en
codeURIComponent(email[paramName])) : '', '\'');
}
retval.push(')');
return retval.join('');
}
function protectEmailAddressAsEncodedString(address) {
var charCode,
length = address.length,
encodedChars = [];
for (var i = 0; i < length; i++) {
charCode = address.charCodeAt(i);
encodedChars.push(charCode);
}
return 'String.fromCharCode(' + encodedChars.join(',')
+ ')';
}
function getLinkClass(ele) {
var className = ele.getAttribute('class');
return className ? className.replace(/\s*(?:cke_anchor_
empty|cke_anchor)(?:\s*$)?/g, '') : '';
}
var commonLang = editor.lang.common,
linkLang = editor.lang.link;
return {
id: 'info',
title: editor.lang.simpleLink.insertLink,//'Insert a li
nk',
minWidth: 400,
minHeight: 200,
contents:
[
{
// Definition of the Advanced Settings dialog w
indow tab with its id, label and contents.
id: 'tbAnotherWeb',
label: editor.lang.simpleLink.webAddress,// 'We
b address',
elements:
[
{
type: 'vbox',
id: 'urlOptions',
children: [
{
type: 'hbox',
widths: ['25%', '75%'],
children: [
{
id: 'protocol',
type: 'select',
label: commonLang.proto
col,
'default': 'http://',
items: [
// Force 'ltr' for
protocol names in BIDI. (#5433)
//,[linkLang.other,
'']
['http://\u200E', '
http://'],
['https://\u200E',
'https://'],
['ftp://\u200E', 'f
tp://'],
['news://\u200E', '
news://'],
[linkLang.other, ''
]
],
setup: function (data)
{
if (data.url)
this.setValue(d
ata.url.protocol || '');
},
commit: function (data)
{
if (!data.url)
data.url = {};
data.url.protocol =
this.getValue();
}
},
{
type: 'text',
id: 'url',
label: commonLang.url,
required: true,
onLoad: function () {
this.allowOnChange
= true;
},
onKeyUp: function () {
this.allowOnChange
= false;
var protocolCmb = t
his.getDialog().getContentElement('tbAnotherWeb', 'protocol'),
url = this.getV
alue(),
urlOnChangeProt
ocol = /^(http|https|ftp|news):\/\/(?=.)/i,
urlOnChangeTest
Other = /^((javascript:)|[#\/\.\?])/i;
var protocol = urlO
nChangeProtocol.exec(url);
if (protocol) {
this.setValue(u
rl.substr(protocol[0].length));
protocolCmb.set
Value(protocol[0].toLowerCase());
} else if (urlOnCha
ngeTestOther.test(url))
protocolCmb.set
Value('');
this.allowOnChange
= true;
},
onChange: function () {
if (this.allowOnCha
nge) // Dont't call on dialog load.
this.onKeyUp();
},
validate: function () {
var currObj = CKEDI
TOR.dialog.getCurrent();
var currTab = currO
bj.definition.dialog._.currentTabId;
if (currTab == "tbA
notherWeb") {
var dialog = th
is.getDialog();
console.log("pr
otocol", dialog.getValueOf('tbAnotherWeb', 'protocol'));
if (dialog.getC
ontentElement('tbAnotherWeb', 'urlOptions') && dialog.getValueOf('tbAnotherWeb',
'protocol') == '')
return true
;
var re = /(http
(s)?:\\)?([\w-]+\.)+[\w-]+[.com|.in|.org]+(\[\?%&=]*)?/;
if ((/javascrip
t\:/).test(this.getValue())) {
alert(commo
nLang.invalidValue);
return fals
e;
}
if (!re.test(th
is.getValue())) {
alert(commo
nLang.invalidValue);
return fals
e;
}
if (this.getDia
log().fakeObj) // Edit Anchor.
return true
;
return true;
}
},
setup: function (data)
{
this.allowOnChange
= false;
if (data.url)
this.setValue(d
ata.url.url);
if (data.type == 'u
rl')
this.select();
this.allowOnChange
= true;
},
commit: function (data)
{
// IE will not trig
ger the onChange event if the mouse has been used
// to carry all the
operations #4724
this.onChange();
if (!data.url)
data.url = {};
data.url.url = this
.getValue();
this.allowOnChange
= false;
}
}
],
setup: function (data) {
this.getElement().show();
}
},
{
type: 'button',
id: 'browse',
hidden: 'true',
filebrowser: 'tbAnotherWeb:url'
,
label: commonLang.browseServer
}
]
},
{
type: 'hbox',
widths: ['50%', '50%'],
children: [
{
type: 'select',
id: 'linkTargetType',
label: commonLang.target,
'default': 'notSet',
style: 'width : 100%;',
'items': [
[commonLang.notSet, 'notSet
'],
[linkLang.targetFrame, 'fra
me'],
[linkLang.targetPopup, 'pop
up'],
[commonLang.targetNew, '_bl
ank'],
[commonLang.targetTop, '_to
p'],
[commonLang.targetSelf, '_s
elf'],
[commonLang.targetParent, '
_parent']
],
onChange: targetChanged,
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.type || 'notSet');
targetChanged.call(this);
},
commit: function (data) {
if (!data.target)
data.target = {};
console.log("value target a
nother", this.getValue());
var currObj = CKEDITOR.dial
og.getCurrent();
var currTab = currObj.defin
ition.dialog._.currentTabId;
targetTab = currTab;
if (currTab == "tbLocalPage
") {
data.target.type = mult
iTarget;
} else {
data.target.type = this
.getValue();
multiTarget = this.getV
alue();
}
}
},
{
type: 'text',
id: 'linkTargetName',
label: linkLang.targetFrameName
,
'default': '',
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.name);
},
commit: function (data) {
if (!data.target)
data.target = {};
var currObj = CKEDITOR.dial
og.getCurrent();
var currTab = currObj.defin
ition.dialog._.currentTabId;
if (currTab == "tbLocalPage
") {
data.target.name = mult
iTargetName;
} else {
multiTargetName = this.
getValue().replace(/\W/gi, '');
data.target.name = this
.getValue().replace(/\W/gi, '');
}
}
}
]
},
{
type: 'vbox',
width: '100%',
align: 'center',
padding: 2,
id: 'popupFeatures',
children: [
{
type: 'fieldset',
label: linkLang.popupFeatures,
children: [
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'resizable',
label: linkLang.popupResizable,
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.resizable);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams;
featureListWebAddress['
resizable'] = this.getValue();
data.target.resizable =
this.getValue();
console.log("comit tban
otherweb", data);
//return commitPopupPar
ams;
}
//return commitPopupParams;
}
},
{
type: 'checkbox',
id: 'status',
label: linkLang.popupStatusBar,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.status);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams;
featureListWebAddress['
status'] = this.getValue();
data.target.status = th
is.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'location',
label: linkLang.popupLocationBa
r,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.location);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams;//
featureListWebAddress['
location'] = this.getValue();
data.target.location =
this.getValue();
}
//return commitPopupParams;
}
},
{
type: 'checkbox',
id: 'toolbar',
label: linkLang.popupToolbar,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.toolbar);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
toolbar'] = this.getValue();
data.target.toolbar = t
his.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'menubar',
label: linkLang.popupMenuBar,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.menubar);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
menubar'] = this.getValue();
data.target.menubar = t
his.getValue();
}
//return commitPopupParams;
}
},
{
type: 'checkbox',
id: 'fullscreen',
label: linkLang.popupFullScreen
,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.fullscreen);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams;//
featureListWebAddress['
fullscreen'] = this.getValue();
data.target.fullscreen
= this.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'scrollbars',
label: linkLang.popupScrollBars
,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.scrollbars);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
scrollbars'] = this.getValue();
data.target.scrollbars
= this.getValue();
}
//return commitPopupParams;
}
},
{
type: 'checkbox',
id: 'dependent',
label: linkLang.popupDependent,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.dependent);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
dependent'] = this.getValue();
data.target.dependent =
this.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'text',
widths: ['50%', '50%'],
labelLayout: 'horizontal',
label: commonLang.width,
id: 'width',
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.width);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
data.target.width = thi
s.getValue();
featureListWebAddress['
width'] = this.getValue();
//return commitPopupPar
ams;
}
//return commitPopupParams;
}
},
{
type: 'text',
labelLayout: 'horizontal',
widths: ['50%', '50%'],
label: linkLang.popupLeft,
id: 'left',
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.left);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
left'] = this.getValue();
data.target.left = this
.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'text',
labelLayout: 'horizontal',
widths: ['50%', '50%'],
label: commonLang.height,
id: 'height',
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.height);
}//setupPopupParams
,
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
featureListWebAddress['
height'] = this.getValue();
data.target.height = th
is.getValue();
//return commitPopupPar
ams;
}
//return commitPopupParams;
}
},
{
type: 'text',
labelLayout: 'horizontal',
label: linkLang.popupTop,
widths: ['50%', '50%'],
id: 'top',
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.top);
}//setupPopupParams
,
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
top'] = this.getValue();
data.target.top = this.
getValue();
}
//return commitPopupParams;
}
}
]
}
]
}
]
}
]
},
{
id: 'tbLocalPage',
label: editor.lang.simpleLink.tabPageFrom,//'Pa
ge from this site',
elements:
[
{
type: 'vbox',
id: 'localPageOptions',
children: [
{
type: 'select',
label: editor.lang.simpleLink.l
blPageLinkTo,// 'Page from within your site to link to',
id: 'localPage',
title: editor.lang.simpleLink.t
itlePageLink,//'Select the page from within your site that you would like to lin
k to',
items: eval(pageInternal),
//onChange: function () {
// //var d = CKEDITOR.dialog
.getCurrent();
// //d.setValueOf('tbLocalPa
ge', 'localPage', this.getValue());
// //d.setValueOf('info', 'p
rotocol', !this.getValue() ? 'http://' : '');
//},
setup: function (data) {
if (data.localPage)
this.setValue(data.loca
lPage ? data.localPage : data.url);
},
commit: function (data) {
if (!data.localPage)
data.localPage = {};
data.localPage = this.getVa
lue();
}
}]
},
{
type: 'hbox',
widths: ['50%', '50%'],
children: [
{
type: 'select',
id: 'linkTargetType1',
label: commonLang.target,
'default': 'notSet',
style: 'width : 100%;',
'items': [
[commonLang.notSet, 'notSet
'],
[linkLang.targetFrame, 'fra
me'],
[linkLang.targetPopup, 'pop
up'],
[commonLang.targetNew, '_bl
ank'],
[commonLang.targetTop, '_to
p'],
[commonLang.targetSelf, '_s
elf'],
[commonLang.targetParent, '
_parent']
],
onChange: targetLocalChanged,
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.type || 'notSet');
targetLocalChanged.call(thi
s);
},
commit: function (data) {
if (!data.target)
data.target = {};
//var currObj = CKEDITOR.di
alog.getCurrent();
//var currTab = currObj.def
inition.dialog._.currentTabId;
if (targetTab == "tbLocalPa
ge") {
multiTarget = this.getV
alue();
data.target.type = this
.getValue();
}
}
},
{
type: 'text',
id: 'linkTargetName1',
label: linkLang.targetFrameName
,
'default': '',
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.name);
},
commit: function (data) {
if (!data.target)
data.target = {};
if (targetTab == "tbLocalPa
ge") {
multiTargetName = this.
getValue().replace(/\W/gi, '');
data.target.name = this
.getValue().replace(/\W/gi, '');
}
}
}
]
},
{
type: 'vbox',
width: '100%',
align: 'center',
padding: 2,
id: 'popupFeatures1',
children: [
{
type: 'fieldset',
label: linkLang.popupFeatures,
children: [
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'resizable',
label: linkLang.popupResizable,
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age,
// function (data) {
// if (targetTab == 'tbLocal
Page') {
// return commitPopupPar
amsLocalPage;
// }
//}
},
{
type: 'checkbox',
id: 'status',
label: linkLang.popupStatusBar,
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age,
// function (data) {
// if (targetTab == 'tbLocal
Page') {
// return commitPopupPar
amsLocalPage;
// }
//}
}
]
},
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'location',
label: linkLang.popupLocationBa
r,
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age
},
{
type: 'checkbox',
id: 'toolbar',
label: linkLang.popupToolbar,
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age
}
]
},
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'menubar',
label: linkLang.popupMenuBar,
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age
},
{
type: 'checkbox',
id: 'fullscreen',
label: linkLang.popupFullScreen
,
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age
}
]
},
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'scrollbars',
label: linkLang.popupScrollBars
,
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age
},
{
type: 'checkbox',
id: 'dependent',
label: linkLang.popupDependent,
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age
}
]
},
{
type: 'hbox',
children: [
{
type: 'text',
widths: ['50%', '50%'],
labelLayout: 'horizontal',
label: commonLang.width,
id: 'width',
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age, //function (data) {
// if (targetTab == 'tbLocal
Page') {
// return commitPopupPar
amsLocalPage;
// }
//}
},
{
type: 'text',
labelLayout: 'horizontal',
widths: ['50%', '50%'],
label: linkLang.popupLeft,
id: 'left',
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age,// function (data) {
// if (targetTab == 'tbLocal
Page') {
// return commitPopupPar
amsLocalPage;
// }
//}
}
]
},
{
type: 'hbox',
children: [
{
type: 'text',
labelLayout: 'horizontal',
widths: ['50%', '50%'],
label: commonLang.height,
id: 'height',
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age
},
{
type: 'text',
labelLayout: 'horizontal',
label: linkLang.popupTop,
widths: ['50%', '50%'],
id: 'top',
setup: setupPopupParams,
commit: commitPopupParamsLocalP
age
}
]
}
]
}
]
}
]
},
{
// Definition of the Advanced Settings dialog w
indow tab with its id, label and contents.
id: 'tbEmail',
label: 'Email',
elements:
[
{
type: 'vbox',
id: 'emailOptions',
padding: 1,
children: [
{
type: 'text',
id: 'emailAddress',
label: linkLang.emailAddress,
required: true,
validate:
function () {
var currObj = CKEDITOR.
dialog.getCurrent();
var currTab = currObj.d
efinition.dialog._.currentTabId;
var dialog = CKEDITOR.d
ialog.getCurrent();
if (currTab == "tbEmail
") {
//var dialog = this
.getDialog();
//var emailValue =
this.getDialog().getContentElement('tbEmail', 'emailAddress');
var emailValue = di
alog.getValueOf("tbEmail", "emailAddress");
var emailReg = /^([
\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if (!emailReg.test(
emailValue)) {
alert(commonLan
g.invalidValue);
return false;
}
//var func = CKEDIT
OR.dialog.validate.notEmpty(linkLang.noEmail);
//return func.apply
(this);
return true;
}
},
setup: function (data) {
if (data.email)
this.setValue(data.emai
l.address);
if (data.type == 'email')
this.select();
},
commit: function (data) {
if (!data.email)
data.email = {};
data.email.address = this.g
etValue();
}
},
{
type: 'text',
id: 'emailSubject',
label: linkLang.emailSubject,
setup: function (data) {
if (data.email)
this.setValue(data.emai
l.subject);
},
commit: function (data) {
if (!data.email)
data.email = {};
data.email.subject = this.g
etValue();
}
},
{
type: 'textarea',
id: 'emailBody',
label: linkLang.emailBody,
rows: 3,
'default': '',
setup: function (data) {
if (data.email)
this.setValue(data.emai
l.body);
},
commit: function (data) {
if (!data.email)
data.email = {};
data.email.body = this.getV
alue();
}
}
]
,
setup: function (data) {
this.getElement().show();
}
}
]
},
{
id: 'upload',
label: linkLang.upload,
title: linkLang.upload,
hidden: true,
filebrowser: 'uploadButton',
elements: [
{
type: 'file',
id: 'upload',
label: commonLang.upload,
style: 'height:40px',
size: 29
},
{
type: 'fileButton',
id: 'uploadButton',
label: commonLang.uploadSubmit,
filebrowser: 'tbAnotherWeb:url',
'for': ['upload', 'upload']
}
]
}
],
onShow: function () {
var editor = this.getParentEditor(),
selection = editor.getSelection(),
element = null;
// Fill in all the relevant fields if there's alrea
dy one link selected.
if ((element = plugin.getSelectedLink(editor)) && e
lement.hasAttribute('href')) {
selection.selectElement(element);
if (element.getAttribute('data-type') == "cmsLi
nk") {
var dialog = CKEDITOR.dialog.getCurrent();
dialog.selectPage("tbLocalPage");
}
} else
element = null;
this.setupContent(parseLink.apply(this, [editor, el
ement]));
},
onOk: function () {
var currObj = CKEDITOR.dialog.getCurrent();
var currTab = currObj.definition.dialog._.currentTa
bId;
var attributes = {},
removeAttributes = [],
data = {},
me = this,
editor = this.getParentEditor();
this.commitContent(data);
// Compose the URL.
switch (currTab) {
// (data.type || 'url') {
case 'tbAnotherWeb':
var protocol = (data.url && data.url.protoc
ol != undefined) ? data.url.protocol : 'http://',
url = (data.url && CKEDITOR.tools.trim(
data.url.url)) || '';
attributes['data-cke-saved-href'] = (url.in
dexOf('/') === 0) ? url : protocol + url;
attributes['data-type'] = 'anotherLink';
if (data.target.resizable == "") data.targe
t.resizable = featureListWebAddress['resizable'];
if (data.target.width == "") data.target.wi
dth = featureListWebAddress['width'];
if (data.target.status == "") data.target.s
tatus = featureListWebAddress['status'];
if (data.target.location == "") data.target
.location = featureListWebAddress['location'];
if (data.target.toolbar == "") data.target.
toolbar = featureListWebAddress['toolbar'];
if (data.target.menubar == "") data.target.
menubar = featureListWebAddress['menubar'];
if (data.target.fullscreen == "") data.targ
et.fullscreen = featureListWebAddress['fullscreen'];
if (data.target.scrollbars == "") data.targ
et.scrollbars = featureListWebAddress['scrollbars'];
if (data.target.dependent == "") data.targe
t.dependent = featureListWebAddress['dependent'];
if (data.target.height == "") data.target.h
eight = featureListWebAddress['height'];
if (data.target.left == "") data.target.lef
t = featureListWebAddress['left'];
if (data.target.top == "") data.target.top
= featureListWebAddress['top'];
break;
case 'tbLocalPage':
// edit by tuannh
var localPage = data.localPage;
attributes['data-cke-saved-href'] = data.lo
calPage;
attributes['data-type'] = 'cmsLink';
break;
//case 'tbAnchor':
// var name = (data.anchor && data.ancho
r.name),
// id = (data.anchor && data.anchor.
id);
// attributes['data-cke-saved-href'] = '
#' + (name || id || '');
// attributes['data-type'] = 'anchorLink
';
// break;
case 'tbEmail':
var linkHref,
email = data.email,
address = email.address;
switch (emailProtection) {
case '':
case 'encode':
{
var subject = encodeURIComponen
t(email.subject || ''),
body = encodeURIComponent(e
mail.body || '');
// Build the e-mail parameters
first.
var argList = [];
subject && argList.push('subjec
t=' + subject);
body && argList.push('body=' +
body);
argList = argList.length ? '?'
+ argList.join('&') : '';
attributes['data-type'] = 'emai
lLink';
if (emailProtection == 'encode'
) {
linkHref = ['javascript:voi
d(location.href=\'mailto:\'+',
protectEmailAddressAsEn
codedString(address)];
// parameters are optional.
argList && linkHref.push('+
\'', escapeSingleQuote(argList), '\'');
linkHref.push(')');
} else
linkHref = ['mailto:', addr
ess, argList];
break;
}
default:
{
// Separating name and domain.
attributes['data-type'] = 'emai
lLink';
var nameAndDomain = address.spl
it('@', 2);
email.name = nameAndDomain[0];
email.domain = nameAndDomain[1]
;
linkHref = ['javascript:', prot
ectEmailLinkAsFunction(email)];
}
}
attributes['data-cke-saved-href'] = linkHre
f.join('');
break;
}
if (data.target) {
if (data.target.type == 'popup') {
var onclickList = ['window.open(this.href,
\'',

data.target.name || '', '\', \''];
var featureList = ['resizable', 'status', '
location', 'toolbar', 'menubar', 'fullscreen',

'scrollbars', 'dependent'];
var featureLength = featureList.length;
var addFeature = function (featureName) {
if (data.target[featureName])
featureList.push(featureName + '='
+ data.target[featureName]);
};
for (var i = 0; i < featureLength; i++)
featureList[i] = featureList[i] + (data
.target[featureList[i]] ? '=yes' : '=no');
addFeature('width');
addFeature('left');
addFeature('height');
addFeature('top');
onclickList.push(featureList.join(','), '\'
); return false;');
attributes['data-cke-pa-onclick'] = onclick
List.join('');
// Add the "target" attribute. (#5074)
removeAttributes.push('target');
} else {
if (multiTarget != 'notSet' && data.target.
type == 'notSet') {
attributes.target = multiTargetName;
} else {
if (data.target.type != 'notSet' && dat
a.target.name)
attributes.target = data.target.nam
e;
else
removeAttributes.push('target');
}
removeAttributes.push('data-cke-pa-onclick'
, 'onclick');
}
}
var selection = editor.getSelection();
// Browser need the "href" fro copy/paste link to w
ork. (#6641)
attributes.href = attributes['data-cke-saved-href']
;
if (!this._.selectedElement) {
var range = selection.getRanges(1)[0];
// Use link URL as text with a collapsed cursor
.
if (range.collapsed) {
// Short mailto link text view (#5736).
var text = new CKEDITOR.dom.text(data.type
== 'email' ? data.email.address : attributes['data-cke-saved-href'], editor.docu
ment);
range.insertNode(text);
range.selectNodeContents(text);
}
// Apply style.
var style = new CKEDITOR.style({ element: 'a',
attributes: attributes });
style.type = CKEDITOR.STYLE_INLINE; // need to
override... dunno why.
style.applyToRange(range);
range.select();
} else {
// We're only editing an existing link, so just
overwrite the attributes.
var element = this._.selectedElement,
href = element.data('cke-saved-href'),
textView = element.getHtml();
element.setAttributes(attributes);
element.removeAttributes(removeAttributes);
if (data.adv && data.adv.advName && CKEDITOR.pl
ugins.link.synAnchorSelector)
element.addClass(element.getChildCount() ?
'cke_anchor' : 'cke_anchor_empty');
// Update text view when user changes protocol
(#4612).
if (href == textView || data.type == 'email' &&
textView.indexOf('@') != -1) {
// Short mailto link text view (#5736).
element.setHtml(data.type == 'email' ? data
.email.address : attributes['data-cke-saved-href']);
}
selection.selectElement(element);
delete this._.selectedElement;
}
},
onLoad: function () {
var selection = editor.getSelection();
// Browser need the "href" fro copy/paste link to w
ork. (#6641)
if (!editor.config.linkShowAdvancedTab)
this.hidePage('advanced'); //Hide Advanded tab.
if (!editor.config.linkShowTargetTab)
this.hidePage('target'); //Hide Target tab.
}//,
// Inital focus on 'url' field if link is of type URL.
//onFocus: function () {
// var linkType = this.getContentElement('info', 'li
nkType'),
// urlField;
// if (linkType && linkType.getValue() == 'url') {
// urlField = this.getContentElement('info', 'ur
l');
// urlField.select();
// }
//}
};
});
}
}
});
}
//function addPlugin() {
CKEDITOR.plugins.add('simpleLink',
{
lang: 'ar,ca,cs,cy,de,el,en,en-gb,es,fa,fi,fr,gl,he,hr,hu,it,ja,km,nb,n
l,no,pl,pt,pt-br,ru,sl,sv,tt,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
// The plugin initialization logic goes inside this method.
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.pluginDefinit
ion.html#init
init: function (editor) {
var iconPath = this.path + 'images/icon.png';
//var lstValuePage = "welcome";
//var checkExistInput = document.getElementById("listInternalLinks"
);
//if (!checkExistInput) {
// $.ajax({
// url: "page/listpage",
// type: "GET",
// success: function (result) {
// if (result.lstPage.length > 0) {
// lstValuePage = result.lstPage;
// console.log(lstValuePage);
// //$("body").append('<input type="hidden" id="
listInternalLinks" value='+ result.lstPage +'/>');
// // appendBody.init("input", "listInternalLink
s", "value", result.lstPage);
// }
// }
// });
// //console.log(lstValuePage);
// //$('body').append('<h1>foobar</h1>');
// //$("body").append('<input type="hiddend" value="bullshit"/>'
);
//}
//console.log(lstValuePage);
var lstValuePage = "";
var checkExistInput = document.getElementById("listInternalLinks");
if (checkExistInput == null) {
getLinkData(function (result) {
if (result.lstPage.length > 0) {
lstValuePage = result.lstPage;
console.log(lstValuePage);
//$("body").append('<input type="hidden" id="listIntern
alLinks" value='+ result.lstPage +'/>');
appendBody.init("input", "listInternalLinks", "value",
result.lstPage);
//addFullPlugin();
} //else {
//addPlugin();
//}
});
}
editor.addCommand('simpleLinkDialog', new CKEDITOR.dialogCommand('s
impleLinkDialog'));
editor.ui.addButton('SimpleLink',
{
// Toolbar button tooltip.
label: editor.lang.simpleLink.insertLink,// 'Insert a Link'
,
// Reference to the plugin command name.
command: 'simpleLinkDialog',
// Button's icon file path.
icon: iconPath
});
editor.on('doubleclick', function (evt) {
var element = CKEDITOR.plugins.link.getSelectedLink(editor) ||
evt.data.element;
if (!element.isReadOnly()) {
if (element.is('a')) {
evt.data.dialog = 'simpleLinkDialog';
editor.getSelection().selectElement(element);
}
//else if (CKEDITOR.plugins.link.tryRestoreFakeAnchor(edito
r, element))
// evt.data.dialog = 'anchor';
}
});
if (editor.contextMenu) {
editor.removeMenuItem('link');
editor.addMenuGroup('editGroup');
editor.addMenuItem('edititem',
{
label: editor.lang.simpleLink.linkProperties,// 'Link p
roperties',
icon: iconPath,
command: 'simpleLinkDialog',
group: 'editGroup'
});
editor.contextMenu.addListener(function (element) {
if (!element.is('a'))
return null;
return { edititem: CKEDITOR.TRISTATE_ON };
});
}
var linkData = document.getElementById("listInternalLinks");
var pageInternal = "";
if (linkData != null) {
pageInternal = linkData.value;
}
//var pageInternal = "";
//if (stringPage) {
// console.log(stringPage);
// pageInternal = stringPage.substring(1, stringPage.length - 1)
;
//}

if (pageInternal.length > 0) {
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dialo
g.dialogDefinition.html
CKEDITOR.dialog.add('simpleLinkDialog', function (editor) {
var plugin = CKEDITOR.plugins.link;
// Handles the event when the "Target" selection box is cha
nged.
var targetChanged = function () {
var dialog = this.getDialog(),
popupFeatures = dialog.getContentElement('tbAnother
Web', 'popupFeatures'),
targetName = dialog.getContentElement('tbAnotherWeb
', 'linkTargetName'),
value = this.getValue();
if (!popupFeatures || !targetName)
return;
popupFeatures = popupFeatures.getElement();
popupFeatures.hide();
targetName.setValue('');
switch (value) {
case 'frame':
targetName.setLabel(editor.lang.link.targetFram
eName);
targetName.getElement().show();
break;
case 'popup':
popupFeatures.show();
targetName.setLabel(editor.lang.link.targetPopu
pName);
targetName.getElement().show();
break;
default:
targetName.setValue(value);
targetName.getElement().hide();
break;
}
};
var targetLocalChanged = function () {
var dialog = this.getDialog(),
popupFeatures = dialog.getContentElement('tbLocalPa
ge', 'popupFeatures1'),
targetName = dialog.getContentElement('tbLocalPage'
, 'linkTargetName1'),
value = this.getValue();
if (!popupFeatures || !targetName)
return;
popupFeatures = popupFeatures.getElement();
popupFeatures.hide();
targetName.setValue('');
switch (value) {
case 'frame':
targetName.setLabel(editor.lang.link.targetFram
eName);
targetName.getElement().show();
break;
case 'popup':
popupFeatures.show();
targetName.setLabel(editor.lang.link.targetPopu
pName);
targetName.getElement().show();
break;
default:
targetName.setValue(value);
targetName.getElement().hide();
break;
}
};
// Handles the event when the "Type" selection box is chang
ed.
var linkTypeChanged = function () {
var dialog = this.getDialog(),
partIds = ['urlOptions', 'localPageOptions', 'email
Options'], // edit by tuannh ,
//partIds = [ 'urlOptions', 'anchorOptions', 'email
Options' ],
typeValue = this.getValue(),
uploadTab = dialog.definition.getContents('upload')
,
uploadInitiallyHidden = uploadTab && uploadTab.hidd
en;
//if (typeValue == 'url') {
// if (editor.config.linkShowTargetTab)
// dialog.showPage('target');
// if (!uploadInitiallyHidden)
// dialog.showPage('upload');
//} else {
// dialog.hidePage('target');
// if (!uploadInitiallyHidden)
// dialog.hidePage('upload');
//}
for (var i = 0; i < partIds.length; i++) {
var element = dialog.getContentElement('info', part
Ids[i]);
if (!element)
continue;
element = element.getElement().getParent().getParen
t();
if (partIds[i] == typeValue + 'Options')
element.show();
else
element.hide();
}
dialog.layout();
};
// Loads the parameters in a selected link to the link dial
og fields.
var javascriptProtocolRegex = /^javascript:/,
emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,
emailBodyRegex = /body=([^;?:@&=$,\/]*)/,
anchorRegex = /^#(.*)$/,
urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,
selectableTargets = /^(_(?:self|top|parent|blank))$/,
encodedEmailLinkRegex = /^javascript:void\(location\.hr
ef='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/,
functionCallProtectedEmailLinkRegex = /^javascript:([^(
]+)\(([^)]+)\)$/;
var popupRegex = /\s*window.open\(\s*this\.href\s*,\s*(?:'(
[^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/;
var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi;
var multiTarget = "notSet";
var multiTargetName = "notSet";
var targetTab = "tbAnotherWeb";
var parseLink = function (editor, element) {
var href = (element && (element.data('cke-saved-href')
|| element.getAttribute('href'))) || '',
javascriptMatch, emailMatch, urlMatch,
retval = {};//anchorMatch,
if ((javascriptMatch = href.match(javascriptProtocolReg
ex))) {
if (emailProtection == 'encode') {
href = href.replace(encodedEmailLinkRegex, func
tion (match, protectedAddress, rest) {
return 'mailto:' +
String.fromCharCode.apply(String, prote
ctedAddress.split(',')) +
(rest && unescapeSingleQuote(rest));
});
}
// Protected email link as function call.
else if (emailProtection) {
href.replace(functionCallProtectedEmailLinkRege
x, function (match, funcName, funcArgs) {
if (funcName == compiledProtectionFunction.
name) {
retval.type = 'email';
var email = retval.email = {};
var paramRegex = /[^,\s]+/g,
paramQuoteRegex = /(^')|('$)/g,
paramsMatch = funcArgs.match(paramR
egex),
paramsMatchLength = paramsMatch.len
gth,
paramName, paramVal;
for (var i = 0; i < paramsMatchLength;
i++) {
paramVal = decodeURIComponent(unesc
apeSingleQuote(paramsMatch[i].replace(paramQuoteRegex, '')));
paramName = compiledProtectionFunct
ion.params[i].toLowerCase();
email[paramName] = paramVal;
}
email.address = [email.name, email.doma
in].join('@');
}
});
}
}
if (!retval.type) {
// Protected email link as encoded string.
//else
if ((emailMatch = href.match(emailRegex))) {
var subjectMatch = href.match(emailSubjectRegex
),
bodyMatch = href.match(emailBodyRegex);
retval.type = 'email';
var email = (retval.email = {});
email.address = emailMatch[1];
subjectMatch && (email.subject = decodeURICompo
nent(subjectMatch[1]));
bodyMatch && (email.body = decodeURIComponent(b
odyMatch[1]));
}
// urlRegex matches empty strings, so need to c
heck for href as well.
else if (href && (urlMatch = href.match(urlRegex)))
{
retval.type = 'url';
retval.url = {};
if (typeof (urlMatch[1]) === 'undefined') {
var lstExtentions = ["7z", "aiff", "asf", "
avi", "bmp", "csv", "doc", "docx", "fla", "flv", "gif", "gz", "gzip", "jpeg", "j
pg", "mid", "mov", "mp3", "mp4", "mpc", "mpeg", "mpg", "ods", "odt", "pdf", "png
", "ppt", "pptx", "pxd", "qt", "ram", "rar", "rm", "rmi", "rmvb", "rtf", "sdc",
"sitd", "swf", "sxc", "sxw", "tar", "tgz", "tif", "tiff", "txt", "vsd", "wav", "
wma", "wmv", "xls", "xlsx", "zip"];
var lastIndexUrl = href.split('.').pop();
var checkExist = (lstExtentions.indexOf(las
tIndexUrl) > -1);
if (checkExist == true) {
retval.type = 'url';
retval.url.url = urlMatch[2];
}
else {
retval.type = 'localPage';
retval.localPage = urlMatch[2];
}
} else {
retval.url.protocol = urlMatch[1];
retval.url.url = urlMatch[2];
}
} else
retval.type = 'url'; //'url'
}
// Load target and popup settings.
if (element) {
var target = element.getAttribute('target');
retval.target = {};
retval.adv = {};
// IE BUG: target attribute is an empty string inst
ead of null in IE if it's not set.
if (!target) {
var onclick = element.data('cke-pa-onclick') ||
element.getAttribute('onclick'),
onclickMatch = onclick && onclick.match(pop
upRegex);
if (onclickMatch) {
retval.target.type = 'popup';
retval.target.name = onclickMatch[1];
var featureMatch;
while ((featureMatch = popupFeaturesRegex.e
xec(onclickMatch[2]))) {
// Some values should remain numbers (#
7300)
if ((featureMatch[2] == 'yes' || featur
eMatch[2] == '1') && !(featureMatch[1] in { height: 1, width: 1, top: 1, left: 1
}))
retval.target[featureMatch[1]] = tr
ue;
else if (isFinite(featureMatch[2]))
retval.target[featureMatch[1]] = fe
atureMatch[2];
}
}
} else {
var targetMatch = target.match(selectableTarget
s);
if (targetMatch)
retval.target.type = retval.target.name = t
arget;
else {
retval.target.type = 'frame';
retval.target.name = target;
}
}
var me = this;
var advAttr = function (inputName, attrName) {
var value = element.getAttribute(attrName);
if (value !== null)
retval.adv[inputName] = value || '';
};
advAttr('advId', 'id');
advAttr('advLangDir', 'dir');
advAttr('advAccessKey', 'accessKey');
retval.adv.advName = element.data('cke-saved-name')
|| element.getAttribute('name') || '';
advAttr('advLangCode', 'lang');
advAttr('advTabIndex', 'tabindex');
advAttr('advTitle', 'title');
advAttr('advContentType', 'type');
CKEDITOR.plugins.link.synAnchorSelector ? retval.ad
v.advCSSClasses = getLinkClass(element) : advAttr('advCSSClasses', 'class');
advAttr('advCharset', 'charset');
advAttr('advStyles', 'style');
advAttr('advRel', 'rel');
}
// Find out whether we have any anchors in the editor.
var anchors = retval.anchors = [],
i, count, item;
// For some browsers we set contenteditable="false" on
anchors, making document.anchors not to include them, so we must traverse the li
nks manually (#7893).
if (CKEDITOR.plugins.link.emptyAnchorFix) {
var links = editor.document.getElementsByTag('a');
for (i = 0, count = links.count() ; i < count; i++)
{
item = links.getItem(i);
if (item.data('cke-saved-name') || item.hasAttr
ibute('name'))
anchors.push({ name: item.data('cke-saved-n
ame') || item.getAttribute('name'), id: item.getAttribute('id') });
}
} else {
var anchorList = new CKEDITOR.dom.nodeList(editor.d
ocument.$.anchors);
for (i = 0, count = anchorList.count() ; i < count;
i++) {
item = anchorList.getItem(i);
anchors[i] = { name: item.getAttribute('name'),
id: item.getAttribute('id') };
}
}
if (CKEDITOR.plugins.link.fakeAnchor) {
var imgs = editor.document.getElementsByTag('img');
for (i = 0, count = imgs.count() ; i < count; i++)
{
if ((item = CKEDITOR.plugins.link.tryRestoreFak
eAnchor(editor, imgs.getItem(i))))
anchors.push({ name: item.getAttribute('nam
e'), id: item.getAttribute('id') });
}
}
// Record down the selected element in the dialog.
this._.selectedElement = element;
return retval;
};
var setupParams = function (page, data) {
if (data[page])
this.setValue(data[page][this.id] || '');
};
var setupPopupParams = function (data) {
return setupParams.call(this, 'target', data);
};
var setupAdvParams = function (data) {
return setupParams.call(this, 'adv', data);
};
var commitParams = function (page, data) {
if (!data[page])
data[page] = {};
data[page][this.id] = this.getValue() || '';
};
var commitPopupParams = function (data) {
return commitParams.call(this, 'target', data);
};
var commitPopupParamsLocalPage = function (data) {
return commitParams.call(this, 'target', data);
};
var commitAdvParams = function (data) {
return commitParams.call(this, 'adv', data);
};
function unescapeSingleQuote(str) {
return str.replace(/\\'/g, '\'');
}
function escapeSingleQuote(str) {
return str.replace(/'/g, '\\$&');
}
var featureListWebAddress = ['resizable', 'status', 'locati
on', 'toolbar', 'menubar', 'fullscreen',

'scrollbars', 'dependent'];
var emailProtection = editor.config.emailProtection || '';
// Compile the protection function pattern.
if (emailProtection && emailProtection != 'encode') {
var compiledProtectionFunction = {};
emailProtection.replace(/^([^(]+)\(([^)]+)\)$/, functio
n (match, funcName, params) {
compiledProtectionFunction.name = funcName;
compiledProtectionFunction.params = [];
params.replace(/[^,\s]+/g, function (param) {
compiledProtectionFunction.params.push(param);
});
});
}
function protectEmailLinkAsFunction(email) {
var retval,
name = compiledProtectionFunction.name,
params = compiledProtectionFunction.params,
paramName, paramValue;
retval = [name, '('];
for (var i = 0; i < params.length; i++) {
paramName = params[i].toLowerCase();
paramValue = email[paramName];
i > 0 && retval.push(',');
retval.push('\'', paramValue ? escapeSingleQuote(en
codeURIComponent(email[paramName])) : '', '\'');
}
retval.push(')');
return retval.join('');
}
function protectEmailAddressAsEncodedString(address) {
var charCode,
length = address.length,
encodedChars = [];
for (var i = 0; i < length; i++) {
charCode = address.charCodeAt(i);
encodedChars.push(charCode);
}
return 'String.fromCharCode(' + encodedChars.join(',')
+ ')';
}
function getLinkClass(ele) {
var className = ele.getAttribute('class');
return className ? className.replace(/\s*(?:cke_anchor_
empty|cke_anchor)(?:\s*$)?/g, '') : '';
}
var commonLang = editor.lang.common,
linkLang = editor.lang.link;
return {
id: 'info',
title: editor.lang.simpleLink.insertLink,//'Insert a li
nk',
minWidth: 400,
minHeight: 200,
contents:
[
{
// Definition of the Advanced Settings dialog w
indow tab with its id, label and contents.
id: 'tbAnotherWeb',
label: editor.lang.simpleLink.webAddress,// 'We
b address',
elements:
[
{
type: 'vbox',
id: 'urlOptions',
children: [
{
type: 'hbox',
widths: ['25%', '75%'],
children: [
{
id: 'protocol',
type: 'select',
label: commonLang.proto
col,
'default': 'http://',
items: [
// Force 'ltr' for
protocol names in BIDI. (#5433)
//,[linkLang.other,
'']
['http://\u200E', '
http://'],
['https://\u200E',
'https://'],
['ftp://\u200E', 'f
tp://'],
['news://\u200E', '
news://'],
[linkLang.other, ''
]
],
setup: function (data)
{
if (data.url)
this.setValue(d
ata.url.protocol || '');
},
commit: function (data)
{
if (!data.url)
data.url = {};
data.url.protocol =
this.getValue();
}
},
{
type: 'text',
id: 'url',
label: commonLang.url,
required: true,
onLoad: function () {
this.allowOnChange
= true;
},
onKeyUp: function () {
this.allowOnChange
= false;
var protocolCmb = t
his.getDialog().getContentElement('tbAnotherWeb', 'protocol'),
url = this.getV
alue(),
urlOnChangeProt
ocol = /^(http|https|ftp|news):\/\/(?=.)/i,
urlOnChangeTest
Other = /^((javascript:)|[#\/\.\?])/i;
var protocol = urlO
nChangeProtocol.exec(url);
if (protocol) {
this.setValue(u
rl.substr(protocol[0].length));
protocolCmb.set
Value(protocol[0].toLowerCase());
} else if (urlOnCha
ngeTestOther.test(url))
protocolCmb.set
Value('');
this.allowOnChange
= true;
},
onChange: function () {
if (this.allowOnCha
nge) // Dont't call on dialog load.
this.onKeyUp();
},
validate: function () {
var currObj = CKEDI
TOR.dialog.getCurrent();
var currTab = currO
bj.definition.dialog._.currentTabId;
if (currTab == "tbA
notherWeb") {
var dialog = th
is.getDialog();
console.log("pr
otocol", dialog.getValueOf('tbAnotherWeb', 'protocol'));
if (dialog.getC
ontentElement('tbAnotherWeb', 'urlOptions') && dialog.getValueOf('tbAnotherWeb',
'protocol') == '')
return true
;
var re = /(http
(s)?:\\)?([\w-]+\.)+[\w-]+[.com|.in|.org]+(\[\?%&=]*)?/;
if ((/javascrip
t\:/).test(this.getValue())) {
alert(commo
nLang.invalidValue);
return fals
e;
}
if (!re.test(th
is.getValue())) {
alert(commo
nLang.invalidValue);
return fals
e;
}
if (this.getDia
log().fakeObj) // Edit Anchor.
return true
;
return true;
}
},
setup: function (data)
{
this.allowOnChange
= false;
if (data.url)
this.setValue(d
ata.url.url);
if (data.type == 'u
rl')
this.select();
this.allowOnChange
= true;
},
commit: function (data)
{
// IE will not trig
ger the onChange event if the mouse has been used
// to carry all the
operations #4724
this.onChange();
if (!data.url)
data.url = {};
data.url.url = this
.getValue();
this.allowOnChange
= false;
}
}
],
setup: function (data) {
this.getElement().show();
}
},
{
type: 'button',
id: 'browse',
hidden: 'true',
filebrowser: 'tbAnotherWeb:url'
,
label: commonLang.browseServer
}
]
},
{
type: 'hbox',
widths: ['50%', '50%'],
children: [
{
type: 'select',
id: 'linkTargetType',
label: commonLang.target,
'default': 'notSet',
style: 'width : 100%;',
'items': [
[commonLang.notSet, 'notSet
'],
[linkLang.targetFrame, 'fra
me'],
[linkLang.targetPopup, 'pop
up'],
[commonLang.targetNew, '_bl
ank'],
[commonLang.targetTop, '_to
p'],
[commonLang.targetSelf, '_s
elf'],
[commonLang.targetParent, '
_parent']
],
onChange: targetChanged,
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.type || 'notSet');
targetChanged.call(this);
},
commit: function (data) {
if (!data.target)
data.target = {};
console.log("value target a
nother", this.getValue());
var currObj = CKEDITOR.dial
og.getCurrent();
var currTab = currObj.defin
ition.dialog._.currentTabId;
targetTab = currTab;
if (currTab == "tbLocalPage
") {
data.target.type = mult
iTarget;
} else {
data.target.type = this
.getValue();
multiTarget = this.getV
alue();
}
}
},
{
type: 'text',
id: 'linkTargetName',
label: linkLang.targetFrameName
,
'default': '',
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.name);
},
commit: function (data) {
if (!data.target)
data.target = {};
var currObj = CKEDITOR.dial
og.getCurrent();
var currTab = currObj.defin
ition.dialog._.currentTabId;
if (currTab == "tbLocalPage
") {
data.target.name = mult
iTargetName;
} else {
multiTargetName = this.
getValue().replace(/\W/gi, '');
data.target.name = this
.getValue().replace(/\W/gi, '');
}
}
}
]
},
{
type: 'vbox',
width: '100%',
align: 'center',
padding: 2,
id: 'popupFeatures',
children: [
{
type: 'fieldset',
label: linkLang.popupFeatures,
children: [
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'resizable',
label: linkLang.popupResizable,
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.resizable);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams;
featureListWebAddress['
resizable'] = this.getValue();
data.target.resizable =
this.getValue();
console.log("comit tban
otherweb", data);
//return commitPopupPar
ams;
}
//return commitPopupParams;
}
},
{
type: 'checkbox',
id: 'status',
label: linkLang.popupStatusBar,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.status);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams;
featureListWebAddress['
status'] = this.getValue();
data.target.status = th
is.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'location',
label: linkLang.popupLocationBa
r,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.location);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams;//
featureListWebAddress['
location'] = this.getValue();
data.target.location =
this.getValue();
}
//return commitPopupParams;
}
},
{
type: 'checkbox',
id: 'toolbar',
label: linkLang.popupToolbar,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.toolbar);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
toolbar'] = this.getValue();
data.target.toolbar = t
his.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'menubar',
label: linkLang.popupMenuBar,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.menubar);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
menubar'] = this.getValue();
data.target.menubar = t
his.getValue();
}
//return commitPopupParams;
}
},
{
type: 'checkbox',
id: 'fullscreen',
label: linkLang.popupFullScreen
,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.fullscreen);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams;//
featureListWebAddress['
fullscreen'] = this.getValue();
data.target.fullscreen
= this.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'checkbox',
id: 'scrollbars',
label: linkLang.popupScrollBars
,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.scrollbars);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
scrollbars'] = this.getValue();
data.target.scrollbars
= this.getValue();
}
//return commitPopupParams;
}
},
{
type: 'checkbox',
id: 'dependent',
label: linkLang.popupDependent,
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.dependent);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
dependent'] = this.getValue();
data.target.dependent =
this.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'text',
widths: ['50%', '50%'],
labelLayout: 'horizontal',
label: commonLang.width,
id: 'width',
setup: function (data) {
if (data.target)
this.setValue(data.targ
et.width);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
data.target.width = thi
s.getValue();
featureListWebAddress['
width'] = this.getValue();
//return commitPopupPar
ams;
}
//return commitPopupParams;
}
},
{
type: 'text',
labelLayout: 'horizontal',
widths: ['50%', '50%'],
label: linkLang.popupLeft,
id: 'left',
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.left);
},
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
left'] = this.getValue();
data.target.left = this
.getValue();
}
//return commitPopupParams;
}
}
]
},
{
type: 'hbox',
children: [
{
type: 'text',
labelLayout: 'horizontal',
widths: ['50%', '50%'],
label: commonLang.height,
id: 'height',
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.height);
}//setupPopupParams
,
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
featureListWebAddress['
height'] = this.getValue();
data.target.height = th
is.getValue();
//return commitPopupPar
ams;
}
//return commitPopupParams;
}
},
{
type: 'text',
labelLayout: 'horizontal',
label: linkLang.popupTop,
widths: ['50%', '50%'],
id: 'top',
setup: function (data) {
if (typeof (data.target) !=
'undefined')
this.setValue(data.targ
et.top);
}//setupPopupParams
,
commit: function (data) {
if (targetTab == "tbLocalPa
ge") {
return commitPopupParam
sLocalPage;
} else {
//return commitPopupPar
ams; //
featureListWebAddress['
top'] = this.getValue();
data.target.top = this.
getValue();
}
//return commitPopupParams;
}
}
]
}
]
}
]
}
]
}, {
// Definition of the Advanced Settings dialog w
indow tab with its id, label and contents.
id: 'tbEmail',
label: 'Email',
elements:
[
{
type: 'vbox',
id: 'emailOptions',
padding: 1,
children: [
{
type: 'text',
id: 'emailAddress',
label: linkLang.emailAddress,
required: true,
validate:
function () {
var currObj = CKEDITOR.
dialog.getCurrent();
var currTab = currObj.d
efinition.dialog._.currentTabId;
var dialog = CKEDITOR.d
ialog.getCurrent();
if (currTab == "tbEmail
") {
//var dialog = this
.getDialog();
//var emailValue =
this.getDialog().getContentElement('tbEmail', 'emailAddress');
var emailValue = di
alog.getValueOf("tbEmail", "emailAddress");
var emailReg = /^([
\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if (!emailReg.test(
emailValue)) {
alert(commonLan
g.invalidValue);
return false;
}
//var func = CKEDIT
OR.dialog.validate.notEmpty(linkLang.noEmail);
//return func.apply
(this);
return true;
}
},
setup: function (data) {
if (data.email)
this.setValue(data.emai
l.address);
if (data.type == 'email')
this.select();
},
commit: function (data) {
if (!data.email)
data.email = {};
data.email.address = this.g
etValue();
}
},
{
type: 'text',
id: 'emailSubject',
label: linkLang.emailSubject,
setup: function (data) {
if (data.email)
this.setValue(data.emai
l.subject);
},
commit: function (data) {
if (!data.email)
data.email = {};
data.email.subject = this.g
etValue();
}
},
{
type: 'textarea',
id: 'emailBody',
label: linkLang.emailBody,
rows: 3,
'default': '',
setup: function (data) {
if (data.email)
this.setValue(data.emai
l.body);
},
commit: function (data) {
if (!data.email)
data.email = {};
data.email.body = this.getV
alue();
}
}
]
,
setup: function (data) {
this.getElement().show();
}
}
]
},
{
id: 'upload',
label: linkLang.upload,
title: linkLang.upload,
hidden: true,
filebrowser: 'uploadButton',
elements: [
{
type: 'file',
id: 'upload',
label: commonLang.upload,
style: 'height:40px',
size: 29
},
{
type: 'fileButton',
id: 'uploadButton',
label: commonLang.uploadSubmit,
filebrowser: 'tbAnotherWeb:url',
'for': ['upload', 'upload']
}
]
}
],
onShow: function () {
var editor = this.getParentEditor(),
selection = editor.getSelection(),
element = null;
// Fill in all the relevant fields if there's alrea
dy one link selected.
if ((element = plugin.getSelectedLink(editor)) && e
lement.hasAttribute('href')) {
selection.selectElement(element);
if (element.getAttribute('data-type') == "cmsLi
nk") {
var dialog = CKEDITOR.dialog.getCurrent();
dialog.selectPage("tbLocalPage");
}
} else
element = null;
this.setupContent(parseLink.apply(this, [editor, el
ement]));
},
onOk: function () {
var currObj = CKEDITOR.dialog.getCurrent();
var currTab = currObj.definition.dialog._.currentTa
bId;
var attributes = {},
removeAttributes = [],
data = {},
me = this,
editor = this.getParentEditor();
this.commitContent(data);
// Compose the URL.
switch (currTab) {
// (data.type || 'url') {
case 'tbAnotherWeb':
var protocol = (data.url && data.url.protoc
ol != undefined) ? data.url.protocol : 'http://',
url = (data.url && CKEDITOR.tools.trim(
data.url.url)) || '';
attributes['data-cke-saved-href'] = (url.in
dexOf('/') === 0) ? url : protocol + url;
attributes['data-type'] = 'anotherLink';
if (data.target.resizable == "") data.targe
t.resizable = featureListWebAddress['resizable'];
if (data.target.width == "") data.target.wi
dth = featureListWebAddress['width'];
if (data.target.status == "") data.target.s
tatus = featureListWebAddress['status'];
if (data.target.location == "") data.target
.location = featureListWebAddress['location'];
if (data.target.toolbar == "") data.target.
toolbar = featureListWebAddress['toolbar'];
if (data.target.menubar == "") data.target.
menubar = featureListWebAddress['menubar'];
if (data.target.fullscreen == "") data.targ
et.fullscreen = featureListWebAddress['fullscreen'];
if (data.target.scrollbars == "") data.targ
et.scrollbars = featureListWebAddress['scrollbars'];
if (data.target.dependent == "") data.targe
t.dependent = featureListWebAddress['dependent'];
if (data.target.height == "") data.target.h
eight = featureListWebAddress['height'];
if (data.target.left == "") data.target.lef
t = featureListWebAddress['left'];
if (data.target.top == "") data.target.top
= featureListWebAddress['top'];
break;
case 'tbLocalPage':
// edit by tuannh
var localPage = data.localPage;
attributes['data-cke-saved-href'] = data.lo
calPage;
attributes['data-type'] = 'cmsLink';
break;
//case 'tbAnchor':
// var name = (data.anchor && data.ancho
r.name),
// id = (data.anchor && data.anchor.
id);
// attributes['data-cke-saved-href'] = '
#' + (name || id || '');
// attributes['data-type'] = 'anchorLink
';
// break;
case 'tbEmail':
var linkHref,
email = data.email,
address = email.address;
switch (emailProtection) {
case '':
case 'encode':
{
var subject = encodeURIComponen
t(email.subject || ''),
body = encodeURIComponent(e
mail.body || '');
// Build the e-mail parameters
first.
var argList = [];
subject && argList.push('subjec
t=' + subject);
body && argList.push('body=' +
body);
argList = argList.length ? '?'
+ argList.join('&') : '';
attributes['data-type'] = 'emai
lLink';
if (emailProtection == 'encode'
) {
linkHref = ['javascript:voi
d(location.href=\'mailto:\'+',
protectEmailAddressAsEn
codedString(address)];
// parameters are optional.
argList && linkHref.push('+
\'', escapeSingleQuote(argList), '\'');
linkHref.push(')');
} else
linkHref = ['mailto:', addr
ess, argList];
break;
}
default:
{
// Separating name and domain.
attributes['data-type'] = 'emai
lLink';
var nameAndDomain = address.spl
it('@', 2);
email.name = nameAndDomain[0];
email.domain = nameAndDomain[1]
;
linkHref = ['javascript:', prot
ectEmailLinkAsFunction(email)];
}
}
attributes['data-cke-saved-href'] = linkHre
f.join('');
break;
}
if (data.target) {
if (data.target.type == 'popup') {
var onclickList = ['window.open(this.href,
\'',

data.target.name || '', '\', \''];
var featureList = ['resizable', 'status', '
location', 'toolbar', 'menubar', 'fullscreen',

'scrollbars', 'dependent'];
var featureLength = featureList.length;
var addFeature = function (featureName) {
if (data.target[featureName])
featureList.push(featureName + '='
+ data.target[featureName]);
};
for (var i = 0; i < featureLength; i++)
featureList[i] = featureList[i] + (data
.target[featureList[i]] ? '=yes' : '=no');
addFeature('width');
addFeature('left');
addFeature('height');
addFeature('top');
onclickList.push(featureList.join(','), '\'
); return false;');
attributes['data-cke-pa-onclick'] = onclick
List.join('');
// Add the "target" attribute. (#5074)
removeAttributes.push('target');
} else {
if (multiTarget != 'notSet' && data.target.
type == 'notSet') {
attributes.target = multiTargetName;
} else {
if (data.target.type != 'notSet' && dat
a.target.name)
attributes.target = data.target.nam
e;
else
removeAttributes.push('target');
}
removeAttributes.push('data-cke-pa-onclick'
, 'onclick');
}
}
var selection = editor.getSelection();
// Browser need the "href" fro copy/paste link to w
ork. (#6641)
attributes.href = attributes['data-cke-saved-href']
;
if (!this._.selectedElement) {
var range = selection.getRanges(1)[0];
// Use link URL as text with a collapsed cursor
.
if (range.collapsed) {
// Short mailto link text view (#5736).
var text = new CKEDITOR.dom.text(data.type
== 'email' ? data.email.address : attributes['data-cke-saved-href'], editor.docu
ment);
range.insertNode(text);
range.selectNodeContents(text);
}
// Apply style.
var style = new CKEDITOR.style({ element: 'a',
attributes: attributes });
style.type = CKEDITOR.STYLE_INLINE; // need to
override... dunno why.
style.applyToRange(range);
range.select();
} else {
// We're only editing an existing link, so just
overwrite the attributes.
var element = this._.selectedElement,
href = element.data('cke-saved-href'),
textView = element.getHtml();
element.setAttributes(attributes);
element.removeAttributes(removeAttributes);
if (data.adv && data.adv.advName && CKEDITOR.pl
ugins.link.synAnchorSelector)
element.addClass(element.getChildCount() ?
'cke_anchor' : 'cke_anchor_empty');
// Update text view when user changes protocol
(#4612).
if (href == textView || data.type == 'email' &&
textView.indexOf('@') != -1) {
// Short mailto link text view (#5736).
element.setHtml(data.type == 'email' ? data
.email.address : attributes['data-cke-saved-href']);
}
selection.selectElement(element);
delete this._.selectedElement;
}
},
onLoad: function () {
var selection = editor.getSelection();
// Browser need the "href" fro copy/paste link to w
ork. (#6641)
if (!editor.config.linkShowAdvancedTab)
this.hidePage('advanced'); //Hide Advanded tab.
if (!editor.config.linkShowTargetTab)
this.hidePage('target'); //Hide Target tab.
}//,
// Inital focus on 'url' field if link is of type URL.
//onFocus: function () {
// var linkType = this.getContentElement('info', 'li
nkType'),
// urlField;
// if (linkType && linkType.getValue() == 'url') {
// urlField = this.getContentElement('info', 'ur
l');
// urlField.select();
// }
//}
};
});
}
}
});
//}

Potrebbero piacerti anche