<commit_before>// Copyright (c) 2017, dmarl. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
import 'dart:html';
import 'dart:math';
import 'package:angular/angular.dart';

@Component(
    selector: 'd-navbar',
    styleUrls: const ['d_navbar.css'],
    templateUrl: 'd_navbar.html')
class NavbarComponent implements OnInit, AfterViewInit {
  NavbarComponent(this.host);

  @override
  void ngOnInit() {    
    _parentElement = trackDocument ? document.documentElement : host.parent;
    _parentElement.onScroll.listen((event) {
      if (alwaysShow)
        offset = 0;
      else {
        final deltaScrollY = _parentElement.scrollTop - _previousScrollY;
        offset = _clamp(offset + deltaScrollY, 0, height);
        _previousScrollY = _parentElement.scrollTop;
      }
    });
  }

  @override
  void ngAfterViewInit() {
    /**
     * Make sure nav doesn't overflow container scrollbar
     */
    final navContainer = host.querySelector('#navContainer');
    navContainer.style.width = '${_parentElement.clientWidth}px';
    window.onResize.listen((_) {
      navContainer.style.width = '${_parentElement.clientWidth}px';
    });
  }

  int _clamp(int value, int minimum, int maximum) =>
      max(minimum, min(maximum, value));

  bool get isTop =>
      (_parentElement == null) ? true : _parentElement.scrollTop == 0;
  int offset = 0;
  int _previousScrollY = 0;

  Element _parentElement;
  final Element host;

  @Input()
  String backgroundColor = 'white';

  @Input()
  int height = 100;

  @Input()
  bool alwaysShow = false;

  @Input()
  bool trackDocument = false;
}
<commit_msg>Added option to set navbar tracking window.document rather than host element #fix 3<commit_after>// Copyright (c) 2017, dmarl. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
import 'dart:html';
import 'dart:math';
import 'package:angular/angular.dart';

@Component(
    selector: 'd-navbar',
    styleUrls: const ['d_navbar.css'],
    templateUrl: 'd_navbar.html')
class NavbarComponent implements OnInit, AfterViewInit {
  NavbarComponent(this.host);

  @override
  void ngOnInit() {
    _parentElement = trackDocument ? document.documentElement : host.parent;
    
    final s = trackDocument ? window : host.parent;
    s.onScroll.listen((event) {
      if (alwaysShow) {
        offset = 0;
      }
      else {
        final deltaScrollY = _parentElement.scrollTop - _previousScrollY;
        offset = _clamp(offset + deltaScrollY, 0, height);
        _previousScrollY = _parentElement.scrollTop;
      }
    });
  }

  @override
  void ngAfterViewInit() {
    /**
     * Make sure nav doesn't overflow container scrollbar
     */
    final navContainer = host.querySelector('#navContainer');
    navContainer.style.width = '${_parentElement.clientWidth}px';
    window.onResize.listen((_) {
      navContainer.style.width = '${_parentElement.clientWidth}px';
    });
  }

  int _clamp(int value, int minimum, int maximum) =>
      max(minimum, min(maximum, value));

  bool get isTop =>
      (_parentElement == null) ? true : _parentElement.scrollTop == 0;
  int offset = 0;
  int _previousScrollY = 0;

  Element _parentElement;
  final Element host;

  @Input()
  String backgroundColor = 'white';

  @Input()
  int height = 100;

  @Input()
  bool alwaysShow = false;

  @Input()
  bool trackDocument = false;
}

{'fraction_non_alphanumeric': 0.11542890040299367, 'fraction_numerical': 0.007196315486470927, 'mean_word_length': 3.3114143920595533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3419994', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1041, 'n_words': 285}