PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.6
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.6
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / assets / lib / wck-api / wordpress-creation-kit.js

wordpress-creation-kit.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.9.6, at assets/lib/wck-api/wordpress-creation-kit.js

389 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* Add width to elements at startup */
2 jQuery(function(){
3 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
4 });
5
6 /* Add width to labels if the post box is closed at load */
7 jQuery(function(){
8
9 /* Callback version */
10 /* postboxes.pbshow = function(box){
11 jQuery('strong, .field-label', jQuery('#'+box)).css( 'width', 'auto' );
12 } */
13
14 jQuery( '.wck-post-box .hndle' ).on( 'click', function(){
15 jQuery('strong, .field-label', jQuery(this).parent() ).css( 'width', 'auto' );
16 })
17
18 });
19
20
21
22
23 /* add reccord to the meta */
24 function addMeta(value, id, nonce){
25
26 /* if tinyMCE then trigger save. save puts the content in the hidden textarea */
27 if( typeof tinyMCE !== 'undefined' )
28 tinyMCE.triggerSave();
29
30 jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
31 /*object to hold the values */
32 var values = {};
33
34 jQuery('#'+value+' .mb-field').each(function(){
35
36 var key = jQuery(this).attr('name');
37
38 if(jQuery(this).attr('type') == 'checkbox' || jQuery(this).attr('type') == 'radio' ) {
39
40 if( typeof values[key.toString()] === "undefined" )
41 values[key.toString()] = '';
42
43 if(jQuery(this).is(':checked')){
44 if( values[key.toString()] == '' )
45 values[key.toString()] += jQuery(this).val().toString();
46 else
47 values[key.toString()] += ', ' + jQuery(this).val().toString();
48 }
49 }
50
51 else
52 values[key.toString()] = jQuery(this).val().toString();
53 });
54
55 meta = value;
56
57 if( value.indexOf("-wcknested-") != -1 ){
58 metaDetails = value.split("-wcknested-");
59 meta = metaDetails[0];
60 }
61
62 jQuery.post( wppbWckAjaxurl , { action:"wck_add_meta"+meta, meta:value, id:id, values:values, _ajax_nonce:nonce}, function(response) {
63
64 jQuery( '#'+value+' .field-label').removeClass('error');
65
66 if( response.error ){
67 jQuery('#'+value).parent().css('opacity','1');
68 jQuery('#mb-ajax-loading').remove();
69
70 jQuery.each( response.errorfields, function (index, field) {
71 jQuery( '#'+value+' .field-label[for="' + field + '"]' ).addClass('error');
72 });
73
74 alert( response.error );
75 }
76 else{
77 /* refresh the list */
78 jQuery('#container_'+value).replaceWith(response.entry_list);
79
80 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
81
82 if( !jQuery( '#'+value ).hasClass('single') )
83 mb_sortable_elements();
84
85 /* restore the add form to the original values */
86 if( !jQuery( '#'+value ).hasClass('single') ){
87 jQuery( '#'+value ).replaceWith( response.add_form );
88 jQuery('#'+value).parent().css('opacity','1');
89 jQuery('#mb-ajax-loading').remove();
90 }
91 else{
92 jQuery('#'+value).parent().css('opacity','1');
93 jQuery('#mb-ajax-loading').remove();
94 }
95
96 jQuery('body').trigger('wck-added-element');
97
98 }
99 });
100
101 }
102
103 /* remove reccord from the meta */
104 function removeMeta(value, id, element_id, nonce){
105
106 var response = confirm( "Delete this item ?" );
107
108 if( response == true ){
109
110 meta = value;
111
112 if( value.indexOf("-wcknested-") != -1 ){
113 metaDetails = value.split("-wcknested-");
114 meta = metaDetails[0];
115 }
116
117 jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
118 jQuery.post( wppbWckAjaxurl , { action:"wck_remove_meta"+meta, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) {
119
120 /* If single add the form */
121 if( jQuery( '#container_'+value ).hasClass('single') ){
122 jQuery( '#container_'+value ).before( response.add_form );
123 jQuery( '#'+value ).addClass('single');
124 }
125
126 /* refresh the list */
127 jQuery('#container_'+value).replaceWith(response.entry_list);
128
129 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
130
131 mb_sortable_elements();
132 jQuery('#'+value).parent().css('opacity','1');
133 jQuery('#mb-ajax-loading').remove();
134
135 });
136 }
137 }
138
139 /* swap two reccords */
140 /*function swapMetaMb(value, id, element_id, swap_with){
141 jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
142 jQuery.post( wppbWckAjaxurl , { action:"swap_meta_mb", meta:value, id:id, element_id:element_id, swap_with:swap_with}, function(response) {
143
144 jQuery.post( wppbWckAjaxurl , { action:"refresh_list", meta:value, id:id}, function(response) {
145 jQuery('#container_'+value).replaceWith(response); jQuery('#'+value).parent().css('opacity','1'); jQuery('#mb-ajax-loading').remove();
146 });
147
148 });
149 }
150 */
151
152 /* reorder elements through drag and drop */
153 function mb_sortable_elements() {
154 jQuery( ".mb-table-container tbody" ).not( jQuery( ".mb-table-container.single tbody, .mb-table-container.not-sortable tbody" ) ).sortable({
155 placeholder: "wck-state-highlight",
156 update: function(event, ui){
157
158 var value = jQuery(this).parent().siblings('.wck-add-form').attr('id');
159 var id = jQuery(this).parent().attr('post');
160
161 var result = jQuery(this).sortable('toArray');
162
163 var values = {};
164 for(var i in result)
165 {
166 values[i] = result[i].replace('element_','');
167 }
168
169 jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
170
171 meta = value;
172
173 if( value.indexOf("-wcknested-") != -1 ){
174 metaDetails = value.split("-wcknested-");
175 meta = metaDetails[0];
176 }
177
178
179 jQuery.post( wppbWckAjaxurl , { action:"wck_reorder_meta"+meta, meta:value, id:id, values:values}, function(response) {
180 jQuery('#container_'+value).replaceWith(response.entry_list);
181
182 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
183
184 mb_sortable_elements();
185 jQuery('#'+value).parent().css('opacity','1');
186 jQuery('#mb-ajax-loading').remove();
187 });
188 },
189 items: "> tr"
190 });
191 /*I don't know if this is necessary. Remove when I have more time for tests */
192 jQuery( "#sortable:not(select)" ).disableSelection();
193
194
195 jQuery('.mb-table-container ul').on( 'mousedown', function(e){
196 e.stopPropagation();
197 });
198 }
199 jQuery(mb_sortable_elements);
200
201
202
203 /* show the update form */
204 function showUpdateFormMeta(value, id, element_id, nonce){
205 if( jQuery( '#update_container_' + value + '_' + element_id ).length == 0 ){
206 jQuery('#container_'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
207
208 if( jQuery( '#container_' + value + " tbody" ).hasClass('ui-sortable') )
209 jQuery( '#container_' + value + " tbody" ).sortable("disable");
210
211
212 meta = value;
213
214 if( value.indexOf("-wcknested-") != -1 ){
215 metaDetails = value.split("-wcknested-");
216 meta = metaDetails[0];
217 }
218
219
220 jQuery.post( wppbWckAjaxurl , { action:"wck_show_update"+meta, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) {
221 //jQuery('#container_'+value+' #element_'+element_id).append(response);
222 jQuery(response).insertAfter('#container_'+value+' > tbody > #element_'+element_id);
223
224 jQuery('#container_'+value).parent().css('opacity','1');
225 jQuery('#mb-ajax-loading').remove();
226 wckGoToByScroll('update_container_' + value + '_' + element_id);
227
228 // Allow for extra client-side hooks to be executed.
229 jQuery('html').trigger('wpbFormMetaLoaded', meta);
230 });
231 }
232 }
233
234 /* remove the update form */
235 function removeUpdateForm( id ){
236 jQuery('html, body').animate({
237 scrollTop: jQuery( '#'+id).prev().offset().top - 40 }, 700);
238
239 jQuery( '#'+id).prev().animate({
240 backgroundColor: '#FFFF9C'
241 }, 700);
242 jQuery( '#'+id).prev().animate({
243 backgroundColor: 'none'
244 }, 700);
245
246 if( jQuery( '#'+id).parent('tbody').hasClass('ui-sortable') )
247 jQuery( '#'+id).parent('tbody').sortable("enable");
248
249 jQuery( '#'+id ).remove();
250 }
251
252 /* update reccord */
253 function updateMeta(value, id, element_id, nonce){
254
255 /* if tinyMCE then trigger save. save puts the content in the hidden textarea */
256 if( typeof tinyMCE !== 'undefined' )
257 tinyMCE.triggerSave();
258
259 jQuery('#container_'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
260 var values = {};
261 jQuery('#update_container_'+value+'_'+element_id+' .mb-field').each(function(){
262 var key = jQuery(this).attr('name');
263
264 if(jQuery(this).attr('type') == 'checkbox' || jQuery(this).attr('type') == 'radio' ) {
265
266 if( typeof values[key.toString()] === "undefined" )
267 values[key.toString()] = '';
268
269 if(jQuery(this).is(':checked')){
270 if( values[key.toString()] == '' )
271 values[key.toString()] += jQuery(this).val().toString();
272 else
273 values[key.toString()] += ', ' + jQuery(this).val().toString();
274 }
275 }
276
277 else
278 values[key.toString()] = jQuery(this).val().toString();
279
280 });
281
282
283 meta = value;
284
285 if( value.indexOf("-wcknested-") != -1 ){
286 metaDetails = value.split("-wcknested-");
287 meta = metaDetails[0];
288 }
289
290
291 jQuery.post( wppbWckAjaxurl , { action:"wck_update_meta"+meta, meta:value, id:id, element_id:element_id, values:values, _ajax_nonce:nonce}, function(response) {
292
293 jQuery( '#update_container_'+value+'_'+element_id + ' .field-label').removeClass('error');
294
295 if( response.error ){
296 jQuery('#container_'+value).parent().css('opacity','1');
297 jQuery('#mb-ajax-loading').remove();
298
299 jQuery.each( response.errorfields, function (index, field) {
300 jQuery( '#update_container_'+value+'_'+element_id + ' .field-label[for="' + field + '"]' ).addClass('error');
301 });
302
303 alert( response.error );
304 }
305 else{
306
307 jQuery('#update_container_'+value+'_'+element_id).remove();
308
309 /* refresh the list */
310 jQuery('#container_'+value+' #element_'+element_id).replaceWith(response.entry_content);
311
312 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
313
314 if( jQuery( '#container_' + value + " tbody" ).hasClass('ui-sortable') && jQuery( '#container_' + value + " tbody .wck_update_container" ).length == 0 )
315 jQuery( '#container_' + value + " tbody" ).sortable("enable");
316
317 jQuery('#container_'+value).parent().css('opacity','1');
318 jQuery('#mb-ajax-loading').remove();
319
320 //the scroll works a little bit funny ( it goes way up then down, prob because we remove the update form ) so comment it out for now
321 /*jQuery('html, body').animate({
322 scrollTop: jQuery('#container_'+value+' #element_' + element_id).offset().top - 40 }, 700);*/
323
324 jQuery('#container_'+value+' #element_' + element_id).animate({
325 backgroundColor: '#FFFF9C'
326 }, 1000);
327 jQuery('#container_'+value+' #element_' + element_id).animate({
328 backgroundColor: 'none'
329 }, 1000);
330 }
331 });
332 }
333
334 /* function syncs the translation */
335 function wckSyncTranslation(id){
336 jQuery.post( wppbWckAjaxurl , { action:"wck_sync_translation", id:id}, function(response) {
337 if( response == 'syncsuccess' )
338 window.location.reload();
339 });
340 }
341
342 function wckGoToByScroll(id){
343 jQuery('html,body').animate({scrollTop: jQuery("#"+id).offset().top - 28},'slow');
344 }
345
346 /* Remove uploaded file */
347 jQuery(function(){
348 jQuery(document).on('click', '.wck-remove-upload', function(e){
349 jQuery(this).parent().parent().parent().children('.mb-field').val("");
350 jQuery(this).parent().parent('.upload-field-details').html('<p><span class="file-name"></span><span class="file-type"></span></p>');
351 });
352 });
353
354 /* Set width for listing "label" equal to the widest */
355 jQuery( function(){
356 jQuery('.wck-post-box').css( {visibility: 'visible', height: 'auto'} );
357 });
358
359 function wck_set_to_widest( element, parent ){
360 if( element == '.field-label' ){
361 if( jQuery( "#" + parent + ' ' + element ).length != 0 ){
362 var widest = null;
363 jQuery( "#" + parent + ' ' + element ).each(function() {
364 if (widest == null)
365 widest = jQuery(this);
366 else
367 if ( jQuery(this).width() > widest.width() )
368 widest = jQuery(this);
369 });
370
371 jQuery( "#" + parent ).append("<style type='text/css'>#"+ parent +" .field-label, #container_"+ parent +" .field-label{display:inline-block;padding-right:5px;width:"+ ( parseInt( widest.width() ) + parseInt( 2 ) ) +"px;}</style>");
372 }
373 }
374 else if( element == 'strong' ){
375 if( jQuery( "#container_" + parent + " #element_0 " + element ).length != 0 ){
376 var widest = null;
377 jQuery( "#container_" + parent + " #element_0 " + element ).each(function() {
378 if (widest == null)
379 widest = jQuery(this);
380 else
381 if ( jQuery(this).width() > widest.width() )
382 widest = jQuery(this);
383 });
384
385 jQuery( "#container_" + parent ).append("<style type='text/css'>#container_"+ parent +" strong{display:inline-block;padding-right:5px;width:"+ ( parseInt( widest.width() ) + parseInt( 2 ) ) +"px;}</style>");
386 }
387 }
388 }
389