nextcloud/apps/atnotes/js/atnotes.min.js

22 lines
7.3 KiB
JavaScript

/**
* ownCloud - ATNotes plugin
*
* @author Xavier Beurois
* @copyright 2012 Xavier Beurois www.djazz-lab.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
function atnotes(){if(typeof atnotes.initialized=="undefined"){atnotes.prototype.A=function(c,g){if(c.val().length!=0){if(c.attr("rel")==0){if($("ul.atnotes-noteslist li.atnotes-elt.active").length!=0){$("ul.atnotes-noteslist li.atnotes-elt.active div.atnotes-elt-title").html(c.val());$("ul.atnotes-noteslist li.atnotes-elt.active div.atnotes-elt-prerender").html(g.html())}else{this.N(1)}}else{$("ul.atnotes-noteslist li.atnotes-elt.active div.atnotes-elt-title").html(c.val());$("ul.atnotes-noteslist li.atnotes-elt.active div.atnotes-elt-state").html("Unsaved");$("ul.atnotes-noteslist li.atnotes-elt.active div.atnotes-elt-date").html(this.B());$("ul.atnotes-noteslist li.atnotes-elt.active div.atnotes-elt-prerender").html(g.html())}$(window).bind("beforeunload",function(){return false})}};atnotes.prototype.B=function(){var j=new Date(),k,b,c;k=j.getDate();if(k<10){k="0"+k}b=parseInt(j.getMonth()+1);if(b<10){b="0"+b}c=j.getFullYear();j=b+"/"+k+"/"+c;return j};atnotes.prototype.C=function(g,e){if(e.val().length==0){e.val("Untitled note")}this.A(e,g)};atnotes.prototype.D=function(){d=$(".atnotes-elt.active");a=this;if(parseInt(d.attr("rel"))>0){$.ajax({type:"POST",dataType:"json",url:OC.linkTo("atnotes","ajax/delete.php"),data:{i:parseInt(d.attr("rel"))},async:false,success:function(c){if(c.e==0){a.E(d,1)}}})}else{a.E(d,1)}};atnotes.prototype.E=function(g,e){if(e==1){g.remove()}$("#note_title").val("");$("#note_title").attr("rel","0");$("#note_path").val("");$(".jqte_Content").html("");$("#note_title").focus()};atnotes.prototype.F=function(c,g){if(c.val().length==0){c.val("Untitled note");this.A($("#note_title"),g)}$.ajax({type:"POST",dataType:"json",url:OC.linkTo("atnotes","ajax/save.php"),data:{i:c.attr("rel"),t:c.val(),c:g.html()},async:false,error:function(b){alert(b.responseText)},success:function(b){if(!b.e){$("ul.atnotes-noteslist li.atnotes-elt.active div.atnotes-elt-state").empty();$("ul.atnotes-noteslist li.atnotes-elt.active").attr("rel",b.i);$("ul.atnotes-noteslist li.atnotes-elt.active").removeClass("unsaved");c.attr("rel",b.i);$(".atnotes-saved").empty().fadeIn(400);$(".atnotes-saved").css("color","#009700");$(".atnotes-saved").html("Saved !").delay(1000).fadeOut(400);if($("ul.atnotes-noteslist li.atnotes-elt.unsaved").length==0){$(window).unbind("beforeunload")}}}})};atnotes.prototype.G=function(i,c,h){if(h.html().length==0){$(".atnotes-saved").empty().fadeIn(400);$(".atnotes-saved").css("color","#990000");$(".atnotes-saved").html("File not exported: empty content ...").delay(1000).fadeOut(400)}else{$.ajax({type:"POST",dataType:"json",url:OC.linkTo("atnotes","ajax/check.php"),data:{p:i.val(),t:c.val()},async:false,success:function(b){f=true;if(b.e){if(!confirm("The file already exists. Are you sure to override it ?")){f=false}}if(f){$.ajax({type:"POST",dataType:"json",url:OC.linkTo("atnotes","ajax/export.php"),data:{p:b.p,t:c.val(),c:h.html()},async:false,success:function(e){$("#save_dialog").dialog("close")}})}}})}};atnotes.prototype.H=function(c,b){c.css("height",$("#content").height()-b+"px")};atnotes.prototype.I=function(e,g){if(typeof g=="undefined"){g="/"}a=this;e=e.find("div.atnotes-explorer table");$.ajax({type:"POST",dataType:"json",url:OC.linkTo("atnotes","ajax/browse.php"),data:{p:g},async:false,success:function(b){e.empty();$.each(b,function(c,i){e.append(i)});t=e.find("td.filename");t.click(function(c){var i=this;setTimeout(function(){var h=parseInt($(this).data("double"),10);if(h>0){$(this).data("double",h-1)}else{$("#note_path").val($(this).attr("data-rel"))}},300)}).dblclick(function(c){$(this).data("double",2);$("#note_path").val($(this).attr("data-rel"));a.I($("#save_dialog"),$(this).attr("data-rel"))})}})};atnotes.prototype.J=function(c){if(c.val().length==0){c.val("Untitled note")}$("#save_dialog").dialog("open")};atnotes.prototype.K=function(i,c,h){c.val(i.find("div.atnotes-elt-title").text());c.attr("rel",i.attr("rel"));h.html(i.find("div.atnotes-elt-prerender").html())};atnotes.prototype.N=function(c){$(".active").removeClass("active");if(c==1){$("ul.atnotes-noteslist").prepend('<li class="atnotes-elt active unsaved" rel="0"><div class="atnotes-elt-title">'+$("#note_title").val()+'</div><div class="atnotes-elt-state">Unsaved</div><div class="atnotes-elt-date">'+this.B()+'</div><div class="atnotes-elt-prerender">'+$(".jqte_Content").html()+"</div></li>")}else{$("ul.atnotes-noteslist").prepend('<li class="atnotes-elt active unsaved" rel="0"><div class="atnotes-elt-title">New note</div><div class="atnotes-elt-state">Unsaved</div><div class="atnotes-elt-date">'+this.B()+'</div><div class="atnotes-elt-prerender"></div></li>');this.E(0,0)}$("ul.atnotes-noteslist li.atnotes-elt.active").bind("click",function(){$(".active").removeClass("active");$(this).addClass("active");A.K($(this),$("#note_title"),$(".jqte_Content"))});$(window).bind("beforeunload",function(){return false})};atnotes.prototype.W=function(c,b){c.css("width",$("#content").width()-$(".atnotes-noteslist").width()-b+"px")}}}$(document).ready(function(){A=new atnotes();$(".atnotes-editor").jqte();$(window).resize(function(){A.H($(".atnotes-noteslist"),36);A.W($(".atnotes-notesedit"),0);A.H($(".jqte"),75);A.W($(".jqte"),0);A.H($(".jqte_Content"),122);A.W($(".jqte_Content"),0);$("#note_title").css("width",$(".anotes-notesedit-title").width()-70+"px")});$(window).trigger("resize");$("#save_dialog").dialog({autoOpen:false,height:300,width:550,modal:true,resizable:false,buttons:{Cancel:function(){$("#save_dialog").dialog("close")},Ok:function(){if($("#note_path").val().length==0){$("#note_path").val("/")}A.G($("#note_path"),$("#note_title"),$(".jqte_Content"))}},open:function(g,e){A.I($(this))}});$("#note_title").change(function(){A.A($(this),$(".jqte_Content"))});$("#note_title").keyup(function(){$(this).change()});$(".jqte_Content").keyup(function(){A.C($(this),$("#note_title"))});$(".atnotes-actions-btns img.atnotes-save").bind("click",function(){A.F($("#note_title"),$(".jqte_Content"))});$(".atnotes-elt").bind("click",function(){$(".active").removeClass("active");$(this).addClass("active");A.K($(this),$("#note_title"),$(".jqte_Content"))});$(".atnotes-actions-list").qtip({prerender:true,overwrite:false,content:{text:$(".atnotes-actions-ddmenu").html()},position:{my:"top right",at:"bottom right"},events:{show:function(g,e){$(".atnotes-delete").bind("click",function(){A.D()});$(".atnotes-new").bind("click",function(){A.N(0)})},hide:function(g,e){$(".atnotes-delete").unbind("click");$(".atnotes-new").unbind("click")}},hide:{delay:100,event:"unfocus mouseleave",fixed:true},style:{classes:"ui-tooltip-shadow ui-tooltip-rounded ui-tooltip-youtube",tip:false,width:150}});$("#note_title").focus()});