Commit f8f05371 authored by Steffen van Bergerem's avatar Steffen van Bergerem
Browse files

Merge pull request #6394 from AugierLe42e/mobile-js-refactor

Mobile JS refactor
parents a416e270 28c509ba
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ Contributions are very welcome, the hard work is done!
* Unifiy max-widths and page layouts [#6675](https://github.com/diaspora/diaspora/pull/6675)
* Enable autosizing for all textareas [#6674](https://github.com/diaspora/diaspora/pull/6674)
* Stream faces are gone [#6686](https://github.com/diaspora/diaspora/pull/6686)
* Refactor mobile javascript and add tests [#6394](https://github.com/diaspora/diaspora/pull/6394)

## Bug fixes
* Destroy Participation when removing interactions with a post [#5852](https://github.com/diaspora/diaspora/pull/5852)
+3 −110
Original line number Diff line number Diff line
@@ -15,119 +15,12 @@
//= require diaspora
//= require helpers/i18n
//= require widgets/timeago
//= require mobile/mobile_application
//= require mobile/mobile_file_uploader
//= require mobile/profile_aspects
//= require mobile/tag_following
//= require mobile/publisher
//= require mobile/mobile_comments

$(document).ready(function(){

  $('.shield a').click(function(){
    $(this).parents(".stream_element").removeClass("shield-active");
    return false;
  });
  var showLoader = function(link){
    link.addClass('loading');
  };

  var removeLoader = function(link){
    link.removeClass('loading')
         .toggleClass('active')
         .toggleClass('inactive');
  };

  // init autosize plugin
  autosize($("textarea"));

  /* Drawer menu */
  $("#menu-badge").bind("tap click", function(evt){
    evt.preventDefault();
    $("#app").toggleClass("draw");
  });

  /* Show / hide aspects in the drawer */
  $("#all_aspects").bind("tap click", function(evt){
    evt.preventDefault();
    $("#all_aspects + li").toggleClass("hide");
  });

  /* Show / hide followed tags in the drawer */
  $("#followed_tags > a").bind("tap click", function(evt){
    evt.preventDefault();
    $("#followed_tags + li").toggleClass("hide");
  });

  /* Heart toggle */
  $(".like-action", ".stream").bind("tap click", function(evt){
    evt.preventDefault();
    var link = $(this),
        likeCounter = $(this).closest(".stream_element").find(".like-count"),
        url = link.data("url");

    if(!link.hasClass("loading")){
      if(link.hasClass('inactive')) {
        $.ajax({
          url: url,
          dataType: 'json',
          type: 'POST',
          beforeSend: showLoader(link),
          success: function(data){
            removeLoader(link);
            link.data("url", url + "/" + data.id);

            if(likeCounter){
              likeCounter.text(parseInt(likeCounter.text(), 10) + 1);
            }
          }
        });
      }
      else if(link.hasClass("active")){
        $.ajax({
          url: url,
          dataType: 'json',
          type: 'DELETE',
          beforeSend: showLoader(link),
          complete: function(){
            removeLoader(link);
            link.data("url", url.replace(/\/\d+$/, ""));

            if(likeCounter){
              likeCounter.text(parseInt(likeCounter.text(), 10) - 1);
            }
          }
        });
      }
    }
  });

  /* Reshare */
  $(".reshare-action:not(.disabled)", ".stream").bind("tap click", function(evt){
    evt.preventDefault();

    var link = $(this),
        href = link.attr("href"),
        confirmText = link.attr('title');

    if(!link.hasClass("loading")) {
      if(link.hasClass('inactive')) {
        if(confirm(confirmText)) {
          $.ajax({
            url: href + "&provider_display_name=mobile",
            dataType: 'json',
            type: 'POST',
            beforeSend: showLoader(link),
            success: function(){
              removeLoader(link);
            },
            error: function(){
              removeLoader(link);
              alert(Diaspora.I18n.t('failed_to_reshare'));
            }
          });
        }
      }
    }
  });
});
//= require mobile/mobile_post_actions
//= require mobile/mobile_drawer
// @license-end
+17 −0
Original line number Diff line number Diff line
(function(){
  Diaspora.Mobile = {
    initialize: function(){
      $(".shield a").click(function(){
        $(this).parents(".stream_element").removeClass("shield-active");
        return false;
      });

      // init autosize plugin
      autosize($("textarea"));
    }
  };
})();

$(document).ready(function(){
  Diaspora.Mobile.initialize();
});
+0 −8
Original line number Diff line number Diff line
@@ -5,19 +5,11 @@
 */

(function() {
  Diaspora.Mobile = {};
  Diaspora.Mobile.Comments = {
    stream: function(){ return $(".stream"); },

    initialize: function() {
      var self = this;
      $(".stream").on("tap click", "a.back_to_stream_element_top", function() {
        var bottomBar = $(this).closest(".bottom_bar").first();
        var streamElement = bottomBar.parent();
        $("html, body").animate({
          scrollTop: streamElement.offset().top - 54
        }, 1000);
      });

      this.stream().on("tap click", "a.show-comments", function(evt){
        evt.preventDefault();
+24 −0
Original line number Diff line number Diff line
(function(){
  Diaspora.Mobile.Drawer = {
    initialize: function(){
      $("#all_aspects").bind("tap click", function(evt){
        evt.preventDefault();
        $(this).find("+ li").toggleClass("hide");
      });

      $("#menu-badge").bind("tap click", function(evt){
        evt.preventDefault();
        $("#app").toggleClass("draw");
      });

      $("#followed_tags").bind("tap click", function(evt){
        evt.preventDefault();
        $(this).find("+ li").toggleClass("hide");
      });
    }
  };
})();

$(function(){
  Diaspora.Mobile.Drawer.initialize();
});
Loading