<commit_before>// The Document Editor View

var Document = Backbone.View.extend({
  events: {
    'click a.toggle-edit-mode': 'toggleEditMode',
    'click a.toggle-show-mode': 'toggleShowMode',
    'click a.subscribe-document': 'subscribeDocument',
    'click a.unsubscribe-document': 'unsubscribeDocument',
    'click a.export-document': 'toggleExport',
    'click a.toggle-settings': 'toggleSettings',
    'click a.toggle-publish-settings': 'togglePublishSettings'
  },
  
  initialize: function() {
    var that = this;
    this.attributes = new Attributes({model: this.model});
    this.settings = new DocumentSettings();
    
    this.publishSettings = new PublishSettings();
    
    this.app = this.options.app;
    this.mode = 'show';
    
    this.bind('changed', function() {
      document.title = that.model.get('title') || 'Untitled';
      // Re-render Document browser
      that.app.browser.render();
    });
    
    _.bindAll(this, 'deselect', 'onKeydown');
    $(document.body)
      .click(this.deselect)
      .keydown(this.onKeydown);
  },

  remove: function () {
    $(document.body)
      .unbind('click', this.deselect)
      .unbind('keydown', this.onKeydown);
  },
  
  render: function() {
    // Render all relevant sub views
    $(this.el).html(_.tpl('document_wrapper', {
      mode: this.mode,
      doc: this.model
    }));
    this.renderMenu();

    if (this.model) {
      // Render Attributes
      this.node = Node.create({ model: this.model });
      this.attributes.render();
      this.$('#attributes').show();
      this.$('#document').show();
      $('#document_tree').html('');
      this.toc = new TOC({ model: this.model, el: this.$('#toc_wrapper').get(0) }).render();
      $(this.node.render().el).appendTo(this.$('#document_tree'));
      
      if (this.authorized && !this.version) this.toggleEditMode();
    }
  },

  toggleEditMode: function(e) {
    if (e) e.preventDefault();
    
    //var user = app.document.model.get('creator')._id.split('/')[2];
    //var name = app.document.model.get('name');
    //$('#document_wrapper').attr('url', user+"/"+name);
    
    this.$('.toggle-show-mode').removeClass('active');
    this.$('.toggle-edit-mode').addClass('active');
    
    if (this.node) {
      this.node.transitionTo('write');
    }
  },

  onKeydown: function (e) {
    if (e.keyCode === 27) {
      // Escape key
      this.deselect();
    }
  },

  deselect: function () {
    if (this.node) {
      this.node.deselect();
    }
  },
  
  toggleShowMode: function(e) {
    if (e) e.preventDefault();
    
    //var user = app.document.model.get('creator')._id.split('/')[2];
    //var name = app.document.model.get('name');
    //$('#document_wrapper').attr('url', user+"/"+name);
    
    $('#document').removeClass('edit-mode');
    this.$('.toggle-edit-mode').removeClass('active');
    this.$('.toggle-show-mode').addClass('active');
    
    if (this.node) {
      this.node.transitionTo('read');
      this.node.deselect();
    }
  },
  
  
  loadedDocuments: {},
  
  togglePublishSettings: function() {
    $('#document_settings').hide();
    $('.view-action-icon.settings').removeClass('active');
    <commit_msg>Remove cursor when removing node selection<commit_after>// The Document Editor View

var Document = Backbone.View.extend({
  events: {
    'click a.toggle-edit-mode': 'toggleEditMode',
    'click a.toggle-show-mode': 'toggleShowMode',
    'click a.subscribe-document': 'subscribeDocument',
    'click a.unsubscribe-document': 'unsubscribeDocument',
    'click a.export-document': 'toggleExport',
    'click a.toggle-settings': 'toggleSettings',
    'click a.toggle-publish-settings': 'togglePublishSettings'
  },
  
  initialize: function() {
    var that = this;
    this.attributes = new Attributes({model: this.model});
    this.settings = new DocumentSettings();
    
    this.publishSettings = new PublishSettings();
    
    this.app = this.options.app;
    this.mode = 'show';
    
    this.bind('changed', function() {
      document.title = that.model.get('title') || 'Untitled';
      // Re-render Document browser
      that.app.browser.render();
    });
    
    _.bindAll(this, 'deselect', 'onKeydown');
    $(document.body)
      .click(this.deselect)
      .keydown(this.onKeydown);
  },

  remove: function () {
    $(document.body)
      .unbind('click', this.deselect)
      .unbind('keydown', this.onKeydown);
  },
  
  render: function() {
    // Render all relevant sub views
    $(this.el).html(_.tpl('document_wrapper', {
      mode: this.mode,
      doc: this.model
    }));
    this.renderMenu();

    if (this.model) {
      // Render Attributes
      this.node = Node.create({ model: this.model });
      this.attributes.render();
      this.$('#attributes').show();
      this.$('#document').show();
      $('#document_tree').html('');
      this.toc = new TOC({ model: this.model, el: this.$('#toc_wrapper').get(0) }).render();
      $(this.node.render().el).appendTo(this.$('#document_tree'));
      
      if (this.authorized && !this.version) this.toggleEditMode();
    }
  },

  toggleEditMode: function(e) {
    if (e) e.preventDefault();
    
    //var user = app.document.model.get('creator')._id.split('/')[2];
    //var name = app.document.model.get('name');
    //$('#document_wrapper').attr('url', user+"/"+name);
    
    this.$('.toggle-show-mode').removeClass('active');
    this.$('.toggle-edit-mode').addClass('active');
    
    if (this.node) {
      this.node.transitionTo('write');
    }
  },

  onKeydown: function (e) {
    if (e.keyCode === 27) {
      // Escape key
      this.deselect();
    }
  },

  deselect: function () {
    if (this.node) {
      this.node.deselect();
      window.editor.deactivate();
      this.$(':focus').blur();
    }
  },
  
  toggleShowMode: function(e) {
    if (e) e.preventDefault();
    
    //var user = app.document.model.get('creator')._id.split('/')[2];
    //var name = app.document.model.get('name');
    //$('#document_wrapper').attr('url', user+"/"+name);
    
    $('#document').removeClass('edit-mode');
    this.$('.toggle-edit-mode').removeClass('active');
    this.$('.toggle-show-mode').addClass('active');
    
    if (this.node) {
      this.node.transitionTo('read');
      this.node.deselect();
    }
  },
  
  
  loadedDocuments: {},
  
  togglePublishSettings: function() {
    $('#document_settings').hide();
    $('.view-action-icon.settings').removeClass('active');
    
{'fraction_non_alphanumeric': 0.19727891156462585, 'fraction_numerical': 0.0015460729746444033, 'mean_word_length': 2.8052941176470587, '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': '3282143', 'n_tokens_mistral': 2062, 'n_tokens_neox': 2072, 'n_words': 339}