Projet

Général

Profil

0001-JS-introduce-combo_scrollY-global-function-45040.patch

Thomas Jund, 13 juillet 2020 09:41

Télécharger (2,2 ko)

Voir les différences:

Subject: [PATCH] JS: introduce combo_scrollY global function (#45040)

Launch callback when page scroll below or above a limit
 combo/public/static/js/combo.public.js | 42 ++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 3 deletions(-)
combo/public/static/js/combo.public.js
76 76
    return search;
77 77
}
78 78

  
79
/*  Launch callbacks when scroll move above and/or below a limit
80
 *     new combo_scrollTY{
81
 *       limit: int,
82
 *       below: callback function,
83
 *       above: callback function
84
 *     })
85
 */
86
function Combo_scrollY(options) {
87
  var defaults = {
88
    limit: 0
89
  };
90
  var _self = this;
91
  _self.options = $.extend({}, defaults, options);
92
  _self.positon = function(){
93
      return (window.pageYOffset <= _self.options.limit) ? "above" : "below";
94
  };
95
  _self.update = function(){
96
    return (_self.positon() === _self.last_callback_position) ? false : true;
97
  };
98

  
99
  window.addEventListener('scroll', function() {
100
    var update = _self.update();
101

  
102
    if (update) {
103
      if (_self.positon() === "below") {
104
        _self.options.below();
105
        _self.last_callback_position = "below";
106
      } else {
107
        _self.options.above();
108
        _self.last_callback_position = "above";
109
      }
110
    }
111
  });
112
}
113

  
79 114
$(function() {
80 115
  $('[data-ajax-cell-refresh]').each(function(idx, elem) {
81 116
    var $elem = $(elem);
......
247 282
  $(document).on('combo:cell-loaded', function(ev, cell) { prepare_foldable(cell); });
248 283

  
249 284
  /* add a scrolled class to body once the user scrolled the page a bit */
250
  $(window).on('scroll', function() {
251
    if ($(window).scrollTop() == 0) {
285
  var body_is_scrolled = new Combo_scrollY({
286
    above: function(){
252 287
      $('body').removeClass('scrolled');
253
    } else {
288
    },
289
    below: function(){
254 290
      $('body').addClass('scrolled');
255 291
    }
256 292
  });
257
-