link.js 2.2 KB

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