trumbowyg.noembed.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* ===========================================================
  2. * trumbowyg.noembed.js v1.0
  3. * noEmbed plugin for Trumbowyg
  4. * http://alex-d.github.com/Trumbowyg
  5. * ===========================================================
  6. * Author : Jake Johns (jakejohns)
  7. */
  8. (function ($) {
  9. 'use strict';
  10. var defaultOptions = {
  11. proxy: 'https://noembed.com/embed?nowrap=on',
  12. urlFiled: 'url',
  13. data: [],
  14. success: undefined,
  15. error: undefined
  16. };
  17. $.extend(true, $.trumbowyg, {
  18. langs: {
  19. // jshint camelcase:false
  20. en: {
  21. noembed: 'Noembed',
  22. noembedError: 'Error'
  23. },
  24. cs: {
  25. noembedError: 'Chyba'
  26. },
  27. da: {
  28. noembedError: 'Fejl'
  29. },
  30. fr: {
  31. noembedError: 'Erreur'
  32. },
  33. hu: {
  34. noembed: 'Noembed',
  35. noembedError: 'Hiba'
  36. },
  37. ja: {
  38. noembedError: 'エラー'
  39. },
  40. ko: {
  41. noembed: 'oEmbed 넣기',
  42. noembedError: '에러'
  43. },
  44. pt_br: {
  45. noembed: 'Incorporar',
  46. noembedError: 'Erro'
  47. },
  48. ru: {
  49. noembedError: 'Ошибка'
  50. },
  51. sk: {
  52. noembedError: 'Chyba'
  53. },
  54. tr: {
  55. noembedError: 'Hata'
  56. },
  57. zh_tw: {
  58. noembed: '插入影片',
  59. noembedError: '錯誤'
  60. },
  61. // jshint camelcase:true
  62. },
  63. plugins: {
  64. noembed: {
  65. init: function (trumbowyg) {
  66. trumbowyg.o.plugins.noembed = $.extend(true, {}, defaultOptions, trumbowyg.o.plugins.noembed || {});
  67. var btnDef = {
  68. fn: function () {
  69. var $modal = trumbowyg.openModalInsert(
  70. // Title
  71. trumbowyg.lang.noembed,
  72. // Fields
  73. {
  74. url: {
  75. label: 'URL',
  76. required: true
  77. }
  78. },
  79. // Callback
  80. function (data) {
  81. $.ajax({
  82. url: trumbowyg.o.plugins.noembed.proxy,
  83. type: 'GET',
  84. data: data,
  85. cache: false,
  86. dataType: 'json',
  87. success: trumbowyg.o.plugins.noembed.success || function (data) {
  88. if (data.html) {
  89. trumbowyg.execCmd('insertHTML', data.html);
  90. setTimeout(function () {
  91. trumbowyg.closeModal();
  92. }, 250);
  93. } else {
  94. trumbowyg.addErrorOnModalField(
  95. $('input[type=text]', $modal),
  96. data.error
  97. );
  98. }
  99. },
  100. error: trumbowyg.o.plugins.noembed.error || function () {
  101. trumbowyg.addErrorOnModalField(
  102. $('input[type=text]', $modal),
  103. trumbowyg.lang.noembedError
  104. );
  105. }
  106. });
  107. }
  108. );
  109. }
  110. };
  111. trumbowyg.addBtnDef('noembed', btnDef);
  112. }
  113. }
  114. }
  115. });
  116. })(jQuery);