twoGisLink.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. CKEDITOR.dialog.add("twoGisLinkDialog", function(editor) {
  2. return {
  3. allowedContent: "a[href,target]",
  4. title: "Âñòàâüòå êëþ÷åâîå ñëîâî",
  5. minWidth: 550,
  6. minHeight: 100,
  7. resizable: CKEDITOR.DIALOG_RESIZE_NONE,
  8. contents:[{
  9. id: "Âñòàâüòå êëþ÷åâîå ñëîâî",
  10. label: "",
  11. elements:[{
  12. type: "text",
  13. label: "Êëþ÷åâîå ñëîâî äëÿ ïîèñêà",
  14. id: "edp-URL",
  15. validate: CKEDITOR.dialog.validate.notEmpty( "Ïîëå ñ êëþ÷åâûì ñëîâîì íå ìîæåò áûòü ïóñòûì" ),
  16. setup: function( element ) {
  17. var href = element.getAttribute("href");
  18. var isExternalURL = /^(http|https):\/\//;
  19. if(href) {
  20. if(!isExternalURL.test(href)) {
  21. href = "http://amic.ru/spravochnik/?s=" + href;
  22. }
  23. this.setValue(href);
  24. }
  25. },
  26. commit: function(element) {
  27. var href = this.getValue();
  28. var isExternalURL = /^(http|https):\/\//;
  29. if(href) {
  30. if(!isExternalURL.test(href)) {
  31. href = "http://amic.ru/spravochnik/?s=" + href;
  32. }
  33. element.setAttribute("href", href);
  34. if(!element.getText()) {
  35. element.setText(this.getValue());
  36. }
  37. }
  38. }
  39. }, {
  40. type: "text",
  41. label: "Âûäåëåííàÿ ÷àñòü òåêñòà",
  42. id: "edp-text-display",
  43. setup: function( element ) {
  44. this.setValue( element.getText() );
  45. },
  46. commit: function(element) {
  47. var currentValue = this.getValue();
  48. if(currentValue !== "" && currentValue !== null) {
  49. element.setText(currentValue);
  50. }
  51. }
  52. }, {
  53. type: "html",
  54. html: ""
  55. }]
  56. }],
  57. onShow: function() {
  58. var selection = editor.getSelection();
  59. var selector = selection.getStartElement()
  60. var element;
  61. if(selector) {
  62. element = selector.getAscendant( 'a', true );
  63. }
  64. if ( !element || element.getName() != 'a' ) {
  65. element = editor.document.createElement( 'a' );
  66. element.setAttribute("target","_blank");
  67. if(selection) {
  68. element.setText(selection.getSelectedText());
  69. }
  70. this.insertMode = true;
  71. }
  72. else {
  73. this.insertMode = false;
  74. }
  75. this.element = element;
  76. this.setupContent(this.element);
  77. },
  78. onOk: function() {
  79. var dialog = this;
  80. var anchorElement = this.element;
  81. this.element.setAttribute('id', 'twoGis')
  82. this.commitContent(this.element);
  83. if(this.insertMode) {
  84. editor.insertElement(this.element);
  85. }
  86. }
  87. };
  88. });