<commit_before>/**
 * AOL Liveblog Lite UI Widget
 *
 * @fileOverview A slim UI widget to publish data from AOL liveblogs.
 *
 * @see https://github.com/aol/liveblog-widget
 * @author <NAME>, <NAME>
 * @requires $.fn.liveBlogLiteApi
 */

(function ($) {

  $.fn.liveBlogLiteUi = function (customOptions) {

    var defaultOptions = {
        /**
         * Whether to show the toolbar UI.
         * @type Boolean
         * @default false
         */
        toolbarEnabled: false,
        /**
         * Number of items to show for pagination. If 0 or not a positive integer, pagination is disabled.
         * @type Number
         * @default 0
         */
        pageSize: 0,
        /**
         * Whether to show the tweet buttons on posts.
         * @type Boolean
         * @default true
         */
        tweetButtons: true,
        /**
         * Height of the post container, required for the timeline slider to
         * function. Must be a positive integer.
         * @type Number
         * @default 0
         */
        height: 0,
        /**
         * Optional URL params to append to all outgoing links within the post
         * text; for link tracking, etc. Ex: 'icid=aol123'
         * @type String
         * @default null
         */
        linkParams: null,
        /**
         * Whether to show the 75 x 75 thumbnail version of images . If set to
         * false, will show the full image. In our default CSS, the image is
         * scaled down to 100px height and proportionally determined width.
         * @type Boolean
         * @default true
         */
        thumbnails: true,
        /**
         * Whether to use DIMS for thumbnails
         * @type Boolean
         * @default true
         */
        dims: true,
        /**
         * Dimension restrictions for thumbnail images - only applicable if
         * using DIMS
         * @type Object
         **/
        thumbnailDimensions: {
          height: 100,
          width: null
        }
      },
      /**
       * Simple way to strip html tags
       * @see http://stackoverflow.com/questions/822452/strip-html-from-text-javascript
       * @param {string} html Text with html tags
       */
      stripHtml = function (html) {
        var tmp = document.createElement('DIV');
        tmp.innerHTML = html;
        return tmp.textContent || tmp.innerText;
      },

      $this = $(this),

      liveBlogLiteUi = function (customOptions) {

        if ($.fn.liveBlogLiteApi) {

          var options = $.extend(true, {}, defaultOptions, customOptions),
            scrolling = false,
            hash = window.location.hash;

          // Check the hash for the presence of a tag filter
          // Only one tag may be filtered at a time (currently)
          if (hash.length) {
            var tag,
              start,
              tagPosition = hash.indexOf('tag=');

            if (tagPosition > -1) {
              start = tagPosition + 4;
              tag = hash.substring(start, hash.length);
              tag = decodeURIComponent(tag);

              options.tagFilter = tag;
            }
          }

          // Make sure linkParams don't begin with a delimiter
          if (options.linkParams && (options.linkParams.charAt(0) === '?' || options.linkParams.charAt(0) === '&')) {
            options.linkParams = options.linkParams.substr(1);
          }

          // Listen to 'begin' event from API, to initialize and build the widget
          $this.bind('begin', function (event) {

            $this.empty();

            var paused = true,
              pageSize = options.pageSize,
              pendingUpdates = [],
              beginTime = 0,
              endTime = 0,
              $alert = null,
              $tagFilter = null,
              $clearTagFilter = null,
              $posts = null,
              $toolbar = null,
              $slider = null,
              $status = null,
              $unreadCount,
              unreadItemCount = 0,
              receivedFirstUpdate = false,

              /**
               * Create DOM element for post item from the given data item. If
               * element is provided then replaces content of that element,
               * else creates new one.
               * @param {Object} item The data item used as source.
               * @param {Object|null} element The optional jQuery object to modify, instead of creating new one.
               * @returns {Object} The jQuery object built from the data, not yet added to the DOM.
               */
              buildItem = function (item, element) {

                var data = item.content,
                  type = item.type,
                  id = item.id,
                  caption = item.caption,
                  tags = item.tags,
                  timestamp = item.date,
                  memberId = item.memberId,
                  timestampString = '<a href="#p' + id + '">' + getFormattedDateTime(timestamp) + '</a> by ' + item.memberName,
                  imageUrl,
                  fullImageUrl,
                  $tweetButton,
                  tweetText,
                  $postInfo;

                //console.log('type', type);

                // If there is a tag filter present...
                if (options.tagFilter && tags) {
                  // If the tag is not present in this item, don't build it
                  if ($.inArray(options.tagFilter, tags) === -1) {
                    // Return an empty array
                    return [];
                  }
                }

                if (!element) {
                  element = $('<p />', {
                    id: 'p' + id,
                    'class': 'lb-post'
                  })
                  .data('date', item.date.getTime());
                } else {
                  element.empty();
                }

                if (type === 'text' || type === 'comment') {
                  element.append(
                    buildTextElement(data, 'lb-post-text')
                  );

                  if (type === 'comment') {
                    element.addClass('lb-comment');
                  } else {
                    // Initialize item's comments to 0
                    if (!element.data('comments')) {
                      element.data('comments', 0);
                    }
                  }

                } else if (type === 'image') {
                  if (options.thumbnails) {
                    // Store a reference to the full-sized image
                    fullImageUrl = data;
                    if (options.dims) {
                      // Use the getDynamicImageSrc plugin to fetch a proper
                      // DIMS URL
                      imageUrl = $.getDynamicImageSrc(data, options.thumbnailDimensions.width, options.thumbnailDimensions.height);
                    } else {
                      // Otherwise, use the Blogsmith CDN way of fetching a
                      // standard 75x75 thumbnail<commit_msg>* Display 'edited' in post timestamp when its been updated; also attach '.lb-edited' class to post, so can style differently if we want * Fixes #17<commit_after>/**
 * AOL Liveblog Lite UI Widget
 *
 * @fileOverview A slim UI widget to publish data from AOL liveblogs.
 *
 * @see https://github.com/aol/liveblog-widget
 * @author <NAME>, <NAME>
 * @requires $.fn.liveBlogLiteApi
 */

(function ($) {

  $.fn.liveBlogLiteUi = function (customOptions) {

    var defaultOptions = {
        /**
         * Whether to show the toolbar UI.
         * @type Boolean
         * @default false
         */
        toolbarEnabled: false,
        /**
         * Number of items to show for pagination. If 0 or not a positive integer, pagination is disabled.
         * @type Number
         * @default 0
         */
        pageSize: 0,
        /**
         * Whether to show the tweet buttons on posts.
         * @type Boolean
         * @default true
         */
        tweetButtons: true,
        /**
         * Height of the post container, required for the timeline slider to
         * function. Must be a positive integer.
         * @type Number
         * @default 0
         */
        height: 0,
        /**
         * Optional URL params to append to all outgoing links within the post
         * text; for link tracking, etc. Ex: 'icid=aol123'
         * @type String
         * @default null
         */
        linkParams: null,
        /**
         * Whether to show the 75 x 75 thumbnail version of images . If set to
         * false, will show the full image. In our default CSS, the image is
         * scaled down to 100px height and proportionally determined width.
         * @type Boolean
         * @default true
         */
        thumbnails: true,
        /**
         * Whether to use DIMS for thumbnails
         * @type Boolean
         * @default true
         */
        dims: true,
        /**
         * Dimension restrictions for thumbnail images - only applicable if
         * using DIMS
         * @type Object
         **/
        thumbnailDimensions: {
          height: 100,
          width: null
        }
      },
      /**
       * Simple way to strip html tags
       * @see http://stackoverflow.com/questions/822452/strip-html-from-text-javascript
       * @param {string} html Text with html tags
       */
      stripHtml = function (html) {
        var tmp = document.createElement('DIV');
        tmp.innerHTML = html;
        return tmp.textContent || tmp.innerText;
      },

      $this = $(this),

      liveBlogLiteUi = function (customOptions) {

        if ($.fn.liveBlogLiteApi) {

          var options = $.extend(true, {}, defaultOptions, customOptions),
            scrolling = false,
            hash = window.location.hash;

          // Check the hash for the presence of a tag filter
          // Only one tag may be filtered at a time (currently)
          if (hash.length) {
            var tag,
              start,
              tagPosition = hash.indexOf('tag=');

            if (tagPosition > -1) {
              start = tagPosition + 4;
              tag = hash.substring(start, hash.length);
              tag = decodeURIComponent(tag);

              options.tagFilter = tag;
            }
          }

          // Make sure linkParams don't begin with a delimiter
          if (options.linkParams && (options.linkParams.charAt(0) === '?' || options.linkParams.charAt(0) === '&')) {
            options.linkParams = options.linkParams.substr(1);
          }

          // Listen to 'begin' event from API, to initialize and build the widget
          $this.bind('begin', function (event) {

            $this.empty();

            var paused = true,
              pageSize = options.pageSize,
              pendingUpdates = [],
              beginTime = 0,
              endTime = 0,
              $alert = null,
              $tagFilter = null,
              $clearTagFilter = null,
              $posts = null,
              $toolbar = null,
              $slider = null,
              $status = null,
              $unreadCount,
              unreadItemCount = 0,
              receivedFirstUpdate = false,

              /**
               * Create DOM element for post item from the given data item. If
               * element is provided then replaces content of that element,
               * else creates new one.
               * @param {Object} item The data item used as source.
               * @param {Object|null} element The optional jQuery object to modify, instead of creating new one.
               * @returns {Object} The jQuery object built from the data, not yet added to the DOM.
               */
              buildItem = function (item, element) {

                var data = item.content,
                  type = item.type,
                  id = item.id,
                  caption = item.caption,
                  tags = item.tags,
                  timestamp = item.date,
                  memberId = item.memberId,
                  timestampString = '<a href="#p' + id + '">' + getFormattedDateTime(timestamp) + '</a> by ' + item.memberName,
                  imageUrl,
                  fullImageUrl,
                  $tweetButton,
                  tweetText,
                  $postInfo,
                  isNew = !element;

                //console.log('type', type);

                // If there is a tag filter present...
                if (options.tagFilter && tags) {
                  // If the tag is not present in this item, don't build it
                  if ($.inArray(options.tagFilter, tags) === -1) {
                    // Return an empty array
                    return [];
                  }
                }

                if (isNew) {
                  element = $('<p />', {
                    id: 'p' + id,
                    'class': 'lb-post'
                  })
                  .data('date', item.date.getTime());
                } else {
                  element.empty()
                    .addClass('lb-edited');
                  
                  timestampString = timestampString + ' - edited';
                }

                if (type === 'text' || type === 'comment') {
                  element.append(
                    buildTextElement(data, 'lb-post-text')
                  );

                  if (type === 'comment') {
                    element.addClass('lb-comment');
                  } else {
                    // Initialize item's comments to 0
                    if (!element.data('comments')) {
                      element.data('comments', 0);
                    }
                  }

                } else if (type === 'image') {
                  if (options.thumbnails) {
                    // Store a reference to the full-sized image
                    fullImageUrl = data;
                    if (options.dims) {
                      // Use the getDynamicImageSrc plugin to fetch a proper
                      // DIMS URL
                      imageUrl = $.getDynamicImageSrc(data, options.thumbnailDimensions.width, options.thumbnailDimensions.height);
                    } else {
                      // Otherwise, use the Blogsmith CDN way of fetching a
                      // standard 75x75 thumbnail
{'fraction_non_alphanumeric': 0.09709212917656927, 'fraction_numerical': 0.005592059275828324, 'mean_word_length': 1.256268727330074, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1267603', 'n_tokens_mistral': 3656, 'n_tokens_neox': 3417, 'n_words': 1121}