| 1 |
(function($) { |
| 2 |
"use strict"; |
| 3 |
$( document ).ready( function () { |
| 4 |
var yeemail_builder_main = { |
| 5 |
json_to_builder: function(){ |
| 6 |
var data_json = $(".yeemail_data_email").val(); |
| 7 |
var datas = {}; |
| 8 |
var html=""; |
| 9 |
if( data_json =="" || typeof data_json === "undefined"){ |
| 10 |
return; |
| 11 |
} |
| 12 |
datas = JSON.parse(data_json); |
| 13 |
$(".builder__list").html(""); |
| 14 |
$(".yeemail-builder-main").css(datas["container"]); |
| 15 |
for (let index_row in datas['rows'] ) { |
| 16 |
var row_style = datas['rows'][index_row].style; |
| 17 |
var row_columns = datas['rows'][index_row].columns; |
| 18 |
var row_type = datas['rows'][index_row].type; |
| 19 |
var row_attr = datas['rows'][index_row].attr; |
| 20 |
var row_condition = datas['rows'][index_row].condition; |
| 21 |
var row = $('<div class="builder-row-container builder__item"></div>'); |
| 22 |
var inner_row = $('<div data-type="'+row_type+'" class="builder-row-container-row builder-row-container-'+row_type+'"></div>'); |
| 23 |
inner_row.css(row_style); |
| 24 |
inner_row.attr(row_attr); |
| 25 |
inner_row.attr("data-condition",row_condition); |
| 26 |
inner_row.appendTo(row); |
| 27 |
var i = 0; |
| 28 |
for (let index_column in row_columns ) { |
| 29 |
i++; |
| 30 |
switch(row_type) { |
| 31 |
case "row3": |
| 32 |
if( i == 1){ |
| 33 |
var column = $('<div class="builder-row bd-row-2 builder-row-empty"></div>'); |
| 34 |
}else{ |
| 35 |
var column = $('<div class="builder-row builder-row-empty"></div>'); |
| 36 |
} |
| 37 |
break; |
| 38 |
case "row4": |
| 39 |
if( i != 1){ |
| 40 |
var column = $('<div class="builder-row bd-row-2 builder-row-empty"></div>'); |
| 41 |
}else{ |
| 42 |
var column = $('<div class="builder-row builder-row-empty"></div>'); |
| 43 |
} |
| 44 |
break; |
| 45 |
default: |
| 46 |
var column = $('<div class="builder-row builder-row-empty"></div>'); |
| 47 |
} |
| 48 |
var elements = row_columns[index_column].elements; |
| 49 |
for (let index_element in elements ) { |
| 50 |
column.removeClass('builder-row-empty'); |
| 51 |
var element_type = elements[index_element].type; |
| 52 |
var element=$.yeemail_load_type(element_type,elements[index_element]); |
| 53 |
element.appendTo(column); |
| 54 |
} |
| 55 |
column.appendTo(row.find(".builder-row-container-row")); |
| 56 |
} |
| 57 |
//row.find(".builder-row").yeemail_element_droppable(); |
| 58 |
row.find(".builder-row").yeemail_element_sortable(); |
| 59 |
row.appendTo(".builder__list--js"); |
| 60 |
} |
| 61 |
}, |
| 62 |
builder_to_json: function(){ |
| 63 |
var datas = {}; |
| 64 |
var container = $(".yeemail-builder-main"); |
| 65 |
datas['container'] = { |
| 66 |
'background-color': $.email_builder_cover_color($(".yeemail-builder-main").css("background-color")), |
| 67 |
'padding-top': $(".yeemail-builder-main").css("padding-top"), |
| 68 |
'padding-bottom': $(".yeemail-builder-main").css("padding-bottom"), |
| 69 |
'padding-left': $(".yeemail-builder-main").css("padding-left"), |
| 70 |
'padding-right': $(".yeemail-builder-main").css("padding-right"), |
| 71 |
'background-image': $(".yeemail-builder-main").css("background-image"), |
| 72 |
"background-position": $(".yeemail-builder-main").css("background-position"), |
| 73 |
"background-repeat": $(".yeemail-builder-main").css("background-repeat"), |
| 74 |
"background-size": $(".yeemail-builder-main").css("background-size"), |
| 75 |
}; |
| 76 |
container.css(datas["container"]); |
| 77 |
datas["rows"] = {}; |
| 78 |
$(".builder-row-container-row").each(function(index,row){ |
| 79 |
var type = $(row).data("type"); |
| 80 |
var style_row = {}; |
| 81 |
var list_css = yeemail_builder["block"][type]["editor"]["container"]["style"]; |
| 82 |
$.each( list_css, function( key, value ) { |
| 83 |
var css = $(row).css(value); |
| 84 |
if( value.indexOf("color") >= 0 ){ |
| 85 |
style_row[value] = $.email_builder_cover_color(css); |
| 86 |
}else{ |
| 87 |
style_row[value] = css; |
| 88 |
} |
| 89 |
}); |
| 90 |
var attr_row = {}; |
| 91 |
attr_row["background_full"] = $(row).attr("background_full"); |
| 92 |
attr_row["responsive"] = $(row).attr("responsive"); |
| 93 |
if( attr_row["background_full"] !="not" ) { |
| 94 |
attr_row["background_full"] = "ok"; |
| 95 |
} |
| 96 |
if( attr_row["responsive"] !="not" ) { |
| 97 |
attr_row["responsive"] = "ok"; |
| 98 |
} |
| 99 |
var condition = $(row).attr("data-condition"); |
| 100 |
if( condition === undefined){ |
| 101 |
condition = ""; |
| 102 |
} |
| 103 |
datas["rows"][index] = {style:style_row, |
| 104 |
attr: attr_row, |
| 105 |
type: type, |
| 106 |
columns: {}, |
| 107 |
condition: condition |
| 108 |
}; |
| 109 |
$(row).find(".builder-row").each(function(index1,row1){ |
| 110 |
datas["rows"][index]["columns"][index1]={ |
| 111 |
elements: {} |
| 112 |
}; |
| 113 |
$(row1).find(".builder-elements-content").each(function(index2,row2){ |
| 114 |
var type = $(row2).data("type"); |
| 115 |
var element = $(row2).yeemail_save_type(); |
| 116 |
datas["rows"][index]["columns"][index1]["elements"][index2]= element; |
| 117 |
}) |
| 118 |
}) |
| 119 |
}) |
| 120 |
return JSON.stringify(datas); |
| 121 |
}, |
| 122 |
json_to_email: function(){ |
| 123 |
var data_json = $(".yeemail_data_email").val(); |
| 124 |
var id = $("#post_ID").val(); |
| 125 |
var datas = {}; |
| 126 |
if( data_json ==""){ |
| 127 |
return; |
| 128 |
} |
| 129 |
datas = JSON.parse(data_json); |
| 130 |
var container =$('<div data-yeemail-id="'+id+'" class="wap" width="100%" style="margin: 0 auto;padding-top:100px;padding-bottom:100px;"><div class="container" style="margin: 0 auto;"class="email-container" ></div></div>'); |
| 131 |
container.css(datas["container"]); |
| 132 |
for (let index_row in datas['rows'] ) { |
| 133 |
var row_style = datas['rows'][index_row].style; |
| 134 |
var row_attr = datas['rows'][index_row].attr; |
| 135 |
var row_columns = datas['rows'][index_row].columns; |
| 136 |
var row_type = datas['rows'][index_row].type; |
| 137 |
var row_container = $('<div class="container-row" style="width:100%"></div>'); |
| 138 |
for (const [key, value] of Object.entries(row_attr)) { |
| 139 |
switch(key) { |
| 140 |
case "background_full": |
| 141 |
if( value !== "not"){ |
| 142 |
row_container.css("background-color",row_style["background-color"]); |
| 143 |
} |
| 144 |
break; |
| 145 |
case "responsive": |
| 146 |
if( value !== "not"){ |
| 147 |
row_container.addClass("yeemail-responsive"); |
| 148 |
} |
| 149 |
break; |
| 150 |
default: |
| 151 |
row_container.attr(key,value); |
| 152 |
break; |
| 153 |
} |
| 154 |
} |
| 155 |
var row =$('<table class="row" width="'+yeemail_script.email_width+'px" class="row" align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin: auto;"><tr></tr></table'); |
| 156 |
row = row.css(row_style); |
| 157 |
var i = 0; |
| 158 |
for (let index_column in row_columns ) { |
| 159 |
i++; |
| 160 |
var col_width = "100%"; |
| 161 |
switch(row_type) { |
| 162 |
case "row2": |
| 163 |
col_width = "50%"; |
| 164 |
break; |
| 165 |
case "row3": |
| 166 |
if( i == 1){ |
| 167 |
col_width = "65%"; |
| 168 |
}else{ |
| 169 |
col_width = "35%"; |
| 170 |
} |
| 171 |
break; |
| 172 |
case "row4": |
| 173 |
if( i == 1){ |
| 174 |
col_width = "35%"; |
| 175 |
}else{ |
| 176 |
col_width = "65%"; |
| 177 |
} |
| 178 |
break; |
| 179 |
case "row5": |
| 180 |
col_width = "33.33%;"; |
| 181 |
break; |
| 182 |
case "row6": |
| 183 |
col_width = "25%;"; |
| 184 |
break; |
| 185 |
default: |
| 186 |
col_width = "100%;"; |
| 187 |
} |
| 188 |
var column = $('<td class="col" width="'+col_width+'"></td>'); |
| 189 |
var elements = row_columns[index_column].elements; |
| 190 |
var col_container = $("<div class='col-container'></div>"); |
| 191 |
for (const [key, value] of Object.entries(elements)) { |
| 192 |
var element_type = value.type; |
| 193 |
var element = $.yeemail_load_type(element_type,value); |
| 194 |
element.find(".builder-elements-content .text-content").remove(); |
| 195 |
element.appendTo(col_container); |
| 196 |
} |
| 197 |
col_container.appendTo(column); |
| 198 |
column.appendTo(row.find("tr")); |
| 199 |
} |
| 200 |
row.appendTo(row_container); |
| 201 |
row_container.appendTo(container.find(".container")); |
| 202 |
} |
| 203 |
return container[0].outerHTML; |
| 204 |
}, |
| 205 |
json_to_email_head: function(){ |
| 206 |
return '' |
| 207 |
} |
| 208 |
} |
| 209 |
yeemail_builder_main.json_to_builder(); |
| 210 |
$( ".builder-row-container-row" ).each(function( index ) { |
| 211 |
if( $(this).attr("background_full") != "not" ){ |
| 212 |
$(this).closest(".builder-row-container").css("background-color",$(this).css("background-color")); |
| 213 |
} |
| 214 |
}); |
| 215 |
$('body').on("click",".builder-row-container",function(e){ |
| 216 |
e.preventDefault(); |
| 217 |
$(this).find(".builder-row-container-row").click(); |
| 218 |
}) |
| 219 |
$('body').on("click",".yeemail-builder-save",function(e){ |
| 220 |
e.preventDefault(); |
| 221 |
var email_json = yeemail_builder_main.builder_to_json(); |
| 222 |
$(".yeemail_data_email").val(email_json); |
| 223 |
$("#publish").click(); |
| 224 |
}) |
| 225 |
$('body').on("click",".yeemail-builder-testting-send",function(e){ |
| 226 |
e.preventDefault(); |
| 227 |
var email = $("#yeemail-builder-testting").val(); |
| 228 |
var id = $("#post_ID").val(); |
| 229 |
if( email =="" || id == ""){ |
| 230 |
alert("Enter Email or Save Post"); |
| 231 |
}else{ |
| 232 |
$(this).html("Sending..."); |
| 233 |
var button = $(this); |
| 234 |
var data = { |
| 235 |
'action': 'yeemail_builder_send_email_testing', |
| 236 |
'id': id, |
| 237 |
'nonce': yeemail_script.nonce, |
| 238 |
'email' : email |
| 239 |
}; |
| 240 |
jQuery.post(ajaxurl, data, function(response) { |
| 241 |
alert(response); |
| 242 |
button.html("Send Email"); |
| 243 |
}); |
| 244 |
} |
| 245 |
}) |
| 246 |
$('body').on("click",".momongaDelete",function(e){ |
| 247 |
e.preventDefault(); |
| 248 |
e.stopPropagation(); |
| 249 |
$(".builder__editor .builder__editor--item").addClass('hidden'); |
| 250 |
if( $(this).closest(".builder-elements").length < 1 ){ |
| 251 |
$(this).closest(".builder-row-container").remove(); |
| 252 |
}else{ |
| 253 |
$(this).closest('.builder-elements').remove(); |
| 254 |
} |
| 255 |
}) |
| 256 |
$('body').on("click",".momongaDuplicate",function(e){ |
| 257 |
e.preventDefault(); |
| 258 |
e.stopPropagation(); |
| 259 |
if( $(this).closest(".builder-elements").length > 0 ){ |
| 260 |
var main_item = $(this).closest('.builder-elements'); |
| 261 |
var newItem = main_item.clone(true); |
| 262 |
newItem.find(".builder__toolbar").remove(); |
| 263 |
newItem.find(".builder-elements-content").removeClass("yeemail_builder_focus"); |
| 264 |
main_item.after(newItem); |
| 265 |
}else{ |
| 266 |
var main_item = $(this).closest('.builder-row-container'); |
| 267 |
var newItem = main_item.clone(true); |
| 268 |
newItem.find(".builder__toolbar").remove(); |
| 269 |
newItem.removeClass('yeemail_builder_show').find(".builder-row-container-row").removeClass("yeemail_builder_focus"); |
| 270 |
newItem.find(".builder-elements-content").removeClass("yeemail_builder_focus"); |
| 271 |
main_item.after(newItem); |
| 272 |
} |
| 273 |
}) |
| 274 |
$("body").on('mouseenter', '.builder-elements', function() { |
| 275 |
if( $(this).closest(".yeemail_builder_show").length < 1 ){ |
| 276 |
$(this).closest('.builder-row-container').addClass('yeemail_builder_hover'); |
| 277 |
$(this).addClass('yeemail_builder_hover'); |
| 278 |
}else{ |
| 279 |
$(this).addClass('yeemail_builder_hover'); |
| 280 |
} |
| 281 |
}); |
| 282 |
$("body").on('mouseleave', '.builder-elements', function() { |
| 283 |
$(this).closest('.builder-row-container').removeClass('yeemail_builder_hover'); |
| 284 |
$(this).removeClass('yeemail_builder_hover'); |
| 285 |
}); |
| 286 |
$("body").on('mouseenter', '.builder-row-container-row', function() { |
| 287 |
if( $(this).closest(".yeemail_builder_show").length < 1 ){ |
| 288 |
$(this).closest('.builder-row-container').addClass('yeemail_builder_hover'); |
| 289 |
} |
| 290 |
}); |
| 291 |
$("body").on('mouseleave', '.builder-row-container-row', function() { |
| 292 |
$(this).closest('.builder-row-container').removeClass('yeemail_builder_hover'); |
| 293 |
}); |
| 294 |
$('body').on("click",".builder__tab a",function(e){ |
| 295 |
e.preventDefault(); |
| 296 |
$(".builder__tab a").removeClass("active"); |
| 297 |
$(this).addClass("active"); |
| 298 |
var tab = $(this).attr('id'); |
| 299 |
$('.tab__content').hide(); |
| 300 |
$(tab).show(); |
| 301 |
}) |
| 302 |
$('body').on("click",".yeemail-builder-goback",function(e){ |
| 303 |
e.preventDefault(); |
| 304 |
$(".builder__tab li").first().find("a").click(); |
| 305 |
}) |
| 306 |
$('body').on('click', '.yeemail-builder-import', function(e){ |
| 307 |
e.preventDefault(); |
| 308 |
var button = $(this), |
| 309 |
custom_uploader = wp.media({ |
| 310 |
title: 'Import template', |
| 311 |
library : { |
| 312 |
type : [ 'json',"text"] |
| 313 |
}, |
| 314 |
button: { |
| 315 |
text: 'Import template' // button label text |
| 316 |
}, |
| 317 |
multiple: false // for multiple image selection set to true |
| 318 |
}).on('select', function() { // it also has "open" and "close" events |
| 319 |
var attachment = custom_uploader.state().get('selection').first().toJSON(); |
| 320 |
$.getJSON(attachment.url, function(data){ |
| 321 |
$(".yeemail_data_email").val(data); |
| 322 |
$(".builder__list").html(""); |
| 323 |
yeemail_builder_main.json_to_builder(); |
| 324 |
$( ".builder-row-container-row" ).each(function( index ) { |
| 325 |
if( $(this).attr("background_full") != "not" ){ |
| 326 |
$(this).closest(".builder-row-container").css("background-color",$(this).css("background-color")); |
| 327 |
} |
| 328 |
}); |
| 329 |
}).fail(function(){ |
| 330 |
alert("Error"); |
| 331 |
}); |
| 332 |
}) |
| 333 |
.open(); |
| 334 |
}); |
| 335 |
$("body").on("click",".yeemail-builder-export",function(){ |
| 336 |
$("<a />", { |
| 337 |
"download": "yeemail_template.json", |
| 338 |
"href" : "data:text/plain;charset=utf-8," + encodeURIComponent(JSON.stringify($(".yeemail_data_email").val())) |
| 339 |
}).appendTo("body") |
| 340 |
.click(function() { |
| 341 |
$(this).remove() |
| 342 |
})[0].click(); |
| 343 |
}) |
| 344 |
$("body").on("click",".yeemail-builder-choose-template",function(e){ |
| 345 |
e.preventDefault(); |
| 346 |
$( "#yeemail-builder-templates" ).dialog({ |
| 347 |
modal: true, |
| 348 |
width: 900, |
| 349 |
title: "Templates", |
| 350 |
buttons: { |
| 351 |
Close: function() { |
| 352 |
$( this ).dialog( "close" ); |
| 353 |
} |
| 354 |
} |
| 355 |
}); |
| 356 |
return false; |
| 357 |
}) |
| 358 |
$("body").on("click",".yeemail-builder-choose-shortcodes",function(e){ |
| 359 |
e.preventDefault(); |
| 360 |
$( "#yeemail-builder-shortcodes-templates" ).dialog({ |
| 361 |
modal: true, |
| 362 |
width: 800, |
| 363 |
title: "All Shortcodes", |
| 364 |
buttons: { |
| 365 |
Close: function() { |
| 366 |
$( this ).dialog( "close" ); |
| 367 |
} |
| 368 |
} |
| 369 |
}); |
| 370 |
return false; |
| 371 |
}) |
| 372 |
$("body").on("click",".yeemail-builder-choose-test-email",function(e){ |
| 373 |
e.preventDefault(); |
| 374 |
$( "#yeemail-builder-templates-test-email" ).dialog({ |
| 375 |
modal: true, |
| 376 |
width: 500, |
| 377 |
title: "Test Email", |
| 378 |
buttons: { |
| 379 |
Close: function() { |
| 380 |
$( this ).dialog( "close" ); |
| 381 |
} |
| 382 |
} |
| 383 |
}); |
| 384 |
return false; |
| 385 |
}) |
| 386 |
$("body").on("click",".yeemail-builder-actions-import",function(e){ |
| 387 |
e.preventDefault(); |
| 388 |
var attachment = $(this).closest(".grid-item").data("file"); |
| 389 |
$.getJSON(attachment, function(data){ |
| 390 |
$(".yeemail_data_email").val(data); |
| 391 |
$(".builder__list").html(""); |
| 392 |
yeemail_builder_main.json_to_builder(); |
| 393 |
$( ".builder-row-container-row" ).each(function( index ) { |
| 394 |
if( $(this).attr("background_full") != "not" ){ |
| 395 |
$(this).closest(".builder-row-container").css("background-color",$(this).css("background-color")); |
| 396 |
} |
| 397 |
}); |
| 398 |
$( "#yeemail-builder-templates" ).dialog( "close" ); |
| 399 |
}).fail(function(){ |
| 400 |
alert("Error"); |
| 401 |
}); |
| 402 |
}) |
| 403 |
$('body').on("click",".yeemail-builder-choose-blank",function(e){ |
| 404 |
e.preventDefault(); |
| 405 |
if (confirm("Changes you made will be lost.") == true) { |
| 406 |
$.getJSON(yeemail_script.yeemail_url_plugin + "backend/demo/yeemail_template0.json", function(data){ |
| 407 |
$(".yeemail_data_email").val(data); |
| 408 |
$(".builder__list").html(""); |
| 409 |
yeemail_builder_main.json_to_builder(); |
| 410 |
$( ".builder-row-container-row" ).each(function( index ) { |
| 411 |
if( $(this).attr("background_full") != "not" ){ |
| 412 |
$(this).closest(".builder-row-container").css("background-color",$(this).css("background-color")); |
| 413 |
} |
| 414 |
}); |
| 415 |
}).fail(function(){ |
| 416 |
alert("Error"); |
| 417 |
}); |
| 418 |
} |
| 419 |
}) |
| 420 |
$('body').on("click",".yeemail-builder-choose-reset",function(e){ |
| 421 |
e.preventDefault(); |
| 422 |
if (confirm("All changes you made won't be saved.") == true) { |
| 423 |
var id = $("#post_ID").val(); |
| 424 |
var data = { |
| 425 |
'action': 'yeemail_builder_reset_template', |
| 426 |
'id': id, |
| 427 |
'nonce': yeemail_script.nonce, |
| 428 |
}; |
| 429 |
jQuery.post(ajaxurl, data, function(response) { |
| 430 |
window.location.reload(true); |
| 431 |
}); |
| 432 |
} |
| 433 |
}) |
| 434 |
$("body").on("click",".yeemail-builder-expand",function(e){ |
| 435 |
e.preventDefault(); |
| 436 |
var type = $(this).data("type"); |
| 437 |
if( type == "left"){ |
| 438 |
$(".builder__widget").effect( "size", { |
| 439 |
to: { width: 900, } |
| 440 |
}, 500 ); |
| 441 |
$(this).closest('div').find(".yeemail-builder-shrink").removeClass("hidden"); |
| 442 |
$(this).addClass('hidden'); |
| 443 |
}else{ |
| 444 |
$("#poststuff #post-body.columns-2").css("margin-right","300px"); |
| 445 |
$(".yeemail-builder-slide").removeClass('hidden'); |
| 446 |
$(".yeemail_builder-expand-right").addClass('hidden'); |
| 447 |
} |
| 448 |
}) |
| 449 |
$("body").on("click",".yeemail-builder-shrink",function(e){ |
| 450 |
e.preventDefault(); |
| 451 |
var type = $(this).data("type"); |
| 452 |
if( type == "left"){ |
| 453 |
$(".builder__widget").effect( "size", { |
| 454 |
to: { width: 420, } |
| 455 |
}, 500 ); |
| 456 |
$(this).closest('div').find(".yeemail-builder-expand").removeClass("hidden"); |
| 457 |
$(this).addClass('hidden'); |
| 458 |
}else{ |
| 459 |
$("#poststuff #post-body.columns-2").css("margin-right","0"); |
| 460 |
$(".yeemail-builder-slide").addClass('hidden'); |
| 461 |
$(".yeemail_builder-expand-right").removeClass('hidden'); |
| 462 |
} |
| 463 |
}) |
| 464 |
}) |
| 465 |
})(jQuery); |