PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.0.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.0.2
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 2.0.7 All 340 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 2.0.2, at assets/lib/wck-api/wordpress-creation-kit.js

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