github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/pubnot/trumbowyg/plugins/noembed/trumbowyg.noembed.js (about) 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 9 (function ($) { 10 'use strict'; 11 12 var defaultOptions = { 13 proxy: 'https://noembed.com/embed?nowrap=on', 14 urlFiled: 'url', 15 data: [], 16 success: undefined, 17 error: undefined 18 }; 19 20 $.extend(true, $.trumbowyg, { 21 langs: { 22 en: { 23 noembed: 'Noembed', 24 noembedError: 'Error' 25 }, 26 sk: { 27 noembedError: 'Chyba' 28 }, 29 fr: { 30 noembedError: 'Erreur' 31 }, 32 cs: { 33 noembedError: 'Chyba' 34 }, 35 ru: { 36 noembedError: 'Ошибка' 37 }, 38 ja: { 39 noembedError: 'エラー' 40 } 41 }, 42 43 plugins: { 44 noembed: { 45 init: function (trumbowyg) { 46 trumbowyg.o.plugins.noembed = $.extend(true, {}, defaultOptions, trumbowyg.o.plugins.noembed || {}); 47 48 var btnDef = { 49 fn: function () { 50 var $modal = trumbowyg.openModalInsert( 51 // Title 52 trumbowyg.lang.noembed, 53 54 // Fields 55 { 56 url: { 57 label: 'URL', 58 required: true 59 } 60 }, 61 62 // Callback 63 function (data) { 64 $.ajax({ 65 url: trumbowyg.o.plugins.noembed.proxy, 66 type: 'GET', 67 data: data, 68 cache: false, 69 dataType: 'json', 70 71 success: trumbowyg.o.plugins.noembed.success || function (data) { 72 if (data.html) { 73 trumbowyg.execCmd('insertHTML', data.html); 74 setTimeout(function () { 75 trumbowyg.closeModal(); 76 }, 250); 77 } else { 78 trumbowyg.addErrorOnModalField( 79 $('input[type=text]', $modal), 80 data.error 81 ); 82 } 83 }, 84 error: trumbowyg.o.plugins.noembed.error || function () { 85 trumbowyg.addErrorOnModalField( 86 $('input[type=text]', $modal), 87 trumbowyg.lang.noembedError 88 ); 89 } 90 }); 91 } 92 ); 93 } 94 }; 95 96 trumbowyg.addBtnDef('noembed', btnDef); 97 } 98 } 99 } 100 }); 101 })(jQuery);