2017-06-20 16:41:01 +02:00

189 lines
6.2 KiB
JavaScript

function updateFaces()
{
// reset faces
$('.chocos-holder').find('.noms-holder').remove();
$('.chocos-holder').find('.date-holder').remove();
$('.container-pochette').find('.noms-holder').remove();
$('.container-pochette').find('.date-holder').remove();
$('.face-custom-txt').removeClass('face-custom-txt');
$('.face-custom-img').removeClass('face-custom-img');
$(".chocos-holder").empty()
$(".container-pochette").empty()
$(".chocos-holder").html($('#temp-base .chocos').contents().clone());
$(".container-pochette").html($('#temp-base .pochettes').contents().clone());
//CHOCOS
// faces chocos identiques
if(theme == "chocolate" || theme == "cinema" || theme == "oriental" || theme == "champetre")
{
//chocos
$('#custom_elmts .noms-holder').clone().appendTo(".chocos-holder .front")
$('#custom_elmts .date-holder-line').clone().appendTo(".chocos-holder .back")
$('.chocos-holder .front').css({'background-image':'url('+themeImg+'/chocos/01.png)'})
$('.chocos-holder .back').css({'background-image':'url('+themeImg+'/chocos/02.png)'})
//pochette
$('#custom_elmts .noms-holder').clone().appendTo(".container-pochette .front")
$('#custom_elmts .date-holder-line').clone().appendTo(".container-pochette .back")
$('.container-pochette .front').css({'background-image':'url('+themeImg+'/chocos/01.png)'})
$('.container-pochette .back').css({'background-image':'url('+themeImg+'/chocos/02.png)'})
}
// faces chocos différentes
else
{
//chocos
$('#custom_elmts .noms-holder').clone().appendTo(".chocos-holder .choco1 .front")
$('#custom_elmts .noms-holder').clone().appendTo(".chocos-holder .choco4 .front")
$('#custom_elmts .date-holder').clone().appendTo(".chocos-holder .choco2 .front")
$('.chocos-holder .choco1 .front').css({'background-image':'url('+themeImg+'/chocos/01.png)'})
$('.chocos-holder .choco1 .back').css({'background-image':'url('+themeImg+'/chocos/02.png)'})
$('.chocos-holder .choco2 .front').css({'background-image':'url('+themeImg+'/chocos/03.png)'})
$('.chocos-holder .choco2 .back').css({'background-image':'url('+themeImg+'/chocos/04.png)'})
$('.chocos-holder .choco3 .front').css({'background-image':'url('+themeImg+'/chocos/05.png)'})
$('.chocos-holder .choco3 .back').css({'background-image':'url('+themeImg+'/chocos/06.png)'})
$('.chocos-holder .choco4 .front').css({'background-image':'url('+themeImg+'/chocos/07.png)'})
$('.chocos-holder .choco4 .back').css({'background-image':'url('+themeImg+'/chocos/08.png)'})
$('.chocos-holder .choco5 .front').css({'background-image':'url('+themeImg+'/chocos/09.png)'})
$('.chocos-holder .choco5 .back').css({'background-image':'url('+themeImg+'/chocos/10.png)'})
//pochette
$('#custom_elmts .noms-holder').clone().appendTo(".container-pochette .pochette1 .front")
$('#custom_elmts .noms-holder').clone().appendTo(".container-pochette .pochette4 .front")
$('#custom_elmts .date-holder').clone().appendTo(".container-pochette .pochette2 .front")
$('.container-pochette .pochette1 .front').css({'background-image':'url('+themeImg+'/chocos/01.png)'})
$('.container-pochette .pochette1 .back').css({'background-image':'url('+themeImg+'/chocos/02.png)'})
$('.container-pochette .pochette2 .front').css({'background-image':'url('+themeImg+'/chocos/03.png)'})
$('.container-pochette .pochette2 .back').css({'background-image':'url('+themeImg+'/chocos/04.png)'})
$('.container-pochette .pochette3 .front').css({'background-image':'url('+themeImg+'/chocos/05.png)'})
$('.container-pochette .pochette3 .back').css({'background-image':'url('+themeImg+'/chocos/06.png)'})
$('.container-pochette .pochette4 .front').css({'background-image':'url('+themeImg+'/chocos/07.png)'})
$('.container-pochette .pochette4 .back').css({'background-image':'url('+themeImg+'/chocos/08.png)'})
}
if(theme == "fleurs" || theme == "tendance" || theme == "uv" || theme == "voyage" || theme == "vintage" || theme == "gourmandise")
{
$('#custom_elmts .noms-holder').clone().appendTo(".chocos-holder .choco5 .front")
}
$('.chocos-holder .flip-container').eq(4).hide();
}
function initDrag()
{
$('#simu-box').on(events.start, function(e) {
if (hasTouchSupport) {
var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
p0 = { 'x': touch.pageX, 'y': touch.pageY };
} else {
p0 = { 'x': e.clientX, 'y': e.clientY };
}
_flag = true;
$(document).on(events.move, drag);
$('.simu-container').removeClass('animated');
e.preventDefault();
});
$(document).on(events.end, function(e) {
var p1;
if (hasTouchSupport) {
var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
p1 = { 'x': touch.pageX, 'y': touch.pageY };
} else {
p1 = { 'x': e.clientX, 'y': e.clientY };
}
_flag = false;
$(document).off(events.move, drag);
_angle = {'x': _anglelast.x, 'y': _anglelast.y}
});
}
function drag(e) {
/* distance and angle values since starting to drag */
var p1;
if(hasTouchSupport) {
var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
p1 = { 'x': touch.pageX - p0.x, 'y': touch.pageY - p0.y }
} else {
p1 = { 'x': e.clientX - p0.x, 'y': e.clientY - p0.y }
}
var angle = {'x': -p1.y*_unit, 'y': p1.x*_unit};
tmp = 'rotateX(' + (_angle.x + angle.x) + 'deg)' + 'rotateY(' + (_angle.y + angle.y) + 'deg) scale(.92)';
$('.simu-container').css({'-webkit-transform' : tmp , 'transform' : tmp});
_anglelast = {'x': (_angle.x + angle.x), 'y': (_angle.y + angle.y)}
};
var
_factor = 1,
_max_amount = 460,
_unit = 360/_max_amount ,
_flag = false,
_angle = {'x': 0, 'y': 0};
_anglelast = {'x': 0, 'y': 0};
;
var _custom =
{
'face_custom' :
{
'image' : null,
'text' : '',
'is_initials' : false
},
'faces_dc_exclu' :
{
},
'faces_chocos_exclu' :
{
}
}
var face_exclu =
{
'index' : 0,
'image' : null,
'color' : '',
'color_text' : '',
'text' : '',
'font' : '',
'is_initials' : false,
'is_custom' : false
}
var rotateR =
[
null,
[-90,0],
[90,0],
[0,180],
[0,0],
[0,100],
[0,-20],
[-90,0],
[90,0],
[0,180],
[0,0],
[0,20],
[0,-100]
]
// Start when DOM is ready
$(function() {
updateFaces();
initDrag();
$('.flip-container').addClass('argent');
$('.pochetteface').not('.front,.back').addClass('argent');
});