link.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. KindEditor.plugin('link', function(K) {
  10. var self = this, name = 'link';
  11. self.plugin.link = {
  12. edit : function() {
  13. var lang = self.lang(name + '.'),
  14. html = '<div style="padding:20px;">' +
  15. //url
  16. '<div class="ke-dialog-row">' +
  17. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  18. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  19. //type
  20. '<div class="ke-dialog-row"">' +
  21. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  22. '<select id="keType" name="type"></select>' +
  23. '</div>' +
  24. '</div>',
  25. dialog = self.createDialog({
  26. name : name,
  27. width : 450,
  28. title : self.lang(name),
  29. body : html,
  30. yesBtn : {
  31. name : self.lang('yes'),
  32. click : function(e) {
  33. var url = K.trim(urlBox.val());
  34. if (url == 'http://' || K.invalidUrl(url)) {
  35. alert(self.lang('invalidUrl'));
  36. urlBox[0].focus();
  37. return;
  38. }
  39. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  40. }
  41. }
  42. }),
  43. div = dialog.div,
  44. urlBox = K('input[name="url"]', div),
  45. typeBox = K('select[name="type"]', div);
  46. urlBox.val('http://');
  47. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  48. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  49. self.cmd.selection();
  50. var a = self.plugin.getSelectedLink();
  51. if (a) {
  52. self.cmd.range.selectNode(a[0]);
  53. self.cmd.select();
  54. urlBox.val(a.attr('data-ke-src'));
  55. typeBox.val(a.attr('target'));
  56. }
  57. urlBox[0].focus();
  58. urlBox[0].select();
  59. },
  60. 'delete' : function() {
  61. self.exec('unlink', null);
  62. }
  63. };
  64. self.clickToolbar(name, self.plugin.link.edit);
  65. });