Advertisement
Guest User

Untitled

a guest
May 27th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getConfWidgetContent(){
  2.     var theCookies = document.cookie.split(';');
  3.     var params={};
  4.     var end=false;
  5.     for (var i = 1 ; i <= theCookies.length; i++) {
  6.         if(theCookies[i-1].trim().substr(0, 3)==='cf_'){
  7.             var cookie=theCookies[i-1].trim().split('=');
  8.             params[cookie[0].trim()]=cookie[1];
  9.         }
  10.     }
  11.     $j.post('http://'+window.location.hostname+'/ajax-configurator',{
  12.         data:JSON.stringify(params)
  13.     },function(data){
  14.         data=JSON.parse(data);
  15.         console.log(data['debug']);
  16.         if(data['code']!=''){
  17.             var html='<div class="hn_cw_subline">'+data['label'];
  18.             if(data['info']!=''){
  19.                 html=html+'<div class="hn_cw_info">i</div>';
  20.             }
  21.             html=html+'</div><select class="hn_cw_select">';
  22.             $j.each(data['options'],function(index,value){
  23.                 if(value.value==''){
  24.                     value.value=0;
  25.                     value.label=data['a'];
  26.                 }
  27.                 html=html+'<option value="'+value.value+'">'+value.label+'</option>';
  28.             });
  29.             html=html+'</select><input type="button" value="'+data['b']+'" class="hn_cw_button hn_cw_back" /></select><input type="button" value="'+data['c']+'" class="hn_cw_button hn_cw_go" />';
  30.         }else{
  31.             var html='<div class="hn_cw_subline">\
  32.                     '+data['d']+'<br />\
  33.                 </div>\
  34.             ';
  35.             end=true;
  36.             console.log('#'+end);
  37.         }
  38.         $j('#hn_cw_transition').html(html);
  39.         $j('.hn_cw_wrapper').animate({
  40.             marginTop: '0px'
  41.         },  200, function() {
  42.             $j('#hn_cw_form').html(html);
  43.             if(data['info']!=''){
  44.                 $j('.hn_cw_info').click(function(){
  45.                     if($j('.hn_cw_popup').css('display')!='block'){
  46.                         $j('.hn_cw_popup').fadeIn(200);
  47.                         $j('.hn_cw_popup').html(data['info']).css('top','-270px').animate({
  48.                             top:"-250px"
  49.                         },{duration: 200, queue: false});
  50.                     }else{
  51.                         $j('.hn_cw_popup').fadeOut(200);
  52.                         $j('.hn_cw_popup').html(data['info']).animate({
  53.                             top:"-270px"
  54.                         },{duration: 200, queue: false});
  55.                     }
  56.                 });
  57.                 $j('.hn_cw_popup').click(function(){
  58.                     $j('.hn_cw_popup').fadeOut(200);
  59.                     $j('.hn_cw_popup').html(data['info']).animate({
  60.                         top:"-270px"
  61.                     },{duration: 200, queue: false});
  62.                 });
  63.             }
  64.             $j('.hn_cw_go').click(function(){
  65.                 var select=$j('#hn_cw_form .hn_cw_select').val();
  66.                 if(select!="0"){
  67.                     setCookie(data['code'], select, 60);
  68.                     setTimeout(getConfWidgetContent(), 1500);
  69.                     $j('.hn_cw_popup').fadeOut(200);
  70.                     $j('.hn_cw_popup').html(data['info']).animate({
  71.                         top:"-270px"
  72.                     },{duration: 200, queue: false});
  73.                 }else{
  74.                     //keine option wurde gewählt
  75.                 }
  76.             });
  77.             $j('.hn_cw_back').click(function(){
  78.                 if(deleteLastConfCookies()) setTimeout(getConfWidgetContent(), 1500);
  79.             });
  80.             $j('.hn_cw_wrapper').css('margin-top','-108px');
  81.         });
  82.     });
  83.     $j.post('http://'+window.location.hostname+'/ajax-configurator/index/state',{
  84.         data:JSON.stringify(params)
  85.     },function(data){
  86.         data=JSON.parse(data);
  87.         var html='';
  88.         $j.each(data,function(index,value){
  89.             if($j.type(value)=='object')$j.each(value,function(field,option){
  90.                 if(html=='')html=html+'<span class="hn_cw_foot_headline">'+data['z']+':</span><br />';
  91.                 html=html+'<span>&bull; '+field+': '+option+' ';
  92.             });
  93.         });
  94.         if(html!=''){
  95.             console.log('+'+end);
  96.             if(!end) html=html+'<div><input type="button" value="'+data['y']+'" class="hn_cw_reset" /></div>';
  97.             else html=html+'<div><input type="button" value="'+data['x']+'" class="hn_cw_result" /></div>';
  98.             $j('.hn_configurator_widget_foot').html(html);
  99.             $j('.hn_cw_reset').click(function(){
  100.                 deleteConfCookies();
  101.                 setTimeout(getConfWidgetContent(), 1500);
  102.             });
  103.             $j('.hn_cw_result').click(function(){
  104.                 window.open('http://'+window.location.hostname+'/'+getConfURL(),'_self');
  105.             });
  106.         }else{
  107.             $j('.hn_configurator_widget_foot').html('');
  108.         }
  109.     });
  110. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement