276 lines
8.4 KiB
JavaScript
276 lines
8.4 KiB
JavaScript
var
|
|
_factor = 1,
|
|
_max_amount = 460,
|
|
_unit = 360/_max_amount ,
|
|
_flag = false,
|
|
_angle = {'x': 0, 'y': 0};
|
|
_anglelast = {'x': 0, 'y': 0};
|
|
;
|
|
|
|
var monthR = ["","Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"];
|
|
|
|
var faceDeg = {
|
|
'top': { 'x': 0, 'y': 0, },
|
|
'bottom': { 'x': 0, 'y': 0, },
|
|
'back': { 'x': 0, 'y': 0, },
|
|
'front': { 'x': 0, 'y': 45, },
|
|
'left': { 'x': 0, 'y': 0, },
|
|
'right': { 'x': 0, 'y': 0, },
|
|
};
|
|
|
|
// Start when DOM is ready
|
|
$(function() {
|
|
initInfos();
|
|
initFaces();
|
|
initDrag();
|
|
});
|
|
|
|
function initFaces()
|
|
{
|
|
// reset faces
|
|
$('.container-db').find('.noms-holder').remove();
|
|
$('.container-db').find('.date-holder').remove();
|
|
$('.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');
|
|
|
|
$(".container-db").empty()
|
|
$(".chocos-holder").empty()
|
|
$(".container-pochette").empty()
|
|
|
|
$(".container-db").html($('#temp-base .doublecube').contents().clone());
|
|
$(".chocos-holder").html($('#temp-base .chocos').contents().clone());
|
|
$(".container-pochette").html($('#temp-base .pochettes').contents().clone());
|
|
|
|
$('.container-db .cubeface').html($('#temp-exclu .excluface').contents().clone()).css({'background' : 'url('+themeImg+'/face.jpg)'})
|
|
$('.chocos-holder .flipper .front').html($('#temp-exclu .excluface').contents().clone()).css({'background' : 'url('+themeImg+'/face.jpg)'})
|
|
$('.chocos-holder .flipper .back').html($('#temp-exclu .excluface').contents().clone()).css({'background' : 'url('+themeImg+'/face.jpg)'})
|
|
$('.container-pochette .pochette .front').html($('#temp-exclu .excluface').contents().clone()).css({'background' : 'url('+themeImg+'/face.jpg)'})
|
|
$('.container-pochette .pochette .back').html($('#temp-exclu .excluface').contents().clone()).css({'background' : 'url('+themeImg+'/face.jpg)'})
|
|
|
|
/*setFacesExclu(_custom.faces_dc_exclu,$('.exclu .container-db .cubeface'))
|
|
setFacesExclu(_custom.faces_chocos_exclu,$('.exclu .chocos-holder .flipper .front'))
|
|
|
|
$('.exclu .container-db .cubeface').on('click',function(){
|
|
|
|
_faceSelected = "dc";
|
|
$_face_exclu = $(this);
|
|
|
|
$('.imgface').removeClass('actif')
|
|
$(this).find('.imgface').addClass('actif');
|
|
_face_exclu_id = parseInt($(this).attr('data-id'));
|
|
_face_exclu = _custom.faces_dc_exclu["face_"+_face_exclu_id];
|
|
|
|
//log('_face_exclu : ' + _face_exclu.text)
|
|
|
|
});
|
|
|
|
$('.exclu .chocos-holder .flipper .front').on('click',function(){
|
|
|
|
_faceSelected = "chocos"
|
|
$_face_exclu = $(this);
|
|
|
|
$('.imgface').removeClass('actif')
|
|
$(this).find('.imgface').addClass('actif');
|
|
_choco_exclu_id = parseInt($(this).attr('data-id'));
|
|
_face_exclu = _custom.faces_chocos_exclu["face_"+_choco_exclu_id];
|
|
|
|
$('.exclu .container-pochette .pochette').eq(_choco_exclu_id-1).find('.front').html($('.exclu .chocos-holder .flipper').eq(_choco_exclu_id-1).find('.front').contents().clone())
|
|
$('.exclu .container-pochette .pochette').eq(_choco_exclu_id-1).find('.back').html($('.exclu .chocos-holder .flipper').eq(_choco_exclu_id-1).find('.front').contents().clone())
|
|
});
|
|
|
|
$('.container-pochette .pochette').on('click',function(){
|
|
|
|
var index = parseInt($(this).attr('data-id'))-1;
|
|
|
|
$('.exclu .chocos-holder .flipper').eq(index).find('.front').click()
|
|
$('.exclu .container-pochette .pochette').eq(index).find('.front').html($('.exclu .chocos-holder .flipper').eq(index).find('.front').contents().clone())
|
|
$('.exclu .container-pochette .pochette').eq(index).find('.back').html($('.exclu .chocos-holder .flipper').eq(index).find('.front').contents().clone())
|
|
});*/
|
|
|
|
$('.exclu .container-db .cubeface').eq(3).click()
|
|
$('.chocos-holder .flip-container').eq(4).show();
|
|
}
|
|
|
|
//=== Events
|
|
$('#NOM1').on('keyup click', function(){
|
|
defNOM1($(this));
|
|
rotateDC(0,45);
|
|
});
|
|
|
|
$('#NOM2').on('keyup click', function(){
|
|
defNOM2($(this));
|
|
rotateDC(0,45);
|
|
});
|
|
|
|
$('#PERSOTXT').on('keyup click', function(){
|
|
var txt = $(this).val().replace(/\n/g, "<br />");
|
|
$('.face-custom-img').empty();
|
|
$('.face-custom-txt').html('<div class="freetext-holder"></div>');
|
|
$('.freetext-holder').html(txt).css({'margin-top':-$('.freetext-holder').height()*0.5});
|
|
rotateDC(0,180);
|
|
});
|
|
|
|
$('#DATEMARIAGE').on('change click', function(e) {
|
|
defDATEMARIAGE($(this));
|
|
rotateDC(0,90);
|
|
});
|
|
|
|
$('.FACELIBRE').on('change', function(e) {
|
|
defFACELIBRE($(this));
|
|
rotateDC(0,180);
|
|
});
|
|
|
|
$('#EMBALLAGE').on('change', function(e) {
|
|
defEMBALLAGE($(this));
|
|
});
|
|
|
|
$('#PELLICULAGE').on('change', function(e) {
|
|
defPELLICULAGE($(this));
|
|
});
|
|
|
|
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)}
|
|
};
|
|
|
|
// === Functions
|
|
|
|
function initInfos()
|
|
{
|
|
defNOM1($('#NOM1'));
|
|
defNOM2($('#NOM2'));
|
|
defDATEMARIAGE($('#DATEMARIAGE'));
|
|
defFACELIBRE($('.FACELIBRE'));
|
|
defPELLICULAGE($('#PELLICULAGE'));
|
|
defEMBALLAGE($('#EMBALLAGE'));
|
|
}
|
|
|
|
function defDATEMARIAGE(obj){
|
|
var day = obj.val().substring(0,2);
|
|
var month = obj.val().substring(3,5);
|
|
var year = obj.val().substring(6,10);
|
|
$('.day').html(day);
|
|
$('.month').html(monthR[parseInt(month)]);
|
|
$('.year').html(year);
|
|
}
|
|
|
|
function defNOM1(obj){
|
|
$('.nom_1').html(obj.val())
|
|
$('.initiale_1').html(obj.val().substring(0,1));
|
|
}
|
|
|
|
function defNOM2(obj){
|
|
$('.nom_2').html(obj.val())
|
|
$('.initiale_2').html(obj.val().substring(0,1));
|
|
}
|
|
|
|
function defFACELIBRE(obj){
|
|
var choice = obj.find('option:selected').text();
|
|
$(".face-custom-txt").empty();
|
|
$('.face-custom-img').empty();
|
|
if (choice == "Aucune") {
|
|
//Nothing
|
|
} else if(choice == "Image") {
|
|
|
|
} else if(choice == "Texte") {
|
|
var txt = $('#PERSOTXT').val().replace(/\n/g, "<br/>");
|
|
$('.face-custom-txt').html('<div class="freetext-holder"></div>');
|
|
$('.freetext-holder').html(txt).css({'margin-top':-$('.freetext-holder').height()*0.5});
|
|
} else if(choice == "Initiales") {
|
|
$('#custom_elmts .initiales-holder').clone().appendTo(".face-custom-txt");
|
|
}
|
|
}
|
|
|
|
function defPELLICULAGE(obj){
|
|
$('.matface').remove();
|
|
if(obj.find('option:selected').text() == "Mat") {
|
|
$('.cubeface').append('<div class="matface"></div>')
|
|
}
|
|
}
|
|
|
|
function defEMBALLAGE(obj){
|
|
var choice = obj.find('option:selected').text();
|
|
$('.flip-container').removeClass('argent');
|
|
$('.flip-container').removeClass('or');
|
|
if (choice == "Argenté") {
|
|
$('.flip-container').addClass('argent');
|
|
} else if (choice == "Doré") {
|
|
$('.flip-container').addClass('or');
|
|
}
|
|
}
|
|
|
|
function formatDateInput(date)
|
|
{
|
|
var day = date.substring(6,8);
|
|
var month = date.substring(4,6)
|
|
var year = date.substring(0,4)
|
|
return year+'-'+month+'-'+day;
|
|
}
|
|
|
|
function todaySimu()
|
|
{
|
|
var today = new Date();
|
|
var dd = (today.getDate()).toString();
|
|
var mm = (today.getMonth()+1).toString(); //January is 0!
|
|
var yyyy = (today.getFullYear()).toString();
|
|
if(dd<10) dd='0'+dd;
|
|
if(mm<10) mm='0'+mm;
|
|
return yyyy+mm+dd;
|
|
}
|
|
|
|
function rotateDC(rX,rY)
|
|
{
|
|
$('.simu-container').addClass('animated');
|
|
tmp = 'rotateX(' + rX + 'deg)' + 'rotateY(' + rY + 'deg)';
|
|
$('.simu-container').css({'transform' : tmp});
|
|
_angle = {'x': rX, 'y': rY}
|
|
_anglelast = {'x': rX, 'y': rY}
|
|
}
|
|
|