(function ($) { 'use strict'; $.extend(true, $.trumbowyg, { langs: { // jshint camelcase:false en: { giphy: 'Insert GIF', }, et: { giphy: 'Sisesta GIF', }, fr: { giphy: 'Insérer un GIF', }, hu: { giphy: 'GIF beszúrás', }, tr: { giphy: 'GIF ekle', }, // jshint camelcase:true } }); var giphyLogo = ''; // jshint ignore:line var CANCEL_EVENT = 'tbwcancel'; // Throttle helper function trumbowygThrottle(callback, delay) { var last; var timer; return function () { var context = this; var now = +new Date(); var args = arguments; if (last && now < last + delay) { clearTimeout(timer); timer = setTimeout(function () { last = now; callback.apply(context, args); }, delay); } else { last = now; callback.apply(context, args); } }; } // Fills modal with response gifs function renderGifs(response, $giphyModal, trumbowyg, mustEmpty) { var width = ($giphyModal.width() - 20) / 3; var html = response.data .filter(function (gifData) { return gifData.images.downsized.url !== ''; }) .map(function (gifData) { var image = gifData.images.downsized, imageRatio = image.height / image.width; return '
You are offline
'); } }; // Load trending gifs as default $.ajax({ url: DEFAULT_URL, dataType: 'json', success: function(response) { renderGifs(response, $giphyModal, trumbowyg, true); }, error: ajaxError }); var searchGifsOnInput = function () { var query = $giphyInput.val(); if (query.length === 0) { return; } try { previousAjaxCall.abort(); } catch (e) {} previousAjaxCall = $.ajax({ url: BASE_URL + '&q=' + encodeURIComponent(query), dataType: 'json', success: function(response) { renderGifs(response, $giphyModal, trumbowyg, true); }, error: ajaxError }); }; var throttledInputRequest = trumbowygThrottle(searchGifsOnInput, trumbowyg.o.plugins.giphy.throttleDelay); $giphyInput.on('input', throttledInputRequest); $giphyInput.focus(); $giphyClose.one('click', function() { $giphyModal.trigger(CANCEL_EVENT); }); }, }); } } } }); })(jQuery);