Hi,
I would like to change the link entered when the onOK event in link dialog fires. Is this possible?
help would be great.
Thanks
I would like to change the link entered when the onOK event in link dialog fires. Is this possible?
dialog.on('ok', function () {
var urlField = this.getContentElement('info', 'url');
$.ajax({
type: "POST",
url: "services/theservice.asmx/GenerateLink",
data: "{ sURL: '" + urlField + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (link) {
//this.setValueOf('info', 'url', link.d);
}
});
});
help would be great.
Thanks

Re: Is it Possible to change link onOK event in link dialog
CKEDITOR.on('dialogDefinition', function (ev) { // Take the dialog name and its definition from the event // data. var dialogName = ev.data.name; var dialogDefinition = ev.data.definition; var dialog = dialogDefinition.dialog; // Check if the definition is from the dialog we're // interested on (the "Link" dialog). if (dialogName == 'link') { //remove unused tabs dialogDefinition.removeContents('advanced'); dialogDefinition.removeContents('target'); // Get a reference to the "Link Info" tab. var infoTab = dialogDefinition.getContents('info'); // Remove the "Link Type" combo and the "Browser // Server" button from the "info" tab. infoTab.remove('linkType'); infoTab.remove('browse'); dialogDefinition.onOk = function () { var attributes = {}, removeAttributes = [], data = {}, me = this, editor = this.getParentEditor(); this.commitContent(data); // Compose the URL. switch (data.type || 'url') { case 'url': var protocol = (data.url && data.url.protocol != undefined) ? data.url.protocol : 'http://', url = (data.url && data.url.url) || ''; $.ajax({ type: "POST", url: "services/theservice.asmx/GenerateLink", data: "{sURL: '" + url + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (link) { attributes['data-cke-saved-href'] = link.d; } }); break; case 'anchor': var name = (data.anchor && data.anchor.name), id = (data.anchor && data.anchor.id); attributes['data-cke-saved-href'] = '#' + (name || id || ''); break; case 'email': var linkHref, email = data.email, address = email.address; switch (emailProtection) { case '': case 'encode': { var subject = encodeURIComponent(email.subject || ''), body = encodeURIComponent(email.body || ''); // Build the e-mail parameters first. var argList = []; subject && argList.push('subject=' + subject); body && argList.push('body=' + body); argList = argList.length ? '?' + argList.join('&') : ''; if (emailProtection == 'encode') { linkHref = ['javascript:void(location.href=\'mailto:\'+', protectEmailAddressAsEncodedString(address)]; // parameters are optional. argList && linkHref.push('+\'', escapeSingleQuote(argList), '\''); linkHref.push(')'); } else linkHref = ['mailto:', address, argList]; break; } default: { // Separating name and domain. var nameAndDomain = address.split('@', 2); email.name = nameAndDomain[0]; email.domain = nameAndDomain[1]; linkHref = ['javascript:', protectEmailLinkAsFunction(email)]; } } attributes['data-cke-saved-href'] = linkHref.join(''); break; } // Popups and target. 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'] = onclickList.join(''); // Add the "target" attribute. (#5074) removeAttributes.push('target'); } else { if (data.target.type != 'notSet' && data.target.name) attributes.target = data.target.name; else removeAttributes.push('target'); removeAttributes.push('data-cke-pa-onclick', 'onclick'); } } // Advanced attributes. if (data.adv) { var advAttr = function (inputName, attrName) { var value = data.adv[inputName]; if (value) attributes[attrName] = value; else removeAttributes.push(attrName); }; advAttr('advId', 'id'); advAttr('advLangDir', 'dir'); advAttr('advAccessKey', 'accessKey'); if (data.adv['advName']) { attributes['name'] = attributes['data-cke-saved-name'] = data.adv['advName']; attributes['class'] = (attributes['class'] ? attributes['class'] + ' ' : '') + 'cke_anchor'; } else removeAttributes = removeAttributes.concat(['data-cke-saved-name', 'name']); advAttr('advLangCode', 'lang'); advAttr('advTabIndex', 'tabindex'); advAttr('advTitle', 'title'); advAttr('advContentType', 'type'); advAttr('advCSSClasses', 'class'); advAttr('advCharset', 'charset'); advAttr('advStyles', 'style'); } // Browser need the "href" fro copy/paste link to work. (#6641) attributes.href = attributes['data-cke-saved-href']; if (!this._.selectedElement) { // Create element if current selection is collapsed. var selection = editor.getSelection(), ranges = selection.getRanges(true); if (ranges.length == 1 && ranges[0].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.document); ranges[0].insertNode(text); ranges[0].selectNodeContents(text); selection.selectRanges(ranges); } // Apply style. var style = new CKEDITOR.style({ element: 'a', attributes: attributes }); style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why. style.apply(editor.document); } 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(); // IE BUG: Setting the name attribute to an existing link doesn't work. // Must re-create the link from weired syntax to workaround. if (CKEDITOR.env.ie && attributes.name != element.getAttribute('name')) { var newElement = new CKEDITOR.dom.element('<a name="' + CKEDITOR.tools.htmlEncode(attributes.name) + '">', editor.document); selection = editor.getSelection(); element.copyAttributes(newElement, { name: 1 }); element.moveChildren(newElement); newElement.replace(element); element = newElement; selection.selectElement(element); } element.setAttributes(attributes); element.removeAttributes(removeAttributes); // 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']); } // Make the element display as an anchor if a name has been set. if (element.getAttribute('name')) element.addClass('cke_anchor'); else element.removeClass('cke_anchor'); if (this.fakeObj) editor.createFakeElement(element, 'cke_anchor', 'anchor').replace(this.fakeObj); delete this._.selectedElement; } };Re: Is it Possible to change link onOK event in link dialog