]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/editor/createlink-base.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / editor / createlink-base.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('createlink-base', function(Y) {
9
10     /**
11      * Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events.
12      * @module editor
13      * @submodule createlink-base
14      */     
15     /**
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
18      * @static
19      */
20     
21     var CreateLinkBase = {};
22     /**
23     * Strings used by the plugin
24     * @property STRINGS
25     * @static
26     */
27     CreateLinkBase.STRINGS = {
28             /**
29             * String used for the Prompt
30             * @property PROMPT
31             * @static
32             */
33             PROMPT: 'Please enter the URL for the link to point to:',
34             /**
35             * String used as the default value of the Prompt
36             * @property DEFAULT
37             * @static
38             */
39             DEFAULT: 'http://'
40     };
41
42     Y.namespace('Plugin');
43     Y.Plugin.CreateLinkBase = CreateLinkBase;
44
45     Y.mix(Y.Plugin.ExecCommand.COMMANDS, {
46         /**
47         * Override for the createlink method from the <a href="Plugin.CreateLinkBase.html">CreateLinkBase</a> plugin.
48         * @for ExecCommand
49         * @method COMMANDS.createlink
50         * @static
51         * @param {String} cmd The command executed: createlink
52         * @return {Node} Node instance of the item touched by this command.
53         */
54         createlink: function(cmd) {
55             var inst = this.get('host').getInstance(), out, a, sel, holder,
56                 url = prompt(CreateLinkBase.STRINGS.PROMPT, CreateLinkBase.STRINGS.DEFAULT);
57
58             if (url) {
59                 holder = inst.config.doc.createElement('div');
60                 url = inst.config.doc.createTextNode(url);
61                 holder.appendChild(url);
62                 url = holder.innerHTML;
63
64
65                 this.get('host')._execCommand(cmd, url);
66                 sel = new inst.Selection();
67                 out = sel.getSelected();
68                 if (!sel.isCollapsed && out.size()) {
69                     //We have a selection
70                     a = out.item(0).one('a');
71                     if (a) {
72                         out.item(0).replace(a);
73                     }
74                     if (Y.UA.gecko) {
75                         if (a.get('parentNode').test('span')) {
76                             if (a.get('parentNode').one('br.yui-cursor')) {
77                                 a.get('parentNode').insert(a, 'before');
78                             }
79                         }
80                     }
81                 } else {
82                     //No selection, insert a new node..
83                     this.get('host').execCommand('inserthtml', '<a href="' + url + '">' + url + '</a>');
84                 }
85             }
86             return a;
87         }
88     });
89
90
91
92 }, '3.3.0' ,{requires:['editor-base'], skinnable:false});