createlink-base-debug.js revision 1e44d35dd310d594ecc977ee4ed7cf6ef3746045
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwYUI.add('createlink-base', function(Y) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /**
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Adds prompt style link creation. Adds an override for the <a href="Plugin.ExecCommand.html#method_COMMANDS.createlink">createlink execCommand</a>.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @module editor
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @submodule createlink-base
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /**
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Adds prompt style link creation. Adds an override for the <a href="Plugin.ExecCommand.html#method_COMMANDS.createlink">createlink execCommand</a>.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @class Plugin.CreateLinkBase
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @static
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw var CreateLinkBase = {};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /**
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Strings used by the plugin
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @property STRINGS
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @static
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw CreateLinkBase.STRINGS = {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /**
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * String used for the Prompt
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @property PROMPT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @static
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright PROMPT: 'Please enter the URL for the link to point to:',
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright /**
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * String used as the default value of the Prompt
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright * @property DEFAULT
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright * @static
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright */
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright DEFAULT: 'http://'
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as };
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright Y.namespace('Plugin');
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright Y.Plugin.CreateLinkBase = CreateLinkBase;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Y.mix(Y.Plugin.ExecCommand.COMMANDS, {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /**
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Override for the createlink method from the <a href="Plugin.CreateLinkBase.html">CreateLinkBase</a> plugin.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @for ExecCommand
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @method COMMANDS.createlink
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @static
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @param {String} cmd The command executed: createlink
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * @return {Node} Node instance of the item touched by this command.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw createlink: function(cmd) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as var inst = this.get('host').getInstance(), out, a, sel,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as url = prompt(CreateLinkBase.STRINGS.PROMPT, CreateLinkBase.STRINGS.DEFAULT);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (url) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as Y.log('Adding link: ' + url, 'info', 'createLinkBase');
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw this.get('host')._execCommand(cmd, url);
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright sel = new inst.Selection();
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright out = sel.getSelected();
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright if (!sel.isCollapsed && out.size()) {
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright //We have a selection
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright a = out.item(0).one('a');
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright if (a) {
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright out.item(0).replace(a);
8d96b23e24cf8db8618f698bfa580a25d7dc6029Alan Wright }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw //No selection, insert a new node..
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw this.get('host').execCommand('inserthtml', '<a href="' + url + '">' + url + '</a>');
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return a;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as });
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}, '@VERSION@' ,{requires:['editor-base'], skinnable:false});
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw