<commit_before>/* global require ajaxify */

(function() {
  'use strict';

  var deps = [
    'plugins/smoothshorts/config',
    'plugins/smoothshorts/dom',
    'plugins/smoothshorts/sockets',
    'plugins/smoothshorts/hashed/post',
    'plugins/smoothshorts/hashed/topic'
  ];

  require(deps, function(config, dom, sockets, HashedPost, HashedTopic) {

    function parseAjaxifyData() {
      var data = ajaxify.data;
      if (data.posts) {
        sockets.getHashes('posts', data.posts.map(postsMap), addHashes);
      } else {
        var dataSet = data.topics || data.categories;
        if (dataSet) {
          sockets.getHashes('posts', dataSet.filter(teaserFilter).map(teaserMap), addHashes);
        }
        if (data.topics) {
          sockets.getHashes('topics', dataSet.map(topicsMap), addHashes);
        }
      }
    }

    function addOnScrollLoad(event, data) {
      var type = event.type.split(':')[1];
      sockets.getHashes(type, data[type].map(postsMap), addHashes);
    }

    function topicsMap(topic) {
      console.log(topic);
      return new HashedTopic({
        slug: topic.slug,
        tid: topic.tid,
        postcount: topic.postcount,
        title: topic.title
      });
    }

    function postsMap(post) {
      var topicTitle = post.topic ? post.topic.title : ajaxify.data.title;
      var topicSlug = post.topic ? post.topic.slug : ajaxify.data.slug;
      var index = post.topic ? post.index : post.index + 1;
      return new HashedPost({
        pid: post.pid,
        url: null,
        index: index,
        topicData: {
          title: topicTitle,
          slug: topicSlug
        }
      });
    }

    function teaserMap(topic) {
      return new HashedPost({
        pid: topic.teaser.pid,
        url: topic.teaser.url,
        index: topic.teaser.index,
        topicData: {
          title: topic.title,
          slug: topic.slug
        }
      });
    }

    function teaserFilter(obj) {
      return !!obj.teaser;
    }

    function addHashes(type, hashedObjects) {
      hashedObjects.forEach(function(obj) {
        obj.addHashToAnchor();
        if (obj instanceof HashedPost && obj.shouldHaveButton() && !obj.hasButton()) {
          obj.addButton(buttonClickDelegate);
        }
      });
    }

    function buttonClickDelegate(hashedPost) {
      var copyShortUrl = function() {
        hashedPost.shortUrlContainer.select();
        console.log(document.execCommand('copy'));
      };
      return copyShortUrl;
    }

    config.load(function() {
      $(window).on('action:ajaxify.contentLoaded', parseAjaxifyData);
      $(window).on('action:posts.loaded', addOnScrollLoad);
      $(window).on('action:topics.loaded', addOnScrollLoad);
      parseAjaxifyData();
    });
  });

})();<commit_msg>Alert user on copy<commit_after>/* global require ajaxify app */

(function() {
  'use strict';

  var deps = [
    'plugins/smoothshorts/config',
    'plugins/smoothshorts/dom',
    'plugins/smoothshorts/sockets',
    'plugins/smoothshorts/hashed/post',
    'plugins/smoothshorts/hashed/topic'
  ];

  require(deps, function(config, dom, sockets, HashedPost, HashedTopic) {

    function parseAjaxifyData() {
      var data = ajaxify.data;
      if (data.posts) {
        sockets.getHashes('posts', data.posts.map(postsMap), addHashes);
      } else {
        var dataSet = data.topics || data.categories;
        if (dataSet) {
          sockets.getHashes('posts', dataSet.filter(teaserFilter).map(teaserMap), addHashes);
        }
        if (data.topics) {
          sockets.getHashes('topics', dataSet.map(topicsMap), addHashes);
        }
      }
    }

    function addOnScrollLoad(event, data) {
      var type = event.type.split(':')[1];
      sockets.getHashes(type, data[type].map(postsMap), addHashes);
    }

    function topicsMap(topic) {
      console.log(topic);
      return new HashedTopic({
        slug: topic.slug,
        tid: topic.tid,
        postcount: topic.postcount,
        title: topic.title
      });
    }

    function postsMap(post) {
      var topicTitle = post.topic ? post.topic.title : ajaxify.data.title;
      var topicSlug = post.topic ? post.topic.slug : ajaxify.data.slug;
      var index = post.topic ? post.index : post.index + 1;
      return new HashedPost({
        pid: post.pid,
        url: null,
        index: index,
        topicData: {
          title: topicTitle,
          slug: topicSlug
        }
      });
    }

    function teaserMap(topic) {
      return new HashedPost({
        pid: topic.teaser.pid,
        url: topic.teaser.url,
        index: topic.teaser.index,
        topicData: {
          title: topic.title,
          slug: topic.slug
        }
      });
    }

    function teaserFilter(obj) {
      return !!obj.teaser;
    }

    function addHashes(type, hashedObjects) {
      hashedObjects.forEach(function(obj) {
        obj.addHashToAnchor();
        if (obj instanceof HashedPost && obj.shouldHaveButton() && !obj.hasButton()) {
          obj.addButton(buttonClickDelegate);
        }
      });
    }

    function buttonClickDelegate(hashedPost) {
      var copyShortUrl = function() {
        hashedPost.shortUrlContainer.select();
        var isCopied = document.execCommand('copy');
        var msg = isCopied ?
                  'Copied \'' + hashedPost.shortUrlContainer.value + '\'' :
                  'Copy command failed.';
        isCopied ? app.alertSuccess(msg) : app.alertError;
      };
      return copyShortUrl;
    }

    config.load(function() {
      $(window).on('action:ajaxify.contentLoaded', parseAjaxifyData);
      $(window).on('action:posts.loaded', addOnScrollLoad);
      $(window).on('action:topics.loaded', addOnScrollLoad);
      parseAjaxifyData();
    });
  });

})();
{'fraction_non_alphanumeric': 0.13305541080423833, 'fraction_numerical': 0.000694806322737537, 'mean_word_length': 2.3053960964408726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2985596', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1797, 'n_words': 315}