link.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. (function(){
  2. var utils = UM.utils;
  3. function hrefStartWith(href, arr) {
  4. href = href.replace(/^\s+|\s+$/g, '');
  5. for (var i = 0, ai; ai = arr[i++];) {
  6. if (href.indexOf(ai) == 0) {
  7. return true;
  8. }
  9. }
  10. return false;
  11. }
  12. UM.registerWidget('link', {
  13. tpl: "<style type=\"text/css\">" +
  14. ".edui-dialog-link .edui-link-table{font-size: 12px;margin: 10px;line-height: 30px}" +
  15. ".edui-dialog-link .edui-link-txt{width:300px;height:21px;line-height:21px;border:1px solid #d7d7d7;}" +
  16. "</style>" +
  17. "<table class=\"edui-link-table\">" +
  18. "<tr>" +
  19. "<td><label for=\"href\"><%=lang_input_url%></label></td>" +
  20. "<td><input class=\"edui-link-txt\" id=\"edui-link-Jhref\" type=\"text\" /></td>" +
  21. "</tr>" +
  22. "<tr>" +
  23. "<td><label for=\"title\"><%=lang_input_title%></label></td>" +
  24. "<td><input class=\"edui-link-txt\" id=\"edui-link-Jtitle\" type=\"text\"/></td>" +
  25. "</tr>" +
  26. "<tr>" +
  27. "<td colspan=\"2\">" +
  28. "<label for=\"target\"><%=lang_input_target%></label>" +
  29. "<input id=\"edui-link-Jtarget\" type=\"checkbox\"/>" +
  30. "</td>" +
  31. "</tr>" +
  32. // "<tr>" +
  33. // "<td colspan=\"2\" id=\"edui-link-Jmsg\"></td>" +
  34. // "</tr>" +
  35. "</table>",
  36. initContent: function (editor) {
  37. var lang = editor.getLang('link');
  38. if (lang) {
  39. var html = $.parseTmpl(this.tpl, lang.static);
  40. }
  41. this.root().html(html);
  42. },
  43. initEvent: function (editor, $w) {
  44. var link = editor.queryCommandValue('link');
  45. if(link){
  46. $('#edui-link-Jhref',$w).val(utils.html($(link).attr('href')));
  47. $('#edui-link-Jtitle',$w).val($(link).attr('title'));
  48. $(link).attr('target') == '_blank' && $('#edui-link-Jtarget').attr('checked',true)
  49. }
  50. $('#edui-link-Jhref',$w).focus();
  51. },
  52. buttons: {
  53. 'ok': {
  54. exec: function (editor, $w) {
  55. var href = $('#edui-link-Jhref').val().replace(/^\s+|\s+$/g, '');
  56. if (href) {
  57. editor.execCommand('link', {
  58. 'href': href,
  59. 'target': $("#edui-link-Jtarget:checked").length ? "_blank" : '_self',
  60. 'title': $("#edui-link-Jtitle").val().replace(/^\s+|\s+$/g, ''),
  61. '_href': href
  62. });
  63. }
  64. }
  65. },
  66. 'cancel':{}
  67. },
  68. width: 400
  69. })
  70. })();