1/** 2 * Recipe add-remove scripts 3 */ 4 5function refresh_recipe_wrappers() { 6 7 var wrappers = $( '.recipe-reload-wrapper' ); 8 var methods = []; 9 10 $.each( wrappers, function( w, wrapper ) { 11 var element = $( wrapper ); 12 var method = element.data( 'method' ); 13 var id = parseInt( element.data( 'post-id' ) || 0 ); 14 methods.push( { method : method, id : id } ); 15 } ); 16 17 $.post( recipes_ajax.url, { action : 'refresh_wrappers', methods : methods }, function( response ) { 18 var html = $.parseJSON( response ); 19 $.each( wrappers, function( w, wrapper ) { 20 $( wrapper ).html( html[ w ] ); 21 } ); 22 } ); 23 24} 25 26$( document ).ready( function() { 27 28 $.ajaxSetup( { 29 global : true, 30 cache : false 31 } ); 32 33 // Add recipe to favorites 34 $( document.body ).on( 'click', '.add-to-favorites', function() { 35 var element = $( this ); 36 var id = parseInt( element.data( 'id' ) ); 37 if( !isNaN( id ) && id ) { 38 element.addClass('remove-from-favorites'); 39 element.removeClass('add-to-favorites'); 40 $.post( recipes_ajax.url, { action : 'add_favorite', id : id }, function( response ) { 41 refresh_recipe_wrappers(); 42 } ); 43 } 44 } ); 45 46 // Remove recipe from favorites 47 $( document.body ).on( 'click', '.remove-from-favorites', function() { 48 var element = $( this ); 49 var id = parseInt( element.data( 'id' ) ); 50 if( !isNaN( id ) && id ) { 51 element.addClass('add-to-favorites'); 52 element.removeClass('remove-from-favorites'); 53 $.post( recipes_ajax.url, { action : 'remove_favorite', id : id }, function( response ) { 54 refresh_recipe_wrappers(); 55 } ); 56 } 57 } ); 58 59} );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.