~mhier/libwt-latest/libwt-package

« back to all changes in this revision

Viewing changes to src/js/ResizeSensor.js

  • Committer: Martin Hierholzer
  • Date: 2020-06-18 12:21:07 UTC
  • Revision ID: martin.hierholzer@desy.de-20200618122107-jxk2kefgptu2hh3v
update to upstream version 4.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 */
27
27
 
28
28
/*
29
 
 * Copyright (C) 2016 Emweb bvba, Kessel-Lo, Belgium.
 
29
 * Copyright (C) 2016 Emweb bv, Herent, Belgium.
30
30
 *
31
31
 * See the LICENSE file for terms of use.
32
32
 */
66
66
    var expandChild = expand.childNodes[0];
67
67
    var shrink = element.resizeSensor.childNodes[1];
68
68
 
 
69
    var initialHiddenCheck = true;
 
70
    var lastAnimationFrameForInvisibleCheck = 0;
 
71
 
69
72
    var reset = function() {
 
73
        // Check if element is hidden
 
74
        if (initialHiddenCheck) {
 
75
            var invisible = element.offsetWidth === 0 && element.offsetHeight === 0;
 
76
            if (invisible) {
 
77
                // Check in next frame
 
78
                if (!lastAnimationFrameForInvisibleCheck) {
 
79
                    lastAnimationFrameForInvisibleCheck = requestAnimationFrame(function(){
 
80
                        lastAnimationFrameForInvisibleCheck = 0;
 
81
                        reset();
 
82
                    });
 
83
                }
 
84
            } else {
 
85
                // Stop checking
 
86
                initialHiddenCheck = false;
 
87
            }
 
88
        }
70
89
        expandChild.style.width  = 100000 + 'px';
71
90
        expandChild.style.height = 100000 + 'px';
72
91
 
78
97
    };
79
98
 
80
99
    element.resizeSensor.trigger = function() {
 
100
      var w = lastWidth;
 
101
      var h = lastHeight;
 
102
 
 
103
      if (!WT.boxSizing(element)) {
 
104
        h -= WT.px(element, 'borderTopWidth');
 
105
        h -= WT.px(element, 'borderBottomWidth');
 
106
        h -= WT.px(element, 'paddingTop');
 
107
        h -= WT.px(element, 'paddingBottom');
 
108
 
 
109
        w -= WT.px(element, 'borderLeftWidth');
 
110
        w -= WT.px(element, 'borderRightWidth');
 
111
        w -= WT.px(element, 'paddingLeft');
 
112
        w -= WT.px(element, 'paddingRight');
 
113
      }
 
114
 
81
115
      if (element.wtResize)
82
 
        element.wtResize(element, lastWidth, lastHeight, false);
 
116
        element.wtResize(element, w, h, false);
83
117
    };
84
118
    
85
119
    reset();
119
153
 
120
154
    addEvent(expand, 'scroll', onScroll);
121
155
    addEvent(shrink, 'scroll', onScroll);
 
156
 
 
157
    lastAnimationFrameForInvisibleCheck = requestAnimationFrame(function(){
 
158
        lastAnimationFrameForInvisibleCheck = 0;
 
159
        reset();
 
160
    });
122
161
});