| 1 |
(function($){function gamipress_insert_shortcode(){var shortcode=gamipress_get_selected_shortcode();var attributes=gamipress_get_attributes(shortcode);var constructed=gamipress_construct_shortcode(shortcode,attributes);window.send_to_editor(constructed)} |
| 2 |
function gamipress_get_selected_shortcode(){return $('#select_shortcode').val()} |
| 3 |
function gamipress_get_attributes(shortcode){var attrs={};var inputs=gamipress_get_shortcode_inputs(shortcode);$.each(inputs,function(index,el){var key,field,value,fields,values,i;var row=$(el).closest('.cmb-row');if(row.hasClass('empty-row')&&row.hasClass('hidden'))return!0;if(row.hasClass('cmb-repeat-row')){key=el.name.replace(shortcode+'_','').replace('[]','');key=key.split('[')[0];if(key==='')return!0;if(attrs[key]===undefined){var field_name=el.name.split('[')[0];fields=$(el).closest('.cmb-tbody').find('[name^="'+field_name+'"]');values=[];for(i=0;i<fields.length-1;i++){field=$(fields[i]);if(field.val().length) |
| 4 |
values.push(field.val())} |
| 5 |
if(values.length) |
| 6 |
attrs[key]=values.join(',')}}else if(row.data('fieldtype')==='multicheck'){key=el.name.replace(shortcode+'_','').replace('[]','');if(key==='')return!0;fields=$(el).closest('.cmb2-checkbox-list').find('[name^="'+el.name+'"]:checked');values=[];for(i=0;i<fields.length;i++){field=$(fields[i]);if(field.val().length) |
| 7 |
values.push(field.val())} |
| 8 |
if(values.length) |
| 9 |
attrs[key]=values.join(',')}else{key=el.name.replace(shortcode+'_','').replace('[]','');if(key==='')return!0;value=$(el).val();if($(el).attr('type')==='checkbox'){value=$(el).prop('checked')?'yes':'no'} |
| 10 |
if($(el).attr('type')==='radio'){value=$(el).closest('.cmb2-radio-list').find('input[type="radio"]:checked').val()} |
| 11 |
if(typeof value==='string'){value=value.replace(/"/g,"'")} |
| 12 |
if(value!==''&&value!==undefined&&value!==null){attrs[key]=value}}});var args={attributes:attrs,inputs:inputs};$('#'+shortcode+'_wrapper').trigger('gamipress_shortcode_attributes',[args]);$('#'+shortcode+'_wrapper').trigger('gamipress_get_shortcode_attributes',[args.attributes,args.inputs]);return args.attributes} |
| 13 |
function gamipress_get_shortcode_inputs(shortcode){return $('input, select, textarea','#'+shortcode+'_wrapper .cmb2-wrap')} |
| 14 |
function gamipress_construct_shortcode(shortcode,attributes){var output='[';output+=shortcode;$.each(attributes,function(key,value){output+=' '+key+'="'+value+'"'});$.trim(output);output+=']';var args={output:output,shortcode:shortcode,attributes:attributes};$('#'+shortcode+'_wrapper').trigger('gamipress_construct_shortcode',[args]);return args.output} |
| 15 |
function gamipress_shortcode_hide_all_sections(){$('.shortcode-section').hide()} |
| 16 |
function gamipress_shortcode_show_section(section_name){$('#'+section_name+'_wrapper').show()} |
| 17 |
$('#select_shortcode').on('change',function(){gamipress_shortcode_hide_all_sections();gamipress_shortcode_show_section(gamipress_get_selected_shortcode())}).trigger('change');$('#gamipress_insert').on('click',function(e){e.preventDefault();gamipress_insert_shortcode()});$('#gamipress_cancel').on('click',function(e){e.preventDefault();tb_remove()});$('#gamipress_achievements_user_id, '+'#gamipress_logs_user_id, '+'#gamipress_points_user_id, '+'#gamipress_user_points_user_id, '+'#gamipress_points_types_user_id, '+'#gamipress_rank_user_id, '+'#gamipress_ranks_user_id, '+'#gamipress_user_rank_user_id, '+'#gamipress_earnings_user_id').gamipress_select2({ajax:{url:ajaxurl,dataType:'json',delay:250,type:'POST',data:function(params){return{q:params.term,page:params.page||1,action:'gamipress_get_users',nonce:gamipress_shortcodes_editor.nonce,}},processResults:gamipress_select2_users_process_results},escapeMarkup:function(markup){return markup},templateResult:gamipress_select2_users_template_result,theme:'default gamipress-select2',placeholder:gamipress_shortcodes_editor.user_placeholder,allowClear:!0,multiple:!1});$('#gamipress_achievements_current_user, '+'#gamipress_points_current_user, '+'#gamipress_user_points_current_user, '+'#gamipress_points_types_current_user, '+'#gamipress_logs_current_user, '+'#gamipress_ranks_current_user, '+'#gamipress_user_rank_current_user, '+'#gamipress_earnings_current_user').on('change',function(){var target=$(this).closest('.cmb-row').next();if($(this).prop('checked')){target.slideUp().addClass('cmb2-tab-ignore')}else{if(target.closest('.cmb-tabs-wrap').length){if(target.hasClass('cmb-tab-active-item')){target.slideDown()}}else{target.slideDown()} |
| 18 |
target.removeClass('cmb2-tab-ignore')}}).trigger('change');$('#gamipress_achievement_earners, #gamipress_achievements_earners, '+'#gamipress_rank_earners, #gamipress_ranks_earners, #gamipress_user_rank_earners').on('change',function(){var target=$(this).closest('.cmb-row').next();if(!$(this).prop('checked')){target.slideUp().addClass('cmb2-tab-ignore')}else{if(target.closest('.cmb-tabs-wrap').length){if(target.hasClass('cmb-tab-active-item')){target.slideDown()}}else{target.slideDown()} |
| 19 |
target.removeClass('cmb2-tab-ignore')}}).trigger('change');$('#gamipress_points_period, #gamipress_user_points_period, #gamipress_site_points_period').on('change',function(){var selector=$(this).attr('id').replace('_period','').replaceAll('_','-');var target=$(this).closest('.cmb2-wrap').find('.cmb2-id-'+selector+'-period-start, '+'.cmb2-id-'+selector+'-period-end');if($(this).val()!=='custom'){target.slideUp().addClass('cmb2-tab-ignore')}else{target.slideDown().removeClass('cmb2-tab-ignore')}}).trigger('change');$('#gamipress_points_inline, #gamipress_user_points_inline, #gamipress_site_points_inline').on('change',function(){var selector=$(this).attr('id').replace('_inline','').replaceAll('_','-');var target=$(this).closest('.cmb2-wrap').find('.cmb2-id-'+selector+'-columns, '+'.cmb2-id-'+selector+'-columns-small, '+'.cmb2-id-'+selector+'-layout');if($(this).prop('checked')){target.slideUp().addClass('cmb2-tab-ignore')}else{target.slideDown().removeClass('cmb2-tab-ignore')}});$('body').on('gamipress_shortcode_attributes','#gamipress_points_wrapper, #gamipress_user_points_wrapper, #gamipress_site_points_wrapper',function(e,args){if(args.attributes.inline==='yes'){delete args.attributes.columns;delete args.attributes.columns_small;delete args.attributes.layout}});$('#gamipress_earnings_points, #gamipress_earnings_achievements, #gamipress_earnings_ranks').on('change',function(){var id=$(this).attr('id');var target;if(id==='gamipress_earnings_points'){target=$('.cmb2-id-gamipress-earnings-points-types, .cmb2-id-gamipress-earnings-awards, .cmb2-id-gamipress-earnings-deducts')}else if(id==='gamipress_earnings_achievements'){target=$('.cmb2-id-gamipress-earnings-achievement-types, .cmb2-id-gamipress-earnings-steps')}else if(id==='gamipress_earnings_ranks'){target=$('.cmb2-id-gamipress-earnings-rank-types, .cmb2-id-gamipress-earnings-rank-requirements')} |
| 20 |
if($(this).prop('checked')){if($(this).closest('.cmb-tabs-wrap').find('.cmb-tab.active[id$="'+id+'"]').length){target.slideDown()} |
| 21 |
target.removeClass('cmb2-tab-ignore')}else{target.slideUp().addClass('cmb2-tab-ignore')}});$('body').on('click','#insert_gamipress_shortcodes',function(e){e.preventDefault();gamipress_shortcode_setup_thickbox($(this))});function gamipress_shortcode_setup_thickbox(link){setTimeout(function(){$('#TB_window').addClass('gamipress-shortcode-thickbox');$('select.select2-hidden-accessible','.gamipress-shortcode-thickbox .cmb2-wrap').val('').trigger('change');$('input[type="checkbox"]','.gamipress-shortcode-thickbox .cmb2-wrap').trigger('change')},0)}}(jQuery)) |