-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdailyoje.min.js
37 lines (37 loc) · 19.6 KB
/
dailyoje.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var OJE=new function(){this.Twitter=new function(){this.startAuthenticate=function(){OJE.Authenticate.indicateLoggingIn(!0);$.ajax({url:OJE.rootUrl+"WebRouter.php",data:OJE.Twitter.StartOAuthRequest(),type:"POST",dataType:"json"}).done(function(a){a&&a.data&&a.data.authorizeUrl?window.location.href=a.data.authorizeUrl:OJE.showMessage("Unfortunately an error occurred with Twitter. Please try again.")}).fail(function(){OJE.Authenticate.indicateLoggingIn(!1);OJE.showMessage("Unfortunately an error occurred with Twitter. Please try again.")})};
this.StartOAuthRequest=function(){return{requestType:"Twitter_StartOAuth",currentUrl:document.URL}}};this.Authenticate=new function(){this.toggleLoginDialog=function(a){a?$("#loginDialog").show():$("#loginDialog").hide()};this.validateAndProcessLogin=function(a){a&&a.preventDefault&&a.preventDefault();a=$("#loginEmail").val();var b=$("#loginPassword").val(),c=!1;a?OJE.Authenticate.setInputState("loginEmail",!1):(c=!0,OJE.Authenticate.setInputState("loginEmail",!0));b?OJE.Authenticate.setInputState("loginPassword",
!1):(c=!0,OJE.Authenticate.setInputState("loginPassword",!0));c||(OJE.Authenticate.indicateLoggingIn(!0),$.ajax({url:OJE.rootUrl+"WebRouter.php",data:OJE.Authenticate.loginRequest(a,b),type:"POST",dataType:"json"}).done(function(a){a&&a.data?a.data.validCredentials?(OJE.Authenticate.setLoginError(""),OJE.Authenticate.setInputState("loginEmail",!1),OJE.Authenticate.setInputState("loginPassword",!1),location.reload()):(OJE.Authenticate.indicateLoggingIn(!1),OJE.Authenticate.setLoginError("Invalid Credentials."),
OJE.Authenticate.setInputState("loginEmail",!0),OJE.Authenticate.setInputState("loginPassword",!0)):OJE.Authenticate.setLoginError("Unknown error occured. #340311")}).fail(function(){OJE.Authenticate.indicateLoggingIn(!1);OJE.Authenticate.setLoginError("Unknown Error Occurred. #340312")}))};this.validateAndProcessRegister=function(a){a&&a.preventDefault&&a.preventDefault();a=$("#registerEmail").val();var b=$("#registerPassword").val(),c=!1;a?OJE.Authenticate.setInputState("registerEmail",!1):(c=!0,
OJE.Authenticate.setInputState("registerEmail",!0));b?6>b.length?(c=!0,OJE.Authenticate.setInputState("registerPassword",!0),OJE.Authenticate.setRegisterError("Password must be 6 characters or more.")):OJE.Authenticate.setInputState("registerPassword",!1):(c=!0,OJE.Authenticate.setInputState("registerPassword",!0));c||(OJE.Authenticate.indicateLoggingIn(!0),$.ajax({url:OJE.rootUrl+"WebRouter.php",data:OJE.Authenticate.registerRequest(a,b),type:"POST",dataType:"json"}).done(function(a){a&&a.data?a.data.invalidEmail?
(OJE.Authenticate.indicateLoggingIn(!1),OJE.Authenticate.setRegisterError("Email is not a valid email address."),OJE.Authenticate.setInputState("registerEmail",!0),OJE.Authenticate.setInputState("registerPassword",!1)):a.data.emailExists?(OJE.Authenticate.indicateLoggingIn(!1),OJE.Authenticate.setRegisterError("Email is already registered."),OJE.Authenticate.setInputState("registerEmail",!0),OJE.Authenticate.setInputState("registerPassword",!1)):a.data.passwordTooShort?(OJE.Authenticate.indicateLoggingIn(!1),
OJE.Authenticate.setRegisterError("Email is already registered."),OJE.Authenticate.setInputState("registerEmail",!1),OJE.Authenticate.setInputState("registerPassword",!0)):a.data.success?(OJE.Authenticate.setRegisterError(""),OJE.Authenticate.setInputState("registerEmail",!1),OJE.Authenticate.setInputState("registerPassword",!1),location.reload()):(OJE.Authenticate.indicateLoggingIn(!1),OJE.Authenticate.setRegisterError("Unknown error occured. #340210")):(OJE.Authenticate.indicateLoggingIn(!1),OJE.Authenticate.setRegisterError("Unknown error occured. #340211"))}).fail(function(a,
c,b){OJE.Authenticate.indicateLoggingIn(!1);OJE.Authenticate.setRegisterError("Unknown Error Occurred. #340212")}))};this.setInputState=function(a,b){b?($("#"+a).addClass("input-error"),OJE.Authenticate.shakeElement("elementId")):$("#"+a).removeClass("input-error")};this.toggleRegisterForm=function(a){a?($("#loginFormContainer").hide(),$("#registerFormContainer").show(),$("#registerText").hide(),$("#loginRibbon").text("Register")):($("#loginFormContainer").show(),$("#registerFormContainer").hide(),
$("#registerText").show(),$("#loginRibbon").text("Login"))};this.setRegisterError=function(a){$("#registerError").text(a)};this.setLoginError=function(a){$("#loginError").text(a)};this.shakeElement=function(a){for(var b=10,c=0;6>c;c++)$("#"+a).animate({"margin-left":"+="+(b=-b)+"px"},60)};this.indicateLoggingIn=function(a){a?($("#loginFormLoadingIndicator").show(),$("#loginContent").hide()):($("#loginFormLoadingIndicator").hide(),$("#loginContent").fadeIn())};this.registerRequest=function(a,b){return{requestType:"Authenticate_Register",
email:a,password:b}};this.loginRequest=function(a,b){return{requestType:"Authenticate_Login",email:a,password:b}}};this.rootUrl="";this.elementTitle=this.element=null;this.tagWhiteList=["p","div"];this.placeholderTitle=this.placeholderText="";this.errors=[];this.messages=[];this.menuStuck=this.edit=this.loggedIn=!1;this.Request=new function(){this.AutoSaveRequest=function(){return{requestType:"Note_AutoSave",noteText:OJE.element.html(),noteTitle:OJE.elementTitle.text(),noteId:OJE.Note.noteId}};this.FetchNotesRequest=
function(a,b,c){return{requestType:"Note_FetchNotes",searchKey:c||"",pageNumber:a,resultsPerPage:OJE.Note.notesPerPage,ajaxRequest:b}};this.LoadNoteRequest=function(a){return{requestType:"Note_LoadNote",noteId:a}};this.UpdatePrivacyRequest=function(){return{requestType:"Note_UpdatePrivacy",notePrivacy:$("#privacySettingsSelect").val(),noteId:OJE.Note.noteId}};this.DeleteNoteRequest=function(a){return{requestType:"Note_DeleteNote",noteId:a}}};this.Note=new function(){this.noteId="";this.notesPerPage=
5;this.currentPage=1;this.pagesDrawn=!1;this.currentSearchKey="";this.Save=new function(){this.autoSaveTimeout=null;this.autoSaveInterval=5E3;this.midSave=!1;this.lastSaveTitle=this.lastSaveText="";this.shouldTriggerAutoSave=function(){var a=!1,b=OJE.Note.isDataDirty();OJE.Note.noteId&&b?a=!0:OJE.Note.noteId&&!b?OJE.Note.markAsUnDirty():!OJE.Note.noteId&&(OJE.element.html()!=OJE.placeholderText&&3<OJE.element.text().length)&&(a=!0);return a};this.triggerAutoSave=function(){!OJE.Note.Save.autoSaveTimeout&&
OJE.edit&&(OJE.Note.Save.shouldTriggerAutoSave()?OJE.Note.Save.sendAutoSaveRequest():OJE.Note.Save.autoSaveTimeout=setTimeout(function(){OJE.Note.Save.autoSaveTimeout=null;OJE.Note.Save.triggerAutoSave()},OJE.Note.Save.autoSaveInterval))};this.sendAutoSaveRequest=function(){var a=$.Deferred();if(OJE.Note.Save.midSave)return a.resolve().promise();var b=!1;OJE.elementTitle.text()!=OJE.Note.Save.lastSaveTitle&&(b=!0);OJE.Note.Save.lastSaveText=OJE.element.html();OJE.Note.Save.lastSaveTitle=OJE.elementTitle.text();
OJE.Note.Save.midSave=!0;$.ajax({url:OJE.rootUrl+"WebRouter.php",data:OJE.Request.AutoSaveRequest(),type:"POST",dataType:"json"}).done(function(c){OJE.Note.markAsUnDirty();OJE.Note.toggleShareButton();OJE.validateAjaxError(c)&&(c.data&&c.data.noteId)&&(!OJE.Note.noteId&&c.data&&c.data.noteId?(OJE.Note.noteId=c.data.noteId,OJE.Note.fetchNotes(OJE.Note.currentPage,!0),a.resolve()):OJE.Note.noteId&&OJE.Note.noteId==c.data.noteId?(b&&OJE.Note.fetchNotes(OJE.Note.currentPage,!0),a.resolve()):a.reject(),
$("#deleteLink").show(),$("#exportLink").show())}).fail(function(c,b,e){a.reject();OJE.showMessage("Problem autosaving. Did you lose your connection?")}).always(function(){OJE.Note.Save.midSave=!1;setTimeout(function(){OJE.Note.Save.triggerAutoSave()},OJE.Note.Save.autoSaveInterval)});return a.promise()}};this.toggleDeleteWarning=function(a){a?$("#deleteBox").show():$("#deleteBox").hide()};this.indicateNoteDeleting=function(a){a?(OJE.element.hide(),OJE.elementTitle.hide(),OJE.Note.toggleDeleteWarning(!1),
$("#footer").hide(),$("#loadingNoteIndicator").show()):(OJE.element.show(),OJE.elementTitle.show(),$("#loadingNoteIndicator").hide(),$("#footer").show())};this.deleteCurrentNote=function(){OJE.Note.Save.autoSaveTimeout&&clearTimeout(OJE.Note.Save.autoSaveTimeout);OJE.Note.noteId?(OJE.Note.indicateNoteDeleting(!0),$.ajax({url:OJE.rootUrl+"WebRouter.php",data:OJE.Request.DeleteNoteRequest(OJE.Note.noteId),type:"POST",dataType:"json"}).done(function(a){OJE.validateAjaxError(a)?window.location=OJE.rootUrl+
"?message=Note_DeleteSuccess":OJE.Note.indicateNoteDeleting(!1)}).fail(function(){OJE.Note.indicateNoteDeleting(!1);OJE.showMessage("Problem deleting your note. Did you lose your connection?")})):OJE.showMessage("There was an error deleting your note. Please report Error #DeleteNote_NONID")};this.toggleExport=function(a){a?$("#exportDialog").show():$("#exportDialog").hide()};this.exportHtml=function(){OJE.Note.exportNote("html")};this.exportText=function(){OJE.Note.exportNote("text")};this.exportNote=
function(a){location.href=OJE.rootUrl+"export.php?type="+a+"¬eId="+OJE.Note.noteId};this.showShare=function(){$("#shareUrl").val(OJE.rootUrl+"v/"+OJE.Note.noteId);$("#shareUrl").click(function(){$(this).select()});$("#shareBox").show()};this.hideShare=function(){$("#shareBox").hide()};this.toggleShareButton=function(){OJE.Note.noteId&&"public"==$("#privacySettingsSelect").val()?$("#shareButton").show():$("#shareButton").hide()};this.indicateNoteLoading=function(a){a?(OJE.element.hide(),OJE.elementTitle.hide(),
$("#loadingNoteIndicator").show()):(OJE.element.show(),OJE.elementTitle.show(),$("#loadingNoteIndicator").hide(),OJE.elementTitleBlur(),OJE.element.focus(),OJE.refreshEditState())};this.loadNote=function(a){OJE.Note.indicateNoteLoading(!0);OJE.Note.isDataDirty()&&OJE.Note.noteId?OJE.Note.Save.sendAutoSaveRequest().pipe(function(){return OJE.Note.sendLoadNoteRequest(a)}).always(function(){OJE.Note.indicateNoteLoading(!1)}):OJE.Note.sendLoadNoteRequest(a).always(function(){OJE.Note.indicateNoteLoading(!1)})};
this.sendLoadNoteRequest=function(a){var b=$.Deferred();$.ajax({url:OJE.rootUrl+"WebRouter.php",data:OJE.Request.LoadNoteRequest(a),type:"POST",dataType:"json"}).done(function(a){OJE.validateAjaxError(a)&&a.data&&(OJE.Note.noteId=a.data.noteId,OJE.Note.Save.lastSaveText=a.data.noteText,OJE.Note.Save.lastSaveTitle=a.data.noteTitle,OJE.element.html(a.data.noteText),OJE.elementTitle.text(a.data.noteTitle),$("#privacySettingsSelect").val(a.data.notePrivacy).prop("selected",!0),OJE.Note.updateCounts(),
$("#deleteLink").show(),$("#exportLink").show(),OJE.Note.markAsUnDirty(),OJE.Note.toggleShareButton(),location.hash=OJE.Note.noteId,OJE.Note.Save.triggerAutoSave())}).fail(function(){OJE.showMessage("Problem Loading your note. Did you lose your connection?")}).always(function(){b.resolve()});return b.promise()};this.indicateFetchingNotes=function(a){a?$("#noteFetchLoading").show():$("#noteFetchLoading").hide()};this.fetchNotesPagination=function(a){OJE.Note.fetchNotes(a,OJE.edit,OJE.Note.currentSearchKey)};
this.fetchNotes=function(a,b,c){a=a||1;c=c||"";OJE.Note.indicateFetchingNotes(!0);$.ajax({url:OJE.rootUrl+"WebRouter.php",data:OJE.Request.FetchNotesRequest(a,b,c),type:"POST",dataType:"json"}).done(function(b){OJE.validateAjaxError(b)&&(b.data&&b.data.html)&&(OJE.Note.currentPage=a,$("#noteResults").html(b.data.html),!OJE.Note.pagesDrawn&&b.data.totalResults>OJE.Note.notesPerPage||c)&&(OJE.Note.pagesDrawn=!0,$(function(){$("#notePagination").pagination({items:b.data.totalResults,itemsOnPage:OJE.Note.notesPerPage,
cssStyle:"compact-theme",onPageClick:OJE.Note.fetchNotesPagination,nextText:"",currentPage:a,prevText:"",displayedPages:3,edges:1,hrefTextPrefix:""})}))}).fail(function(){OJE.showMessage("Problem fetching notes. Did you lose your connection?")}).always(function(){OJE.Note.indicateFetchingNotes(!1);setTimeout(function(){OJE.Note.Save.triggerAutoSave()},OJE.Note.Save.autoSaveInterval)})};this.isDataDirty=function(){return OJE.elementTitle.text()!=OJE.Note.Save.lastSaveTitle||OJE.element.html()!=OJE.Note.Save.lastSaveText?
!0:!1};this.markAsUnDirty=function(){$("#saveStatus").html("Saved");$("#saveStatus").removeClass("save-status-unsaved")};this.markAsDirty=function(){$("#saveStatus").html("Unsaved");$("#saveStatus").addClass("save-status-unsaved")};this.updatePrivacy=function(){$("#privacyLoader").show();$("#privacySuccess").hide();OJE.Note.noteId?OJE.Note.sendUpdatePrivacyRequest():OJE.Note.Save.sendAutoSaveRequest().done(function(){OJE.Note.sendUpdatePrivacyRequest()}).fail(function(){$("#privacyLoader").hide()})};
this.sendUpdatePrivacyRequest=function(){$.ajax({url:OJE.rootUrl+"WebRouter.php",data:OJE.Request.UpdatePrivacyRequest(),type:"POST",dataType:"json"}).done(function(a){OJE.Note.toggleShareButton();$("#privacyLoader").hide();OJE.validateAjaxError(a)&&($("#privacySuccess").show(),setTimeout(function(){$("#privacySuccess").hide()},5E3))}).fail(function(){$("#privacyLoader").hide();OJE.showMessage("Problem updating privacy. Did you lose your connection?")})};this.updateCounts=function(){var a=OJE.element.text(),
b=$.trim(a).split(" ");$("#wordCount").html(b.length);$("#characterCount").html($.trim(a).length)};this.cleanTags=function(){OJE.element.find("*").each(function(){$(this).removeAttr("style");var a=$(this).prop("tagName").toLocaleLowerCase();0>OJE.tagWhiteList.indexOf(a)&&$(this).contents().unwrap()})}};this.parseHash=function(){if(location.hash){var a=location.hash.replace("#","");if(3<a.length)return OJE.Note.loadNote(a),!0}return!1};this.showMessage=function(a,b,c){b=b||1E4;var d=c?"messages":"errors",
e=c?this.messages:this.errors,f=(new Date).getTime();e.push(a);$("#"+d).show();$("#"+d).append('<p id="message-'+f+'">'+a+"</p>");setTimeout(function(){e.pop();$("#message-"+f).remove();1>e.length&&$("#"+d).hide()},b)};this.validateAjaxError=function(a){return a&&a.hasError?(this.showMessage(a.errorMessage+" Error Code #"+a.errorCode),!1):!0};this.view=function(a,b,c){this.element=$("#"+a);this.elementTitle=$("#"+b);this.Note.noteId=c;$("#noteSearch").keyup(OJE.noteSearch)};this.initialize=function(a,
b,c,d){this.placeholderText=c;this.placeholderTitle=d;this.element=$("#"+a);this.elementTitle=$("#"+b);this.element.keydown(this.elementKeyDown);this.element.keyup(this.elementKeyUp);this.element.blur(this.elementBlur);this.element.click(this.elementClick);this.elementTitle.keydown(this.elementTitleKeyDown);this.elementTitle.keyup(this.elementTitleKeyUp);this.elementTitle.blur(this.elementTitleBlur);this.elementTitle.click(this.elementTitleClick);this.element.bind("paste",function(a){setTimeout(function(){OJE.Note.markAsDirty();
OJE.Note.cleanTags()},1)});OJE.parseHash()||(this.element.html(this.placeholderText),this.elementTitle.html(this.placeholderTitle),OJE.loggedIn&&this.Note.Save.triggerAutoSave());$(window).bind("beforeunload",function(){var a=a||window.event;if(OJE.loggedIn&&OJE.Note.Save.shouldTriggerAutoSave())return a&&(a.returnValue="You have unsaved changes, if you leave these unsaved changes will be lost."),"You have unsaved changes, if you leave these unsaved changes will be lost."});$("#noteSearch").on("input",
OJE.noteSearch)};this.noteTimeout=null;this.noteSearch=function(){OJE.noteTimeout&&clearTimeout(OJE.noteTimeout);var a=$("#noteSearch").val();2>a.length&&(a="");OJE.noteTimeout=setTimeout(function(){OJE.noteTimeout=null;OJE.Note.currentSearchKey=a;OJE.Note.fetchNotes(1,OJE.edit,a)},400)};this.forceCursorToStart=function(a,b){a.preventDefault();b.focus();if(window.getSelection&&document.createRange){var c=window.getSelection(),d=document.createRange();d.setStart(b,0);d.collapse(!0);c.removeAllRanges();
c.addRange(d)}else document.body.createTextRange&&(c=document.body.createTextRange(),c.moveToElementText(b),c.collapse(!0),c.select())};this.getTitleText=function(){return $.trim(OJE.elementTitle.text())};this.getText=function(){return OJE.element.html()};this.refreshEditState=function(){OJE.getTitleText();var a=0<OJE.elementTitle.find("#placeholderEmptyTitleTextId").length;a&&OJE.elementTitle.is(":focus")?OJE.elementTitle.addClass("editable-title-initial"):a&&OJE.loggedIn?OJE.elementTitle.addClass("editable-title-initial"):
OJE.elementTitle.removeClass("editable-title-initial");OJE.getText();0<OJE.element.find("#placeholderEmptyTextId").length?OJE.element.addClass("editable-initial"):OJE.element.removeClass("editable-initial")};this.elementTitleClick=function(a){0<OJE.element.find("#placeholderEmptyTextId").length&&OJE.forceCursorToStart(a,OJE.elementTitle[0]);OJE.refreshEditState()};this.elementTitleKeyDown=function(a){if(13==a.which)return!1;0<OJE.elementTitle.find("#placeholderEmptyTitleTextId").length&&OJE.elementTitle.html("");
OJE.refreshEditState()};this.elementTitleKeyUp=function(){OJE.getTitleText()||OJE.elementTitle.html(OJE.placeholderTitle);OJE.refreshEditState();OJE.Note.markAsDirty()};this.elementTitleBlur=function(){OJE.getTitleText()||OJE.elementTitle.html(OJE.placeholderTitle);OJE.refreshEditState()};this.elementClick=function(a){0<OJE.element.find("#placeholderEmptyTextId").length&&OJE.forceCursorToStart(a,OJE.element[0]);OJE.refreshEditState()};this.elementBlur=function(){OJE.element.text()||OJE.element.html(OJE.placeholderText);
OJE.refreshEditState()};this.elementKeyUp=function(){OJE.element.text()||OJE.element.html(OJE.placeholderText);OJE.refreshEditState();OJE.Note.updateCounts();OJE.Note.markAsDirty()};this.elementKeyDown=function(){0<OJE.element.find("#placeholderEmptyTextId").length&&OJE.element.html("");OJE.refreshEditState()};this.refreshSettings=function(){var a=$("#fontSize").val();OJE.element.css("font-size",a)};this.toggleMenu=function(a){a?($("#menuContent").show(),$("#menuNavigation").show(),$("#menu").addClass("menu-visible"),
200>$("#wrapper").offset().left&&$("#wrapper").css("margin-left","210px")):($("#menuContent").hide(),$("#menuNavigation").hide(),$("#menu").removeClass("menu-visible"),$("#wrapper").css("margin-left","auto"))};this.setupMenu=function(){var a=$("#menu"),b=$("#menuContent"),c=$("#wrapper").offset().left,c=c+40>a.width()?a.width():c+40,d=$('<div class="menu-hover" id="menuHover"> </div>');d.css({width:c});$("body").append(d);$("#menuIcon").click(function(){OJE.menuStuck?(OJE.toggleMenu(!1),OJE.menuStuck=
!1):(OJE.toggleMenu(!0),OJE.menuStuck=!0)});a.mouseleave(function(){OJE.menuStuck||OJE.toggleMenu(!1)});$("body").mousemove(function(a){OJE.menuStuck||(a=a.pageX,d.width()>a&&!b.is(":visible")&&OJE.toggleMenu(!0))})};this.changeUrl=function(a){window.location=a};this.checkForMobile=function(){/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)&&OJE.showMessage("Hello Mobile User! We are still in beta and mobile support is limited.",45E3,!0)};this.attachListeners=function(){$("#loginForm").submit(OJE.Authenticate.validateAndProcessLogin);
$("#registerForm").submit(OJE.Authenticate.validateAndProcessRegister)}};