//Creado con Ardora - www.webardora.net
//bajo licencia Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)
//para otros usos contacte con el autor
var isFull=false;var isLog=false;
function createBar(){var element = document.createElement("div");element.setAttribute("id", "ardNavBar");$(element).css("position","fixed");$(element).css("z-index", 998);
$(element).css("right",0);$(element).css("bottom",0);
document.getElementById("ardoraMain").appendChild(element);
$(element).html('<p id="startBut" title="Start" class="butfont butLe">i</p>');
$("#startBut").on("touchstart click",function(e){   var canSave=true;if (isLog) {$.ajax({data: {"action": "canSave","type": "0"},type: "POST",dataType: "json",url: "php/ardoraXML.php",success: function(data, textStatus, jqXHR) {if (data["status"]!="Ok"){$("#editBut").remove();}}});}
if ($("#ardNB").length>0){$("#ardNB").animate({height:"0px"},100);$("#ardNB").promise().done(function(){$("#ardNB").remove();});$("#startBut").text("i");}else{
$("#startBut").text("E");var NB = document.createElement("div");NB.setAttribute("id", "ardNB");$(NB).css("position","fixed");$(NB).css("z-index", 998);
$(NB).css("right",0);$(NB).css("bottom","40px");$(NB).css("width",35);$(NB).css("height",0);
var codeAud =""
if (!isLog){codeAud='<p id="loginBut" title="User" class="butfont butLe">U</p>';
codeAud = codeAud + '<p id="refreshBut" title="Refresh" class="butfont butLe">Z</p>';
codeAud = codeAud + '<p id="fullBut" title="Full screen" class="butfont butLe">H</p>';
$(NB).html(codeAud);document.getElementById("ardoraMain").appendChild(NB);
}
if (isLog){codeAud=codeAud+'<p id="pusN"><span id="usN" title="">'+userN+'</span></p>';
codeAud=codeAud+'<p id="editBut" title="Add" class="butfont butLe">P</p>';
codeAud=codeAud+'<p id="refreshBut" title="Refresh" class="butfont butLe">Z</p>';
codeAud=codeAud+'<p id="fullBut" title="Full screen" class="butfont butLe">H</p>';
codeAud = codeAud + '<p id="closeS" title="Close" class="butfont butLe">z</p>';
$(NB).html(codeAud);document.getElementById("ardoraMain").appendChild(NB);}
if (isLog){
var nWidth=($("#pusN").width()+160+40)+"px";
$(NB).animate({height: nWidth}, 500);
}else{$(NB).animate({height: "160px"}, 500);}
$("#fullBut").on("touchstart click",function(v){if (!isFull){var e = document.body;if (e.requestFullscreen) {e.requestFullscreen();} else if (e.mozRequestFullScreen) {e.mozRequestFullScreen();} else if (e.webkitRequestFullScreen) {e.webkitRequestFullScreen();}
document.addEventListener("fullscreenchange", function() {if (!document.fullscreen) {$("#imaFull").remove();}}, false);document.addEventListener("mozfullscreenchange", function() {if (!document.mozFullScreen) {$("#imaFull").remove();}}, false);
document.addEventListener("webkitfullscreenchange", function() {if (!document.webkitIsFullScreen) {$("#imafull").remove();;}}, false);isFull=true;}
else{var docElement, request;docElement = document;request = docElement.cancelFullScreen || docElement.webkitCancelFullScreen || docElement.mozCancelFullScreen || docElement.msCancelFullScreen || docElement.exitFullscreen; if (typeof request != "undefined" && request) {request.call(docElement);} isFull=false;}
});
$("#loginBut").on("touchstart click", function(e) {$("#modal-content").empty();$("#modal-content").css("height", "auto");$("#modal-content").addClass("widthAuto");
var newHtml = '<div id="divLogin"><div id="modalTit">Username</div>';newHtml = newHtml + '<iframe id="if_login" src="php/ardoraLogin.php" width="640" height="400"></iframe>';newHtml = newHtml + "</div>";
$("#modal-content").append(newHtml);$("#modal-content,#modal-background").toggleClass("active");$("#modal-background, #modal-close, #cancelBut").click(function() {$("#modal-content,#modal-background").toggleClass("active");});
$("#ardNB").animate({height: "0px"}, 100);$("#ardNB").promise().done(function() {$("#ardNB").remove();});$("#startBut").text("i");$("#modal-content").draggable();$("#modal-content").css("left",($("#ardoraMain").width()- $("#modal-content").width()) / 2).toString()+"px";$("#modal-content").css("top","50px");});
$("#editBut").on("touchstart click", function(e) {$("#modal-content").empty();$("#modal-content").css("height","auto");$("#modal-content").css("width", "800px");
var newHtml='<div id="modalTit">Add</div>';
newHtml =newHtml+'<div id="area_form" ><form id="entraDatos" class="formLogin" name="entraDatos" method="post" action="" enctype="multipart/form-data">';
newHtml =newHtml+'<div id="traballos"><p>Insert the data</p></div>';
newHtml = newHtml + '<div id="datos_form"><label for="titulo">Title  </label><input type="text" name="titulo" id="titulo" placeholder="" required value="" maxlength="30"/>';
newHtml = newHtml + '<div id="clear"></div>';
newHtml = newHtml + '<label for="descri">Author  </label><input type="text" name="descricion" id="descricion" placeholder="" required value=""/>';
newHtml = newHtml + '<div id="clear"></div>';
newHtml = newHtml + '<label for="fileinput">File</label><input type="file" id="fileinput" name="fileinput" accept="image/*" />';
newHtml = newHtml + '<br><div id="clear"></div>';
newHtml = newHtml + '<textarea class="ckeditor" name="editor1" id="editor1" rows="100" cols="80">';
newHtml = newHtml + '<div id="clear"></div>';
newHtml = newHtml + '</div></form></div>';
$("#modal-content").append(newHtml);
//a configuracion de cor vai no config.js do ckeditor.
CKEDITOR.replace( "editor1", {customConfig: "ardora/ckeditor_config.js",
toolbar:[{ name:"clipboard",items:["Cut","Copy","Paste","PasteText","-","Undo","Redo"]},{ name:"editing",items:["Find"]},{ name:"insert",items:["Table","HorizontalRule","Smiley","SpecialChar"]},{ name:"basicstyles",items:["Bold","Italic","Underline","Strike","Subsrcipt","Superscript"]},{ name:"paragraph",items:["NumberedList","-","Blockquote","-","JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"]},{ name:"styles",items:["Font","FontSize"]},{ name:"colors",items:["TextColor","BGColor"]},{ name:"links",items:["Link","Unlink"]},],toolbarGroups:[{ name: "clipboard"},{ name: "editing"},{ name: "insert"},{ name: "basicstyles"},{ name: "paragraph"},{ name: "styles"},{ name: "colors"},{ name: "links"},]});CKEDITOR.config.height=100;
newHtml = '<div id="clear"></div>';
newHtml = newHtml + '<div id="clear"></div>';
newHtml = newHtml + '<div id="modalBar"><p id="cancelBut" class="butfont butLe red" title="">E</p><p id="oKBut" class="butfont butRi green" title="">g</p></div></div>';
$("#modal-content").append(newHtml);
$("#modal-content").css("left",($("#ardoraMain").width()- $("#modal-content").width()) / 2).toString()+"px";
$("#modal-content").css("top","50px");
$("#modal-content,#modal-background").toggleClass("active");
$("#modal-background, #modal-close, #cancelBut").click(function() {$("#modal-content,#modal-background").toggleClass("active");});
$("#modal-content").draggable();
$("#titulo").on("touchstart click", function(e) {$("#titulo").select();});
$("#descricion").on("touchstart click", function(e) {$("#descricion").select();});
$("#fileinput").on("touchstart click", function(e) {$("#fileinput").select();});
$("#oKBut").on("touchstart click", function(e) {$("#alertDiv").remove();var input_Tit= $("#titulo").val();var input_Des= $("#descricion").val();var input_Fil = $("#fileinput").val();
if (input_Tit.length > 0) {if (input_Fil.length > 0) {input = document.getElementById("fileinput");
//vamos a comprobar tamaño
file = input.files[0];
//comprobamos que é unha imaxe
if(file.type.match(/image.*/)) {var scaleWidth=300;var scaleHeight=0;Lector = new FileReader();
Lector.onloadend = function(e){var origen;origen = e.target;var img = document.createElement("img");img.setAttribute("id", "IMAXEPARASUBIR");img.src=origen.result;
img.onload=function(){var canvas=document.getElementById("myCanvas");var ctx = canvas.getContext("2d");
if (img.width>scaleWidth){scaleHeight=scaleWidth*img.height/img.width;} else {scaleWidth=img.width;scaleHeight=img.height;}
canvas.width=scaleWidth;canvas.height=scaleHeight;$("#myCanvas").css("top",((-1)*scaleHeight-20));ctx.drawImage(img,0,0,img.width,img.height,0,0,scaleWidth,scaleHeight);var input_Ima=canvas.toDataURL();input_Htm=CKEDITOR.instances.editor1.getData();
$.ajax({data: {"action": "new","tit": input_Tit,"des": input_Des,"ima": input_Ima,"htm": input_Htm,"type": "0","nameUser":""},type: "POST",dataType: "json",async: false,url: "php/ardoraXML.php",
success: function(data, textStatus, jqXHR) {
if (data["status"]=="Ok"){$("#modal-content,#modal-background").toggleClass("active");getJob();}
if (data["status"]=="UpMaxUpload"){$("#modal-content,#modal-background").toggleClass("active");alert("Límite de usuario excedido");}
if (data["status"]=="ItemMaxUpload"){$("#modal-content,#modal-background").toggleClass("active");alert("Alcanzouse o máximo de rexistros");}
}});}};
Lector.readAsDataURL(input.files[0]);$("#oKBut").hide();}
else{$("#datos_form").append("<div id='alertDiv'><p id=alertIco>a</p><p id='errorMen'>Wrong type of file</p></div>");$("#fileinput").focus();}}
else{$("#datos_form").append("<div id='alertDiv'><p id=alertIco>a</p><p id='errorMen'>You must choose an image</p></div>");$("#fileinput").focus();}
} else {$("#datos_form").append("<div id='alertDiv'><p id=alertIco>a</p><p id='errorMen'>You must insert a text or a sentence</p></div>");$("#titulo").focus();}
});
$("#startBut").click();
});
$("#refreshBut").on("touchstart click", function(e) {getJob();});
$("#closeS").on("touchstart click", function(e) {$.ajax({data: {"action": "logout"},type: "POST",dataType: "json",url: "php/ardoraXML.php",success: function(data, textStatus, jqXHR) {if (data["status"]=="logout"){isLog=false;$("#startBut").click();getJob();};}});});
}});}
