| @@ -1,418 +1,399 @@ | ||
| 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 | -} | |
| 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 | +} | |