/** * Admin Control Panel JavaScripts * * @version 1.0.0 * @since 1.0.0 */ // add extra fields for actors // http://www.saaraan.com/2013/03/addremove-input-fields-dynamically-with-jquery jQuery(document).ready(function() { var MaxInputs = 9; //maximum input boxes allowed var InputsWrapper = jQuery("#aps_add_actors_wrapper"); //Input boxes wrapper ID var AddButton = jQuery("#aps_movie_add_actors"); //Add button ID var x = InputsWrapper.length; //initlal text box count var FieldCount=1; //to keep track of text box added jQuery(AddButton).click(function (e) //on add input button click { if(x <= MaxInputs) //max input box allowed { FieldCount++; //text box added increment //add input box jQuery(InputsWrapper).append('
×
'); x++; //text box increment } return false; }); jQuery("body").on("click",".removeclass", function(e){ //user click on remove text if( x > 1 ) { jQuery(this).parent('div').remove(); //remove text box x--; //decrement textbox } return false; }) //remove the fields on loaded schema jQuery("body").on("click",".removeclassloaded", function(e){ //user click on remove text jQuery(this).parent('div').remove(); //remove text box return false; }) }); // add extra fields for ingredients // http://www.saaraan.com/2013/03/addremove-input-fields-dynamically-with-jquery jQuery(document).ready(function() { var MaxInputs = 30; //maximum input boxes allowed var InputsWrapper = jQuery("#aps_add_ingredients_wrapper"); //Input boxes wrapper ID var AddButton = jQuery("#aps_recipe_add_ingredients"); //Add button ID var x = InputsWrapper.length; //initlal text box count var FieldCount=1; //to keep track of text box added jQuery(AddButton).click(function (e) //on add input button click { if(x <= MaxInputs) //max input box allowed { FieldCount++; //text box added increment //add input box jQuery(InputsWrapper).append('
×
'); x++; //text box increment } return false; }); jQuery("body").on("click",".removeclass", function(e){ //user click on remove text if( x > 1 ) { jQuery(this).parent('div').remove(); //remove text box x--; //decrement textbox } return false; }) }); //duplicate the name as the save name and change " to ' jQuery(document).ready(function(){ jQuery('input[name="aps_book_name"]').keyup(function() { var txtClone = jQuery(this).val(); txtClone2 = txtClone.replace(/"/g,"'"); jQuery('input[name="aps_book_save_name"]').val(txtClone2); }); jQuery('input[name="aps_event_name"]').keyup(function() { var txtClone = jQuery(this).val(); txtClone2 = txtClone.replace(/"/g,"'"); jQuery('input[name="aps_event_save_name"]').val(txtClone2); }); jQuery('input[name="aps_movie_name"]').keyup(function() { var txtClone = jQuery(this).val(); txtClone2 = txtClone.replace(/"/g,"'"); jQuery('input[name="aps_movie_save_name"]').val(txtClone2); }); jQuery('input[name="aps_organisation_name"]').keyup(function() { var txtClone = jQuery(this).val(); txtClone2 = txtClone.replace(/"/g,"'"); jQuery('input[name="aps_organisation_save_name"]').val(txtClone2); }); jQuery('input[name="aps_person_name"]').keyup(function() { var txtClone = jQuery(this).val(); txtClone2 = txtClone.replace(/"/g,"'"); jQuery('input[name="aps_person_save_name"]').val(txtClone2); }); jQuery('input[name="aps_product_name"]').keyup(function() { var txtClone = jQuery(this).val(); txtClone2 = txtClone.replace(/"/g,"'"); jQuery('input[name="aps_product_save_name"]').val(txtClone2); }); jQuery('input[name="aps_recipe_name"]').keyup(function() { var txtClone = jQuery(this).val(); txtClone2 = txtClone.replace(/"/g,"'"); jQuery('input[name="aps_recipe_save_name"]').val(txtClone2); }); jQuery('input[name="aps_review_name"]').keyup(function() { var txtClone = jQuery(this).val(); txtClone2 = txtClone.replace(/"/g,"'"); jQuery('input[name="aps_review_save_name"]').val(txtClone2); }); /* sorts out the hide/show for admin schema forms http://stackoverflow.com/questions/4923716/how-to-change-element-class-on-select-option-using-jquery */ // show or hide the main input forms dependant on selection jQuery('#form_selector').change(function() { /* datepicker - needs to be here otherwise interferes with other js*/ var aps_jquey_dateformat = jQuery("input[name='aps_wp_dateformat']").val(); if(aps_jquey_dateformat === 'F j, Y') { //eg March 6, 2013 jQuery('.apschema_date_picker').datepicker({ dateFormat: 'M d, yy', changeYear: true, yearRange: '1700:c+10', changeMonth: true }); } else if (aps_jquey_dateformat === 'Y/m/d') { jQuery('.apschema_date_picker').datepicker({ dateFormat: 'yy/mm/dd', changeYear: true, yearRange: '1700:c+10', changeMonth: true }); } else if (aps_jquey_dateformat === 'm/d/Y') { jQuery('.apschema_date_picker').datepicker({ dateFormat: 'mm/dd/yy', changeYear: true, yearRange: '1700:c+10', changeMonth: true }); } else if (aps_jquey_dateformat === 'd/m/Y') { jQuery('.apschema_date_picker').datepicker({ dateFormat: 'dd/mm/yy', changeYear: true, yearRange: '1700:c+10', changeMonth: true }); } else if (aps_jquey_dateformat === 'd.m.Y') { jQuery('.apschema_date_picker').datepicker({ dateFormat: 'dd.mm.yy', changeYear: true, yearRange: '1700:c+10', changeMonth: true }); } else { jQuery('.apschema_date_picker').datepicker({ dateFormat: 'dd/mm/yy', changeYear: true, yearRange: '1700:c+10', changeMonth: true }); //revert to UK, } jQuery('#aps_schema_form_person, #aps_schema_form_product, #aps_schema_form_book, #aps_schema_form_event, #aps_schema_form_movie, #aps_schema_form_organisation, #aps_schema_form_recipe, #aps_schema_form_review').hide(); jQuery('#aps_schema_form_' + jQuery(this).find('option:selected').attr('value')).show(); }); // show the Product star options jQuery("#aps_product_startype_container").hide(); jQuery("#aps_product_startype_enable").click(function(){ jQuery("#aps_product_startype_container").toggle(); }); // show the Review star options jQuery("#aps_review_startype_container").hide(); jQuery("#aps_review_startype_enable").click(function(){ jQuery("#aps_review_startype_container").toggle(); }); // show the Recipe star options jQuery("#aps_recipe_startype_container").hide(); jQuery("#aps_recipe_startype_enable").click(function(){ jQuery("#aps_recipe_startype_container").toggle(); }); // show the Book review_by option jQuery("#aps_book_review_by_container").hide(); jQuery("#aps_book_review_by_enable").click(function(){ jQuery("#aps_book_review_by_container").toggle(); }); // show the Event review_by option jQuery("#aps_event_review_by_container").hide(); jQuery("#aps_event_review_by_enable").click(function(){ jQuery("#aps_event_review_by_container").toggle(); }); // show the Movie review_by option jQuery("#aps_movie_review_by_container").hide(); jQuery("#aps_movie_review_by_enable").click(function(){ jQuery("#aps_movie_review_by_container").toggle(); }); // show the Organisation review_by option jQuery("#aps_organisation_review_by_container").hide(); jQuery("#aps_organisation_review_by_enable").click(function(){ jQuery("#aps_organisation_review_by_container").toggle(); }); // show the Person review_by option jQuery("#aps_person_review_by_container").hide(); jQuery("#aps_person_review_by_enable").click(function(){ jQuery("#aps_person_review_by_container").toggle(); }); // show the Product review_by option jQuery("#aps_product_review_by_container").hide(); jQuery("#aps_product_review_by_enable").click(function(){ jQuery("#aps_product_review_by_container").toggle(); }); // show the Recipe review_by option jQuery("#aps_recipe_review_by_container").hide(); jQuery("#aps_recipe_review_by_enable").click(function(){ jQuery("#aps_recipe_review_by_container").toggle(); }); //shows/hides the post preview on the post page dependant on which option selected // probably not the best jQuery in the world but it works. jQuery('.aps_book_container').hide(); // NOTE THAT THISIS A CLASS - the front end uses classes but the back end is using IDs!! jQuery('#aps_event_container').hide(); jQuery('#aps_movie_container').hide(); jQuery('#aps_organisation_container').hide(); jQuery('#aps_person_container').hide(); jQuery('#aps_product_container').hide(); jQuery('#aps_recipe_container').hide(); jQuery('#aps_review_container').hide(); jQuery("#form_selector").change(function(){ if(this.value == 'book') {jQuery(".aps_book_container").show();} else {jQuery(".aps_book_container").hide();} if(this.value == 'event') {jQuery("#aps_event_container").show();} else {jQuery("#aps_event_container").hide();} if(this.value == 'movie') {jQuery("#aps_movie_container").show();} else {jQuery("#aps_movie_container").hide();} if(this.value == 'organisation') {jQuery("#aps_organisation_container").show();} else {jQuery("#aps_organisation_container").hide();} if(this.value == 'person') {jQuery("#aps_person_container").show();} else {jQuery("#aps_person_container").hide();} if(this.value == 'product') {jQuery("#aps_product_container").show();} else {jQuery("#aps_product_container").hide();} if(this.value == 'recipe') {jQuery("#aps_recipe_container").show();} else {jQuery("#aps_recipe_container").hide();} if(this.value == 'review') {jQuery("#aps_review_container").show();} else {jQuery("#aps_review_container").hide();} }); }); jQuery(document).ready(function() { //stop the forms from submitting with jquery is on jQuery("#aps_schema_form_book").submit(function () { return false; }); jQuery("#aps_schema_form_event").submit(function () { return false; }); jQuery("#aps_schema_form_movie").submit(function () { return false; }); jQuery("#aps_schema_form_organisation").submit(function () { return false; }); jQuery("#aps_schema_form_person").submit(function () { return false; }); jQuery("#aps_schema_form_product").submit(function () { return false; }); jQuery("#aps_schema_form_recipe").submit(function () { return false; }); jQuery("#aps_schema_form_review").submit(function () { return false; }); // save function function apsSaveUpdate(table_name, schema_data, schema_type, message) { //nonce = jQuery(this).attr('data-nonce'); //alert(currentid); var message = message; data = { action: 'aps_save_update_schema', type: 'POST', dataType: 'JSON', "table_name" : table_name, "schema_data" : schema_data, "schema_type" : schema_type //nonce: nonce }; jQuery.post(ajaxurl, data, function(response) { var dataz = response; //console.log(dataz); var obj = jQuery.parseJSON(dataz); if (message == "save") { jQuery('#aps_schema_messages').append('

Your Schema shortcode has been saved and inserted.

'); jQuery('.aps_save_message').delay(3000).fadeOut("slow") } if (message == "update") { jQuery('#aps_schema_messages').append('

Your Schema shortcode has been updated.

'); jQuery('.aps_update_message').delay(3000).fadeOut("slow") } // check to see if save name exists on list, if it does do nothing, else add the save name o tth elist, in case the user needs to select it before a page reload. var aps_schema_dropdown = "aps_" + schema_type + "_load_selection"; var aps_schema_get_save_name = "aps_" + schema_type + "_save_name"; var aps_opt = jQuery("input[name='"+aps_schema_get_save_name+"']").val(); if (jQuery('#'+aps_schema_dropdown+' option:contains('+ aps_opt +')').length) {} else { jQuery('#'+aps_schema_dropdown).append( jQuery('