createlink-base.js revision 33a04233c7a32ec1ac1b5d5991097fe0b099e87b
0N/AYUI.add('createlink-base', function(Y) {
196N/A
0N/A
0N/A /**
0N/A * Adds prompt style link creation. Adds an override for the <a href="Plugin.ExecCommand.html#method_COMMANDS.createlink">createlink execCommand</a>.
0N/A * @class Plugin.CreateLinkBase
0N/A * @static
0N/A * @submodule createlink-base
0N/A * @module editor
0N/A */
0N/A
0N/A var CreateLinkBase = {};
0N/A /**
0N/A * Strings used by the plugin
0N/A * @property STRINGS
0N/A * @static
0N/A */
0N/A CreateLinkBase.STRINGS = {
0N/A /**
0N/A * String used for the Prompt
0N/A * @property PROMPT
0N/A * @static
0N/A */
0N/A PROMPT: 'Please enter the URL for the link to point to:',
0N/A /**
0N/A * String used as the default value of the Prompt
0N/A * @property DEFAULT
0N/A * @static
0N/A */
0N/A DEFAULT: 'http://'
0N/A };
0N/A
0N/A Y.namespace('Plugin');
0N/A Y.Plugin.CreateLinkBase = CreateLinkBase;
0N/A
0N/A Y.mix(Y.Plugin.ExecCommand.COMMANDS, {
0N/A /**
0N/A * Override for the createlink method from the <a href="Plugin.CreateLinkBase.html">CreateLinkBase</a> plugin.
0N/A * @for ExecCommand
0N/A * @method COMMANDS.createlink
0N/A * @static
0N/A * @param {String} cmd The command executed: createlink
0N/A * @return {Node} Node instance of the item touched by this command.
0N/A */
0N/A createlink: function(cmd) {
0N/A var inst = this.get('host').getInstance(), out, a, sel, holder,
0N/A url = prompt(CreateLinkBase.STRINGS.PROMPT, CreateLinkBase.STRINGS.DEFAULT);
0N/A
0N/A if (url) {
0N/A holder = inst.config.doc.createElement('div');
0N/A url = url.replace(/"/g, '').replace(/'/g, ''); //Remove single & double quotes
0N/A url = inst.config.doc.createTextNode(url);
0N/A holder.appendChild(url);
0N/A url = holder.innerHTML;
0N/A
0N/A
0N/A this.get('host')._execCommand(cmd, url);
0N/A sel = new inst.Selection();
0N/A out = sel.getSelected();
0N/A if (!sel.isCollapsed && out.size()) {
0N/A //We have a selection
0N/A a = out.item(0).one('a');
0N/A if (a) {
0N/A out.item(0).replace(a);
0N/A }
0N/A if (Y.UA.gecko) {
0N/A if (a.get('parentNode').test('span')) {
1015N/A if (a.get('parentNode').one('br.yui-cursor')) {
1015N/A a.get('parentNode').insert(a, 'before');
1015N/A }
1015N/A }
0N/A }
0N/A } else {
0N/A //No selection, insert a new node..
0N/A this.get('host').execCommand('inserthtml', '<a href="' + url + '">' + url + '</a>');
0N/A }
0N/A }
0N/A return a;
0N/A }
0N/A });
0N/A
0N/A
1488N/A
1488N/A}, '@VERSION@' ,{requires:['editor-base'], skinnable:false});
1488N/A