source: trunk/modules/CreateLink/link.js @ 999

Last change on this file since 999 was 999, checked in by ray, 11 years ago

#1195 Allow to specify an external url to load a plugin from

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 4.3 KB
Line 
1
2  /*--------------------------------------:noTabs=true:tabSize=2:indentSize=2:--
3    --  Xinha (is not htmlArea) - http://xinha.org
4    --
5    --  Use of Xinha is granted by the terms of the htmlArea License (based on
6    --  BSD license)  please read license.txt in this package for details.
7    --
8    --  Copyright (c) 2005-2008 Xinha Developer Team and contributors
9    --
10    --  Xinha was originally based on work by Mihai Bazon which is:
11    --      Copyright (c) 2003-2004 dynarch.com.
12    --      Copyright (c) 2002-2003 interactivetools.com, inc.
13    --      This copyright notice MUST stay intact for use.
14    --
15    --  This is the standard implementation of the Xinha.prototype._createLink method,
16    --  which provides the functionality to insert a hyperlink in the editor.
17    --
18    --  he file is loaded as a special plugin by the Xinha Core when no alternative method (plugin) is loaded.
19    --
20    --
21    --  $HeadURL:http://svn.xinha.webfactional.com/trunk/modules/CreateLink/link.js $
22    --  $LastChangedDate:2008-04-12 19:10:04 +0200 (Sa, 12 Apr 2008) $
23    --  $LastChangedRevision:990 $
24    --  $LastChangedBy:ray $
25    --------------------------------------------------------------------------*/
26CreateLink._pluginInfo = {
27  name          : "CreateLink",
28  origin        : "Xinha Core",
29  version       : "$LastChangedRevision:990 $".replace(/^[^:]*: (.*) \$$/, '$1'),
30  developer     : "The Xinha Core Developer Team",
31  developer_url : "$HeadURL:http://svn.xinha.webfactional.com/trunk/modules/CreateLink/link.js $".replace(/^[^:]*: (.*) \$$/, '$1'),
32  sponsor       : "",
33  sponsor_url   : "",
34  license       : "htmlArea"
35};
36
37function CreateLink(editor) {
38}                                                       
39
40Xinha.prototype._createLink = function(link)
41{
42  var editor = this;
43  var outparam = null;
44  if ( typeof link == "undefined" )
45  {
46    link = this.getParentElement();
47    if ( link )
48    {
49      while (link && !/^a$/i.test(link.tagName))
50      {
51        link = link.parentNode;
52      }
53    }
54  }
55  if ( !link )
56  {
57    var sel = editor.getSelection();
58    var range = editor.createRange(sel);
59    var compare = 0;
60    if ( Xinha.is_ie )
61    {
62      if ( sel.type == "Control" )
63      {
64        compare = range.length;
65      }
66      else
67      {
68        compare = range.compareEndPoints("StartToEnd", range);
69      }
70    }
71    else
72    {
73      compare = range.compareBoundaryPoints(range.START_TO_END, range);
74    }
75    if ( compare === 0 )
76    {
77      alert(Xinha._lc("You need to select some text before creating a link"));
78      return;
79    }
80    outparam =
81    {
82      f_href : '',
83      f_title : '',
84      f_target : '',
85      f_usetarget : editor.config.makeLinkShowsTarget
86    };
87  }
88  else
89  {
90    outparam =
91    {
92      f_href   : Xinha.is_ie ? editor.stripBaseURL(link.href) : link.getAttribute("href"),
93      f_title  : link.title,
94      f_target : link.target,
95      f_usetarget : editor.config.makeLinkShowsTarget
96    };
97  }
98  Dialog(
99    editor.config.URIs.link,
100    function(param)
101    {
102      if ( !param )
103      {
104        return false;
105      }
106      var a = link;
107      if ( !a )
108      {
109        try
110        {
111          var tmp = Xinha.uniq('http://www.example.com/Link');
112          editor._doc.execCommand('createlink', false, tmp);
113
114          // Fix them up
115          var anchors = editor._doc.getElementsByTagName('a');
116          for(var i = 0; i < anchors.length; i++)
117          {
118            var anchor = anchors[i];
119            if(anchor.href == tmp)
120            {
121              // Found one.
122              if (!a) a = anchor;
123              anchor.href =  param.f_href;
124              if (param.f_target) anchor.target =  param.f_target;
125              if (param.f_title)  anchor.title =  param.f_title;
126            }
127          }
128        } catch(ex) {}
129      }
130      else
131      {
132        var href = param.f_href.trim();
133        editor.selectNodeContents(a);
134        if ( href === '' )
135        {
136          editor._doc.execCommand("unlink", false, null);
137          editor.updateToolbar();
138          return false;
139        }
140        else
141        {
142          a.href = href;
143        }
144      }
145      if ( ! ( a && a.tagName.toLowerCase() == 'a' ) )
146      {
147        return false;
148      }
149      a.target = param.f_target.trim();
150      a.title = param.f_title.trim();
151      editor.selectNodeContents(a);
152      editor.updateToolbar();
153    },
154    outparam);
155};
Note: See TracBrowser for help on using the repository browser.