de la "section 3" gagne la classe "lm-dawsy_active" (la plus proche de la ligne de demarcation)
- L'element pointe par l'attribut data-lm-dawsy_other_active_element_selector (#point_section_3) du
de la section 3:
- Gagne aussi la classe "lm-dawsy_active"
*/
Lalema.Tools.Dawsy = {
init: function() {
var self = this;
var $anchors = $(".lm-dawsy");
if ($anchors.length <= 0) { return 0; }
var $active_anchor = self.dawsy_find_active_anchor($anchors);
var old_active_id = $active_anchor.attr("id");
self.dawsy_set_new_active_anchor($active_anchor);
$(document).ready(function() {
$(window).scroll(function() {
$active_anchor = self.dawsy_find_active_anchor($anchors);
if ($active_anchor.attr("id") != old_active_id) {
self.dawsy_set_new_active_anchor($active_anchor);
old_active_id = $active_anchor.attr("id");
}
});
});
},
dawsy_find_active_anchor: function($list_of_anchors) {
var y = $(window).scrollTop();
var smallest_delta = 999999;
var $active_anchor = {};
for (var i = 0; i < $list_of_anchors.length; i++) {
var $a = $($list_of_anchors[i]);
var top_of_the_element = $a.offset().top;
var delta_element_scrolltop = Math.abs(top_of_the_element - y);
if (delta_element_scrolltop < smallest_delta) {
smallest_delta = delta_element_scrolltop;
$active_anchor = $a;
}
}
return $active_anchor;
},
dawsy_set_new_active_anchor: function($active_anchor) {
$(".lm-dawsy_active").removeClass("lm-dawsy_active");
$active_anchor.addClass("lm-dawsy_active");
$($active_anchor.data("lm-dawsy_other_active_element_selector")).addClass("lm-dawsy_active");
}
};/*
Permet de setuper automatiquement une "fancybox" (fenetre modale). Il suffit de donner une classe a l'element pour faire
fonctionner la fancybox.
Les types de "fancybox" disponibles sont:
- .fancybox_image : permet d'ouvrir une image
*/
Lalema.Tools.Fancyboxes = {
init: function() {
if (!$.fn.fancybox) { return false; }
var self = this;
self.setup_fancybox_for_images();
self.setup_fancybox_for_iframes();
self.setup_fancybox_for_ajax();
self.setup_fancybox_for_inline_content();
},
setup_fancybox_for_images: function() {
var opened = false;
$(".fancybox_image").fancybox({
"openEffect": "elastic",
"helpers": {
"overlay": {
"locked": false
},
"thumbs": {
width : 90,
height : 90
}
},
"beforeShow" : function() {
if (opened) { return true; }
opened = true;
if ($(this.element).data("fbox-hide-target")) {
$($(this.element).data("fbox-hide-target")).css("visibility", "hidden");
}
},
"afterClose" : function() {
opened = false;
if ($(this.element).data("fbox-hide-target")) {
$($(this.element).data("fbox-hide-target")).css("visibility", "visible");
}
}
});
},
setup_fancybox_for_iframes: function() {
$(".fb_iframe").fancybox({
"openEffect" : "fade",
"closeEffect" : "none",
"type" : "iframe",
"autoSize" : false,
"scrolling" : "no",
"arrows" : false,
"helpers" : {
"overlay": {
"locked": false
}
},
"beforeShow" : function() {
var $body = $('.fancybox-iframe').contents().find("body");
this.width = $body.width() + 1;
this.height = $body.height() + 1;
},
"afterShow" : function() {
$('.fancybox-iframe')[0].contentWindow.$("body").trigger("fboxLoaded");
}
});
},
setup_fancybox_for_ajax: function() {
$(".fb_ajax").fancybox({
"openEffect" : "fade",
"type" : "ajax"
});
},
setup_fancybox_for_inline_content: function() {
$(".fb_inline").fancybox({
"openEffect" : "fade",
"type" : "inline",
"autoSize" : true,
"maxWidth" : "800"
});
}
};Lalema.Tools.Faux_Radios_Buttons = {
init: function() {
var self = this;
$(".faux_radios_group").each(function() {
self.repaint_group($(this));
});
$(".faux_radios_button").click(function() {
self.set_group_value($(this).closest(".faux_radios_group"), $(this).data("faux-radios-value"));
});
},
repaint_group: function($faux_radios_group) {
var self = this;
$input = $faux_radios_group.find("input[type=hidden]");
$faux_radios_group.find(".faux_radios_button").removeClass("selected");
$active_faux_radio_button = $faux_radios_group.find(".faux_radios_button[data-faux-radios-value='" + $input.val() + "']");
$active_faux_radio_button.addClass("selected");
$.extend($faux_radios_group.data(), $active_faux_radio_button.data());
},
set_group_value: function($faux_radios_group, value) {
var self = this;
$input = $faux_radios_group.find("input[type=hidden]");
if ($input.val() == value) {
return false;
}
$input.val(value);
self.repaint_group($faux_radios_group);
$faux_radios_group.trigger("change");
}
};Lalema.Tools.Flash_Messages = {
init: function() {
$(".lm-flash").each(function() {
var $flash = $(this);
$bouton_effacer = $("
");
$bouton_effacer.click(function() {
$flash.fadeOut("fast");
});
$(this).append($bouton_effacer);
$flash.delay(350).slideDown();
});
}
};Lalema.Tools.Google_Analytics_Events = {
init: function() {
if (typeof(ga) !== "function") {
ga = function(ga_command, ga_event, ga_category, ga_action, ga_label, ga_additional_params) {
//console.log("CATEGORY: " + ga_category + " | ACTION: " + ga_action + " | LABEL: " + ga_label );
}
}
$(".ga_track_event").each(function() {
var $self = $(this);
var ga_action = $self.data("ga-trigger");
var google_analytics_event_function = function() {
ga(
"send",
"event",
$self.data("ga-category"),
$self.data("ga-action"),
$self.data("ga-label"),
{
"url" : $self.data("ga-url")
}
);
};
$self.on(ga_action, google_analytics_event_function);
});
}
};Lalema.Tools.Placeholder_For_Textboxes = {
init: function() {
$("input[data-placeholder]").focus(function() {
if ($(this).val() == $(this).data("placeholder")) {
$(this).val("");
}
}).focusout(function() {
if ($(this).val() == "") {
$(this).val($(this).data("placeholder"));
}
});
}
};
Lalema.Tools.Scaffoldings = {
toggle_class_if: function(selector, className, callback ) {
if (callback()) {
$(selector).addClass(className);
}
else {
$(selector).removeClass(className);
}
},
toggler_champs_autres: function(params) {
var self = this;
for (var i = 0; i < params.length; i++) {
(function(p) {
$(p.question).on("change", function() {
self.toggle_class_if(p.autre, p.klass, function() {
var value = $(p.question).data(p.datasource).toLowerCase();
return (value == "autre" || value == "other");
});
});
})(params[i]);
}
}
};
Lalema.Tools.Show_More_Less = {
init: function() {
$(".lm-showmoreless").each(function() {
var $that = $(this);
var $target = $that.find($that.data("lm-showmoreless-selector"));
if ($target.height() >= parseInt($target.css("max-height"))) {
var $div =
$(""
+ "
"
);
$that.append($div);
$div.data("lm-showmoreless-maxheight", $target.css("max-height"));
$div.find(".lm-showmoreless_state_showless").toggle();
$div.click(function() {
if ($(this).data("state") == 0) {
$(this).data("state", 1);
$target.css("max-height", "999px");
}
else {
$(this).data("state", 0);
$target.css("max-height", $(this).data("lm-showmoreless-maxheight"));
}
$(this).find(".lm-showmoreless_state_showmore").toggle();
$(this).find(".lm-showmoreless_state_showless").toggle();
});
}
});
}
};Lalema.Tools.Slideables = {
init: function() {
$(".slides_container").each(function() {
var $slide_container = $(this);
$slide_container.find(".slideable").click(function() {
var $slide = $(this);
$slide_container.animate({
"margin-left": "-100%"
}, 200, function () {
$slide_container.css("margin-left", "0");
window.scrollTo(0, 0);
$slide.closest(".slide").removeClass("active");
$($slide.data("slide-target")).addClass("active");
});
});
});
}
};
Lalema.Tools.Smooth_Scrolling_To_Elements = {
init: function() {
$("a.lm-smooth_scroll").click(function(event) {
event.preventDefault();
var $target = $("#" + $(this).data("smooth_scroll_target"));
if ($target.length == 1) {
var hauteur_barre_catalogue = 90;
$("html, body").animate({
scrollTop: $target.offset().top - hauteur_barre_catalogue
}, 500);
}
});
}
};
Lalema.Tools.HTML_Tables_Sorter = {
init: function() {
if (!$.fn.stupidtable) { return false; }
$(".st-th_sortable").each(function() {
$(this).css("cursor", "pointer");
$(this).append("
");
});
$(".st-sortable")
.stupidtable()
.bind("aftertablesort", function(event, data) {
var th = $(this).find("th");
th.find("span").removeClass().addClass("unsorted_arrow");
var arrow = data.direction === "asc" ? "sorted_arrow_up" : "sorted_arrow_down";
th.eq(data.column).find("span").attr("class", arrow);
});
}
};
Lalema.Tools.Tabs_Containers = {
init: function() {
$(".tabs").tabs();
}
};Lalema.Tools.Tooltips = {
init: function() {
$(".jq_tooltips").tooltip({
show: {
"effect": "none",
"delay": 0
},
hide: {
"effect": "none",
"delay": 0
},
tooltipClass: "custom-tooltip",
position: {
"my": "center top",
"at": "center bottom+10"
}
});
$(".jq_tooltips_east").tooltip({
show: {
"effect": "none",
"delay": 0
},
hide: {
"effect": "none",
"delay": 0
},
tooltipClass: "custom-tooltip",
position: {my: "left center", at: "right center"}
});
}
};Lalema.Desktop = {
Views: {},
init: function() {
Lalema.Tools.run_all_basic_tools();
this.Skeleton.init();
this.Skeleton.Catalog_Menu.init();
this.Views.Mini_Fiche_Produit.init();
this.load_script_for_controller("questionnaire", this.Views.Scaffold);
this.load_script_for_controller("survey", this.Views.Scaffold);
this.load_script_for_controller("catalogue", this.Views.Catalogue);
this.load_script_for_controller("catalog", this.Views.Catalogue);
this.load_script_for_controller("produit", this.Views.Fiche_Produit);
this.load_script_for_controller("product", this.Views.Fiche_Produit);
this.load_script_for_controller("chariot", this.Views.Chariot);
this.load_script_for_controller("cart", this.Views.Chariot);
this.load_script_for_controller("soumission", this.Views.Soumission);
this.load_script_for_controller("pricequote", this.Views.Soumission);
},
load_script_for_controller: function(controller_name, ui_object) {
routes = window.location.href.split("/");
controller_loaded = routes[3];
if (controller_loaded == controller_name) {
ui_object.init();
}
}
};
Lalema.Desktop.Skeleton = {
init: function() {
this.setup_autocomplete_in_the_search_box();
this.setup_repaint_cart_preview_on_hover();
this.setup_submit_search_form_on_button_click();
this.reload_cart_on_mouseover = true;
},
repaint_cart_qty: function(data) {
$.fancybox.close();
var visibility = data.nb_of_items > 0 ? "visible" : "invisible";
$("#cart .nb_of_items")
.removeClass("visible")
.removeClass("invisible")
.addClass(visibility)
.html(data.nb_of_items);
this.reload_cart_on_mouseover = false;
this.repaint_cart_preview(function() {
$("#cart-preview_content").show(0,
function() {
var $that = $(this);
var $last_item_added = $(this).find(".item_cart:first-child");
$last_item_added
.effect("highlight", {"color": "#fff"}, 2000)
.find(".recently_added_item").show();
$(this).parent().find(">a").effect("highlight", {"color": "#FF8E25"}, 2000, function() {
$that.css("display", "");
$last_item_added.find(".recently_added_item").hide();
this.reload_cart_on_mouseover = true;
});
}
);
});
},
repaint_cart_preview: function(callback) {
callback = (typeof(callback) === "undefined") ? $.noop() : callback;
$("#cart #cart-preview_content")
.empty()
.load($("#cart").data("preview-url"), callback);
},
setup_autocomplete_in_the_search_box: function() {
$("#main_searchbox").autocomplete({
"source": function(request, response) {
var url = $("#frm_recherche").data("autocomplete-source") + "?q=" + encodeURIComponent(request.term);
$.getJSON(url, function(data) {
response(data);
});
},
"open": function() {
var $auto = $(this).autocomplete("widget");
var searchbox_left = $(this).offset().left - 1;
$auto.css("left", searchbox_left + "px");
$auto.css("width", $(this).outerWidth());
},
"select": function(event, ui) {
document.location.href = "/" + ui.item.permalink;
}
});
$(".ui-autocomplete").removeClass("ui-corner-all");
var new_render_function = function(ul, item) {
var $row = $("");
if (item.type == "famille") {
$row.append(
"
" +
" " + item.prefixe + ": " + item.nom + "
" +
""
);
}
else if (item.type == "bundle") {
$row.append(
"
" +
" " + item.prefixe + ": " + item.nom + "
" +
""
);
}
else if (item.type == "certification") {
$row.append(
"
" +
" " + item.prefixe + ": " + item.nom + "
" +
""
);
}
else if (item.type == "fournisseur") {
$row.append(
"
" +
" " +
" " +
"
" +
" " + item.prefixe + ": " + item.nom +
"
" +
"
" +
""
);
}
else {
var classe_discontinue = item.discontinue != "" ? "discontinue" : "";
$row.append(
"
" +
" " +
"

" +
"
" +
" " +
"
" + item.nom + (classe_discontinue != "" ? " [" + item.discontinue + "]" : "") + "
" +
"
" + item.usage + "
" +
"
" +
"
" +
""
);
}
$row.appendTo(ul);
return $row;
};
$.each($("#main_searchbox"), function(i, e) {
$(e).data("ui-autocomplete")._renderItem = new_render_function;
});
},
setup_repaint_cart_preview_on_hover: function() {
var self = this;
$("#cart").mouseenter(function() {
if (self.reload_cart_on_mouseover) {
self.repaint_cart_preview();
}
});
},
setup_submit_search_form_on_button_click: function() {
$("#searchbox .btn-search-bar").click(function() {
var $search_box = $("#main_searchbox");
if ($search_box.val() == $search_box.data("placeholder")) {
$search_box.val("");
}
$("#frm_recherche").submit();
});
}
};
Lalema.Desktop.Skeleton.Catalog_Menu = {
DELAIS_AVANT_OUVERTURE_CATALOGUE: 200,
DELAIS_AVANT_FERMETURE_CATALOGUE: 300,
DELAIS_ANIMATION_SLIDEDOWN_MENU: 300,
DELAIS_CHANGEMENT_SELECTION_FAMILLE: 200,
init: function() {
var self = this;
self.$catalog = $("#catalog");
self.$catalog_title = $("#catalog_title");
self.$catalog_choices = $("#catalog_choices");
self.$root_categories = $("#root_categories");
self.$child_categories = $("#child_categories");
self.$category_image = $("#category_image img");
self.timer_root_choice = 0;
self.timer_catalog = 0;
self.is_opening = false;
var is_tablet_touching = false;
self.$catalog.mouseleave(function() {
window.clearTimeout(self.timer_catalog);
self.timer_catalog = window.setTimeout(function() {
self._close_catalog_menu();
}, self.DELAIS_AVANT_FERMETURE_CATALOGUE);
});
self.$catalog.mouseenter(function() {
window.clearTimeout(self.timer_catalog);
if ($(this).hasClass("opened")) {
self.timer_catalog = 0;
}
else {
self.timer_catalog = window.setTimeout(function() {
self._open_catalog_menu();
}, self.DELAIS_AVANT_OUVERTURE_CATALOGUE);
}
});
self.$catalog_title.click(function() {
window.clearTimeout(self.timer_catalog);
if ($(this).hasClass("opened") && !self.is_opening) {
self._close_catalog_menu();
}
else {
if (self.is_opening) { return 1; }
self._open_catalog_menu();
}
});
self.$child_categories.mouseover(function() {
window.clearTimeout(self.timer_root_choice);
});
$(".root_category").mouseover(function() {
window.clearTimeout(self.timer_root_choice);
var $that = $(this);
self.timer_root_choice = window.setTimeout(function() {
if (!self.$child_categories.is(".table_cell_visible")) {
self.$child_categories.addClass("table_cell_visible");
self.$root_categories.addClass("childs_are_visible");
self.$catalog_choices.css("width", "960px");
}
self.$child_categories.find(".child_category:visible").hide();
self.$child_categories.find("#child_category_of_" + $that.data("id")).show();
self.$root_categories.find(".selected_root_element").removeClass("selected_root_element");
$that.addClass("selected_root_element");
self.$category_image.attr("src", $that.data("image"));
}, (is_tablet_touching ? 0 : self.DELAIS_CHANGEMENT_SELECTION_FAMILLE) );
}).on("touchstart", function() {
is_tablet_touching = true;
}).click(function(e) {
if (is_tablet_touching) {
e.preventDefault();
is_tablet_touching = false;
}
});
$(".category_name").mouseover(function() {
self.$category_image.attr("src", $(this).data("image"));
});
this.switch_to_fixed_when_scrolled();
},
switch_to_fixed_when_scrolled: function() {
var height_treshold = $("#shopping").offset().top;
$(window).scroll(function() {
if ($(window).scrollTop() > height_treshold) {
/* Fixed colle au top */
$("#shopping_container").addClass("fixed_to_the_top");
$("ul.ui-autocomplete")
.css("position", "fixed")
.css("top", ($("#main_searchbox").offset().top - $("#shopping").offset().top) + $("#main_searchbox").outerHeight());
}
else {
/* Flow normal */
$("#shopping_container").removeClass("fixed_to_the_top");
$("ul.ui-autocomplete")
.css("position", "absolute")
.css("top", $("#main_searchbox").offset().top + $("#main_searchbox").outerHeight() - 1);
}
$("ul.ui-autocomplete").css("left", $("#main_searchbox").offset().left - 1);
});
},
_close_catalog_menu: function() {
var self = this;
window.clearTimeout(self.timer_root_choice);
self.$catalog_choices.removeClass("table_visible");
self.$child_categories.removeClass("table_cell_visible");
self.$root_categories.find(".selected_root_element").removeClass("selected_root_element");
self.$root_categories.removeClass("childs_are_visible");
self.$catalog_choices.css("width", "auto");
self.$catalog_title.removeClass("opened").addClass("closed");
},
_open_catalog_menu: function() {
var self = this;
self.is_opening = true;
self.$catalog_choices.addClass("table_visible");
self.$catalog_title.removeClass("closed").addClass("opened");
}
};
Lalema.Desktop.Views.Catalogue = {
init: function() {
var self = this;
var $form = $("#frmFiltres");
this.setup_submit_form_when_checkbox_clicked($form);
this.setup_remove_filter_and_resubmit_form($form);
this.setup_position_retour_en_haut();
},
filtrer_produits_disponibles_sur_lalema_express: function(afficher_les_produits) {
},
recalculer_position_retour_en_haut: function() {
var $retour = $("#container_retour_en_haut_famille");
var position_retour_en_haut = $("#liste_produits").offset().left + $("#liste_produits").width();
$retour.css("left", position_retour_en_haut);
},
setup_position_retour_en_haut: function() {
var $retour = $("#container_retour_en_haut_famille");
var self = this;
$(window).resize(function() {
self.recalculer_position_retour_en_haut();
});
$(window).scroll(function() {
if ($("#shopping_container").hasClass("fixed_to_the_top")) {
$retour.addClass("active");
}
else {
$retour.removeClass("active");
}
});
self.recalculer_position_retour_en_haut();
},
setup_submit_form_when_checkbox_clicked: function($form) {
$form.find(".chk_filtre").change(function() {
$form.submit();
});
},
setup_remove_filter_and_resubmit_form: function($form) {
$("#liste_filtres_appliques .filtre_applique a").click(function() {
var $that = $(this);
$(this).parent().fadeOut("fast", function() {
$checkbox = $form.find("#carac_" + $that.attr("rel"));
$checkbox.attr("checked", false);
$form.submit();
});
});
}
};
Lalema.Desktop.Views.Chariot = {
init: function() {
this.setup_submit_buttons();
this.setup_delete_quantity_buttons();
//this.setup_find_google_map_infos();
this.setup_class_pulse_button_over();
this.prevent_infinite_recursion = false;
},
setup_find_google_map_infos: function() {
/*
Procedure pour intercepter les calls fautifs a l'API de google (genre si la clef API fonctionne pas)
window.gm_authFailure() = function() {
alert("le call a l'api est bloque AVANT le callback...");
}
*/
var $form = $("#chariot_etape_remplir_coordonnees #frm_chariot");
var self = this;
$form.submit(function(e) {
if (!self.prevent_infinite_recursion) {
e.preventDefault();
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { "address": $form.find("#codepostal").val() }, function(results, status) {
self.prevent_infinite_recursion = true;
if (status == "OK" && "formatted_address" in results[0]) {
$form.find("#googlemap_infos").val(results[0].formatted_address);
}
else {
$form.find("#googlemap_infos").val("NA on Google Maps API");
}
$form.submit();
});
}
});
},
setup_class_pulse_button_over: function() {
$(".bouton_soumettre_chariot").hover(function() {
$(".etapes").toggleClass('pulse');
});
},
setup_submit_buttons: function() {
var $form = $("#chariot_etape_ajuster_quantites #frm_chariot");
$("#chariot_etape_ajuster_quantites .bouton_ajuster_quantite").click(function() {
$form.submit();
});
$("#chariot_etape_ajuster_quantites .bouton_soumettre_chariot").click(function(event) {
event.preventDefault();
$form.find("#show_step2").val("1");
$form.submit();
});
},
setup_delete_quantity_buttons: function() {
$("#chariot_etape_ajuster_quantites .bouton_effacer_quantite").click(function() {
$(this).parent().find("input[type='text']").val("0");
$("#frm_chariot").submit();
});
}
};
/*
##############################################################
# LalemaUI.Views.Fiche_Produit #
##############################################################
*/
Lalema.Desktop.Views.Fiche_Produit = {
/*
+------------------------------+
| Public |
+------------------------------+
*/
init: function() {
this.setup_ajuster_position_boite_demander_un_prix_sur_scroll();
this.setup_image_tooltip_for_list_of_skus();
this.setup_interactive_options_selection();
},
/*................................*/
setup_ajuster_position_boite_demander_un_prix_sur_scroll: function() {
var etat_boite_demander_un_prix = "absolute-top";
var margin_top = 40;
var $section_demander_un_prix = $("#demander_un_prix");
$(window).scroll(function() {
if (window.innerWidth < 640) { return 0; }
var offset_bottom_barre_catalogue = $("#shopping_container").offset().top + $("#shopping_container").height();
var offset_top_footer = $(".menu_principal").offset().top;
var delta_footer_barre = offset_top_footer - offset_bottom_barre_catalogue;
var hauteur_total_requise = $section_demander_un_prix.outerHeight(true) + margin_top;
if ($("#shopping_container").hasClass("fixed_to_the_top")) {
if (delta_footer_barre > hauteur_total_requise) {
if (etat_boite_demander_un_prix != "fixed") {
$section_demander_un_prix.css({ "position" : "fixed", "bottom" : "auto", "top" : ($("#shopping_container").height() + margin_top) });
etat_boite_demander_un_prix = "fixed";
}
}
else {
if (etat_boite_demander_un_prix != "absolute-bottom") {
$section_demander_un_prix.css({ "position" :" absolute", "bottom" : "0", "top": "auto" });
etat_boite_demander_un_prix = "absolute-bottom";
}
}
}
else {
if (etat_boite_demander_un_prix != "absolute-top") {
$section_demander_un_prix.css({"position":"absolute", "bottom":"auto", "top": "0"});
etat_boite_demander_un_prix = "absolute-top";
}
}
});
},
/*................................*/
setup_image_tooltip_for_list_of_skus: function() {
$(".lm-img_tooltip").tooltip({
"content": function() {
return "
.data("img") + ")
";
},
tooltipClass: "custom-tooltip",
position: {my: "left center", at: "right+10 center"}
});
},
/*................................*/
setup_interactive_options_selection: function() {
var self = this;
/* transforme ("skin") le input select */
$("#fiche_produit .section_demander_un_prix .liste_options").selectBoxIt({
"autoWidth": false,
"aggressiveChange": true
});
$("#fiche_produit .section_demander_un_prix span.selectboxit-container").each(function() {
var i = 0;
var select_boxit = $(this).prev().data("selectBox-selectBoxIt");
$(this).find(".selectboxit-list").each(function() {
$(this).css("width", Lalema.Tools.get_invisible_width($(this)) + 20);
});
$(this).find("li.selectboxit-option").mouseenter(function() {
var index = parseInt($(this).data("id"));
select_boxit.selectOption(index);
});
});
$("#fiche_produit .section_demander_un_prix .liste_options").change(function() {
//alert(this.value);
var hash_key = self._get_concatenation_des_valeurs_des_options();
var sku = self.database_skus[hash_key];
self._set_active_sku(sku);
}).on("open", function() {
$(this).next().css("z-index", "9999");
}).on("close", function() {
$(this).next().css("z-index", "1");
});
;
},
/*
+------------------------------+
| Private |
+------------------------------+
*/
_get_concatenation_des_valeurs_des_options: function() {
var valeur = "";
$("#fiche_produit .section_demander_un_prix select.liste_options").each(function() {
valeur += this.value;
});
return valeur;
},
/*................................*/
_set_active_sku: function(sku) {
var self = this;
if (sku === undefined) {
$("#fiche_produit").removeClass("sku_existe").addClass("sku_existe_pas");
}
else {
/* afficher l'image et la form */
$("#fiche_produit").removeClass("sku_existe_pas").addClass("sku_existe");
/* changer l'image du sku */
var $image = $("#fiche_produit #section_media .trim_image_container img.image_principale");
$image.attr("src", sku.path_image_trim);
$image.data("default_src", sku.path_image_trim);
$image.css("height", sku.height_image_trim);
/* changer l'image du sku_magnetique */
var $image_magnetique = $("#fiche_produit #demander_un_prix .fiche_magnetique img");
$image_magnetique.attr("src", sku.path_image_small);
/* changer le sku */
var $sku = $("#fiche_produit #sommaire_produit .sku");
var $sku_magnetique = $("#fiche_produit .section_demander_un_prix .sku");
$sku.html("#" + sku.sku);
$sku_magnetique.html("#" + sku.sku);
/* changer le code fournisseur */
var $code_fournisseur = $("#fiche_produit #sommaire_produit .code_fournisseurs");
$code_fournisseur.html(sku.code_fournisseur);
/* changer le format de vente */
var $format_vente = $("#fiche_produit #demander_un_prix #format_vente");
$format_vente.html(sku.format_vente);
/* changer le minimum requis à l'achat */
var $qte_minimum_achat = $("#fiche_produit .qte_minimum_achat");
if (sku.qte_minimum_achat !== "") {
$qte_minimum_achat.addClass("visible");
}
else {
$qte_minimum_achat.removeClass("visible");
}
$qte_minimum_achat.find(".valeur").html(sku.qte_minimum_achat);
/* changer les notes specifiques au sku */
var $notes = $("#fiche_produit #sommaire_produit .notes_sku");
$notes.html(sku.notes);
/* changer l'etat de la livraison rapide */
if (sku.qte_disponible > 0) {
$(".badge.livraison_rapide").addClass("visible");
}
else {
$(".badge.livraison_rapide").removeClass("visible");
}
/* changer l'url du bouton pour ajouter au chariot */
$("#fiche_produit #frm_ajouter_chariot #id_sku").val(sku.id);
/* changer l'etat du bouton des pieces supplementaires */
if (sku.nb_pieces > 0) {
$(".badge.pieces_disponibles").addClass("visible");
$(".badge.pieces_disponibles").attr("href", sku.url_pieces);
}
else {
$(".badge.pieces_disponibles").removeClass("visible");
$(".badge.pieces_disponibles").attr("href", "");
}
/* changer l'etat des disponibilites */
$("#demander_un_prix .etats_disponibilites .message.bientot_disponible .date").html(sku.date_disponibilite);
$("#demander_un_prix .etats_disponibilites .message.bientot_en_peremption .date").html(sku.date_peremption);
$("#demander_un_prix .etats_disponibilites").removeClass("bientot_disponible bientot_en_peremption en_peremption").addClass(sku.etats_disponibilites);
self.setup_dimensions_du_sommaire();
}
}
};
Lalema.Desktop.Views.Fiche_Produit.Options_Seulement = {
init: function() {
var self = this;
self.setup_interactive_options_selection();
self.setup_cancel_button();
self.setup_form_submit();
self.resize_selectbox_because_internet_explorer_is_a_really_really_REALLY_stupid_browser();
},
resize_selectbox_because_internet_explorer_is_a_really_really_REALLY_stupid_browser: function() {
$("body").on("fboxLoaded", function() {
$(this).find(".selectboxit-list").each(function() {
var LARGEUR_COMBO_BOX_PAR_DEFAUT = 227;
$(this).css("width", Math.max(LARGEUR_COMBO_BOX_PAR_DEFAUT, Lalema.Tools.get_invisible_width($(this)) + 10));
});
});
},
setup_cancel_button: function() {
$(".bouton_cancel").click(function() {
parent.$.fancybox.close();
});
},
setup_form_submit: function() {
var $form = $("#iframe_configuration_options_sku");
$form.submit(function(e) {
e.preventDefault();
$.ajax({
"url": $form.attr("action"),
"data": $form.serialize(),
success: function(data) {
if (data.errors != 0) {
parent.window.alert(data.flashes[0].message);
}
else {
var refresh_parent = $("#refresh_parent").val();
if (refresh_parent == "1") {
parent.location.href = parent.location.href;
}
else {
parent.Lalema.Desktop.Skeleton.repaint_cart_qty(data);
}
}
}
});
});
$(".bouton_ajouter").click(function() { $form.submit(); })
},
setup_interactive_options_selection: function() {
var self = this;
$(".liste_options").selectBoxIt({
"autoWidth": true
});
$("span.selectboxit-container").each(function() {
var $select_boxit = $(this).prev().data("selectBox-selectBoxIt");
var i = 0;
$(this).find("li.selectboxit-option").mouseenter(function() {
var index = parseInt($(this).data("id"));
$select_boxit.selectOption(index);
});
});
$(".liste_options").change(function() {
var hash_key = self._get_concatenation_des_valeurs_des_options();
var sku = self.database_skus[hash_key];
self._set_active_sku(sku);
}).on("open", function() {
$(this).next().css("z-index", "9999");
}).on("close", function () {
$(this).next().css("z-index", "1");
});
},
_get_concatenation_des_valeurs_des_options: function() {
var valeur = "";
$("#iframe_configuration_options_sku select.liste_options").each(function() {
valeur += this.value;
});
return valeur;
},
_set_active_sku: function(sku) {
if (sku === undefined) {
$("#iframe_configuration_options_sku").addClass("sku_existe_pas").removeClass("sku_existe");
}
else {
$("#iframe_configuration_options_sku").addClass("sku_existe").removeClass("sku_existe_pas");
/* changer l'image du sku */
var $image = $("#iframe_configuration_options_sku .section_image .image_et_sku img");
$image.attr("src", sku.path_image_medium);
/* changer le sku */
var $sku = $(".sku");
$sku.html(sku.sku);
/* changer "livraison rapide" */
if (sku.qte_disponible > 0) {
$(".tag_livraison_rapide").addClass("etat_livraison_rapide");
}
else {
$(".tag_livraison_rapide").removeClass("etat_livraison_rapide");
}
/* changer le format de vente */
var $format_vente = $("#format_vente");
$format_vente.html(sku.format_vente);
/* changer le minimum requis à l'achat */
var $qte_minimum_achat = $(".qte_minimum_achat");
if (sku.qte_minimum_achat !== "") {
$qte_minimum_achat.addClass("visible");
}
else {
$qte_minimum_achat.removeClass("visible");
}
$qte_minimum_achat.find(".valeur").html(sku.qte_minimum_achat);
/* changer l'etat des disponibilites */
$(".etats_disponibilites .date_disponibilite").html(sku.date_disponibilite);
$(".etats_disponibilites .date_peremption").html(sku.date_peremption);
$(".etats_disponibilites").removeClass("bientot_disponible bientot_en_peremption en_peremption").addClass(sku.etats_disponibilites);
/* changer l'url du bouton pour ajouter au chariot */
$("#iframe_configuration_options_sku #id_sku").val(sku.id);
parent.$.fancybox.update();
}
}
}
Lalema.Desktop.Views.Mini_Fiche_Produit = {
init: function() {
var self = this;
$(".liste_de_skus").each(function() {
var $liste = $(this);
self.setup_boutons_modes_affichage($liste);
self.setup_boutons_filtres_lives($liste);
if ($liste.data("utilise-cookies") == 1 && $.cookie("mode_affichage_liste_skus")) {
$liste.data("mode-affichage", $.cookie("mode_affichage_liste_skus"));
}
var mode_affichage_courant = $(".liste_de_skus").data("mode-affichage");
mode_affichage_courant = mode_affichage_courant === "" ? "portrait" : mode_affichage_courant;
self.repaint_mode_affichage($liste, mode_affichage_courant);
});
self.setup_z_index_sections_specifications();
},
detecter_si_listes_specifications_trop_hautes: function($liste) {
var PADDING_PARENT = 10;
$liste.find(".mini_fiche_produit").each(function() {
$liste_specs = $(this).find("ul.certifications_minifiche");
if ($liste_specs.height() + PADDING_PARENT > $liste_specs.parent().height()){
$liste_specs.parent().addClass("expandable");
}
});
},
repaint_mode_affichage: function($liste, mode_affichage) {
var self = this;
$liste.removeClass("portrait").removeClass("paysage").addClass(mode_affichage);
$liste.find(".mini_fiche_produit")
.removeClass("portrait")
.removeClass("paysage")
.addClass(mode_affichage);
if (mode_affichage == "paysage") {
$liste.find(".mini_fiche_produit").css("min-height", "");
self.detecter_si_listes_specifications_trop_hautes($liste);
}
if (mode_affichage == "portrait") {
self.setup_min_height_fiches_en_mode_portrait($liste);
}
},
setup_boutons_filtres_lives: function($liste) {
var self = this;
$liste.find(".bouton_filtre_live").click(function(e) {
$(this).toggleClass("on");
});
},
setup_boutons_modes_affichage: function($liste) {
var self = this;
$(".liste_de_skus .icon_affichage").click(function(e) {
e.preventDefault();
self.set_mode_affichage($liste, $(this).data("mode-affichage"));
});
},
setup_min_height_fiches_en_mode_portrait : function($liste) {
var max_height = 0;
$liste.find(".mini_fiche_produit.portrait").each(function() {
if ($(this).outerHeight() > max_height) {
max_height = $(this).outerHeight();
}
});
$liste.find(".mini_fiche_produit.portrait").css("min-height", max_height+5);
},
set_mode_affichage: function($liste, mode_affichage) {
var self = this;
var mode_affichage_courant = $liste.data("mode-affichage");
if ( mode_affichage_courant === mode_affichage) { return 0; }
$liste.data("mode-affichage", mode_affichage);
$.cookie("mode_affichage_liste_skus", mode_affichage, {"expires" : 365, "path": "/"} );
self.repaint_mode_affichage($liste, mode_affichage);
},
setup_z_index_sections_specifications: function() {
var zindex = 999;
$(".mini_fiche_produit .section_specifications").each(function() {
$(this).css("z-index", zindex--);
});
}
};
/*
##############################################################
# LalemaUI.Views.Scaffold #
##############################################################
*/
Lalema.Desktop.Views.Scaffold = {
init: function() {
var self = this;
self.setup_file_input();
self.setup_advanced_selectbox();
},
setup_advanced_selectbox: function() {
},
setup_file_input: function() {
$("input:file").change(function() {
$("label[for=" + $(this).attr("id") + "]").html($(this).val());
});
}
};Lalema.Desktop.Views.Soumission = {
init: function() {
this.timer_id = 0;
this.setup_transitions();
this.setup_timer();
},
setup_transitions: function() {
var self = this;
$("#soumission .square").click(function() {
if (!$(this).hasClass("active")) {
var index = parseInt($(this).index() + 1);
$(this)
.addClass("active")
.siblings(".square")
.removeClass("active");
$(".screen")
.removeClass()
.addClass('screen')
.addClass("screen_position" + index);
$(".phrase_contextuelle" + index)
.show("ease")
.siblings()
.hide("ease");
$(".arrow_medium_south")
.removeClass()
.addClass("arrow_position" + index)
.addClass("arrow_medium_south");
self.setup_timer();
}
});
$(".os > div").click(function() {
var classes = $(".laptop").attr("class");
classes = classes.replace(/\bos_.+\b/gi, "") + " os_" + $(this).data("os");
$(".laptop").attr("class", classes);
});
},
setup_timer: function() {
var self = this;
clearInterval(self.timer_id);
self.timer_id = setTimeout(function() {
var index_active_square = $(".indicator .square.active").index();
var next_index = (index_active_square + 1) % 3;
var next_selector = ".indicator .square.position" + (next_index + 1);
$(next_selector).click();
self.setup_timer();
}, 3000);
}
};