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,
56
url = prompt(CreateLinkBase.STRINGS.PROMPT, CreateLinkBase.STRINGS.DEFAULT);
60
this.get('host')._execCommand(cmd, url);
61
sel = new inst.Selection();
62
out = sel.getSelected();
63
if (!sel.isCollapsed && out.size()) {
65
a = out.item(0).one('a');
67
out.item(0).replace(a);
70
//No selection, insert a new node..
71
this.get('host').execCommand('inserthtml', '<a href="' + url + '">' + url + '</a>');
80
}, '3.2.0' ,{skinnable:false, requires:['editor-base']});