/* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html version: 3.3.0 build: 3167 */ YUI.add('createlink-base', function(Y) { /** * Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events. * @module editor * @submodule createlink-base */ /** * Adds prompt style link creation. Adds an override for the createlink execCommand. * @class Plugin.CreateLinkBase * @static */ var CreateLinkBase = {}; /** * Strings used by the plugin * @property STRINGS * @static */ CreateLinkBase.STRINGS = { /** * String used for the Prompt * @property PROMPT * @static */ PROMPT: 'Please enter the URL for the link to point to:', /** * String used as the default value of the Prompt * @property DEFAULT * @static */ DEFAULT: 'http://' }; Y.namespace('Plugin'); Y.Plugin.CreateLinkBase = CreateLinkBase; Y.mix(Y.Plugin.ExecCommand.COMMANDS, { /** * Override for the createlink method from the CreateLinkBase plugin. * @for ExecCommand * @method COMMANDS.createlink * @static * @param {String} cmd The command executed: createlink * @return {Node} Node instance of the item touched by this command. */ createlink: function(cmd) { var inst = this.get('host').getInstance(), out, a, sel, holder, url = prompt(CreateLinkBase.STRINGS.PROMPT, CreateLinkBase.STRINGS.DEFAULT); if (url) { holder = inst.config.doc.createElement('div'); url = inst.config.doc.createTextNode(url); holder.appendChild(url); url = holder.innerHTML; this.get('host')._execCommand(cmd, url); sel = new inst.Selection(); out = sel.getSelected(); if (!sel.isCollapsed && out.size()) { //We have a selection a = out.item(0).one('a'); if (a) { out.item(0).replace(a); } if (Y.UA.gecko) { if (a.get('parentNode').test('span')) { if (a.get('parentNode').one('br.yui-cursor')) { a.get('parentNode').insert(a, 'before'); } } } } else { //No selection, insert a new node.. this.get('host').execCommand('inserthtml', '' + url + ''); } } return a; } }); }, '3.3.0' ,{requires:['editor-base'], skinnable:false});