Commit 5c2e2411 authored by augier's avatar augier Committed by Augier
Browse files

Displaying the markdown editor on publisher

parent 8deef544
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ source "https://rails-assets.org" do
  gem "rails-assets-markdown-it-sub",                     "1.0.0"
  gem "rails-assets-markdown-it-sup",                     "1.0.0"
  gem "rails-assets-highlightjs",                         "9.4.0"
  gem "rails-assets-bootstrap-markdown",                  "2.9.0"

  # jQuery plugins

+5 −0
Original line number Diff line number Diff line
@@ -646,6 +646,10 @@ GEM
      sprockets-rails
    rails-assets-autosize (3.0.15)
    rails-assets-blueimp-gallery (2.21.2)
    rails-assets-bootstrap (3.3.6)
      rails-assets-jquery (>= 1.9.1, < 3)
    rails-assets-bootstrap-markdown (2.9.0)
      rails-assets-bootstrap (~> 3)
    rails-assets-diaspora_jsxc (0.1.5.develop.1)
      rails-assets-favico.js (~> 0.3.9)
      rails-assets-jquery (>= 1.11)
@@ -994,6 +998,7 @@ DEPENDENCIES
  rails (= 4.2.7.1)
  rails-assets-autosize (= 3.0.15)!
  rails-assets-blueimp-gallery (= 2.21.2)!
  rails-assets-bootstrap-markdown (= 2.9.0)!
  rails-assets-diaspora_jsxc (= 0.1.5.develop.1)!
  rails-assets-highlightjs (= 9.4.0)!
  rails-assets-jasmine-ajax (= 3.2.0)!
+41 −0
Original line number Diff line number Diff line
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later

app.views.PreviewPost = app.views.Post.extend({
  templateName: "stream-element",
  className: "stream_element loaded",

  subviews: {
    ".feedback": "feedbackView",
    ".post-content": "postContentView",
    ".oembed": "oEmbedView",
    ".opengraph": "openGraphView",
    ".poll": "pollView",
    ".status-message-location": "postLocationStreamView"
  },

  tooltipSelector: [
    ".timeago",
    ".delete",
    ".permalink"
  ].join(", "),

  initialize: function() {
    this.model.set("preview", true);
    this.oEmbedView = new app.views.OEmbed({model: this.model});
    this.openGraphView = new app.views.OpenGraph({model: this.model});
    this.pollView = new app.views.Poll({model: this.model});
  },

  feedbackView: function() {
    return new app.views.Feedback({model: this.model});
  },

  postContentView: function() {
    return new app.views.StatusMessage({model: this.model});
  },

  postLocationStreamView: function() {
    return new app.views.LocationStream({model: this.model});
  }
});
// @license-end
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ app.views.PublisherGettingStarted = Backbone.View.extend({

  // initiate all the popover message boxes
  show: function() {
    app.publisher.open();
    this._addPopover(this.firstMessage, {
      trigger: "manual",
      id: "first_message_explain",
+52 −57
Original line number Diff line number Diff line
@@ -20,10 +20,8 @@ app.views.Publisher = Backbone.View.extend({
  events : {
    "keydown #status_message_fake_text" : "keyDown",
    "focus textarea" : "open",
    "click #hide_publisher" : "clear",
    "submit form" : "createStatusMessage",
    "click #submit" : "createStatusMessage",
    "click .post_preview_button" : "createPostPreview",
    "textchange #status_message_fake_text": "handleTextchange",
    "click #locator" : "showLocation",
    "click #poll_creator" : "togglePollCreator",
@@ -41,12 +39,12 @@ app.views.Publisher = Backbone.View.extend({
    this.hiddenInputEl = this.$("#status_message_text");
    this.wrapperEl = this.$("#publisher_textarea_wrapper");
    this.submitEl = this.$("input[type=submit], button#submit");
    this.previewEl = this.$("button.post_preview_button");
    this.photozoneEl = this.$("#photodropzone");

    // if there is data in the publisher we ask for a confirmation
    // before the user is able to leave the page
    $(window).on("beforeunload", _.bind(this._beforeUnload, this));
    $(window).unload(this.clear.bind(this));

    // sync textarea content
    if( this.hiddenInputEl.val() === "" ) {
@@ -60,8 +58,6 @@ app.views.Publisher = Backbone.View.extend({
    // in case publisher is standalone
    // (e.g. bookmarklet, mentions popup)
    if( this.standalone ) {
      this.$("#hide_publisher").hide();
      this.previewEl.hide();
      this.$(".question_mark").hide();
    }

@@ -130,6 +126,36 @@ app.views.Publisher = Backbone.View.extend({
    });
    this.viewUploader.on("change", this.checkSubmitAvailability, this);

    var self = this;
    var mdEditorOptions = {
      onPreview: function() {
        self.wrapperEl.addClass("markdown-preview");
        return self.createPostPreview();
      },

      onHidePreview: function() {
        self.wrapperEl.removeClass("markdown-preview");
      },

      onPostPreview: function() {
        var photoAttachments = self.wrapperEl.find(".photo_attachments");
        if (photoAttachments.length > 0) {
          new app.views.Gallery({el: photoAttachments});
        }
      },

      onChange: function() {
        self.inputEl.trigger("textchange");
      }
    };

    if (!this.standalone) {
      mdEditorOptions.onClose = function() {
        self.clear();
      };
    }
    this.markdownEditor = new Diaspora.MarkdownEditor(this.inputEl, mdEditorOptions);

    this.viewPollCreator = new app.views.PublisherPollCreator({
      el: this.$("#poll_creator_container")
    });
@@ -251,7 +277,7 @@ app.views.Publisher = Backbone.View.extend({
  },

  togglePollCreator: function(){
    this.viewPollCreator.$el.toggle();
    this.wrapperEl.toggleClass("with-poll");
    this.inputEl.focus();
  },

@@ -300,17 +326,14 @@ app.views.Publisher = Backbone.View.extend({
    return poll;
  },

  createPostPreview : function(evt) {
    if(evt){ evt.preventDefault(); }
    if(!app.stream) { return; }

  createPostPreview: function() {
    //add missing mentions at end of post:
    this.handleTextchange();

    var serializedForm = $(evt.target).closest("form").serializeObject();
    var serializedForm = $("#new_status_message").serializeObject();
    var text = this.mention.getTextForSubmit();
    var photos = this.getUploadedPhotos();
    var mentionedPeople = this.mention.mentionedPeople;
    var date = (new Date()).toISOString();
    var poll = this.getPollData(serializedForm);
    var locationCoords = serializedForm["location[coords]"];
    if(!locationCoords || locationCoords === "") {
@@ -326,11 +349,10 @@ app.views.Publisher = Backbone.View.extend({

    var previewMessage = {
      "id": 0,
      "text" : serializedForm["status_message[text]"],
      "text": text,
      "public": serializedForm["aspect_ids[]"] === "public",
      "created_at" : date,
      "interacted_at" : date,
      "post_type" : "StatusMessage",
      "created_at": new Date().toISOString(),
      "interacted_at": new Date().toISOString(),
      "author": app.currentUser ? app.currentUser.attributes : {},
      "mentioned_people": mentionedPeople,
      "photos": photos,
@@ -340,29 +362,8 @@ app.views.Publisher = Backbone.View.extend({
      "poll": poll
    };

    this.removePostPreview();
    app.stream.addNow(previewMessage);
    this.recentPreview=previewMessage;
    this.modifyPostPreview($(".stream_element:first",$(".stream_container")));
  },

  modifyPostPreview : function(post) {
    post.addClass("post_preview");
    $(".collapsible",post).removeClass("collapsed").addClass("opened");
    $("a.delete.remove_post",post).hide();
    $("a.like, a.focus_comment_textarea",post).removeAttr("href");
    $("a.like",post).addClass("like_preview")
                    .removeClass("like");
    $("a.focus_comment_textarea",post).addClass("focus_comment_textarea_preview")
                                      .removeClass("focus_comment_textarea");
    $("a",$("span.details.grey",post)).removeAttr("href");
  },

  removePostPreview : function() {
    if(app.stream && this.recentPreview) {
      app.stream.items.remove(this.recentPreview);
      delete this.recentPreview;
    }
    var previewPost = new app.views.PreviewPost({model: new app.models.Post(previewMessage)}).render().el;
    return $("<div/>").append(previewPost).html();
  },

  keyDown : function(evt) {
@@ -392,12 +393,10 @@ app.views.Publisher = Backbone.View.extend({
    // empty upload-photo
    this.$("#fileInfo").empty();

    // close publishing area (CSS)
    // remove preview and close publishing area (CSS)
    this.markdownEditor.hidePreview();
    this.close();

    // remove preview
    this.removePostPreview();

    // disable submitting
    this.checkSubmitAvailability();

@@ -445,7 +444,7 @@ app.views.Publisher = Backbone.View.extend({
    $(this.el).addClass("closed");
    this.wrapperEl.removeClass("active");
    this.inputEl.css("height", "");
    this.viewPollCreator.$el.hide();
    this.wrapperEl.removeClass("with-poll");
    return this;
  },

@@ -476,10 +475,8 @@ app.views.Publisher = Backbone.View.extend({
  setButtonsEnabled: function(bool) {
    if (bool) {
      this.submitEl.removeAttr("disabled");
      this.previewEl.removeAttr("disabled");
    } else {
      this.submitEl.prop("disabled", true);
      this.previewEl.prop("disabled", true);
    }
  },

@@ -503,8 +500,6 @@ app.views.Publisher = Backbone.View.extend({
  },

  handleTextchange: function() {
    var self = this;

    this.checkSubmitAvailability();
    this.hiddenInputEl.val(this.mention.getTextForSubmit());
  },
Loading