{"size": 2249, "ext": "js", "max_stars_repo_path": "public/wordpress/wp-content/plugins/h5p/admin/scripts/h5p-data-views.js", "max_stars_repo_name": "raydavies/starsystems_v2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/wordpress/wp-content/plugins/h5p/admin/scripts/h5p-data-views.js", "max_issues_repo_name": "raydavies/starsystems_v2", "max_issues_repo_issues_event_min_datetime": "2020-03-31T02:00:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T21:46:22.000Z", "max_forks_repo_path": "public/wordpress/wp-content/plugins/h5p/admin/scripts/h5p-data-views.js", "max_forks_repo_name": "raydavies/starsystems_v2", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 11, "max_forks_count": null, "avg_line_length": 27.0963855422, "max_line_length": 106, "alphanum_fraction": 0.5331258337}
/* globals H5PDataView send_to_editor tb_remove tb_show */
// Create content results data view
(function ($) {

  /**
   * @private
   */
  var createDataView = function (dataView, wrapper, loaded) {
    new H5PDataView(
      wrapper,
      dataView.source,
      dataView.headers,
      dataView.l10n,
      {
        table: 'wp-list-table widefat fixed'
      },
      dataView.filters,
      loaded,
      dataView.order
    );
  };

  /**
   * @private
   */
  var insertionDataView = function (id) {
    var $wrapper;
    var $add = $(document).on('click', '#add-h5p', function () {
      // Open ThickBox
      tb_show($(this).attr('title'), '#TB_inline?inlineId=h5p-nope');
      $('#TB_window').addClass('h5p-insertion');

      if ($wrapper === undefined) {
        // Create new data view
        $wrapper = $('<div id="h5p-insert-content"/>').appendTo('#TB_ajaxContent');

        var reportUrl = H5PIntegration.dataViews[id].source.replace('h5p_insert_content', 'h5p_inserted');
        createDataView(H5PIntegration.dataViews[id], $wrapper.get(0), function () {
          // Data loaded
          $wrapper.find('.h5p-insert').click(function () {
            // Inserting content
            var contentId = $(this).data('id');
            if ($add.data('method') === 'slug') {
              send_to_editor('[h5p slug="' + $(this).data('slug') + '"]');
            }
            else {
              send_to_editor('[h5p id="' + contentId + '"]');
            }

            $wrapper.detach();
            $('#TB_window').removeClass('h5p-insertion');
            tb_remove();
            $.post(reportUrl, {id: contentId});
          });
        });
      }
      else {
        // Append existing data view
        $wrapper.appendTo('#TB_ajaxContent');
      }

      return false;
    });
  };

  $(document).ready(function () {
    for (var id in H5PIntegration.dataViews) {
      if (!H5PIntegration.dataViews.hasOwnProperty(id)) {
        continue;
      }
      if (id === 'h5p-insert-content') {
        insertionDataView(id);
        continue;
      }

      var wrapper = $('#' + id).get(0);
      if (wrapper !== undefined) {
        createDataView(H5PIntegration.dataViews[id], wrapper);
      }
    }
  });
})(H5P.jQuery);
