Skip to content

Commit

Permalink
Merge pull request #53 from hahow/feature/addSameTimeNote-BlurEvent
Browse files Browse the repository at this point in the history
feat(lectureNote): edit lecture note when same time, onBlur save lect…
  • Loading branch information
raccoon-lee authored Aug 22, 2018
2 parents 25d17f2 + 7409b46 commit 59df560
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/js/plugins/lectureNote.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,17 @@ export default class LectureNote {

addLectureNote () {
const time = Math.round(this.player.currentTime);
if (this.hasSameTimeLectureNote(time)) {
const note = this.getSameTimeLectureNote(time);
if (note) {

const lectureNoteContainer = getElement.call(this.player, '.lecture-note[data-id="' + note._id + '"]');
if (lectureNoteContainer) {
const contentContianer = lectureNoteContainer.querySelector('lecture-note__content-container ');
if (contentContianer) {
const clickEvent = new Event('click');
contentContianer.dispatchEvent(clickEvent)
}
}

} else {
this.disableLectureNote();
Expand Down Expand Up @@ -147,6 +157,15 @@ export default class LectureNote {
return false;
}

getSameTimeLectureNote (time) {
for (let i = 0; i < this.lectureNoteList.length; i += 1) {
if (this.lectureNoteList[i].time === time) {
return this.lectureNoteList[i];
}
}
return null;
}

/**
* @private
* @return {null|*}
Expand Down Expand Up @@ -304,6 +323,21 @@ export default class LectureNote {
}
});

contentTextarea.addEventListener('blur', (e) => {
lectureNote.note = contentTextarea.value;
contentShowText.innerHTML = lectureNote.note;
toggleClass(contentContainer, 'lecture-note__content-container--edit', false);
lectureNote.showStatus = LectureNoteModel.ShowStatus.Hide;
toggleClass(lectureNoteContainer, 'hover', true);
cancelTimeout = setTimeout(() => {
toggleClass(lectureNoteContainer, 'hover', false);
}, 1000);
triggerEvent.call(this.player, this.player.media, 'lecturenoteupdate', true, {
lectureNote: lectureNote,
});
e.preventDefault();
});

mark.addEventListener('mouseenter', (e) => {
if (cancelTimeout) {
clearTimeout(cancelTimeout);
Expand Down

0 comments on commit 59df560

Please sign in to comment.