/***************** * browser update * *****************/ jQuery(document).ready(function() { var $buoop = {}; $buoop.ol = window.onload; window.onload = function() { if ($buoop.ol) $buoop.ol(); var e = document.createElement('script'); e.setAttribute('type', 'text/javascript'); e.setAttribute('src', 'http://browser-update.org/update.js'); document.body.appendChild(e); }; }); /* check for html5 placeholder support */ (function($) { $.support.html5 = {}; $.support.html5.autocomplete = false; $.support.html5.placeholder = false; test = document.createElement('input'); if('autocomplete' in test) $.support.html5.autocomplete = true; if('placeholder' in test) $.support.html5.placeholder = true; })(this.jQuery); /* placeholder function with fallback */ (function($) { $.fn.placeholder = function() { var el = $(this); var color = el.css('color'); var gray = '#999'; var ph = el.attr('placeholder'); var val = ph || el.val(); if ($.support.html5.placeholder && !ph) { el.attr('placeholder', el.val()).val(''); } else if (!$.support.html5.placeholder) { el.css('color', gray).addClass('placeholder').val(val).focus(function() { if (el.val() == val) { el.val(''); el.css('color', color); } }).blur(function() { if (el.val() === '') { el.val(val); el.css('color', gray); } else { el.css('color', color); } }); } }; })(this.jQuery); /* run code */ //$('input').placeholder();​ /*************** * autocomplete * ***************/ jQuery(document).ready(function($) { $('body').append('
'); var search = $("#search input"); search.change(function() { if ($(this).val().length > 4) location.href = '/' + $(this).val(); }); search.val('Artikelnr.').focus(function() { $(this).animate({ 'width': 165 }, 400); }).blur(function() { $(this).delay(600).animate({ 'width': 100 }, 400); }).autocomplete({ source: function(request, response) { $.getJSON('/suche/ajax/' + request.term, { data: request.term }, function(data, status) { if (status === 'success') { response($.map(data, function(item) { return { image: item.modfile1, value: item.artikel }; })); } }); }, minLength: 2, select: function(event, ui) { window.location.href = '/' + ui.item.label; } }); }); /*********** * tooltips * ***********/ this.tooltip = function() { var xOffset = 15; var yOffset = -15; $('.tooltip').hover(function(e) { this.t = this.title; this.title = ''; $('body').append('

' + this.t + '

'); $('#tooltip').css({ 'left': (e.pageX + xOffset) + 'px', 'top': (e.pageY - yOffset) + 'px' }).fadeIn('fast'); }, function() { this.title = this.t; $('#tooltip').remove(); }); $('.tooltip').mousemove(function(e) { $('#tooltip').css({ 'left': (e.pageX + xOffset) + 'px', 'top': (e.pageY - yOffset) + 'px' }); }); }; jQuery(document).ready(tooltip); /***************** * validate forms * *****************/ jQuery(document).ready(function($) { $('#search input').setMask({ mask: '99999' }).closest('form').submit(function() { return false; }); $('input.quantity').setMask({ mask: '999' }); $("#cart-form").validate({ invalidHandler: function(event, validator) { var infowin = $('#info'); infowin.html('Please check red hints.').dialog({ autoOpen: true, title: 'Order not sent!', resizable: false, width: 600, open: function(event, ui){ $("body").css({ overflow: 'hidden' }); /* $(".ui-widget-overlay").css({ background:"rgb(0, 0, 0)", opacity: ".50 !important", filter: "Alpha(Opacity=50)", });*/ $(".ui-widget-overlay").show(); }, beforeClose: function(event, ui) { $("body").css({ overflow: 'inherit' }) $(".ui-widget-overlay").hide(); }, buttons: { 'OK': function() { $(this).dialog('close'); }, } }, 'open'); } }); }); /********************** * check product asset * **********************/ function checkAsset(artgrp, bestand, vrpinh, farbe, groesse) { var formvalidate = false; var form = $('#form_quantity'); form.submit(function() { //if (typeof console == 'object') console.log(formvalidate); if (formvalidate) { return; } else { return false; } }); var inputs = form.find('input.quantity'); var infowin = $('#info'); inputs.each(function(i, val) { $(this).change(function() { // quantity changed // $t ist das input var $t = $(this); // Feld leeren wenn 0 eingegeben wurde $t.val() === 0 ? $(this).val('') : $(this); formvalidate = false; if (typeof console == 'object') { //console.log('quantity changed'); //console.log('i: ' + i); console.log('artgrp: ' + artgrp[i]); console.log('bestand: ' + bestand[i]); console.log('vrpinh: ' + vrpinh[i]); console.log('eingegeben: ' + $t.val()); } // ist bestellenmenge durch VPE teilbar? (s1) if ($t.val() % vrpinh[i] == 0) { // bestellmenge ist durch VPE teilbar | s1 == ja // ist bestellmenge <= offbestand (s2) if ($t.val() <= bestand[i]) { // bestellmenge ist kleiner offbestand | s2 == ja // nachliefern bis leeren var date = ''; $t.parent().next().children().val(date).attr("disabled", "disabled"); // bestellung ist validiede, nichts zu tun. formvalidate = true; } else { // bestellmenge ist NICHT kleiner offbestand | s2 == nein // ist artikel auslaufartikel? (s3) if (artgrp[i] == 'AL') { // artikel ist ein auslaufartikel | s3 == ja // popup4 popup4($t); } else { // artikel ist ein auslaufartikel | s3 == nein if (bestand[i] == 0) { // bestand ist 0 | s6 == ja $t.parent().next().children().val(date).removeAttr('disabled').datepicker({ dateFormat: 'dd.mm.yy', minDate: +1 }); formvalidate = true; popup5($t); } else { // bestand ist nicht 0 | s6 == nein // popup3 popup3($t); } } } } else { // bestellmenge ist NICHT durch VPE teilbar | s1 == nein // ist bestellmenge kleiner offbestand (s4) if ($t.val() < bestand[i]) { // bestellmenge ist kleiner offbestand | s4 == ja popup1($t); } else { // bestellmenge ist NICHT kleiner offbestand | s4 == nein // ist artikel auslaufartikel? (s5) if (artgrp[i] == 'AL') { // artikel ist ein auslaufartikel | s5 == ja // popup4 popup4($t); // setze val = offbestand (passiert im popup4) } else { // artikel ist ein auslaufartikel | s5 == nein // popup2 popup2($t); } } } function popup1($t) { console.log('popup 1'); // auf nächste VPE verringern oder erhöhen var increaseby = vrpinh[i] - $t.val() % vrpinh[i]; var increaseto = parseInt($t.val(), 10) + parseInt(vrpinh[i] - $t.val() % vrpinh[i], 10); var decreaseby = $t.val() % vrpinh[i]; var decreaseto = $t.val() - $t.val() % vrpinh[i]; infowin.html('

This style has a packing unit of ' + vrpinh[i] + ' items

' + '
' + '
').dialog({ autoOpen: true, title: 'Packing unit of ' + vrpinh[i], resizable: false, width: 600, buttons: { 'OK': function() { $(this).dialog('close'); $t.val(infowin.find('input:checked').val()); $t.focus(); formvalidate = true; }, 'Cancel': function() { $(this).dialog('close'); $t.val(''); formvalidate = false; // nachliefern bis leeren date = ''; $t.parent().next().children().val(date).attr("disabled", "disabled"); } } }, 'open'); } function popup2($t) { console.log('popup 2'); var date = ''; $t.parent().next().children().val(date).attr("disabled", "disabled"); var increaseto = parseInt($t.val(), 10) + parseInt(vrpinh[i] - $t.val() % vrpinh[i], 10); formvalidate = false; infowin.html('This style has a packing unit of ' + vrpinh[i] + '. Stock is ' + bestand[i] + '.
Would you like to



').dialog({ autoOpen: true, title: 'Stock and packing unit do not match!', resizable: false, width: 600, open: function() { infowin.find('.datepicker').datepicker({ dateFormat: 'dd.mm.yy', minDate: +3, onSelect: function(dateText, inst) { date = dateText; } }); }, buttons: { 'OK': function() { $(this).dialog('close'); var whatToDo = infowin.find('input:checked').val(); console.log(whatToDo); // decrease // increase // increaseAsap // increaseDate if(whatToDo == 'decrease') { $t.val(bestand[i]); // nachliefern bis leeren date = ''; $t.parent().next().children().val(date).attr("disabled", "disabled"); } if(whatToDo == 'increase') { $t.val(increaseto); date = 'Partial, remainings asap'; $t.parent().next().children().val(date).removeAttr('disabled').datepicker({ dateFormat: 'dd.mm.yy', minDate: +1 }); } if(whatToDo == 'increaseAsap') { date = 'Complete delivery'; $t.parent().next().children().val(date).removeAttr('disabled').datepicker({ dateFormat: 'dd.mm.yy', minDate: +1 }); $t.val(increaseto); } if(whatToDo == 'increaseDate') { // nothing to do, cause set date is in onSelect from Datepicker $t.parent().next().children().val(date).removeAttr('disabled').datepicker({ dateFormat: 'dd.mm.yy', minDate: +1 }); $t.val(increaseto); } infowin.dialog('close'); $t.focus(); formvalidate = true; }, 'Cancel': function() { $(this).dialog('close'); $t.val(''); formvalidate = false; // nachliefern bis leeren date = ''; $t.parent().next().children().val(date).attr("disabled", "disabled"); } } }, 'open'); } function popup3($t) { console.log('popup 3'); formvalidate = false; infowin.html('

Set backorder term or adjust quantity to ' + bestand[i] + '



').dialog({ autoOpen: true, title: 'Not enough items on stock!', resizable: false, width: 600, open: function() { infowin.find('.datepicker').datepicker({ dateFormat: 'dd.mm.yy', minDate: +3, onSelect: function(dateText, inst) { date = dateText; } }); }, buttons: { 'OK': function() { $(this).dialog('close'); var whatToDo = infowin.find('input:checked').val(); console.log(whatToDo); if(whatToDo == 'asap') { date = 'Partial, remainings asap'; $t.parent().next().children().val(date).removeAttr('disabled').datepicker({ dateFormat: 'dd.mm.yy', minDate: +1 }); } if(whatToDo == 'latest') { // nothing to do, cause set date is in onSelect from Datepicker $t.parent().next().children().val(date).removeAttr('disabled').datepicker({ dateFormat: 'dd.mm.yy', minDate: +1 }); } if(whatToDo == 'decrease') { $t.val(bestand[i]); // nachliefern bis leeren date = ''; $t.parent().next().children().val(date).attr("disabled", "disabled"); } infowin.dialog('close'); $t.focus(); formvalidate = true; }, 'Cancel': function() { $(this).dialog('close'); $t.val(''); formvalidate = false; // nachliefern bis leeren date = ''; $t.parent().next().children().val(date).attr("disabled", "disabled"); } } }, 'open'); } function popup4($t) { console.log('popup 4'); // rest streichen formvalidate = false; infowin.html('Your order quantity was reduced to the items available.').dialog({ autoOpen: true, title: 'Discontinued Style!', resizable: false, width: 600, buttons: { 'Close': function() { infowin.dialog('close'); formvalidate = true; $t.val(bestand[i]); $t.focus(); } } }, 'open'); } function popup5($t) { console.log('popup 5'); formvalidate = false; infowin.html('

Delivery:



').dialog({ autoOpen: true, title: 'No stock. Set term of delivery?', resizable: false, width: 600, open: function() { infowin.find('.datepicker').datepicker({ dateFormat: 'dd.mm.yy', minDate: +3, onSelect: function(dateText, inst) { date = dateText; } }); }, buttons: { 'OK': function() { $(this).dialog('close'); var whatToDo = infowin.find('input:checked').val(); console.log(whatToDo); if(whatToDo == 'asap') { date = 'Soonest'; $t.parent().next().children().val(date).removeAttr('disabled').datepicker({ dateFormat: 'dd.mm.yy', minDate: +1 }); } if(whatToDo == 'latest') { // nothing to do, cause set date is in onSelect from Datepicker $t.parent().next().children().val(date).removeAttr('disabled').datepicker({ dateFormat: 'dd.mm.yy', minDate: +1 }); } infowin.dialog('close'); $t.focus(); formvalidate = true; }, 'Cancel': function() { $(this).dialog('close'); $t.val(''); formvalidate = false; // nachliefern bis leeren date = ''; $t.parent().next().children().val(date).attr("disabled", "disabled"); } } }, 'open'); } }); }); } /******* * cart * *******/ jQuery(document).ready(function($) { var agb = $('#agb-dialog'); var btn = $('#cart-form').children('a'); agb.dialog({ autoOpen: false, modal: true, resizable: true, title: 'Terms and conditions', width: 700, buttons: { 'Accept': function() { $(this).dialog('close'); $('#agb').attr('checked', 'checked'); }, 'Decline': function() { $(this).dialog('close'); $('#agb').removeAttr('checked'); } } }); btn.click(function() { agb.dialog('open'); }); }); /****************** * advanced search * ******************/ jQuery(document).ready(function($) { var form = $('#advancedsearch'); if (form[0]) { var article = form.find('.article'); article.autocomplete({ source: function(request, response) { $.getJSON('/suche/ajax/' + request.term, { data: request.term }, function(data, status) { if (status === 'success') { response($.map(data, function(item) { return { value: item.artikel }; })); } }); }, minLength: 2 }); var color = form.find('.color'); color.autocomplete({ source: function(request, response) { $.getJSON('/suche/farbe/' + request.term, { data: request.term }, function(data, status) { if (status === 'success') { response($.map(data, function(item) { return { value: item.farbe }; })); } }); }, minLength: 1 }); var size = form.find('.size'); size.autocomplete({ source: function(request, response) { $.getJSON('/suche/groesse/' + request.term, { data: request.term }, function(data, status) { if (status === 'success') { response($.map(data, function(item) { return { value: item.groesse }; })); } }); }, minLength: 2 }); } }); /*************** * add favorite * ***************/ jQuery(document).ready(function($) { var favbtn = $('.togglefav'); favbtn.each(function(i, item) { $(this).click(function() { var img = $(this).children('img'); $.getJSON($(this).attr('href'), function(data, status) { if (status == 'success') { if (data.action == 'added') { img.attr('src', '/img/icon-star.png'); } else { img.attr('src', '/img/icon-star-empty.png'); if (location.pathname.split('/')[1] == 'favoriten') $(item).closest('.item').slideUp('fast'); } } }); return false; }); }); });