~ted/lazr-js/annoying-debug-message

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/editor/createlink-base-debug.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2010-09-09 14:20:30 UTC
  • mfrom: (182.1.3 yui-3.2)
  • Revision ID: launchpad@pqm.canonical.com-20100909142030-13w6vo0ixfysxc15
[r=beuno] Update lazr-js to yui-3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.2.0
 
6
build: 2676
 
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,
 
56
                url = prompt(CreateLinkBase.STRINGS.PROMPT, CreateLinkBase.STRINGS.DEFAULT);
 
57
 
 
58
            if (url) {
 
59
                Y.log('Adding link: ' + url, 'info', 'createLinkBase');
 
60
 
 
61
                this.get('host')._execCommand(cmd, url);
 
62
                sel = new inst.Selection();
 
63
                out = sel.getSelected();
 
64
                if (!sel.isCollapsed && out.size()) {
 
65
                    //We have a selection
 
66
                    a = out.item(0).one('a');
 
67
                    if (a) {
 
68
                        out.item(0).replace(a);
 
69
                    }
 
70
                } else {
 
71
                    //No selection, insert a new node..
 
72
                    this.get('host').execCommand('inserthtml', '<a href="' + url + '">' + url + '</a>');
 
73
                }
 
74
            }
 
75
            return a;
 
76
        }
 
77
    });
 
78
 
 
79
 
 
80
 
 
81
}, '3.2.0' ,{skinnable:false, requires:['editor-base']});