File: /home/artinside/sites.artinside.com.br/mainpro/source/App/Admin/themes/admin/assets/js/scripts.js
// JQUERY INIT
$(function () {
var ajaxResponseBaseTime = 3;
var ajaxResponseRequestError = "<div class='message error icon-warning'>Desculpe mas não foi possível processar sua requisição...</div>";
// MOBILE MENU
$(".mobile_menu").click(function (e) {
e.preventDefault();
var menu = $(".dash_sidebar");
menu.animate({right: 0}, 200, function (e) {
$("body").css("overflow", "hidden");
});
menu.one("mouseleave", function () {
$(this).animate({right: '-260'}, 200, function (e) {
$("body").css("overflow", "auto");
});
});
});
//NOTIFICATION CENTER
function notificationsCount() {
var center = $(".notification_center_open");
$.post(center.data("count"), function (response) {
if (response.count) {
center.html(response.count);
} else {
center.html("0");
}
}, "json");
}
function notificationHtml(link, image, notify, date) {
return '<div data-notificationlink="' + link + '" class="notification_center_item radius transition">\n' +
' <div class="image">\n' +
' <img class="rounded" src="' + image + '"/>\n' +
' </div>\n' +
' <div class="info">\n' +
' <p class="title">' + notify + '</p>\n' +
' <p class="time icon-clock-o">' + date + '</p>\n' +
' </div>\n' +
'</div>';
}
notificationsCount();
setInterval(function () {
notificationsCount();
}, 1000 * 50);
$(".notification_center_open").click(function (e) {
e.preventDefault();
var notify = $(this).data("notify");
var center = $(".notification_center");
$.post(notify, function (response) {
if (response.message) {
ajaxMessage(response.message, ajaxResponseBaseTime);
}
var centerHtml = "";
if (response.notifications) {
$.each(response.notifications, function (e, notify) {
centerHtml += notificationHtml(notify.link, notify.image, notify.title, notify.created_at);
});
center.html(centerHtml);
center.css("display", "block").animate({right: 0}, 200, function (e) {
$("body").css("overflow", "hidden");
});
}
}, "json");
center.one("mouseleave", function () {
$(this).animate({right: '-320'}, 200, function (e) {
$("body").css("overflow", "auto");
$(this).css("display", "none");
});
});
notificationsCount();
});
$(".notification_center").on("click", "[data-notificationlink]", function () {
window.location.href = $(this).data("notificationlink");
});
//DATA SET
$("[data-post]").click(function (e) {
e.preventDefault();
var clicked = $(this);
var data = clicked.data();
var load = $(".ajax_load");
if (data.confirm) {
var deleteConfirm = confirm(data.confirm);
if (!deleteConfirm) {
return;
}
}
$.ajax({
url: data.post,
type: "POST",
data: data,
dataType: "json",
beforeSend: function () {
load.fadeIn(200).css("display", "flex");
},
success: function (response) {
//redirect
if (response.redirect) {
window.location.href = response.redirect;
} else {
load.fadeOut(200);
}
//reload
if (response.reload) {
window.location.reload();
} else {
load.fadeOut(200);
}
//message
if (response.message) {
ajaxMessage(response.message, ajaxResponseBaseTime);
}
},
error: function () {
ajaxMessage(ajaxResponseRequestError, 5);
load.fadeOut();
}
});
});
//VERIFICAÇÃO DE IMAGENS
$("#j_img_preview").change(function () {
var file = this.files[0], img;
var oldFile = $("#old-file").attr("src");
if (Math.round(file.size / (1024 * 1024)) > 5) { // make it in MB so divide by 1024*1024
ajaxMessage("<div class='message warning icon-warning'>Tamanho máximo permitido de imagens 5MB. Favor escolher uma imagem menor!</div>", 8);
$("#j_img_preview").val(null);
$("#image-preview").attr("src", oldFile);
return false;
}
});
$('#gallery-upload').change(function () {
var fp = $("#gallery-upload");
var lg = fp[0].files.length; // get length
var items = fp[0].files;
var fileSize = 0;
if (lg > 0) {
for (var i = 0; i < lg; i++) {
fileSize = fileSize + items[i].size; // get file size
}
if (Math.round(fileSize / (1024 * 1024)) > 5) {
ajaxMessage("<div class='message warning icon-warning'>Tamanho máximo permitido de imagens 5MB. Favor escolher imagens menores para galeria!</div>", 8);
$('#gallery-upload').val('');
}
}
});
//FORMS
$("form:not('.ajax_off')").submit(function (e) {
e.preventDefault();
var form = $(this);
var load = $(".ajax_load");
var url = form.attr("action");
if (typeof tinyMCE !== 'undefined') {
tinyMCE.triggerSave();
}
form.ajaxSubmit({
url: url,
type: "POST",
dataType: "json",
beforeSend: function () {
load.fadeIn(200).css("display", "flex");
},
uploadProgress: function (event, position, total, completed) {
var loaded = completed;
var load_title = $(".ajax_load_box_title");
load_title.text("Enviando (" + loaded + "%)");
if (completed >= 100) {
load_title.text("Aguarde, carregando...");
}
},
success: function (response) {
//redirect
if (response.redirect) {
window.location.href = response.redirect;
} else {
form.find("input[type='file']").val(null);
load.fadeOut(200);
}
//reload
if (response.reload) {
window.location.reload();
} else {
load.fadeOut(200);
}
//message
if (response.message) {
ajaxMessage(response.message, ajaxResponseBaseTime);
}
//image by fsphp mce upload
if (response.mce_image) {
$('.mce_upload').fadeOut(200);
tinyMCE.activeEditor.insertContent(response.mce_image);
}
},
complete: function () {
if (form.data("reset") === true) {
form.trigger("reset");
}
},
error: function () {
ajaxMessage(ajaxResponseRequestError, 5);
load.fadeOut();
}
});
});
// AJAX RESPONSE
function ajaxMessage(message, time) {
var ajaxMessage = $(message);
ajaxMessage.append("<div class='message_time'></div>");
ajaxMessage.find(".message_time").animate({"width": "100%"}, time * 1000, function () {
$(this).parents(".message").fadeOut(200);
});
$(".ajax_response").append(ajaxMessage);
ajaxMessage.effect("bounce");
}
// AJAX RESPONSE MONITOR
$(".ajax_response .message").each(function (e, m) {
ajaxMessage(m, ajaxResponseBaseTime += 1);
});
// AJAX MESSAGE CLOSE ON CLICK
$(".ajax_response").on("click", ".message", function (e) {
e.preventDefault();
$(this).effect("bounce").fadeOut(1);
});
//Preview das Imagens
function readIMG(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#image-preview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#j_img_preview").change(function () {
readIMG(this);
});
$(".ajax_response").on("click", ".message", function (e) {
$(this).effect("bounce").fadeOut(1);
});
$(".img-open").on("click", function (e) {
e.preventDefault();
if (($("input[name='cover']").length > 0)) {
$("input[name='cover']").click();
}
if (($("input[name='photo']").length > 0)) {
$("input[name='photo']").click();
}
});
$(".j-deleta").on("click", "#delete-gallery", function (e) {
e.preventDefault();
var id = $(this).data("id");
var url = $(this).data("url");
var dataset = $(this).data();
var flashClass = "ajax_response";
var flash = $("." + flashClass);
$.post(url, dataset, function (response) {
//reload by error
if (response.reload) {
window.location.reload();
}
if (response.resposta == "sucesso") {
$('[data-delete="' + id + '"]').fadeOut("slow");
}
//message
if (response.message) {
if (flash.length) {
flash.html(response.message).fadeIn(100).effect("bounce", 300);
} else {
form.prepend("<div class='" + flashClass + "'>" + response.message + "</div>")
.find("." + flashClass).effect("bounce", 300);
}
} else {
flash.fadeOut(100);
}
}, "json");
});
// MAKS
$(".mask-date").mask('00/00/0000');
$(".mask-cep").mask('00000-000');
$(".mask-datetime").mask('00/00/0000 00:00');
$(".mask-month").mask('00/0000', {reverse: true});
$(".mask-doc").mask('000.000.000-00', {reverse: true});
$(".mask-uf").mask('SS');
$(".mask-card").mask('0000 0000 0000 0000', {reverse: true});
$(".mask-money").mask('000.000.000.000.000,00', {reverse: true, placeholder: "0,00"});
$('.mask-celular').mask('(00) 0000-00009');
$('.mask-celular').blur(function (event) {
if ($(this).val().length == 15) { // Celular com 9 dígitos + 2 dígitos DDD e 4 da máscara
$('.mask-celular').mask('(00) 00000-0009');
} else {
$('.mask-celular').mask('(00) 0000-00009');
}
});
$('.mask-phone').mask('(00) 0000-00009');
$('.mask-phone').blur(function (event) {
if ($(this).val().length == 15) { // Celular com 9 dígitos + 2 dígitos DDD e 4 da máscara
$('.mask-phone').mask('(00) 00000-0009');
} else {
$('.mask-phone').mask('(00) 0000-00009');
}
});
});
// TINYMCE INIT
tinyMCE.init({
selector: "textarea.mce",
language: 'pt_BR',
menubar: false,
theme: "modern",
height: 132,
skin: 'light',
entity_encoding: "raw",
theme_advanced_resizing: true,
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor media"
],
toolbar: "styleselect | pastetext | removeformat | bold | italic | underline | strikethrough | bullist | numlist | table | alignleft | aligncenter | alignright | link | unlink | fsphpimage | code | fullscreen",
style_formats: [
{title: 'Normal', block: 'p'},
{title: 'Titulo 3', block: 'h3'},
{title: 'Titulo 4', block: 'h4'},
{title: 'Titulo 5', block: 'h5'},
{title: 'Código', block: 'pre', classes: 'brush: php;'}
],
link_class_list: [
{title: 'None', value: ''},
{title: 'Blue CTA', value: 'btn btn_cta_blue'},
{title: 'Green CTA', value: 'btn btn_cta_green'},
{title: 'Yellow CTA', value: 'btn btn_cta_yellow'},
{title: 'Red CTA', value: 'btn btn_cta_red'}
],
setup: function (editor) {
editor.addButton('fsphpimage', {
title: 'Enviar Imagem',
icon: 'image',
onclick: function () {
$('.mce_upload').fadeIn(200, function (e) {
$("body").click(function (e) {
if ($(e.target).attr("class") === "mce_upload") {
$('.mce_upload').fadeOut(200);
}
});
}).css("display", "flex");
}
});
},
link_title: false,
target_list: false,
theme_advanced_blockformats: "h1,h2,h3,h4,h5,p,pre",
media_dimensions: false,
media_poster: false,
media_alt_source: false,
media_embed: false,
extended_valid_elements: "a[href|target=_blank|rel|class]",
imagemanager_insert_template: '<img src="{$url}" title="{$title}" alt="{$title}" />',
image_dimensions: false,
relative_urls: false,
remove_script_host: false,
paste_as_text: true
});