Last active
July 24, 2017 14:10
-
-
Save radiosterne/b82b17beae2fddd35e0ca3cca13d62bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Класс для заметок | |
| function Note($link, $scope) { | |
| this.$link = $link; | |
| this.isOpened = false; | |
| this.scope = $scope; | |
| this.scrollListener = this.scrollListener.bind(this); | |
| var self = this; | |
| this.$link.on("click", ".cibkpi__title-block", this.clickListener.bind(this)); | |
| $(document).on("closeAllNotes", function (event, triggeredNote) { | |
| if (triggeredNote !== self && self.isOpened) { | |
| self.changeState(); | |
| } | |
| }) | |
| } | |
| Note.prototype.scrollListener = function () { | |
| if (this.$content[0].scrollHeight - this.$content.height() === this.$content.scrollTop() || this.$content.height() <= 120) { | |
| this.$fader.hide(); | |
| } else { | |
| this.$fader.show(); | |
| } | |
| } | |
| Note.prototype.clickListener = function (evt) { | |
| this.changeState(evt); | |
| $(document).trigger("closeAllNotes", this); | |
| } | |
| Note.prototype.changeState = function (event) { | |
| this.$content = this.$link.find(".cibkpi__note-content"); | |
| this.$fader = this.$link.find(".cibkpi__fader"); | |
| this.$content.scrollTop(0); | |
| if (event !== undefined) { | |
| event.preventDefault(); | |
| event.stopPropagation(); | |
| } | |
| this.isOpened = !this.isOpened; | |
| //Андрюха хитрый петушок, Андрюха вводит счётчик | |
| //Андрюхе такое позволяет делать то, что JS асинхронный, но однопоточный | |
| if(this.isOpened) | |
| { | |
| this.scope.openedNotesCounter = this.scope.openedNotesCounter + 1; | |
| } else { | |
| this.scope.openedNotesCounter = this.scope.openedNotesCounter - 1; | |
| } | |
| //Таперича можно скрывать ссылки, если this.scope.openedNotesCounter > 0. | |
| this.$link.find('.cibkpi__note').toggleClass('cibkpi__note--show'); | |
| this.$link.find(".cibkpi__note-btn").toggleClass("cibkpi__note-btn--checked"); | |
| if (!this.isOpened) { | |
| this.$content.off("scroll", this.scrollListener); | |
| } | |
| else { | |
| this.scrollListener(); | |
| this.$content.on("scroll", this.scrollListener); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment