1 |
efrain |
1 |
YUI.add('createlink-base', function (Y, NAME) {
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
* Adds prompt style link creation. Adds an override for the
|
|
|
6 |
* <a href="Plugin.ExecCommand.html#method_COMMANDS.createlink">createlink execCommand</a>.
|
|
|
7 |
* @class Plugin.CreateLinkBase
|
|
|
8 |
* @static
|
|
|
9 |
* @submodule createlink-base
|
|
|
10 |
* @module editor
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
var CreateLinkBase = {};
|
|
|
14 |
/**
|
|
|
15 |
* Strings used by the plugin
|
|
|
16 |
* @property STRINGS
|
|
|
17 |
* @static
|
|
|
18 |
*/
|
|
|
19 |
CreateLinkBase.STRINGS = {
|
|
|
20 |
/**
|
|
|
21 |
* String used for the Prompt
|
|
|
22 |
* @property PROMPT
|
|
|
23 |
* @static
|
|
|
24 |
*/
|
|
|
25 |
PROMPT: 'Please enter the URL for the link to point to:',
|
|
|
26 |
/**
|
|
|
27 |
* String used as the default value of the Prompt
|
|
|
28 |
* @property DEFAULT
|
|
|
29 |
* @static
|
|
|
30 |
*/
|
|
|
31 |
DEFAULT: 'http://'
|
|
|
32 |
};
|
|
|
33 |
|
|
|
34 |
Y.namespace('Plugin');
|
|
|
35 |
Y.Plugin.CreateLinkBase = CreateLinkBase;
|
|
|
36 |
|
|
|
37 |
Y.mix(Y.Plugin.ExecCommand.COMMANDS, {
|
|
|
38 |
/**
|
|
|
39 |
* Override for the createlink method from the <a href="Plugin.CreateLinkBase.html">CreateLinkBase</a> plugin.
|
|
|
40 |
* @for Plugin.ExecCommand.COMMANDS
|
|
|
41 |
* @method createlink
|
|
|
42 |
* @static
|
|
|
43 |
* @param {String} cmd The command executed: createlink
|
|
|
44 |
* @return {Node} Node instance of the item touched by this command.
|
|
|
45 |
*/
|
|
|
46 |
createlink: function(cmd) {
|
|
|
47 |
var inst = this.get('host').getInstance(), out, a, sel, holder,
|
|
|
48 |
url = prompt(CreateLinkBase.STRINGS.PROMPT, CreateLinkBase.STRINGS.DEFAULT);
|
|
|
49 |
|
|
|
50 |
if (url) {
|
|
|
51 |
holder = inst.config.doc.createElement('div');
|
|
|
52 |
url = url.replace(/"/g, '').replace(/'/g, ''); //Remove single & double quotes
|
|
|
53 |
url = inst.config.doc.createTextNode(url);
|
|
|
54 |
holder.appendChild(url);
|
|
|
55 |
url = holder.innerHTML;
|
|
|
56 |
|
|
|
57 |
Y.log('Adding link: ' + url, 'info', 'createLinkBase');
|
|
|
58 |
|
|
|
59 |
this.get('host')._execCommand(cmd, url);
|
|
|
60 |
sel = new inst.EditorSelection();
|
|
|
61 |
out = sel.getSelected();
|
|
|
62 |
if (!sel.isCollapsed && out.size()) {
|
|
|
63 |
//We have a selection
|
|
|
64 |
a = out.item(0).one('a');
|
|
|
65 |
if (a) {
|
|
|
66 |
out.item(0).replace(a);
|
|
|
67 |
}
|
|
|
68 |
if (Y.UA.gecko) {
|
|
|
69 |
if (a.get('parentNode').test('span')) {
|
|
|
70 |
if (a.get('parentNode').one('br.yui-cursor')) {
|
|
|
71 |
a.get('parentNode').insert(a, 'before');
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
} else {
|
|
|
76 |
//No selection, insert a new node..
|
|
|
77 |
this.get('host').execCommand('inserthtml', '<a href="' + url + '">' + url + '</a>');
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
return a;
|
|
|
81 |
}
|
|
|
82 |
});
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
}, '3.18.1', {"requires": ["editor-base"]});
|