Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. //Класс для заметок
  2. function Note($link, $scope) {
  3. this.$link = $link;
  4. this.isOpened = false;
  5. this.scrollListener = this.scrollListener.bind(this);
  6. var self = this;
  7. this.$link.on("click", ".cibkpi__title-block", this.clickListener.bind(this));
  8.  
  9. $(document).on("closeAllNotes", function (event, triggeredNote) {
  10. if (triggeredNote !== self && self.isOpened) {
  11. self.changeState();
  12. }
  13. })
  14. }
  15.  
  16. Note.prototype.scrollListener = function () {
  17. if (this.$content[0].scrollHeight - this.$content.height() === this.$content.scrollTop() || this.$content.height() <= 120) {
  18. this.$fader.hide();
  19. } else {
  20. this.$fader.show();
  21. }
  22. }
  23.  
  24. Note.prototype.clickListener = function (evt) {
  25. this.changeState(evt);
  26. $(document).trigger("closeAllNotes", this);
  27. }
  28.  
  29. Note.prototype.changeState = function (event) {
  30. this.$content = this.$link.find(".cibkpi__note-content");
  31. this.$fader = this.$link.find(".cibkpi__fader");
  32.  
  33. this.$content.scrollTop(0);
  34.  
  35. if (event !== undefined) {
  36. event.preventDefault();
  37. event.stopPropagation();
  38. }
  39.  
  40. this.isOpened = !this.isOpened;
  41.  
  42. this.$link.find('.cibkpi__note').toggleClass('cibkpi__note--show');
  43. this.$link.find(".cibkpi__note-btn").toggleClass("cibkpi__note-btn--checked");
  44.  
  45. if (this.isOpened) {
  46. console.log(this.$content.height());
  47. $scope.anyNoteOpened = true;
  48. this.scrollListener();
  49. this.$content.on("scroll", this.scrollListener);
  50. }
  51. else {
  52. this.$content.off("scroll", this.scrollListener);
  53. $scope.anyNoteOpened = false;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement