PageRenderTime 697ms CodeModel.GetById 595ms RepoModel.GetById 2ms app.codeStats 0ms

/media/jscripts/tiny_mce/themes/advanced/js/link.js

https://bitbucket.org/chuns/cms
JavaScript | 156 lines | 121 code | 31 blank | 4 comment | 26 complexity | ae89b3188171b7185c2e981b68f3f6cb MD5 | raw file
Possible License(s): LGPL-2.1
  1. tinyMCEPopup.requireLangPack();
  2. var LinkDialog = {
  3. preInit : function() {
  4. var url;
  5. if (url = tinyMCEPopup.getParam("external_link_list_url"))
  6. document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
  7. },
  8. init : function() {
  9. var f = document.forms[0], ed = tinyMCEPopup.editor;
  10. // Setup browse button
  11. document.getElementById('hrefbrowsercontainer').innerHTML = getBrowserHTML('hrefbrowser', 'href', 'file', 'theme_advanced_link');
  12. if (isVisible('hrefbrowser'))
  13. document.getElementById('href').style.width = '180px';
  14. this.fillClassList('class_list');
  15. this.fillFileList('link_list', 'tinyMCELinkList');
  16. this.fillTargetList('target_list');
  17. if (e = ed.dom.getParent(ed.selection.getNode(), 'A')) {
  18. f.href.value = ed.dom.getAttrib(e, 'href');
  19. f.linktitle.value = ed.dom.getAttrib(e, 'title');
  20. f.insert.value = ed.getLang('update');
  21. selectByValue(f, 'link_list', f.href.value);
  22. selectByValue(f, 'target_list', ed.dom.getAttrib(e, 'target'));
  23. selectByValue(f, 'class_list', ed.dom.getAttrib(e, 'class'));
  24. }
  25. },
  26. update : function() {
  27. var f = document.forms[0], ed = tinyMCEPopup.editor, e, b;
  28. tinyMCEPopup.restoreSelection();
  29. e = ed.dom.getParent(ed.selection.getNode(), 'A');
  30. // Remove element if there is no href
  31. if (!f.href.value) {
  32. if (e) {
  33. tinyMCEPopup.execCommand("mceBeginUndoLevel");
  34. b = ed.selection.getBookmark();
  35. ed.dom.remove(e, 1);
  36. ed.selection.moveToBookmark(b);
  37. tinyMCEPopup.execCommand("mceEndUndoLevel");
  38. tinyMCEPopup.close();
  39. return;
  40. }
  41. }
  42. tinyMCEPopup.execCommand("mceBeginUndoLevel");
  43. // Create new anchor elements
  44. if (e == null) {
  45. ed.getDoc().execCommand("unlink", false, null);
  46. tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
  47. tinymce.each(ed.dom.select("a"), function(n) {
  48. if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
  49. e = n;
  50. ed.dom.setAttribs(e, {
  51. href : f.href.value,
  52. title : f.linktitle.value,
  53. target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
  54. 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
  55. });
  56. }
  57. });
  58. } else {
  59. ed.dom.setAttribs(e, {
  60. href : f.href.value,
  61. title : f.linktitle.value,
  62. target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
  63. 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
  64. });
  65. }
  66. // Don't move caret if selection was image
  67. if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') {
  68. ed.focus();
  69. ed.selection.select(e);
  70. ed.selection.collapse(0);
  71. tinyMCEPopup.storeSelection();
  72. }
  73. tinyMCEPopup.execCommand("mceEndUndoLevel");
  74. tinyMCEPopup.close();
  75. },
  76. checkPrefix : function(n) {
  77. if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email')))
  78. n.value = 'mailto:' + n.value;
  79. if (/^\s*www\./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external')))
  80. n.value = 'http://' + n.value;
  81. },
  82. fillFileList : function(id, l) {
  83. var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
  84. l = window[l];
  85. if (l && l.length > 0) {
  86. lst.options[lst.options.length] = new Option('', '');
  87. tinymce.each(l, function(o) {
  88. lst.options[lst.options.length] = new Option(o[0], o[1]);
  89. });
  90. } else
  91. dom.remove(dom.getParent(id, 'tr'));
  92. },
  93. fillClassList : function(id) {
  94. var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
  95. if (v = tinyMCEPopup.getParam('theme_advanced_styles')) {
  96. cl = [];
  97. tinymce.each(v.split(';'), function(v) {
  98. var p = v.split('=');
  99. cl.push({'title' : p[0], 'class' : p[1]});
  100. });
  101. } else
  102. cl = tinyMCEPopup.editor.dom.getClasses();
  103. if (cl.length > 0) {
  104. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
  105. tinymce.each(cl, function(o) {
  106. lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']);
  107. });
  108. } else
  109. dom.remove(dom.getParent(id, 'tr'));
  110. },
  111. fillTargetList : function(id) {
  112. var dom = tinyMCEPopup.dom, lst = dom.get(id), v;
  113. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
  114. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_same'), '_self');
  115. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank');
  116. if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) {
  117. tinymce.each(v.split(','), function(v) {
  118. v = v.split('=');
  119. lst.options[lst.options.length] = new Option(v[0], v[1]);
  120. });
  121. }
  122. }
  123. };
  124. LinkDialog.preInit();
  125. tinyMCEPopup.onInit.add(LinkDialog.init, LinkDialog);