Commit c7f91956 authored by agnez's avatar agnez

jQuery pour 3producteurs wip

parent 8c43fcf6
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before
"trackPageView" */
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.www.gasap.be"]);
_paq.push(["setDomains", ["*.www.gasap.be","*.gasap.be"]]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//piwik.domainepublic.net/";
_paq.push(['setTrackerUrl', u+'piwwik.php']);
_paq.push(['setSiteId', '20']);
var d=document, g=d.createElement('script'),
s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true;
g.src=u+'piwwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//piwik.domainepublic.net/piwwik.php?idsite=20&rec=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
\ No newline at end of file
<?php
// array tout les prods
$query_lesprods = new WP_Query( array(
'post_type' => 'producer',
'post_status' => 'publish',
'orderby' => 'id',
'order' => 'ASC',
'posts_per_page' => -1
));
$prods = $query_lesprods->get_posts();
$lesproducteurs = array();
foreach( $prods as $post ) {
$lesproducteurs[] = array(
'id' => $post->ID,
'title' => $post->post_title,
'thumb' => htmlentities(get_the_post_thumbnail( $post->ID )),
'content' => $post->post_content,
'terms' => $post->post_term
);
}
// json encode array. doit être appelé avant gasap_trois_prod.js.. voir comment assurer ?>
<script type="text/javascript">
var lesproducteurs = <?php echo json_encode( $lesproducteurs ); ?>;
</script>
<?php
add_action( 'wp_ajax_gasap_deuxprods', 'gasap_2prods' );
add_action( 'wp_ajax_nopriv_gasap_deuxprods', 'gasap_2prods' );
function gasap_2prods() {
//deux producteurs - teaser ?>
<div class="uk-grid">
<div class="uk-width-1 uk-width-medium-1-2">
img ici
<h2 id="deuxprods_titre1"></h2>
<div id="deuxprods_terms1">terms producertype ici</div>
<a class="uk-button uk-button-success clickme1" href="#3producteurs_test" data-uk-smooth-scroll><?php esc_html_e( 'Discover', 'beans_gasap' ); ?></a>
<span class="edit-link">edit post link ? comment ? <?php esc_html_e( 'Edit producer', 'beans_gasap' ); ?></span>
</div>
<div class="uk-width-1 uk-width-medium-1-2"><?php
if ( has_post_thumbnail() ) { the_post_thumbnail('medium2'); } ?>
<h2 id="deuxprods_titre2"></h2>
<div>get_the_term_list( get_the_ID(), 'producertype'</div>
<a class="uk-button uk-button-success clickme2" href="#3producteurs_test" data-uk-smooth-scroll><?php esc_html_e( 'Discover', 'beans_gasap' ); ?></a>
<span class="edit-link">edit post link ? comment ? <?php esc_html_e( 'Edit producer', 'beans_gasap' ); ?></span>
</div>
</div>
<?php
//fiche producteur ?>
<div id="fiche_producteur" class="uk-block">
<div class="uk-grid">
<div class="uk-width-1 uk-width-medium-1-2">
the_post_thumbnail ici
</div>
<div class="uk-width-1 uk-width-medium-1-2">
<h2 id="ficheprod_titre">the_title</h2>
<div id="ficheprod_content"></div>
<span class="edit-link">edit post link ? comment ? <?php esc_html_e( 'Edit producer', 'beans_gasap' ); ?></span>
</div>
</div>
</div>
<?php
return;
die();
}?>
<section id="3producteurs_test" class="uk-block">
<div class="largeur1">
<?php gasap_2prods()?>
</div>
</section>
\ No newline at end of file
jQuery( document ).ready(function()
{
function get_producteurs() {
return lesproducteurs;
}
var arr_ids_deuxprod=[];
var fiche_prod_id;
var index_id1_deuxprod;
var index_id2_deuxprod;
var deuxprod_titre1 = jQuery( "#deuxprods_titre1" );
var deuxprods_terms1 = jQuery( "#deuxprods_terms1" );
var deuxprod_titre2 = jQuery( "#deuxprods_titre2" );
var ficheprod_titre = jQuery( "#ficheprod_titre" );
var ficheprod_content = jQuery( "#ficheprod_content" );
// faire une fonction ici et l'appeller pour clickme 1 et 2
jQuery( '.clickme1' || '.clickme2' ).on('click', function(){
console.log(this);
var fiche_prod_id_temp = arr_ids_deuxprod[0];
arr_ids_deuxprod.push(fiche_prod_id_temp);
arr_ids_deuxprod = choix_prods(2);
fiche_prod_id = fiche_prod_id_temp;
deuxprod_titre1.html(lesproducteurs[arr_ids_deuxprod[0]].title);
deuxprod_titre2.html(lesproducteurs[arr_ids_deuxprod[1]].title);
ficheprod_titre.html(lesproducteurs[fiche_prod_id].title);
ficheprod_content.html(lesproducteurs[fiche_prod_id].content);
//console.log("fiche_prod_id: " + fiche_prod_id);
//console.log("arr_ids_deuxprod: "+arr_ids_deuxprod);
});
// shuffle array http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
function choix_prods(count) {
var arr_ids_deuxprod_temp=[];
var bln_bon;
for (var i = 0; i< count; i++) {
bln_bon=false;
while (bln_bon == false) {
randomId = Math.floor(Math.random() * lesproducteurs.length);
var bln_bon2 = true;
for (var j = 0; j < arr_ids_deuxprod.length; j++) {
if (arr_ids_deuxprod[j] == randomId) {
bln_bon2 = false;
break;
}
}
if (fiche_prod_id && fiche_prod_id == randomId) {
bln_bon2 = false;
}
for (var j = 0; j < arr_ids_deuxprod_temp.length; j++) {
if (arr_ids_deuxprod_temp[j] == randomId) {
bln_bon2 = false;
break;
}
}
if (bln_bon2 == true) {
bln_bon=true;
arr_ids_deuxprod_temp.push(randomId);
}
}
}
if (arr_ids_deuxprod_temp.length == 1) {
return arr_ids_deuxprod_temp[0]
} else {
return arr_ids_deuxprod_temp;
}
}
/*au 1er chargement de la page avant le click*/
//console.log("arr_ids_deuxprod encore vide "+arr_ids_deuxprod);
fiche_prod_id = choix_prods(1);
arr_ids_deuxprod = choix_prods(2);
index_id1_deuxprod=arr_ids_deuxprod[0];
index_id2_deuxprod=arr_ids_deuxprod[1];
deuxprod_titre1.html(lesproducteurs[arr_ids_deuxprod[0]].title);
deuxprods_terms1.html(lesproducteurs[arr_ids_deuxprod[0]].terms);
deuxprod_titre2.html(lesproducteurs[arr_ids_deuxprod[1]].title);
ficheprod_titre.html(lesproducteurs[fiche_prod_id].title);
ficheprod_content.html(lesproducteurs[fiche_prod_id].content);
//console.log("fiche_prod_id: " + fiche_prod_id);
//console.log("arr_ids_deuxprod: "+arr_ids_deuxprod);
//console.log(index_id1_deuxprod);
//console.log(lesproducteurs[fiche_prod_id].title);
/*function set_producteurs(index, cat, value) {
lesproducteurs[index][cat] = value;
}*/
/*jQuery.post(
gasap_frontend_ajax.ajaxurl,
{action: 'gasap_2prods'})
.done(function(lesproducteurs){
//var test = get_producteurs();
//console.log(test[29].title);
//set_producteurs(0, "post_title", "trqlqlq");
console.log(lesproducteurs[0].title);
$('.thetitle').text(lesproducteurs[0].title);
}); */
});
function gasap_post_id (post) {
var postid = (post.id);
$.ajax({
type: 'POST',
action: gasap_get_activepost,
url: gasap_frontend_ajax.ajaxurl,
data: { postid : postid },
});
};
\ No newline at end of file
jQuery( document ).ready(function()
{
jQuery('.clickid').on('click', function(){
var id = jQuery(this).attr("id");
jQuery.post(
gasap_frontend_ajax.ajaxurl,
{action: 'gasap_activepost', postid: id}).done(function(data){console.log(id);console.log(data)});
});
});
\ No newline at end of file
......@@ -37,7 +37,7 @@ jQuery( document ).ready(function()
<section id="snippet_la_carte">
<div class="uk-grid" id="uk-grid">
<div class="uk-width-1-1 uk-width-medium-2-3"><!-- left side -->
<h2 class="textegauche trouver"><?php esc_html_e( 'Trouvez', 'beans_gasap' ) ?></h2>
<h2 class="textegauche trouver"><?php esc_html_e( 'Trouvez', 'beans_gasap' ) ?></h2>
<ul class="uk-tab" data-uk-tab="{connect:'#tab-content'}">
<li><a href="#" id="getmap1"><h3><?php esc_html_e( 'un GASAP ', 'beans_gasap' ) ?></h3></a></li>
<li><a href="#" id="getmap2"><h3><?php esc_html_e( 'un producteur', 'beans_gasap' ) ?></h3></a></li>
......
<?php
add_action( 'wp_ajax_gasap_get_activepost', 'gasap_get_activepost' );
add_action( 'wp_ajax_nopriv_gasap_get_activepost', 'gasap_get_activepost' );
function gasap_get_activepost() {
if(isset($_POST['postid'])) {
$activepost = get_posts(array('postid' => $_POST['postid']));
return $activepost;
die();
}
else {
$activepost = '';
return $activepost;
die();
}
}?>
<section id="3producteurs" class="uk-block">
<div class="largeur1">
<div class="uk-text-center"><?php
......@@ -28,7 +12,7 @@ function gasap_get_activepost() {
<?php
$do_not_duplicate = array();
$active_prod = $activepost;
$active_prod = ''; //gasap_get_activepost();
//deux producteurs
$short_producteurs = new WP_Query( array(
......@@ -45,7 +29,7 @@ function gasap_get_activepost() {
if ( has_post_thumbnail() ) { the_post_thumbnail('medium2'); } ?>
<h2><?php echo get_the_title(); ?></h2>
<?php echo get_the_term_list( get_the_ID(), 'producertype', '<div>', ', ', '</div>' ); ?>
<a id="<?php echo get_the_ID(); ?>" class="uk-button uk-button-success" onclick="gasap_post_id(this);" href="#presentation_producteur" data-uk-smooth-scroll><?php esc_html_e( 'Discover', 'beans_gasap' ); ?></a>
<a id="<?php echo get_the_ID(); ?>" class="uk-button uk-button-success clickid" href="#presentation_producteur" data-uk-smooth-scroll><?php esc_html_e( 'Discover', 'beans_gasap' ); ?></a>
<?php edit_post_link( esc_html__( 'Edit producer', 'beans_gasap' ), '<span class="edit-link">', '</span>' ); ?>
</div>
<?php $do_not_duplicate[] = get_the_ID();
......
......@@ -36,12 +36,33 @@ function gasap_enqueue_uikit_assets() {
add_action( 'wp_enqueue_scripts', 'gasap_js_scripts' );
function gasap_js_scripts() {
wp_enqueue_script( 'gasap_map_script', get_stylesheet_directory_uri() . '/assets/js/gasap_post_id.js', array('jquery') );
wp_enqueue_script( 'gasap_map_script', get_stylesheet_directory_uri() . '/assets/js/gasap_map.js', array('jquery') );// pour GASAP map
wp_enqueue_script( 'google_map', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js' );// pour GASAP map
wp_localize_script( 'frontend-ajax', 'gasap_frontend_ajax',array('ajaxurl' => admin_url( 'admin-ajax.php' ),));
wp_register_script('gasap_post_id_script', get_stylesheet_directory_uri() . '/assets/js/gasap_post_id.js', array('jquery'));
wp_register_script('gasap_trois_prod', get_stylesheet_directory_uri() . '/assets/js/fill_page_trois_prod.js', array('jquery'));
//wp_register_script( 'gasap_map_script', get_stylesheet_directory_uri() . '/assets/js/gasap_map.js', array('jquery') );// pour GASAP map
//wp_register_script( 'google_map', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js' );// pour GASAP map
//wp_enqueue_script( 'gasap_map_script');
//wp_enqueue_script( 'google_map');
wp_localize_script( 'gasap_post_id_script', 'gasap_frontend_ajax',array('ajaxurl' => admin_url( 'admin-ajax.php' ),));
wp_localize_script( 'gasap_trois_prod', 'gasap_frontend_ajax',array('ajaxurl' => admin_url( 'admin-ajax.php' ),));
}
add_action( 'wp_ajax_gasap_activepost', 'gasap_get_activepost' );
add_action( 'wp_ajax_nopriv_gasap_activepost', 'gasap_get_activepost' );
//add_filter( 'gasap_get_activepost', 'gasap_get_activepost' );
function gasap_get_activepost() {
if(isset($_POST['postid'])) {
$activepost = $_POST['postid'];
$fiche_producteur = new WP_Query( array( 'p' => $active_prod) );
$activepost = "fff";
}
else {
$activepost = 'hhhh';
}
echo $activepost."ddd";
die();
}
//overwrite beans site branding
beans_modify_action_callback( 'beans_site_branding', 'beans_gasap_site_branding' );
function beans_gasap_site_branding() {
......@@ -86,6 +107,9 @@ function gasap_setup_document() {
beans_remove_action( 'beans_breadcrumb' );
beans_remove_action( 'beans_footer_partial_template' );
beans_remove_action( 'beans_post_meta_categories' );
//emojis not needed
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
}
// remove author from posts
add_filter( 'beans_post_meta_items', 'beans_child_remove_post_meta_items' );
......@@ -141,21 +165,23 @@ function wp_get_attachment( $attachment_id ) {
);
}
// Register calendar widget area to use in home.php
// Register calendar widget area to use in home.php ?? obsolethe ?
/*
add_action( 'widgets_init', 'calendar_widget_areas' );
function calendar_widget_areas() {
beans_register_widget_area( array(
'name' => __( 'Calendar Widget Area', 'beans_gasap' ),
'id' => 'calendar_widget_area',
) );
}
} */
//pour three_producers
//pour three_producers ?? obsolethe ?
/*
add_filter( 'query_vars', 'add_gasap_query_vars_filter' );
function add_gasap_query_vars_filter( $vars ){
$vars[] = "prod";
return $vars;
}
} */
// pour GASAP map
add_action( 'gmw_before_no_results', 'nen_communities_no_results_show_map' );
......@@ -168,4 +194,3 @@ function nen_communities_no_results_show_map( $form ) {
$gmw->map_element();
}
// End GASAP map
\ No newline at end of file
......@@ -3,6 +3,14 @@
* page Le GASAP
*
*/
add_action( 'wp_enqueue_scripts', 'scripts_three_producers' );
function scripts_three_producers() {
wp_enqueue_script( 'gasap_post_id_script');
wp_enqueue_script( 'gasap_trois_prod');
}
add_action( 'beans_post_before_markup', 'page_le_gasap_before' );
function page_le_gasap_before() {
?>
......@@ -68,6 +76,7 @@ function add_page_le_gasap_content_pieces() {
</div></section>
<?php
include (get_stylesheet_directory() . '/assets/template_parts/three_steps.php');// Comment devenir membre en 3 étapes ?
include (get_stylesheet_directory() . '/assets/helpers/trois_random_prods.php');
include (get_stylesheet_directory() . '/assets/template_parts/three_producers.php');
include (get_stylesheet_directory() . '/assets/template_parts/news_slider.php');
include (get_stylesheet_directory() . '/assets/template_parts/latest_news.php');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment