PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
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 4.0.3, at assets/lib/wck-api/wordpress-creation-kit.js

400 lines 12.7 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 // Extend with a custom tooltip instead of alert
75 jQuery('<div>' + response.error + '</div>').dialog({
76 modal: true,
77 title: 'Error',
78 width: 400,
79 minHeight: 200,
80 buttons: {
81 Ok: function() {
82 jQuery(this).dialog('close');
83 }
84 }
85 });
86 }
87 else{
88 /* refresh the list */
89 jQuery('#container_'+value).replaceWith(response.entry_list);
90
91 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
92
93 if( !jQuery( '#'+value ).hasClass('single') )
94 mb_sortable_elements();
95
96 /* restore the add form to the original values */
97 if( !jQuery( '#'+value ).hasClass('single') ){
98 jQuery( '#'+value ).replaceWith( response.add_form );
99 jQuery('#'+value).parent().css('opacity','1');
100 jQuery('#mb-ajax-loading').remove();
101 }
102 else{
103 jQuery('#'+value).parent().css('opacity','1');
104 jQuery('#mb-ajax-loading').remove();
105 }
106
107 jQuery('body').trigger('wck-added-element');
108
109 }
110 });
111
112 }
113
114 /* remove reccord from the meta */
115 function removeMeta(value, id, element_id, nonce){
116
117 var response = confirm( "Delete this item ?" );
118
119 if( response == true ){
120
121 meta = value;
122
123 if( value.indexOf("-wcknested-") != -1 ){
124 metaDetails = value.split("-wcknested-");
125 meta = metaDetails[0];
126 }
127
128 jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
129 jQuery.post( wppbWckAjaxurl , { action:"wck_remove_meta"+meta, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) {
130
131 /* If single add the form */
132 if( jQuery( '#container_'+value ).hasClass('single') ){
133 jQuery( '#container_'+value ).before( response.add_form );
134 jQuery( '#'+value ).addClass('single');
135 }
136
137 /* refresh the list */
138 jQuery('#container_'+value).replaceWith(response.entry_list);
139
140 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
141
142 mb_sortable_elements();
143 jQuery('#'+value).parent().css('opacity','1');
144 jQuery('#mb-ajax-loading').remove();
145
146 });
147 }
148 }
149
150 /* swap two reccords */
151 /*function swapMetaMb(value, id, element_id, swap_with){
152 jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
153 jQuery.post( wppbWckAjaxurl , { action:"swap_meta_mb", meta:value, id:id, element_id:element_id, swap_with:swap_with}, function(response) {
154
155 jQuery.post( wppbWckAjaxurl , { action:"refresh_list", meta:value, id:id}, function(response) {
156 jQuery('#container_'+value).replaceWith(response); jQuery('#'+value).parent().css('opacity','1'); jQuery('#mb-ajax-loading').remove();
157 });
158
159 });
160 }
161 */
162
163 /* reorder elements through drag and drop */
164 function mb_sortable_elements() {
165 jQuery( ".mb-table-container tbody" ).not( jQuery( ".mb-table-container.single tbody, .mb-table-container.not-sortable tbody" ) ).sortable({
166 placeholder: "wck-state-highlight",
167 update: function(event, ui){
168
169 var value = jQuery(this).parent().siblings('.wck-add-form').attr('id');
170 var id = jQuery(this).parent().attr('post');
171
172 var result = jQuery(this).sortable('toArray');
173
174 var values = {};
175 for(var i in result)
176 {
177 values[i] = result[i].replace('element_','');
178 }
179
180 jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
181
182 meta = value;
183
184 if( value.indexOf("-wcknested-") != -1 ){
185 metaDetails = value.split("-wcknested-");
186 meta = metaDetails[0];
187 }
188
189
190 jQuery.post( wppbWckAjaxurl , { action:"wck_reorder_meta"+meta, meta:value, id:id, values:values}, function(response) {
191 jQuery('#container_'+value).replaceWith(response.entry_list);
192
193 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
194
195 mb_sortable_elements();
196 jQuery('#'+value).parent().css('opacity','1');
197 jQuery('#mb-ajax-loading').remove();
198 });
199 },
200 items: "> tr"
201 });
202 /*I don't know if this is necessary. Remove when I have more time for tests */
203 jQuery( "#sortable:not(select)" ).disableSelection();
204
205
206 jQuery('.mb-table-container ul').on( 'mousedown', function(e){
207 e.stopPropagation();
208 });
209 }
210 jQuery(mb_sortable_elements);
211
212
213
214 /* show the update form */
215 function showUpdateFormMeta(value, id, element_id, nonce){
216 if( jQuery( '#update_container_' + value + '_' + element_id ).length == 0 ){
217 jQuery('#container_'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
218
219 if( jQuery( '#container_' + value + " tbody" ).hasClass('ui-sortable') )
220 jQuery( '#container_' + value + " tbody" ).sortable("disable");
221
222
223 meta = value;
224
225 if( value.indexOf("-wcknested-") != -1 ){
226 metaDetails = value.split("-wcknested-");
227 meta = metaDetails[0];
228 }
229
230
231 jQuery.post( wppbWckAjaxurl , { action:"wck_show_update"+meta, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) {
232 //jQuery('#container_'+value+' #element_'+element_id).append(response);
233 jQuery(response).insertAfter('#container_'+value+' > tbody > #element_'+element_id);
234
235 jQuery('#container_'+value).parent().css('opacity','1');
236 jQuery('#mb-ajax-loading').remove();
237 wckGoToByScroll('update_container_' + value + '_' + element_id);
238
239 // Allow for extra client-side hooks to be executed.
240 jQuery('html').trigger('wpbFormMetaLoaded', meta);
241 });
242 }
243 }
244
245 /* remove the update form */
246 function removeUpdateForm( id ){
247 jQuery('html, body').animate({
248 scrollTop: jQuery( '#'+id).prev().offset().top - 40 }, 700);
249
250 jQuery( '#'+id).prev().animate({
251 backgroundColor: '#FFFF9C'
252 }, 700);
253 jQuery( '#'+id).prev().animate({
254 backgroundColor: 'none'
255 }, 700);
256
257 if( jQuery( '#'+id).parent('tbody').hasClass('ui-sortable') )
258 jQuery( '#'+id).parent('tbody').sortable("enable");
259
260 jQuery( '#'+id ).remove();
261 }
262
263 /* update reccord */
264 function updateMeta(value, id, element_id, nonce){
265
266 /* if tinyMCE then trigger save. save puts the content in the hidden textarea */
267 if( typeof tinyMCE !== 'undefined' )
268 tinyMCE.triggerSave();
269
270 jQuery('#container_'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
271 var values = {};
272 jQuery('#update_container_'+value+'_'+element_id+' .mb-field').each(function(){
273 var key = jQuery(this).attr('name');
274
275 if(jQuery(this).attr('type') == 'checkbox' || jQuery(this).attr('type') == 'radio' ) {
276
277 if( typeof values[key.toString()] === "undefined" )
278 values[key.toString()] = '';
279
280 if(jQuery(this).is(':checked')){
281 if( values[key.toString()] == '' )
282 values[key.toString()] += jQuery(this).val().toString();
283 else
284 values[key.toString()] += ', ' + jQuery(this).val().toString();
285 }
286 }
287
288 else
289 values[key.toString()] = jQuery(this).val().toString();
290
291 });
292
293
294 meta = value;
295
296 if( value.indexOf("-wcknested-") != -1 ){
297 metaDetails = value.split("-wcknested-");
298 meta = metaDetails[0];
299 }
300
301
302 jQuery.post( wppbWckAjaxurl , { action:"wck_update_meta"+meta, meta:value, id:id, element_id:element_id, values:values, _ajax_nonce:nonce}, function(response) {
303
304 jQuery( '#update_container_'+value+'_'+element_id + ' .field-label').removeClass('error');
305
306 if( response.error ){
307 jQuery('#container_'+value).parent().css('opacity','1');
308 jQuery('#mb-ajax-loading').remove();
309
310 jQuery.each( response.errorfields, function (index, field) {
311 jQuery( '#update_container_'+value+'_'+element_id + ' .field-label[for="' + field + '"]' ).addClass('error');
312 });
313
314 alert( response.error );
315 }
316 else{
317
318 jQuery('#update_container_'+value+'_'+element_id).remove();
319
320 /* refresh the list */
321 jQuery('#container_'+value+' #element_'+element_id).replaceWith(response.entry_content);
322
323 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
324
325 if( jQuery( '#container_' + value + " tbody" ).hasClass('ui-sortable') && jQuery( '#container_' + value + " tbody .wck_update_container" ).length == 0 )
326 jQuery( '#container_' + value + " tbody" ).sortable("enable");
327
328 jQuery('#container_'+value).parent().css('opacity','1');
329 jQuery('#mb-ajax-loading').remove();
330
331 //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
332 /*jQuery('html, body').animate({
333 scrollTop: jQuery('#container_'+value+' #element_' + element_id).offset().top - 40 }, 700);*/
334
335 jQuery('#container_'+value+' #element_' + element_id).animate({
336 backgroundColor: '#FFFF9C'
337 }, 1000);
338 jQuery('#container_'+value+' #element_' + element_id).animate({
339 backgroundColor: 'none'
340 }, 1000);
341 }
342 });
343 }
344
345 /* function syncs the translation */
346 function wckSyncTranslation(id){
347 jQuery.post( wppbWckAjaxurl , { action:"wck_sync_translation", id:id}, function(response) {
348 if( response == 'syncsuccess' )
349 window.location.reload();
350 });
351 }
352
353 function wckGoToByScroll(id){
354 jQuery('html,body').animate({scrollTop: jQuery("#"+id).offset().top - 28},'slow');
355 }
356
357 /* Remove uploaded file */
358 jQuery(function(){
359 jQuery(document).on('click', '.wck-remove-upload', function(e){
360 jQuery(this).parent().parent().parent().children('.mb-field').val("");
361 jQuery(this).parent().parent('.upload-field-details').html('<p><span class="file-name"></span><span class="file-type"></span></p>');
362 });
363 });
364
365 /* Set width for listing "label" equal to the widest */
366 jQuery( function(){
367 jQuery('.wck-post-box').css( {visibility: 'visible', height: 'auto'} );
368 });
369
370 function wck_set_to_widest( element, parent ){
371 if( element == '.field-label' ){
372 if( jQuery( "#" + parent + ' ' + element ).length != 0 ){
373 var widest = null;
374 jQuery( "#" + parent + ' ' + element ).each(function() {
375 if (widest == null)
376 widest = jQuery(this);
377 else
378 if ( jQuery(this).width() > widest.width() )
379 widest = jQuery(this);
380 });
381
382 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>");
383 }
384 }
385 else if( element == 'strong' ){
386 if( jQuery( "#container_" + parent + " #element_0 " + element ).length != 0 ){
387 var widest = null;
388 jQuery( "#container_" + parent + " #element_0 " + element ).each(function() {
389 if (widest == null)
390 widest = jQuery(this);
391 else
392 if ( jQuery(this).width() > widest.width() )
393 widest = jQuery(this);
394 });
395
396 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>");
397 }
398 }
399 }
400