Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « js « static - github.com/janraasch/hugo-scroll.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 820d3c195cfbd153c50b386af9de9d469f7efcf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * Main JS file for GhostScroll behaviours
 */

var $post = $(".post");
var $first = $(".post.first");
var $last = $(".post.last");
var $fnav = $(".fixed-nav");
var $postholder = $(".post-holder");
var $postafter = $(".post-after");
var $sitehead = $("#site-head");

/* Globals jQuery, document */
(function ($) {
  "use strict";
  function srcTo(el) {
    $("html, body").animate(
      {
        scrollTop: el.offset().top,
      },
      1000
    );
  }
  function srcToAnchorWithTitle(str) {
    var $el = $("#" + str);
    if ($el.length) {
      srcTo($el);
    }
  }
  $(document).ready(function () {
    $postholder.each(function (e) {
      if (e % 2 != 0) $(this).addClass("odd");
    });

    $postafter.each(function (e) {
      var bg = $(this).parent().css("background-color");
      $(this).css("border-top-color", bg);

      if (e % 2 == 0) {
        $(this).addClass("even");
      }
    });

    $("a.btn.site-menu").click(function (e) {
      srcToAnchorWithTitle($(e.target).data("title-anchor"));
    });
    $("#header-arrow").click(function () {
      srcTo($first);
    });

    $(".post-title").each(function () {
      var t = $(this).text();
      var index = $(this).parents(".post-holder").index();
      $fnav.append(
        "<a class='fn-item' item_index='" + index + "'>" + t + "</a>"
      );
      $(".fn-item").click(function () {
        var i = $(this).attr("item_index");
        var s = $(".post[item_index='" + i + "']");

        $("html, body").animate(
          {
            scrollTop: s.offset().top,
          },
          400
        );
      });
    });

    $(".post.last").next(".post-after").hide();
    if ($sitehead.length) {
      $(window).scroll(function () {
        var w = $(window).scrollTop();
        var g = $sitehead.offset().top;
        var h = $sitehead.offset().top + $sitehead.height() - 100;

        if (w >= g && w <= h) {
          $(".fixed-nav").fadeOut("fast");
        } else if ($(window).width() > 500) {
          $(".fixed-nav").fadeIn("fast");
        }

        $post.each(function () {
          var f = $(this).offset().top;
          var b = $(this).offset().top + $(this).height();
          var t = $(this).parent(".post-holder").index();
          var i = $(".fn-item[item_index='" + t + "']");
          var a = $(this)
            .parent(".post-holder")
            .prev(".post-holder")
            .find(".post-after");

          $(this).attr("item_index", t);

          if (w >= f && w <= b) {
            i.addClass("active");
            a.fadeOut("slow");
          } else {
            i.removeClass("active");
            a.fadeIn("slow");
          }
        });
      });
    }

    $("ul li").before(
      '<span class="bult fa fa-asterisk icon-asterisk"></span>'
    );
    $("blockquote p").prepend('<span class="quo icon-quote-left"></span>');
    $("blockquote p").append('<span class="quo icon-quote-right"></span>');
  });

  $post.each(function () {
    var postText = $(this).html();
    var fa = [];
    for (var i = 0; i < icons.length; i++) {
      fa[i] = {};
      fa[i].str = "@" + icons[i] + "@";
      fa[i].icon = icons[i];
      fa[i].int = postText.search(fa[i].str);

      if (fa[i].int > -1) {
        fa[i].count = postText.match(new RegExp(fa[i].str, "g")).length;
        for (var j = 0; j < fa[i].count; j++) {
          $(this).html(
            $(this)
              .html()
              .replace(fa[i].str, "<i class='fa " + fa[i].icon + "'></i>")
          );
        }
      }
    }
  });
})(jQuery);