/static/scripts/tiny_mce/themes/advanced/js/link.js

http://n23.googlecode.com/ · JavaScript · 155 lines · 120 code · 31 blank · 4 comment · 26 complexity · ddc32af7d8452b53676b8fec54c2d162 MD5 · raw file

  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. tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
  46. tinymce.each(ed.dom.select("a"), function(n) {
  47. if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
  48. e = n;
  49. ed.dom.setAttribs(e, {
  50. href : f.href.value,
  51. title : f.linktitle.value,
  52. target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
  53. 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
  54. });
  55. }
  56. });
  57. } else {
  58. ed.dom.setAttribs(e, {
  59. href : f.href.value,
  60. title : f.linktitle.value,
  61. target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
  62. 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
  63. });
  64. }
  65. // Don't move caret if selection was image
  66. if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') {
  67. ed.focus();
  68. ed.selection.select(e);
  69. ed.selection.collapse(0);
  70. tinyMCEPopup.storeSelection();
  71. }
  72. tinyMCEPopup.execCommand("mceEndUndoLevel");
  73. tinyMCEPopup.close();
  74. },
  75. checkPrefix : function(n) {
  76. if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email')))
  77. n.value = 'mailto:' + n.value;
  78. if (/^\s*www./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external')))
  79. n.value = 'http://' + n.value;
  80. },
  81. fillFileList : function(id, l) {
  82. var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
  83. l = window[l];
  84. if (l && l.length > 0) {
  85. lst.options[lst.options.length] = new Option('', '');
  86. tinymce.each(l, function(o) {
  87. lst.options[lst.options.length] = new Option(o[0], o[1]);
  88. });
  89. } else
  90. dom.remove(dom.getParent(id, 'tr'));
  91. },
  92. fillClassList : function(id) {
  93. var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
  94. if (v = tinyMCEPopup.getParam('theme_advanced_styles')) {
  95. cl = [];
  96. tinymce.each(v.split(';'), function(v) {
  97. var p = v.split('=');
  98. cl.push({'title' : p[0], 'class' : p[1]});
  99. });
  100. } else
  101. cl = tinyMCEPopup.editor.dom.getClasses();
  102. if (cl.length > 0) {
  103. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
  104. tinymce.each(cl, function(o) {
  105. lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']);
  106. });
  107. } else
  108. dom.remove(dom.getParent(id, 'tr'));
  109. },
  110. fillTargetList : function(id) {
  111. var dom = tinyMCEPopup.dom, lst = dom.get(id), v;
  112. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
  113. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_same'), '_self');
  114. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank');
  115. if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) {
  116. tinymce.each(v.split(','), function(v) {
  117. v = v.split('=');
  118. lst.options[lst.options.length] = new Option(v[0], v[1]);
  119. });
  120. }
  121. }
  122. };
  123. LinkDialog.preInit();
  124. tinyMCEPopup.onInit.add(LinkDialog.init, LinkDialog);