2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('createlink-base', function(Y) {
11 * Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events.
13 * @submodule createlink-base
16 * Adds prompt style link creation. Adds an override for the <a href="Plugin.ExecCommand.html#method_COMMANDS.createlink">createlink execCommand</a>.
17 * @class Plugin.CreateLinkBase
21 var CreateLinkBase = {};
23 * Strings used by the plugin
27 CreateLinkBase.STRINGS = {
29 * String used for the Prompt
33 PROMPT: 'Please enter the URL for the link to point to:',
35 * String used as the default value of the Prompt
42 Y.namespace('Plugin');
43 Y.Plugin.CreateLinkBase = CreateLinkBase;
45 Y.mix(Y.Plugin.ExecCommand.COMMANDS, {
47 * Override for the createlink method from the <a href="Plugin.CreateLinkBase.html">CreateLinkBase</a> plugin.
49 * @method COMMANDS.createlink
51 * @param {String} cmd The command executed: createlink
52 * @return {Node} Node instance of the item touched by this command.
54 createlink: function(cmd) {
55 var inst = this.get('host').getInstance(), out, a, sel, holder,
56 url = prompt(CreateLinkBase.STRINGS.PROMPT, CreateLinkBase.STRINGS.DEFAULT);
59 holder = inst.config.doc.createElement('div');
60 url = inst.config.doc.createTextNode(url);
61 holder.appendChild(url);
62 url = holder.innerHTML;
65 this.get('host')._execCommand(cmd, url);
66 sel = new inst.Selection();
67 out = sel.getSelected();
68 if (!sel.isCollapsed && out.size()) {
70 a = out.item(0).one('a');
72 out.item(0).replace(a);
75 if (a.get('parentNode').test('span')) {
76 if (a.get('parentNode').one('br.yui-cursor')) {
77 a.get('parentNode').insert(a, 'before');
82 //No selection, insert a new node..
83 this.get('host').execCommand('inserthtml', '<a href="' + url + '">' + url + '</a>');
92 }, '3.3.0' ,{requires:['editor-base'], skinnable:false});