<commit_before>/*global assetPath:true */

/**
  This view handles rendering of the composer

  @class ComposerView
  @extends Discourse.View
  @namespace Discourse
  @module Discourse
**/
Discourse.ComposerView = Discourse.View.extend(Ember.Evented, {
  templateName: 'composer',
  elementId: 'reply-control',
  classNameBindings: ['model.creatingPrivateMessage:private-message',
                      'composeState',
                      'model.loading',
                      'model.canEditTitle:edit-title',
                      'postMade',
                      'model.creatingTopic:topic',
                      'model.showPreview',
                      'model.hidePreview'],

  model: Em.computed.alias('controller.model'),

  // This is just in case something still references content. Can probably be removed
  content: Em.computed.alias('model'),

  composeState: function() {
    var state = this.get('model.composeState');
    if (state) return state;
    return Discourse.Composer.CLOSED;
  }.property('model.composeState'),

  draftStatus: function() {
    $('#draft-status').text(this.get('model.draftStatus') || "");
  }.observes('model.draftStatus'),

  // Disable fields when we're loading
  loadingChanged: function() {
    if (this.get('loading')) {
      $('#wmd-input, #reply-title').prop('disabled', 'disabled');
    } else {
      $('#wmd-input, #reply-title').prop('disabled', '');
    }
  }.observes('loading'),

  postMade: function() {
    return this.present('controller.createdPost') ? 'created-post' : null;
  }.property('model.createdPost'),


  refreshPreview: Discourse.debounce(function() {
    if (this.editor) {
      this.editor.refreshPreview();
      // if the caret is on the last line ensure preview scrolled to bottom
      var caretPosition = Discourse.Utilities.caretPosition(this.wmdInput[0]);
      if (!this.wmdInput.val().substring(caretPosition).match(/\n/)) {
        var $wmdPreview = $('#wmd-preview');
        if ($wmdPreview.is(':visible')) {
          $wmdPreview.scrollTop($wmdPreview[0].scrollHeight);
        }
      }
    }
  }, 30),

  observeReplyChanges: function() {
    if (this.get('model.hidePreview')) return;
    Ember.run.scheduleOnce('afterRender', this, 'refreshPreview');
  }.observes('model.reply', 'model.hidePreview'),

  movePanels: function(sizePx) {
    $('.composer-popup').css('bottom', sizePx);
  },

  focusIn: function() {
    var controller = this.get('controller');
    if (controller) controller.updateDraftStatus();
  },

  resize: function() {
    // this still needs to wait on animations, need a clean way to do that
    return Em.run.schedule('afterRender', function() {
      var replyControl = $('#reply-control');
      var h = replyControl.height() || 0;
      var sizePx = "" + h + "px";
      $('.topic-area').css('padding-bottom', sizePx);
      $('.composer-popup').css('bottom', sizePx);
    });
  }.observes('model.composeState'),

  keyUp: function() {
    var controller = this.get('controller');
    controller.checkReplyLength();

    var lastKeyUp = new Date();
    this.set('lastKeyUp', lastKeyUp);

    // One second from now, check to see if the last key was hit when
    // we recorded it. If it was, the user paused typing.
    var composerView = this;
    Em.run.later(function() {
      if (lastKeyUp !== composerView.get('lastKeyUp')) return;

      // Search for similar topics if the user pauses typing
      controller.findSimilarTopics();
    }, 1000);
  },

  keyDown: function(e) {
    // If the user hit ESC
    if (e.which === 27) {
      this.get('controller').hitEsc();
    }
  },

  didInsertElement: function() {
    var $replyControl = $('#reply-control');
    $replyControl.DivResizer({ resize: this.resize, onDrag: this.movePanels });
    Discourse.TransitionHelper.after($replyControl, this.resize);
    this.ensureMaximumDimensionForImagesInPreview();
  },

  ensureMaximumDimensionForImagesInPreview: function() {
    $('<style>#wmd-preview img, .cooked img {' +
      'max-width:' + Discourse.SiteSettings.max_image_width + 'px!important;' +
      'max-height:' + Discourse.SiteSettings.max_image_height + 'px!important;' +
      '}</style>'
     ).appendTo('head');
  },
<commit_msg>remove !important override from img here<commit_after>/*global assetPath:true */

/**
  This view handles rendering of the composer

  @class ComposerView
  @extends Discourse.View
  @namespace Discourse
  @module Discourse
**/
Discourse.ComposerView = Discourse.View.extend(Ember.Evented, {
  templateName: 'composer',
  elementId: 'reply-control',
  classNameBindings: ['model.creatingPrivateMessage:private-message',
                      'composeState',
                      'model.loading',
                      'model.canEditTitle:edit-title',
                      'postMade',
                      'model.creatingTopic:topic',
                      'model.showPreview',
                      'model.hidePreview'],

  model: Em.computed.alias('controller.model'),

  // This is just in case something still references content. Can probably be removed
  content: Em.computed.alias('model'),

  composeState: function() {
    var state = this.get('model.composeState');
    if (state) return state;
    return Discourse.Composer.CLOSED;
  }.property('model.composeState'),

  draftStatus: function() {
    $('#draft-status').text(this.get('model.draftStatus') || "");
  }.observes('model.draftStatus'),

  // Disable fields when we're loading
  loadingChanged: function() {
    if (this.get('loading')) {
      $('#wmd-input, #reply-title').prop('disabled', 'disabled');
    } else {
      $('#wmd-input, #reply-title').prop('disabled', '');
    }
  }.observes('loading'),

  postMade: function() {
    return this.present('controller.createdPost') ? 'created-post' : null;
  }.property('model.createdPost'),


  refreshPreview: Discourse.debounce(function() {
    if (this.editor) {
      this.editor.refreshPreview();
      // if the caret is on the last line ensure preview scrolled to bottom
      var caretPosition = Discourse.Utilities.caretPosition(this.wmdInput[0]);
      if (!this.wmdInput.val().substring(caretPosition).match(/\n/)) {
        var $wmdPreview = $('#wmd-preview');
        if ($wmdPreview.is(':visible')) {
          $wmdPreview.scrollTop($wmdPreview[0].scrollHeight);
        }
      }
    }
  }, 30),

  observeReplyChanges: function() {
    if (this.get('model.hidePreview')) return;
    Ember.run.scheduleOnce('afterRender', this, 'refreshPreview');
  }.observes('model.reply', 'model.hidePreview'),

  movePanels: function(sizePx) {
    $('.composer-popup').css('bottom', sizePx);
  },

  focusIn: function() {
    var controller = this.get('controller');
    if (controller) controller.updateDraftStatus();
  },

  resize: function() {
    // this still needs to wait on animations, need a clean way to do that
    return Em.run.schedule('afterRender', function() {
      var replyControl = $('#reply-control');
      var h = replyControl.height() || 0;
      var sizePx = "" + h + "px";
      $('.topic-area').css('padding-bottom', sizePx);
      $('.composer-popup').css('bottom', sizePx);
    });
  }.observes('model.composeState'),

  keyUp: function() {
    var controller = this.get('controller');
    controller.checkReplyLength();

    var lastKeyUp = new Date();
    this.set('lastKeyUp', lastKeyUp);

    // One second from now, check to see if the last key was hit when
    // we recorded it. If it was, the user paused typing.
    var composerView = this;
    Em.run.later(function() {
      if (lastKeyUp !== composerView.get('lastKeyUp')) return;

      // Search for similar topics if the user pauses typing
      controller.findSimilarTopics();
    }, 1000);
  },

  keyDown: function(e) {
    // If the user hit ESC
    if (e.which === 27) {
      this.get('controller').hitEsc();
    }
  },

  didInsertElement: function() {
    var $replyControl = $('#reply-control');
    $replyControl.DivResizer({ resize: this.resize, onDrag: this.movePanels });
    Discourse.TransitionHelper.after($replyControl, this.resize);
    this.ensureMaximumDimensionForImagesInPreview();
  },

  ensureMaximumDimensionForImagesInPreview: function() {
    $('<style>#wmd-preview img, .cooked img {' +
      'max-width:' + Discourse.SiteSettings.max_image_width + 'px;' +
      'max-height:' + Discourse.SiteSettings.max_image_height + 'px;' +
      '}</style>'
     ).appendTo('head');
  },

{'fraction_non_alphanumeric': 0.15634986388921765, 'fraction_numerical': 0.0026038584447863654, 'mean_word_length': 3.090029041626331, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2768566', 'n_tokens_mistral': 2583, 'n_tokens_neox': 2488, 'n_words': 541}