PageRenderTime 32ms CodeModel.GetById 13ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/source/Plug-in/kind/plugins/link/link.js

http://prosporous.googlecode.com/
JavaScript | 66 lines | 55 code | 1 blank | 10 comment | 0 complexity | f0eb478495db2730c03f9e1fdbd89e7d MD5 | raw file
 1/*******************************************************************************
 2* KindEditor - WYSIWYG HTML Editor for Internet
 3* Copyright (C) 2006-2011 kindsoft.net
 4*
 5* @author Roddy <luolonghao@gmail.com>
 6* @site http://www.kindsoft.net/
 7* @licence http://www.kindsoft.net/license.php
 8*******************************************************************************/
 9
10KindEditor.plugin('link', function(K) {
11	var self = this, name = 'link';
12	self.plugin.link = {
13		edit : function() {
14			var lang = self.lang(name + '.'),
15				html = '<div style="padding:10px 20px;">' +
16					//url
17					'<div class="ke-dialog-row">' +
18					'<label for="keUrl">' + lang.url + '</label>' +
19					'<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:90%;" /></div>' +
20					//type
21					'<div class="ke-dialog-row"">' +
22					'<label for="keType">' + lang.linkType + '</label>' +
23					'<select id="keType" name="type"></select>' +
24					'</div>' +
25					'</div>',
26				dialog = self.createDialog({
27					name : name,
28					width : 400,
29					title : self.lang(name),
30					body : html,
31					yesBtn : {
32						name : self.lang('yes'),
33						click : function(e) {
34							var url = K.trim(urlBox.val());
35							if (url == 'http://' || K.invalidUrl(url)) {
36								alert(self.lang('invalidUrl'));
37								urlBox[0].focus();
38								return;
39							}
40							self.exec('createlink', url, typeBox.val()).hideDialog().focus();
41						}
42					}
43				}),
44				div = dialog.div,
45				urlBox = K('input[name="url"]', div),
46				typeBox = K('select[name="type"]', div);
47			urlBox.val('http://');
48			typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
49			typeBox[0].options[1] = new Option(lang.selfWindow, '');
50			self.cmd.selection();
51			var a = self.plugin.getSelectedLink();
52			if (a) {
53				self.cmd.range.selectNode(a[0]);
54				self.cmd.select();
55				urlBox.val(a.attr('data-ke-src'));
56				typeBox.val(a.attr('target'));
57			}
58			urlBox[0].focus();
59			urlBox[0].select();
60		},
61		'delete' : function() {
62			self.exec('unlink', null);
63		}
64	};
65	self.clickToolbar(name, self.plugin.link.edit);
66});