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