PluginProbe
YeeMail — Email Template Builder & Customizer / trunk
YeeMail — Email Template Builder & Customizer vtrunk
3.0.1 2.2.1 3.0.0 2.2.0 trunk 2.0.0 2.0.3 2.0.5 2.0.8 2.1.6 2.1.7 2.1.8
yeemail / backend / src / set_editor.js

set_editor.js in YeeMail — Email Template Builder & Customizer trunk, at backend/src/set_editor.js

344 lines 16.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2 "use strict";
3 $( document ).ready( function () {
4 var ajax_change_editor = null;
5 function formatState_data (state) {
6 if (!state.id) {
7 return state.text;
8 }
9 var baseUrl = "/user/pages/images/flags";
10 var data_class = $(state.element).data("class");
11 var $state = $(
12 '<span class="slect-main-rs"><span class="'+data_class+'"></span> ' + state.text + '</span>'
13 );
14 return $state;
15 };
16 $('.yeemail_choose_template_status').select2({
17 templateResult: formatState_data,
18 minimumResultsForSearch: -1,
19 width: '100%',
20 containerCssClass: "yeemail_select_width"
21 });
22 $('.builder__editor1 select').select2({
23 minimumResultsForSearch: -1
24 });
25 //upload IMG
26 $('body').on('click', '.upload-editor--image', function(e){
27 e.preventDefault();
28 var input = $(this).closest(".builder__editor--button-url").find(".image_url");
29 var button = $(this),
30 custom_uploader = wp.media({
31 title: 'Insert image',
32 library : {
33 type : 'image'
34 },
35 button: {
36 text: 'Use this image' // button label text
37 },
38 multiple: false // for multiple image selection set to true
39 }).on('select', function() { // it also has "open" and "close" events
40 var attachment = custom_uploader.state().get('selection').first().toJSON();
41 input.val(attachment.url).change();
42 var img = new Image();
43 img.src = attachment.url;
44 img.onload = function() {
45 var pr_width = $(".yeemail_builder_focus").width();
46 pr_width = Math.round( pr_width);
47 var width = Math.round( this.width);
48 var height = Math.round( this.height);
49 if( width > pr_width ){
50 var pe = Math.round(width / pr_width);
51 $(".builder__editor--item-width .text_width").val(pr_width);
52 $(".builder__editor--item-height .text_height").val(Math.round(height/pe)).change();
53 }else{
54 $(".builder__editor--item-width .text_width").val(width);
55 $(".builder__editor--item-height .text_height").val(height).change();
56 }
57 }
58 })
59 .open();
60 });
61 //Menu
62 $('body').on("click",".yeemail_builder_add_menu",function(e){
63 e.preventDefault();
64 var data =$(".builder__editor--item-menu-hidden").html();
65 $(".menu-content-tool>ul").append("<li class='data'>"+data+"</li>");
66 $('.menu-content-tool .text_background,.menu-content-tool .text_color').wpColorPicker({
67 change: function(event, ui){
68 $(".yeemail_builder_focus").yeemail_set_type_editor();
69 if( $(".yeemail_builder_focus").attr("background_full") == "ok" ){
70 $(".yeemail_builder_focus").closest(".builder-row-container").css("background-color",$(".yeemail_builder_focus").css("background-color"));
71 }else{
72 $(".yeemail_builder_focus").closest(".builder-row-container").css("background-color","transparent");
73 }
74 }
75 });
76 })
77 //Editor Change
78 $('body').on("change keyup",".builder__editor input, .builder__editor--item input, .builder__editor--item select, .builder__editor--item textarea",function(e){
79 $(".yeemail_builder_focus").yeemail_set_type_editor();
80 if( $(".yeemail_builder_focus").attr("background_full") == "ok" ){
81 $(".yeemail_builder_focus").closest(".builder-row-container").css("background-color",$(".yeemail_builder_focus").css("background-color"));
82 }else{
83 $(".yeemail_builder_focus").closest(".builder-row-container").css("background-color","transparent");
84 }
85 })
86 $('body').on("change",".yeemail_settings_update",function(e){
87 e.preventDefault();
88 var id = $(this).val();
89 var status = "disable";
90 if($(this).is(':checked')){
91 status = "enable";
92 }
93 var data = {
94 'action': 'yeemail_update_settings_template',
95 'id': id,
96 'status': status,
97 'nonce': yeemail_script.nonce
98 };
99 $.post(ajaxurl, data, function(response) {
100 if(status == "enable"){
101 $(".yeemail_settings_update-"+id).prop('checked', true);
102 }else{
103 $(".yeemail_settings_update-"+id).prop('checked', false);
104 }
105 });
106 //sync 2 checkbox
107 })
108 //set width container
109 $('body').on("change keyup",".builder__editor--item-setting_width .text_width",function(e){
110 e.preventDefault();
111 var width = $(this).val();
112 if(width < 480){
113 width = 480;
114 }
115 if(width > 900){
116 width = 900;
117 }
118 $(".builder-row-container-row").css("width",width);
119 })
120 //align
121 $('body').on("click",".builder__editor--align a",function(e){
122 e.preventDefault();
123 $(".builder__editor--align a").removeClass("active");
124 $(this).addClass("active");
125 var vl = $(this).data("value");
126 $(this).closest(".builder__editor--align").find(".text_align").val(vl).change();
127 })
128 $("body").on("click",".builder__editor--js",function(e){
129 tinymce.execCommand('mceToggleEditor', false, 'content');
130 })
131 //text
132 tinymce.init({
133 selector: '.builder__editor--js',
134 mode: 'exact',
135 content_style: "body { font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;background:#eeeeee;} h1,h2,h3,h4,h5,h6 { font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; }",
136 font_formats: yeemail_script.google_font_font_formats,
137 height: 'auto',
138 skin: "lightgray",
139 theme: "modern",
140 menubar: false,
141 statusbar: false,
142 relative_urls: false,
143 remove_script_host: false,
144 convert_urls: false,
145 forced_root_block : false,
146 plugins: ["link textcolor colorpicker image code_toggle"],
147 toolbar:
148 [
149 'bold italic underline | fontselect styleselect',
150 'fontsizeselect | forecolor | backcolor | link image',
151 'yeemail_shortcode | code_toggle'
152 ],
153 fontsize_formats: '10px 11px 12px 13px 14px 15px 16px 17px 18px 19px 20px 22px 24px 26px 28px 30px 35px 40px 50px 60px',
154 setup:function(ed) {
155 var full_shortcodes = [];
156 $.each(yeemail_script.shortcodes, function( index_1, values_1 ) {
157 var menu1 = [];
158 $.each(values_1, function( index_2, value_2 ) {
159 if (typeof value_2 === 'object' && value_2 !== null){
160 var menu2 = [];
161 $.each(value_2, function( index_3, value_3 ) {
162 menu2.push({"text":value_3,onclick: function() {
163 if( index_3.search("{") <0) {
164 ed.insertContent("["+index_3+"]");
165 }else{
166 ed.insertContent(index_3);
167 }
168 }});
169 });
170 menu1.push({"text":index_2,"menu":menu2});
171 }else{
172 menu1.push({"text":value_2,onclick: function() {
173 if( index_2.search("{") <0) {
174 ed.insertContent("["+index_2+"]");
175 }else{
176 ed.insertContent(index_2);
177 }
178 }});
179 }
180 });
181 full_shortcodes.push({"text": index_1, "menu":menu1 });
182 });
183 ed.addButton('yeemail_shortcode', {
184 text: 'Shortcodes',
185 type: "menubutton",
186 menu: full_shortcodes,
187 });
188 ed.addButton('icons', {
189 onclick: function() {
190 ed.windowManager.open( {
191 title: 'Insert icon',
192 body: [{
193 type: 'textbox',
194 name: 'icon',
195 label: 'Icon'
196 },
197 {
198 type: 'textbox',
199 name: 'size',
200 label: 'Size'
201 },
202 {
203 type: 'textbox',
204 name: 'color',
205 label: 'Color'
206 },
207 ],
208 onsubmit: function( e ) {
209 ed.insertContent( '&lt;h3&gt;' + e.data.title + '&lt;/h3&gt;');
210 }
211 });
212 }
213 });
214 ed.on('keyup paste change', function(e) {
215 $(".builder-elements-content.yeemail_builder_focus .text-content-data").html(ed.getContent());
216 $(".builder-elements-content.yeemail_builder_focus .text-content").html($.yeemail_replace_shorcode(ed.getContent()));
217 });
218 }
219 });
220 //color
221 $('.builder__editor_color').wpColorPicker({
222 change: function(event, ui){
223 $(".yeemail_builder_focus").yeemail_set_type_editor();
224 if( $(".yeemail_builder_focus").attr("background_full") == "ok" ){
225 $(".yeemail_builder_focus").closest(".builder-row-container").css("background-color",$(".yeemail_builder_focus").css("background-color"));
226 }else{
227 $(".yeemail_builder_focus").closest(".builder-row-container").css("background-color","transparent");
228 }
229 }
230 });
231 //color link
232 $('.builder__editor_color_link').wpColorPicker({
233 change: function(event, ui){
234 $("#poststuff .yeemail-builder-main a").css("color",ui.color.toString());
235 }
236 });
237 $.selector_element = function(){
238 var button_tab = $('.builder__tab li a');
239 button_tab.each(function () {
240 var button = $(this);
241 if(button.attr('id') == '#tab__editor' ) {
242 $('.builder__tab li a').removeClass('active');
243 button.addClass('active');
244 var tab = $(button.attr('id'));
245 $('.tab__content').hide();
246 tab.show();
247 }
248 });
249 $('.builder__toolbar').remove();
250 $(".builder__editor--item").addClass("hidden");
251 $("div").removeClass("yeemail_builder_focus").removeClass("yeemail_builder_show");
252 }
253 ///Get ----------------------------------------
254 $('body').on("click",".yeemail-builder-main-change_backgroud",function(e){
255 e.preventDefault();
256 e.stopPropagation();
257 if(!yeemail_script.disable_builder){
258 $.selector_element();
259 $(".yeemail-builder-main").addClass("yeemail_builder_focus yeemail_builder_show");
260 $(".yeemail-builder-main").yeemail_load_type_editor(true);
261 }
262 })
263 //settings
264 $('body').on("click",".yeemail_button_settings",function(e){
265 e.preventDefault();
266 e.stopPropagation();
267 if(!yeemail_script.disable_builder){
268 $.selector_element();
269 $(".yeemail-builder-main").addClass("yeemail_builder_focus yeemail_builder_show");
270 $(".yeemail-builder-main").yeemail_load_type_editor(true);
271 }
272 })
273 $('body').on("change",".yeemail_choose_template_status",function(e){
274 e.preventDefault();
275 if (confirm("You need to save data before switching to another template!") == true) {
276 var url = $(this).find(':selected').data('link');
277 window.location = url;
278 }
279 })
280 $('body').on("click",".builder__widget_tab_title",function(e){
281 e.preventDefault();
282 $(this).toggleClass("yeemail_tab_hide");
283 $(this).closest(".builder__widget_tab").find("ul").slideToggle();
284 })
285 //click out
286 $('body').on("click",".builder__tab,.yeemail-builder-slide,.builder-actions,#builder-header,#titlediv",function(e){
287 $("div").removeClass('yeemail_builder_show yeemail_builder_focus');
288 $("div").remove(".builder__toolbar");
289 $(".builder__editor--item").addClass('hidden');
290 })
291 $('body').on("click",".builder-elements-content",function(e){
292 e.preventDefault();
293 e.stopPropagation();
294 if(!yeemail_script.disable_builder){
295 $.selector_element();
296 var toolbar= $('<div class="builder__toolbar">' +
297 '<div class="momongaDragHandle"><i class="yeemail_builder-icon icon-menu-1"></i></div>' +
298 '<div class="momongaEdit"><i class="yeemail_builder-icon icon-pencil"></i></div>' +
299 '<div class="momongaDuplicate"><i class="yeemail_builder-icon icon-docs"></i></div>' +
300 '<div class="momongaDelete"><i class="yeemail_builder-icon icon-trash"></i></div>' +
301 '</div>');
302 $(this).addClass("yeemail_builder_focus");
303 $(this).closest(".builder-row-container").addClass("yeemail_builder_show");
304 $(this).append(toolbar.clone());
305 $(this).closest(".builder-row-container").append(toolbar);
306 $(this).yeemail_load_type_editor();
307 }
308 })
309 $("body").on("click",".momongaEdit",function(e){
310 e.preventDefault();
311 $(this).closest('.builder__toolbar').parent( ".builder-row-container").find(".builder-row-container-row").click();
312 })
313 $('body').on("click",".builder-row-container-row",function(e){
314 e.preventDefault();
315 e.stopPropagation();
316 if(!yeemail_script.disable_builder){
317 $.selector_element();
318 var toolbar= $('<div class="builder__toolbar">' +
319 '<div class="momongaDragHandle"><i class="yeemail_builder-icon icon-menu-1"></i></div>' +
320 '<div class="momongaEdit"><i class="yeemail_builder-icon icon-pencil"></i></div>' +
321 '<div class="momongaDuplicate"><i class="yeemail_builder-icon icon-docs"></i></div>' +
322 '<div class="momongaDelete"><i class="yeemail_builder-icon icon-trash"></i></div>' +
323 '</div>');
324 $(this).addClass("yeemail_builder_focus");
325 $(this).closest(".builder-row-container").addClass('yeemail_builder_show');
326 $(this).closest(".builder-row-container").removeClass('.builder-row-empty');
327 $.check_row_empty();
328 $(this).closest(".builder-row-container").append(toolbar);
329 $(this).yeemail_load_type_editor(true);
330 }
331 })
332 $.check_row_empty = function() {
333 $( ".builder-row-container" ).each(function( index ) {
334 $(this ).find(".builder-row").each(function( index ) {
335 var check = $(this).find('.builder-elements');
336 if( check.length > 0 ){
337 $(this).removeClass('builder-row-empty');
338 $(this).closest('.builder-row-container').removeClass('builder-row-empty');
339 }
340 })
341 });
342 }
343 })
344 })(jQuery);