Mon Nov 06 2017
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
function switchToMonthlyPricesDesktop($productsquare, justprice){
          console.log('desktop ran')
          function changePriceDisplay($bigpricesquare){
              var $bps = $bigpricesquare.find('.oct_2016_big_price_square');              
              var currentprice = parseInt($bps.text(), 10);
              var months = parseInt($bps.data('lvl'), 10);
              var monthlyprice = Math.round((currentprice / months) * 100);
              var dollars = ~~(monthlyprice / 100);
              var cents = monthlyprice - dollars * 100;              
      
              $bps.text(dollars);              
              $bps.append('<div style="display: inline-block; font-size: 0.385em; vertical-align: top; text-align: left; margin-top: 0.3em"><p>.' + ('00' + cents).slice(-2) + '</p><p>/Month</p></div>');
              return currentprice;
          }
          function changeMSRPDisplay($msrpcontainer, originalprice){
              var nodes = Array.prototype.slice.call($msrpcontainer.get(0).childNodes);
              nodes[0] && nodes[0].nodeName.match(/text/gi) && nodes[0].remove();
              $msrpcontainer.append('<strong style="display: inline-block; margin: 0 .5em; font-family: GothamBold;">$' + originalprice + '</strong><span>due today</span>');              
          }
          
          var $pricecontainer = $productsquare.find('.oct_2016_price_container_square');
          var $msrpcontainer = $productsquare.find('.oct_2016_msrp_square');
          var originalprice = $pricecontainer && changePriceDisplay($pricecontainer);
          !justprice && $msrpcontainer && changeMSRPDisplay($msrpcontainer, originalprice);
      }
      
      
      
      function switchToMonthlyPricesMobile($mobileproductlabel, i, justprice){
          console.log('mobile ran');    


          var $mpc = $mobileproductlabel.find('.mobile_prices_container');
          var $msrp = $mpc.find('.mobile_msrp').detach();
          var $mobileprice = $mpc.find('.mobile_price');
          var currentprice = parseInt($mobileprice.text(), 10);
          var months = parseInt($mobileprice.data('lvl'), 10);
          var monthlyprice = Math.round((currentprice / months) * 100);
          var dollars = ~~(monthlyprice / 100);
          var cents = monthlyprice - dollars * 100;          
          console.log(currentprice,'#',months,'#',monthlyprice,'#',dollars,'#',cents);                               
            $mobileprice.text(dollars).css('font-size','2.5em');          
          
          if(justprice){              
              return 1;
          }
          $mpc.append('<div style="display: inline-block; font-size: 1em; vertical-align: top; text-align: left; margin-top: 0.3em"><p>.' + ('00' + cents).slice(-2) + '</p><p>/Month</p></div>');          
          $mobileproductlabel.find('.mobile_product_name_container').css('top','7px');
          $mobileproductlabel.css('border-radius','unset');
          
          var $bot = $('<div class="monthly_mobilebottom labelcontain"><strong style="font-family: GothamBold; display: inline-block; margin: 0 .1em;">$'+ currentprice +'</strong> due today</div>');
          $mobileproductlabel.after($bot);
          $bot.css({
             'font-size': '16px',
             'color': '#555',
             'background-color': '#e5e5e5',
             'padding': '.25em 0',
             'border-bottom-left-radius': '5px',
             'border-bottom-right-radius': '5px' 
          });
          $bot.prepend($msrp);
      
          if(!i){
              var $top = $('<div class="labelcontain">Best Value</div>');
              $top.css({
                 'font-size': '16px',
                 'color': '#333',
                 'background-color': '#EFC344',
                 'padding': '.25em 0',
                 'border-top-left-radius': '5px',
                 'border-top-right-radius': '5px',
                 'text-transform': 'uppercase',
                 'font-family': 'GothamBold' 
              });
              $mobileproductlabel.before($top);
              $mobileproductlabel.css('margin-top','0');
          }
          else {
              $mobileproductlabel.css({
                 'border-top-left-radius': '5px',
                 'border-top-right-radius': '5px'
              });
          }
      }
      
      
      function swapSquaresOrder(){
          var swapper = $('<div id="sqswap"></div>');
          var squares = $('.oct_2016_blue_bg .oct_2016_product_square').replaceWith(swapper);
          var tmp = [];
          squares.each(function(i,v){ tmp.unshift(v); });
          swapper.replaceWith($(tmp));
      }
      
      
      //EXPA::
      $(function(){          
          $('body').append('<style>@media (max-width: 560px){ .labelcontain{ max-width: 370px; margin: 0 auto; } }</style>');
      
          function doMonthlySwap(justprice){

            // ugly hack
            if(!window.monthlyContentSet && justprice==1 ){
                return;
            }
              
                        
              $('.oct_2016_blue_bg .oct_2016_product_square').map(function(i,el){
                switchToMonthlyPricesDesktop($(el), justprice);
              });

              
              

              $('.oct_2016_blue_bg .js_oct_2016_product .mobile_product_label:lt(4)').map(function(i,el){
                switchToMonthlyPricesMobile($(el), i, justprice);
              });
            
          }
          
          
            setTimeout(function(){ $(function(){ !window.monthlyContentSet && doMonthlySwap();  window.monthlyContentSet = 1; }) }, 1000);                    
             $(document).on('lang_change', function(){ doMonthlySwap(1) })

               $(document).on('price_update', function( e){                                                         
                      if(e.currentTarget.activeElement.className == "oct_2016_cd_download"){
                             doMonthlySwap(1); 
                       } 
                  });
              });