var SPMaskBehaviorFlyer = function (val) {
return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
};
var spOptionsFlyer = {
onKeyPress: function (val, e, field, options) {
field.mask(SPMaskBehaviorFlyer.apply({}, arguments), options);
}
};
var form = {
texts: [],
inputs: [],
cargo:{
0:{
nome:'Assistente',
},
1:{
nome:'Gerente',
}
},
address:1,
key:0,
id_model:0,
appendForm:'#produto-form-personalizar .panel-body',
buttonHandler:'#pagina-produto #produto-resumo button.confirm',
init: function(){
self = this;
if ($(self.buttonHandler).length > 1){
self.buttonHandler = '#produto-resumo > div > div.col-7.button--paddingLeft > button'
}
$.ajax({
url: "https://editor.print-one.com.br/api/modelo/"+this.id_model+"/layers/?key="+this.key,
type: "GET",
dataType:'json',
beforeSend: function () {
},
success: function (objJSON) {
self.texts = objJSON.layers.texts
self.configForm();
self.createContainer();
self.createForm();
},
error: function (objXHR, txtStatus, txtErro) {
console.error('erro', objXHR);
},
complete: function (xhr) {
}
});
},
configForm: function () {
for (let key = 0; key < this.texts.length; key++) {
const element = this.texts[key].name;
const elementID = this.texts[key].name.replace(' ', '').toLowerCase();
// const mask = element.toLowerCase().indexOf('telefone') != -1 || element.toLowerCase().indexOf('celular') != -1 ? true : false;
const maxlength = element.toLowerCase().indexOf('nome') != -1 ? 45 : false;
let type = element.toLowerCase().indexOf('endereco') != -1 ? 'select' : 'text';
type = element.toLowerCase().indexOf('cargo') != -1 ? 'select' : 'text';
const label = element.toLowerCase().indexOf('endereco') != -1 ? 'Endereço' : this.capitalize(element.replace(/\#/g,''));
let value = element.toLowerCase().indexOf('endereco') != -1 ? this.endereco : '';
value = element.toLowerCase().indexOf('cargo') != -1 ? this.cargo : '';
if (element.toLowerCase().indexOf('endereco4') == -1 & element.toLowerCase().indexOf('endereco2') == -1 & element.toLowerCase().indexOf('endereco3') == -1){
if (this.findArray(elementID)){
this.inputs.push({
name:elementID,
label: label,
match:"#"+elementID+"#",
value:value,
required: false,
id: elementID,
type: type,
// mask: mask,
maxlength, maxlength
});
}
}
}
},
save:function(){
self = this;
var validate = true;
for (var i in self.inputs){
if(self.inputs[i].required && $('#'+self.inputs[i].id).val() == ''){
alert('Campo '+self.inputs[i].label+' obrigatório');
$('#'+self.inputs[i].id).focus();
validate = false;
break;
}else{
localStorage.setItem($('#'+self.inputs[i].id).data('match'),$('#'+self.inputs[i].id).val());
}
}
if(validate){
$(self.buttonHandler).click();
}
},
createContainer:function(){
$container = $('
');
$container.insertAfter('#produto-descricao-reduzida');
},
capitalize: function (string) {
string = string[0].toUpperCase() + string.slice(1);
//tem número na string? Ex: Telefone1, Telefone2...
hasNumber = string.match(/[0-9]/);
if(hasNumber){
//Separa para ficar Telefone 1, Telefone 2, Telefone 3
string = string.replace(hasNumber[0], ' ' + hasNumber[0]);
}
return string;
},
findArray: function (string) {
//Verifica se já existe um campo com o nome igual, se tiver não deixa criar o input
if (this.inputs.filter(p => p.name == string).length > 0){
return false;
}else{
return true;
}
},
createForm:function(){
self = this;
if(!self.inputs.length){
console.error('Nenhum input definido');
}else{
for (var i in self.inputs){
$(self.appendForm).append(self.getInput(self.inputs[i]));
}
$button = $('');
$button.css({
'position':'absolute',
'top':0,
'left':0,
'right':0,
'bottom':0,
'z-index':1,
'cursor':'pointer',
'width': $(self.buttonHandler).width() + 15
}).click(function(event) {
event.preventDefault();
form.save();
});
$(self.buttonHandler).css({
'position':'relative'
}).parent().css({
'position':'relative'
}).append($button)
}
},
getInput:function(input, key){
$field = $('');
var $input;
if(input.type == 'text'){
$input = $('');
}
if(input.type == 'select'){
$input = $('');
for (var i in input.value) {
$input.append('');
}
}
$input.attr({
'name':input.name,
'id':input.id
}).data({
'match':input.match,
'required':input.required,
})
if(!!localStorage.getItem(input.match)){
$input.val(localStorage.getItem(input.match));
}
if(input.maxlength){
$input.attr({
'maxlength':input.maxlength,
}).data({
'maxlength':input.maxlength
})
}
var $label = $('');
$label.attr({
'for':input.id
}).text(input.label);
var $span;
if(input.maxlength){
$span = $(''+($input.val().length)+'/'+input.maxlength+'');
$input.on('input',function(){
max = $(this).data('maxlength');
current = $(this).val().length;
$(this).next('span').text(current+'/'+max);
})
}
// if(input.mask !== false){
// $input.mask(SPMaskBehaviorFlyer, spOptionsFlyer);
// }
$field.append($label);
$field.append($input);
$field.append($span);
return $field;
}
}
var WhatsApp = {
caracterSeparadorDeTelefones: '/',
WhatsAppFlag: 'WhatsApp',
telefones:[],
$footerLocation: false,
$headerLocation: false,
init:function(opcoes){
if (typeof opcoes !== 'undefined') {
this.caracterSeparadorDeTelefones = (typeof opcoes.caracterSeparadorDeTelefones !== 'undefined') ? opcoes.caracterSeparadorDeTelefones : this.caracterSeparadorDeTelefones;
this.WhatsAppFlag = (typeof opcoes.WhatsAppFlag !== 'undefined') ? opcoes.WhatsAppFlag : this.WhatsAppFlag;
this.telefones = (typeof opcoes.telefones !== 'undefined') ? opcoes.telefones : this.telefones;
}
this.setTelefones();
this.createTopoElement();
this.createRodapeElement();
},
getTelefones:function(){
var $telefoneHeaderDiv = $('#upper-header .user-actions.clearfix.phone-store');
var $telefoneFooterDiv = $('#footer .col-items .contact-item');
var $telefoneHeader = $telefoneHeaderDiv.find('a:contains("Tel.:")');
var $telefoneFooter = $telefoneFooterDiv.find('a:contains("Tel.:")');
if ($telefoneHeader.length > 0 && $telefoneFooter.length > 0 ) {
this.$headerLocation = $telefoneHeaderDiv;
this.$footerLocation = $telefoneFooterDiv;
return $telefoneFooter.text();
} else if($telefoneFooter.length > 0) {
this.$footerLocation = $telefoneFooterDiv;
return $telefoneFooter.text();
} else if($telefoneHeader.length) {
this.$headerLocation = $telefoneHeaderDiv;
return $telefoneHeader.text();
} else {
return false;
}
},
setTelefones:function(){
var self = this;
var isWhatsApp = function(telefone){
return telefone.indexOf(self.WhatsAppFlag) > -1;
};
var removeWhatsAppFlag = function(telefone){
return telefone.replace(self.WhatsAppFlag,'').trim();
};
if (this.telefones.length <= 0) {
var telefones = this.getTelefones();
if (typeof telefones !== 'undefined' ) {
telefones = telefones.replace('Tel.:','').trim();
var telefonesArray = telefones.split(this.caracterSeparadorDeTelefones);
var telefonesLength = telefonesArray.length;
if (telefonesLength > 0) {
for (var i = 0; i < telefonesLength; i++) {
var telefone = telefonesArray[i];
var telefoneOBJ = {numero:'',href:'',cssClass:'',style:'',target:'',texto:'',isWhatsApp:false};
if (isWhatsApp(telefone)) {
telefone = removeWhatsAppFlag(telefone);
var href = telefone.match(/[0-9]/g);
if (href[0] != 5 || href[1] != 5) {
href = '55' + href.join('').toString();
} else {
href = href.join('');
}
telefoneOBJ = {
numero:telefone,
href:'href="https://api.whatsapp.com/send?phone=' + href + '"',
cssClass:'class="phone-link whatsapp-link"',
style:"",
target:'target="_blank"',
texto: telefone,
isWhatsApp:true
};
} else {
telefoneOBJ = {
numero:telefone,
href:'href="#"',
cssClass:'class="phone-link phone-link-normal"',
style:'style="cursor: default; text-decoration: none;"',
target:'target="_blank"',
texto: telefone,
isWhatsApp:false
};
}
this.telefones.push(telefoneOBJ);
}
}
}
}
},
removeClickEvent:function($elem){
$elem.on('click', function(event) {
event.preventDefault();
});
return $elem;
},
createTopoElement:function(){
var self = this;
var $location = self.$headerLocation;
if ($location.length > 0 & self.telefones.length > 0) {
$location.empty();
var elements = [];
$.each(self.telefones, function(index, val) {
var $a = $('' + val.texto + '');
$a = (val.isWhatsApp === false) ? self.removeClickEvent($a) : $a;
elements.push($a);
});
$location.append(elements);
}
},
createRodapeElement:function(){
var $ul = $('');
var self = this;
if (self.$footerLocation.length > 0 & self.telefones.length > 0 ) {
var $location = self.$footerLocation.find('a:contains("Tel.:")').parent();
$location.empty();
var elements = [];
$.each(self.telefones, function(index, val) {
var $a = $('' + val.texto + '');
$a = (val.isWhatsApp === false) ? self.removeClickEvent($a) : $a;
elements.push($('- ').append($a));
});
$location.append($ul.append(elements));
}
},
};
function BlockContent(classe,where){
if($("#custom-blocks").length ==0){
$("#main").append('');
}
$("#custom-blocks").append('');
}
$(document).ready(function(){
if ((document.URL.indexOf('produtos-detalhes') > 0 || document.URL.indexOf('produtos-editor') > 0) && $('h1.subtitle:contains("LOTE")').length == 0 && $('h1.subtitle:contains("lote")').length == 0) {
idProduto = document.URL.split("/");
$.ajax({
url: location.protocol + "//" + window.location.host + "/loja/theme/nav/getEditorProduto.asp",
type: "POST",
dataType:'json',
data : {
idProduto : idProduto[5]
},
beforeSend: function () {
},
success: function (objJSON) {
console.log(objJSON);
if (objJSON.txtErro == ""){
form.key = objJSON.key;
form.id_model = objJSON.model;
form.init();
}else{
console.log(objJSON.txtErro);
}
},
error: function (objXHR, txtStatus, txtErro) {
console.log(objXHR);
},
complete: function (xhr) {
}
});
}
//if(location.href.indexOf('produtos-detalhes-concluir') > -1){
// location.href = 'https://lojapromopress.com.br/loja/carrinho-compras/';
// }
WhatsApp.init({WhatsAppFlag:'whatsapp'});
if($('#formProposta').length){
// $('#produto-resumo button.confirm b').text('')
}
BlockContent(7,'last');
BlockContent(7,'depoiments');
if(typeof(BibliotecaImagens)=="function") BibliotecaImagens('last');
if(typeof(Depoimento)=="function") Depoimento('depoiments');
if(location.href.indexOf('produtos-categorias/0LQNPKNJ') == -1){
$('body').addClass('show-mask');
}
});
if(typeof EdPO == 'object'){
var FORM = {
endpoint:'https://editor.print-one.com.br/api/personalizacao/',
key:'',
texts:{},
models:['PTC','MDRT 3','MDRT 4','MDRT 3 PTC','MDRT 4 PTC','MDRT Member','MDRT Court','MDRT Member PTC','MDRT Court PTC'],
content:{
$:$(''),
style:{
'width':'25%',
'float':'left',
'background-color':'#424242',
'border-right':'1px solid #000',
'position':'relative'
}
},
$submitBtn:{
$:'',
style:{
'background':'#00c853',
'border':'none',
'text-tranform':'uppercase',
'text-align':'center',
'width':'100%',
'padding':'20px',
'font-size':'18px',
'color':'#FFF'
}
},
$form:'',
$editor:$('#'+EdPO.config.iframe),
label:{
$:$(''),
style:{
'display':'block',
'color':'#FFF',
}
},
input:{
$:$(''),
style:{
'color':'#FFF',
'display':'block',
'margin-bottom':'15px',
'width':'100%',
'background-color':'transparent',
'border':'none',
'border-bottom':'2px solid #26a69a',
'box-shadow':'none',
'padding':'7px 0px'
}
},
select:{
$:$(''),
style:{
'color':'#FFF',
'display':'block',
'margin-bottom':'15px',
'width':'100%',
'background-color':'transparent',
'border':'none',
'border-bottom':'2px solid #26a69a',
'box-shadow':'none',
'padding':0,
'height':36
}
},
masks:{
'Telefone':{
meiomask:{
type:'fixed',
mask:'(nn) nnnn-nnnn',
autoTab:false,
},
},
'Celular':{
meiomask:{
type:'fixed',
mask:'(nn) nnnnn-nnnn',
autoTab:false,
},
},
},
init:function(){
FORM.getTexts();
},
qrcode:false,
getTexts:function(){
$.ajax({
url:FORM.endpoint+EdPO.config.model,
type:'GET',
dataType:'json',
data:{
key:EdPO.config.key
},
success:function(data){
FORM.texts = data.personalizacao[0].texts;
FORM.form();
}
});
},
form:function(){
FORM.$editor = $('#'+EdPO.config.iframe);
FORM.$editor.css({
'width':'75%'
});
for(var i in FORM.texts){
text = FORM.texts[i];
name = text.match.charAt(0).toUpperCase() + text.match.substr(1);
$input = FORM.input.$.attr({'id':'input-'+i,'name':name}).css(FORM.input.style).clone().data({layer:text.name,match:'#'+text.match+'#',name:name}).attr({'required':'required'});
v = FORM.hasData(name);
if(v !== false){
$input.val(v.replace).data({'match':r.match});
}
if(typeof FORM.masks[name] == 'object'){
$input.setMask(FORM.masks[name].meiomask);
}
$label = FORM.label.$.text(name).attr({'for':'input-'+i}).css(FORM.label.style).clone();
if(name == 'Email' || name == 'E-mail'){
$input.attr('type','email');
}
FORM.content.$.find('.card-body').append($label);
FORM.content.$.find('.card-body').append($input);
}
FORM.content.$.find('.card-head').css({
position:'absolute',
padding:'22px 15px',
width:'100%',
top:0,
'border-bottom':'1px solid #000'
});
FORM.content.$.find('.card-body').css({
position:'absolute',
top:64,
bottom:110,
padding:'15px',
width:'100%',
'overflow-y':'auto'
});
FORM.content.$.find('.card-footer').css({
position:'absolute',
padding:'15px',
width:'100%',
bottom:0,
height:110,
'background-color':'#212121'
});
FORM.content.$.height(FORM.$editor.height());
FORM.content.$.css(FORM.content.style);
FORM.content.$.insertBefore(FORM.$editor);
FORM.$submitBtn.$ = $('#btn-put-data-on-model');
FORM.$submitBtn.$.css(FORM.$submitBtn.style);
FORM.$form = $('#submit-form-to-editor');
FORM.$form.submit(function(e){
e.preventDefault();
FORM.apply();
});
// FORM.$form.submit();
},
vcard:{
data:{
'key':'B28752184046517F27738FA6CC739F84E84670EC5EF0A4F71B2E9D942EFE2458',
'width':2000,
},
endpoint:'http://developer.brochura.com.br/pergraf/qrcode/api/vcard',
},
apply:function(){
FORM.$form.find('input').each(function(index,input){
FORM.vcard.data[$(this).data().name.toLowerCase()] = $(this).val();
EdPO.replaceTextLayer($(this).data().layer,$(this).data().match,$(this).val());
$(this).data().match = $(this).val();
});
// EdPO.setImageLayer('qrcode',{'url':'https://cdn-images-1.medium.com/max/1200/0*zPG9dqz508rmRR70.','position':'contain'})
$.ajax({
url: FORM.vcard.endpoint,
type: 'POST',
dataType: 'json',
data: FORM.vcard.data,
crossDomain:true,
success:function(data){
EdPO.setImageLayer('qrcode',{'url':data.url,'position':'contain'})
},
error:function(data){
console.log(data);
},
});
},
hasData:function(match){
r = false;
if(Object.keys(EdPO.config.texts).length > 0){
for(var i in EdPO.config.texts){
t = EdPO.config.texts[i];
if(t.match == '#'+match.toLowerCase()+'#'){
r = t;
break;
}
}
}
return r;
}
}
}
$(function(){
if(typeof EdPO == 'object'){
if(EdPO.config.model == 1246){
EdPO.ready = function(){
FORM.init();
}
}
}
});