anchor.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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('anchor', function(K) {
  10. var self = this, name = 'anchor', lang = self.lang(name + '.');
  11. self.plugin.anchor = {
  12. edit : function() {
  13. var html = ['<div style="padding:20px;">',
  14. '<div class="ke-dialog-row">',
  15. '<label for="keName">' + lang.name + '</label>',
  16. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  17. '</div>',
  18. '</div>'].join('');
  19. var dialog = self.createDialog({
  20. name : name,
  21. width : 300,
  22. title : self.lang(name),
  23. body : html,
  24. yesBtn : {
  25. name : self.lang('yes'),
  26. click : function(e) {
  27. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  28. }
  29. }
  30. });
  31. var div = dialog.div,
  32. nameBox = K('input[name="name"]', div);
  33. var img = self.plugin.getSelectedAnchor();
  34. if (img) {
  35. nameBox.val(unescape(img.attr('data-ke-name')));
  36. }
  37. nameBox[0].focus();
  38. nameBox[0].select();
  39. },
  40. 'delete' : function() {
  41. self.plugin.getSelectedAnchor().remove();
  42. }
  43. };
  44. self.clickToolbar(name, self.plugin.anchor.edit);
  45. });