PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/themes/advanced/js/link.js

#
JavaScript | 153 lines | 119 code | 30 blank | 4 comment | 26 complexity | ba62151ce29f9af4387a172e72bde93f MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  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, href = f.href.value.replace(/ /g, '%20');
  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. b = ed.selection.getBookmark();
  34. ed.dom.remove(e, 1);
  35. ed.selection.moveToBookmark(b);
  36. tinyMCEPopup.execCommand("mceEndUndoLevel");
  37. tinyMCEPopup.close();
  38. return;
  39. }
  40. }
  41. // Create new anchor elements
  42. if (e == null) {
  43. ed.getDoc().execCommand("unlink", false, null);
  44. tinyMCEPopup.execCommand("mceInsertLink", false, "#mce_temp_url#", {skip_undo : 1});
  45. tinymce.each(ed.dom.select("a"), function(n) {
  46. if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
  47. e = n;
  48. ed.dom.setAttribs(e, {
  49. href : href,
  50. title : f.linktitle.value,
  51. target : f.target_list ? getSelectValue(f, "target_list") : null,
  52. 'class' : f.class_list ? getSelectValue(f, "class_list") : null
  53. });
  54. }
  55. });
  56. } else {
  57. ed.dom.setAttribs(e, {
  58. href : href,
  59. title : f.linktitle.value,
  60. target : f.target_list ? getSelectValue(f, "target_list") : null,
  61. 'class' : f.class_list ? getSelectValue(f, "class_list") : null
  62. });
  63. }
  64. // Don't move caret if selection was image
  65. if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') {
  66. ed.focus();
  67. ed.selection.select(e);
  68. ed.selection.collapse(0);
  69. tinyMCEPopup.storeSelection();
  70. }
  71. tinyMCEPopup.execCommand("mceEndUndoLevel");
  72. tinyMCEPopup.close();
  73. },
  74. checkPrefix : function(n) {
  75. if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email')))
  76. n.value = 'mailto:' + n.value;
  77. if (/^\s*www\./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external')))
  78. n.value = 'http://' + n.value;
  79. },
  80. fillFileList : function(id, l) {
  81. var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
  82. l = window[l];
  83. if (l && l.length > 0) {
  84. lst.options[lst.options.length] = new Option('', '');
  85. tinymce.each(l, function(o) {
  86. lst.options[lst.options.length] = new Option(o[0], o[1]);
  87. });
  88. } else
  89. dom.remove(dom.getParent(id, 'tr'));
  90. },
  91. fillClassList : function(id) {
  92. var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
  93. if (v = tinyMCEPopup.getParam('theme_advanced_styles')) {
  94. cl = [];
  95. tinymce.each(v.split(';'), function(v) {
  96. var p = v.split('=');
  97. cl.push({'title' : p[0], 'class' : p[1]});
  98. });
  99. } else
  100. cl = tinyMCEPopup.editor.dom.getClasses();
  101. if (cl.length > 0) {
  102. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
  103. tinymce.each(cl, function(o) {
  104. lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']);
  105. });
  106. } else
  107. dom.remove(dom.getParent(id, 'tr'));
  108. },
  109. fillTargetList : function(id) {
  110. var dom = tinyMCEPopup.dom, lst = dom.get(id), v;
  111. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
  112. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_same'), '_self');
  113. lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank');
  114. if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) {
  115. tinymce.each(v.split(','), function(v) {
  116. v = v.split('=');
  117. lst.options[lst.options.length] = new Option(v[0], v[1]);
  118. });
  119. }
  120. }
  121. };
  122. LinkDialog.preInit();
  123. tinyMCEPopup.onInit.add(LinkDialog.init, LinkDialog);