Files
WebStackPage.github.io/assets/js/min/xenon-notes-min.js
2017-12-20 13:23:22 +08:00

1 line
3.0 KiB
JavaScript

var xenonNotes=xenonNotes||{};!function($,e,n){"use strict";$(e).load(function(){xenonNotes.$container=$(".notes-env"),$.extend(xenonNotes,{isPresent:xenonNotes.$container.length>0,noTitleText:"Untitled",noDescriptionText:"(No content)",$currentNote:$(null),$currentNoteTitle:$(null),$currentNoteDescription:$(null),$currentNoteContent:$(null),addNote:function(){var e=$('<li><a href="#"><strong></strong><span></li></a></li>');e.append('<div class="content"></div>').append('<button class="note-close">&times;</button>'),e.find("strong").html(xenonNotes.noTitleText),e.find("span").html(xenonNotes.noDescriptionText),xenonNotes.$notesList.prepend(e),TweenMax.set(e,{autoAlpha:0});var n=new TimelineMax;n.append(TweenMax.to(e,.1,{css:{autoAlpha:1}})),n.append(TweenMax.to(e,.15,{css:{autoAlpha:.8}})),n.append(TweenMax.to(e,.15,{css:{autoAlpha:1}})),xenonNotes.$notesList.find("li").removeClass("current"),e.addClass("current"),xenonNotes.$writePadTxt.focus(),xenonNotes.checkCurrentNote()},checkCurrentNote:function(){var e=xenonNotes.$notesList.find("li.current").first();if(e.length)xenonNotes.$currentNote=e,xenonNotes.$currentNoteTitle=e.find("strong"),xenonNotes.$currentNoteDescription=e.find("span"),xenonNotes.$currentNoteContent=e.find(".content"),xenonNotes.$writePadTxt.val($.trim(xenonNotes.$currentNoteContent.html())).trigger("autosize.resize");else{var n=xenonNotes.$notesList.find("li:first:not(.no-notes)");n.length?(n.addClass("current"),xenonNotes.checkCurrentNote()):(xenonNotes.$writePadTxt.val(""),xenonNotes.$currentNote=$(null),xenonNotes.$currentNoteTitle=$(null),xenonNotes.$currentNoteDescription=$(null),xenonNotes.$currentNoteContent=$(null))}},updateCurrentNoteText:function(){var e=$.trim(xenonNotes.$writePadTxt.val());if(xenonNotes.$currentNote.length){console.log(xenonNotes.$currentNote[0]);var n="",t="";if(e.length)for(var o=e.split("\n"),s=1,r=0;r<o.length&&(o[r]&&(1==s?n=o[r]:2==s&&(t=o[r]),s++),!(s>2));r++);xenonNotes.$currentNoteTitle.text(n.length?n:xenonNotes.noTitleText),xenonNotes.$currentNoteDescription.text(t.length?t:xenonNotes.noDescriptionText),xenonNotes.$currentNoteContent.text(e)}else e.length&&xenonNotes.addNote()}}),xenonNotes.isPresent&&(xenonNotes.$notesList=xenonNotes.$container.find(".list-of-notes"),xenonNotes.$writePad=xenonNotes.$container.find(".write-pad"),xenonNotes.$writePadTxt=xenonNotes.$writePad.find("textarea"),xenonNotes.$addNote=xenonNotes.$container.find("#add-note"),xenonNotes.$addNote.on("click",function(e){xenonNotes.addNote()}),xenonNotes.$writePadTxt.on("keyup",function(e){xenonNotes.updateCurrentNoteText()}),xenonNotes.checkCurrentNote(),xenonNotes.$notesList.on("click","li a",function(e){e.preventDefault(),xenonNotes.$notesList.find("li").removeClass("current"),$(this).parent().addClass("current"),xenonNotes.checkCurrentNote()}),xenonNotes.$notesList.on("click","li .note-close",function(e){e.preventDefault();var n=$(this).parent(),t=new TimelineMax;t.append(TweenMax.to(n,.15,{css:{autoAlpha:0},onComplete:function(){n.remove(),xenonNotes.checkCurrentNote()}}))}))})}(jQuery,window);