nextcloud-notes/js/public/app.min.js

3 lines
7.0 KiB
JavaScript

!function(e,n,o,i,r){"use strict";var u=e.module("Notes",["restangular","ngRoute"]).config(["$provide","$routeProvider","RestangularProvider","$httpProvider","$windowProvider",function(e,t,n,i,r){i.defaults.headers.common.requesttoken=o,e.value("Constants",{saveInterval:5e3}),t.when("/notes/:noteId",{templateUrl:"note.html",controller:"NoteController",resolve:{note:["$route","$q","is","Restangular",function(e,t,n,o){var i=t.defer(),r=e.current.params.noteId;return n.loading=!0,o.one("notes",r).get().then(function(e){n.loading=!1,i.resolve(e)},function(){n.loading=!1,i.reject()}),i.promise}]}}).otherwise({redirectTo:"/"});var u=OC.generateUrl("/apps/notes");n.setBaseUrl(u)}]).run(["$rootScope","$location","NotesModel",function(e,t,o){n('link[rel="shortcut icon"]').attr("href",OC.filePath("notes","img","favicon.png")),e.$on("$routeChangeError",function(){var e=o.getAll();if(e.length>0){var n=e.sort(function(e,t){return e.modified>t.modified?1:e.modified<t.modified?-1:0}),i=e[n.length-1];t.path("/notes/"+i.id)}else t.path("/")})}]);u.controller("AppController",["$scope","$location","is",function(e,t,n){e.is=n,e.init=function(e,n){0!==e&&t.path("/notes/"+e),0!==n&&OC.Notification.showTemporary(n)},e.search=""}]),u.controller("NoteController",["$routeParams","$scope","NotesModel","SaveQueue","note","debounce","$document",function(e,n,o,i,r,u,s){o.updateIfExists(r),n.note=o.get(e.noteId),n.isSaving=function(){return i.isSaving()},n.isManualSaving=function(){return i.isManualSaving()},n.updateTitle=function(){n.note.title=n.note.content.split("\n")[0]||t("notes","New note")},n.onEdit=function(){var e=n.note;e.unsaved=!0,n.autoSave(e)},n.autoSave=u(function(e){i.add(e)},1e3),n.manualSave=function(){var e=n.note;e.error=!1,i.addManual(e)},s.unbind("keypress.notes.save"),s.bind("keypress.notes.save",function(e){if(e.ctrlKey||e.metaKey)switch(String.fromCharCode(e.which).toLowerCase()){case"s":e.preventDefault(),n.manualSave()}}),n.toggleDistractionFree=function(){function e(e){e.requestFullscreen?e.requestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen()}function t(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()}document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement?t():e(document.getElementById("app-content"))}}]),u.controller("NotesController",["$routeParams","$scope","$location","Restangular","NotesModel","$window",function(e,n,o,i,r,u){n.route=e,n.notes=r.getAll();var s=i.all("notes");s.getList().then(function(e){r.addAll(e)}),n.create=function(){s.post().then(function(e){r.add(e),o.path("/notes/"+e.id)})},n["delete"]=function(e){var t=r.get(e);t.remove().then(function(){r.remove(e),n.$emit("$routeChangeError")})},n.toggleFavorite=function(e){var t=r.get(e);t.customPUT({favorite:!t.favorite},"favorite",{},{}).then(function(e){t.favorite=!!e})},u.onbeforeunload=function(){for(var e=r.getAll(),n=0;n<e.length;n++)if(e[n].unsaved)return t("notes","There are unsaved notes. Leaving the page will discard all changes!");return null}}]),u.controller("NotesSettingsController",["$scope","Restangular","$document",function(n,o,i){n.extensions=[".txt",".md"],o.one("settings").get().then(function(t){e.isObject(t)?n.settings=t:n.settings=o.one("settings")}),i.on("change","#notesPath",function(){var e=t("notes","Please wait while new settings are applied ...");OC.Notification.showTemporary(e),n.settings.put().then(function(){window.location.reload(!0)})}),i.on("change","#fileSuffix",function(){n.settings.put()})}]),u.directive("notesAutofocus",function(){return{restrict:"A",link:function(e,t){t.focus()}}}),u.directive("editor",["$timeout","urlFinder",function(t,o){return{restrict:"A",link:function(r,u){var s=new i({element:u[0],spellChecker:!1,autoDownloadFontAwesome:!1,toolbar:!1,status:!1,forceSync:!0}),l=n(s.codemirror.getWrapperElement());s.value(r.note.content),s.codemirror.on("change",function(){t(function(){r.$apply(function(){r.note.content=s.value(),r.onEdit(),r.updateTitle()})})}),l.on("click",".cm-link, .cm-url",function(t){if(t.ctrlKey){var n=o(this);e.isDefined(n)&&window.open(n,"_blank")}})}}}]),u.directive("notesTooltip",function(){return{restrict:"A",link:function(e,t){t.tooltip({container:"body"}),t.on("$destroy",function(){t.tooltip("hide")})}}}),u.filter("and",["$filter",function(e){return function(t,n){var o=n.split(" "),i=t;for(var r in o)i=e("filter")(i,o[r]);return i}}]),u.filter("noteTitle",function(){return function(e){return e=e.split("\n")[0]||"newNote",e.trim().replace(/^#+/g,"")}}),u.filter("wordCount",function(){return function(e){if(e&&"string"==typeof e){var t=e.split(/\s+/).filter(function(e){return e.search(/[A-Za-z0-9]/)!==-1}).length;return window.n("notes","%n word","%n words",t)}return 0}}),u.factory("debounce",["$timeout",function(e){return function(t,n){var o;return function(){var i=this,r=arguments;o&&e.cancel(o),o=e(function(){t.apply(i,r)},n)}}}]),u.factory("is",function(){return{loading:!1}}),u.factory("NotesModel",function(){var n=function(){this.notes=[],this.notesIds={}};return n.prototype={addAll:function(e){for(var t=0;t<e.length;t+=1)this.add(e[t])},add:function(e){this.updateIfExists(e)},getAll:function(){return this.notes},get:function(e){return this.notesIds[e].error?(OC.dialogs.alert(this.notesIds[e].errorMessage,t("notes","An error occurred!")),!1):this.notesIds[e]},updateIfExists:function(t){var n=this.notesIds[t.id];e.isDefined(n)?(n.title=t.title,n.modified=t.modified,n.content=t.content,n.favorite=t.favorite):(this.notes.push(t),this.notesIds[t.id]=t)},remove:function(e){for(var t=0;t<this.notes.length;t+=1){var n=this.notes[t];if(n.id===e){this.notes.splice(t,1),delete this.notesIds[e];break}}}},new n}),u.factory("SaveQueue",["$q",function(e){var t=function(){this._queue={},this._flushLock=!1,this._manualSaveActive=!1};return t.prototype={add:function(e){this._queue[e.id]=e,this._flush()},addManual:function(e){this._manualSaveActive=!0,this.add(e)},_flush:function(){var t=Object.keys(this._queue);if(0!==t.length&&!this._flushLock){this._flushLock=!0;for(var n=this,o=[],i=0;i<t.length;i+=1){var r=this._queue[t[i]];o.push(r.put().then(this._noteUpdateRequest.bind(null,r))["catch"](this._saveFailed.bind(null,r)))}this._queue={},e.all(o).then(function(){n._flushLock=!1,n._flush(),n._manualSaveActive=!1})}},_noteUpdateRequest:function(e,t){e.error=!1,e.title=t.title,e.modified=t.modified,t.content===e.content&&(e.unsaved=!1)},_saveFailed:function(e){e.error=!0},isSaving:function(){return this._flushLock},isManualSaving:function(){return this._manualSaveActive}},new t}]),u.factory("urlFinder",[function(){return function(e){for(e=n(e),e.is(".cm-url.cm-formatting")&&0!==e.prev().length&&(e=e.prev());e.is(".cm-link");)e=e.next();for(;e.is(".cm-url.cm-formatting");)e=e.next();return e.is(".cm-url:not(.cm-formatting)")?e.text():r}}])}(angular,jQuery,oc_requesttoken,SimpleMDE);
//# sourceMappingURL=app.min.js.map