initialize: function()

in assets/app/views/editor/edit-file.js [27:77]


  initialize: function (opts) {
    var self      = window.z = this,
        file      = this.filePathFromModel(this.model),
        fileExt   = this.fileExtensionFromName(this.model.get('file')),
        html      = {
          fileName: this.model.get('file'),
          draft: this.model.get('isDraft')
        };

    this.editors = {};
    this.path = opts.path;
    this.isNewPage = opts.isNewPage || false;
    this.settingsFields = this.extendSettingFields(opts.settingsFields);

    this.doc = this.initializeDocument({
      fileExt: fileExt,
      isNewPage: this.isNewPage
    });

    // On builds, toggle preview button
    federalist.sites.on('sync', this.previewButton.bind(this));
    this.previewButton(federalist.sites);

    html.settingsDisplayStyle = this.getSettingsDisplayStyle(this.doc);

    this.$el.html(this.template(html));
    this.initializeSettingsEditor(this.doc);
    this.initializeContentEditor(this.doc, fileExt);

    io.socket.get('/v0/site/lock', { file: file }, function(data) {

      // Store the socket ID for future reference
      self.socket = data.id;

      // Apply the lock
      self.lockContent.bind(self);

      // On any change events (others open or leave the page), reapply the lock
      io.socket.on('change', self.lockContent.bind(self));

      // If the user navigates away from the page, remove the lock
      // The server will do this automatically if the socket session breaks
      federalist.once('route', function() {
        $('.alert-container').html('');
        io.socket.get('/v0/site/unlock', { file: file });
      });

    });

    return this;
  },