options.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * @var $options array contains all the options the current block we're ediging contains
  4. * @var $controls NewsletterControls
  5. */
  6. ?>
  7. <?php $fields->text('q', __('Search')) ?>
  8. <div style="clear: both; max-height: 300px; overflow: scroll; margin-bottom: 15px" id="tnp-giphy-results"></div>
  9. <?php $controls->hidden('giphy_url') ?>
  10. <div id="giphy-preview">
  11. <?php if (!empty($controls->data['giphy_url'])) { ?>
  12. <img src="<?php echo esc_attr($controls->data['giphy_url'])?>" style="max-width: 300px">
  13. <?php } ?>
  14. </div>
  15. <?php $fields->block_commons() ?>
  16. <script type="text/javascript">
  17. function choose_gif(url) {
  18. //jQuery("#tnp-giphy-results").html("");
  19. jQuery("#options-giphy_url").val(url);
  20. jQuery("#giphy-preview").html('<img src="' + url + '" style="max-width: 300px">');
  21. jQuery("#options-giphy_url").trigger("change");
  22. }
  23. jQuery("#options-q").keyup(
  24. function () {
  25. if (typeof(tid) != "undefined") {
  26. window.clearTimeout(tid);
  27. }
  28. tid = window.setTimeout(function () {
  29. var rating = "r";
  30. var limit = 20;
  31. var offset = 0;
  32. jQuery.get("https://api.giphy.com/v1/gifs/search", {limit: limit, rating: rating, api_key: "57FLbVJJd7oQBZ0fEiRnzhM2VtZp5OP1", q: jQuery("#options-q").val()}, function (data) {
  33. jQuery("#tnp-giphy-results").html("");
  34. jQuery.each(data.data, function (index, value) {
  35. jQuery("#tnp-giphy-results").append('<div style="overflow: hidden; width: 120px; height: 120px; float: left; margin: 5px"><img src="' + value.images.fixed_width_small.url + '" onclick="choose_gif(\'' + value.images.fixed_height.url + '\')" style="float:left; max-width: 100%"></div>');
  36. });
  37. }, "json");
  38. }, 500);
  39. });
  40. jQuery("#options-q").trigger('keyup');
  41. </script>