{"size": 890, "ext": "js", "max_stars_repo_path": "assets/js/fetch_titles.js", "max_stars_repo_name": "TheRealGD/therealgd", "max_stars_repo_stars_event_min_datetime": "2018-03-23T02:17:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-24T21:44:43.000Z", "max_issues_repo_path": "assets/js/fetch_titles.js", "max_issues_repo_name": "TheRealGD/therealgd", "max_issues_repo_issues_event_min_datetime": "2018-03-23T01:32:43.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-02T01:02:54.000Z", "max_forks_repo_path": "assets/js/fetch_titles.js", "max_forks_repo_name": "TheRealGD/therealgd", "max_forks_repo_forks_event_min_datetime": "2018-03-23T01:54:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-21T05:34:10.000Z"}
{"max_stars_count": 13, "max_issues_count": 159, "max_forks_count": 11, "avg_line_length": 29.6666666667, "max_line_length": 72, "alphanum_fraction": 0.4157303371}
'use strict';

import $ from 'jquery';
import Routing from 'fosjsrouting';

$(function () {
    $('.auto-fetch-submission-titles .fetch-title').blur(function () {
        const $receiver = $('.receive-title');
        const url = $(this).val().trim();

        if ($receiver.val().trim() === '' && /^https?:\/\//.test(url)) {
            $.ajax({
                url: Routing.generate('fetch_title'),
                method: 'POST',
                dataType: 'json',
                data: { url: url }
            }).done(data => {
                if ($receiver.val().trim() === '') {
                    $('.receive-title').val(data.title);
                }
                if (data.image) {
                  $('#submission_originalImage').val(data.image);
                }
            }).fail(err => {
                console && console.log(err);
            });
        }
    });
});
