library_scripts.js
8.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
(function($){
$( document ).ready( function() {
var url = window.location.href,
tab_link = url.split( 'edit.php' )[1];
if ( typeof tab_link !== 'undefined' ) {
var $menu_items = $( '#toplevel_page_et_divi_library' ).find( '.wp-submenu li' );
$menu_items.removeClass( 'current' );
$menu_items.find( 'a' ).each( function() {
var $this_el = $( this ),
this_href = $this_el.attr( 'href' ),
full_tab_link = 'edit.php' + tab_link;
if ( -1 !== full_tab_link.indexOf( this_href ) ) {
$this_el.closest( 'li' ).addClass( 'current' );
}
});
$( '#toplevel_page_et_divi_library' ).removeClass( 'wp-not-current-submenu' ).addClass( 'wp-has-current-submenu' );
$( 'a.toplevel_page_et_divi_library' ).removeClass( 'wp-not-current-submenu' ).addClass( 'wp-has-current-submenu wp-menu-open' );
}
$( 'body' ).on( 'click', '.add-new-h2, a.page-title-action', function() {
var all_cats = $.parseJSON( et_pb_new_template_options.layout_cats ),
$modal = '',
cats_selector = '<label>' + et_pb_new_template_options.cats_label + '</label>';
if( ! $.isEmptyObject( all_cats ) ) {
cats_selector += '<div class="layout_cats_container">';
$.each( all_cats, function( i, single_cat ) {
if ( ! $.isEmptyObject( single_cat ) ) {
cats_selector += '<label>' + single_cat.name + '<input type="checkbox" value="' + single_cat.id + '"/></label>';
}
});
cats_selector += '</div>';
}
cats_selector += '<input type="text" value="" id="et_pb_new_cat_name" class="regular-text">';
$modal = "<div class='et_pb_modal_overlay et_modal_on_top et_pb_new_template_modal'>\
<div class='et_pb_prompt_modal'>\
<h2>" + et_pb_new_template_options.modal_text + "</h2>\
<div class='et_pb_prompt_modal_inside'>\
<label>" + et_pb_new_template_options.modal_name + "</label> \
<input type='text' value='' id='et_pb_new_template_name' class='regular-text'>\
<label>" + et_pb_new_template_options.modal_type + "</label> \
<select id='new_template_type'>\
<option value='module'>" + et_pb_new_template_options.module_text + "</option>\
<option value='fullwidth_module'>" + et_pb_new_template_options.fw_module_text + "</option>\
<option value='row'>" + et_pb_new_template_options.row_text + "</option>\
<option value='section'>" + et_pb_new_template_options.section_text + "</option>\
<option value='fullwidth_section'>" + et_pb_new_template_options.fw_section_text + "</option>\
<option value='specialty_section'>" + et_pb_new_template_options.sp_section_text + "</option>\
<option value='layout'>" + et_pb_new_template_options.layout_text + "</option>\
</select>\
<div class='et_module_tabs_options'>\
<label>" + et_pb_new_template_options.general_text + "<input type='checkbox' value='general' id='et_pb_template_general' checked /></label> \
<label>" + et_pb_new_template_options.adv_text + "<input type='checkbox' value='advanced' id='et_pb_template_general' checked /></label> \
<label>" + et_pb_new_template_options.css_text + "<input type='checkbox' value='css' id='et_pb_template_general' checked /></label> \
<p class='et_pb_error_message_save_template' style='display: none;'>" + et_pb_new_template_options.tabs_error + "</p> \
</div>\
<label>" + et_pb_new_template_options.global_text + "<input type='checkbox' value='' id='et_pb_template_global'></label>\
" + cats_selector + " \
<input id='et_builder_layout_built_for_post_type' type='hidden' value='et_pb_layout'>\
</div>\
<a href='#' class='et_pb_prompt_dont_proceed et-pb-modal-close'></a>\
<div class='et_pb_prompt_buttons'>\
<br>\
<span class='spinner'></span>\
<input type='submit' class='et_pb_create_template button-primary et_pb_prompt_proceed'>\
</div>";
$( 'body' ).append( $modal );
return false;
} );
$( 'body' ).on( 'click', '.et_pb_prompt_dont_proceed', function() {
$( this ).closest( '.et_pb_modal_overlay' ).remove();
} );
$( 'body' ).on( 'change', '#new_template_type', function() {
var selected_type = $( this ).val();
if ( 'module' === selected_type || 'fullwidth_module' === selected_type ) {
$( '.et_module_tabs_options' ).css( 'display', 'block' );
} else {
$( '.et_module_tabs_options' ).css( 'display', 'none' );
}
} );
$( 'body' ).on( 'click', '.et_pb_create_template:not(.clicked_button)', function() {
var $this_button = $( this ),
$this_form = $this_button.closest( '.et_pb_prompt_modal' ),
template_name = $this_form.find( '#et_pb_new_template_name' ).val();
if ( '' === template_name ) {
$this_form.find( '#et_pb_new_template_name' ).focus();
} else {
var template_shortcode = '',
layout_scope = $this_form.find( $( '#et_pb_template_global' ) ).is( ':checked' ) ? 'global' : 'not_global',
layout_type = $this_form.find( '#new_template_type' ).val(),
module_width = 'regular',
template_built_for_post_type = '',
selected_tabs = '',
selected_cats = '',
new_cat = $this_form.find( '#et_pb_new_cat_name' ).val();
if ( 'module' === layout_type || 'fullwidth_module' === layout_type ) {
if ( ! $( '.et_module_tabs_options input' ).is( ':checked' ) ) {
$( '.et_pb_error_message_save_template' ).css( "display", "block" );
return;
} else {
selected_tabs = '';
$( '.et_module_tabs_options input' ).each( function() {
var this_input = $( this );
if ( this_input.is( ':checked' ) ) {
selected_tabs += '' !== selected_tabs ? ',' + this_input.val() : this_input.val();
}
});
selected_tabs = 'general,advanced,css' === selected_tabs ? 'all' : selected_tabs;
}
}
if ( $( '.layout_cats_container input' ).is( ':checked' ) ) {
$( '.layout_cats_container input' ).each( function() {
var this_input = $( this );
if ( this_input.is( ':checked' ) ) {
selected_cats += '' !== selected_cats ? ',' + this_input.val() : this_input.val();
}
});
}
switch ( layout_type ) {
case 'row' :
template_shortcode = '[et_pb_row template_type="row"][/et_pb_row]';
break;
case 'section' :
template_shortcode = '[et_pb_section template_type="section"][et_pb_row][/et_pb_row][/et_pb_section]';
break;
case 'module' :
template_shortcode = '[et_pb_module_placeholder selected_tabs="' + selected_tabs + '"]';
break;
case 'fullwidth_module' :
template_shortcode = '[et_pb_fullwidth_module_placeholder selected_tabs="' + selected_tabs + '"]';
module_width = 'fullwidth';
layout_type = 'module';
break;
case 'fullwidth_section' :
template_shortcode = '[et_pb_section template_type="section" fullwidth="on"][/et_pb_section]';
layout_type = 'section';
break;
case 'specialty_section' :
template_shortcode = '[et_pb_section template_type="section" specialty="on" skip_module="true" specialty_placeholder="true"][/et_pb_section]';
layout_type = 'section';
break;
}
$this_button.addClass( 'clicked_button' );
$this_button.closest( '.et_pb_prompt_buttons' ).find( '.spinner' ).addClass( 'et_pb_visible_spinner' );
$.ajax( {
type: "POST",
url: et_pb_new_template_options.ajaxurl,
dataType: 'json',
data:
{
action : 'et_pb_save_layout',
et_load_nonce : et_pb_new_template_options.et_load_nonce,
et_layout_name : template_name,
et_layout_built_for_post_type: template_built_for_post_type,
et_layout_content : template_shortcode,
et_layout_scope : layout_scope,
et_layout_type : layout_type,
et_module_width : module_width,
et_layout_cats : selected_cats,
et_layout_new_cat : new_cat
},
success: function( data ) {
window.location.href = decodeURIComponent( unescape( data.edit_link ) );
}
} );
}
} );
$( '#et_show_export_section' ).click( function() {
var this_link = $( this ),
margin_value = this_link.hasClass( 'et_pb_opened' ) ? '-100%' : '0';
$( '.et_pb_export_section' ).animate( { marginTop: margin_value }, 500 );
this_link.toggleClass( 'et_pb_opened' );
});
});
})(jQuery)