Wed Apr 11 2018
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
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
function update_prices(selector) {
    //Control: default is set by var above. Default will be overridden in either case by setting "showfull" or "showmonthly"
    window.__showFullPrices = showfullpricesasdefault;
    window.location.search.match(/showfull=/) && (window.__showFullPrices = 1);
    window.location.search.match(/showmonthly=/) &&
      delete window.__showFullPrices;

    var prices = document.querySelectorAll(selector);
    var rsidata, lvl, media, isMsrp, multipay_divisor, msrp, price, isMobile;

    for (var i = 0; i < prices.length; i++) {
      lvl = prices[i].getAttribute('data-lvl');
      media = prices[i].getAttribute('data-media');
      isMsrp = prices[i].getAttribute('data-is-msrp');
      isMobile = /mobile_/.test(prices[i].className);
      console.log(prices[i]);

      multipay_divisor = prices[i].getAttribute('data-multipay-divisor');

      rsidata = RSI({ lvl: lvl, media: media })[0];

      // check if rsidata exists (to avoid errors such as looking for S5 data in an S3 product)
      if (rsidata) {
        msrp = multipay_divisor
          ? Math.ceil(rsidata.msrp / multipay_divisor)
          : rsidata.msrp;

        price = multipay_divisor
          ? Math.ceil(rsidata.price / multipay_divisor)
          : rsidata.price;

        if (isMsrp) {
          //Reset MSRPs:
          if (
            !window.__showFullPrices &&
            rsidata.lvl in { '24': 1, '12': 1, '06': 1, '03': 1, '01': 1 }
          ) {
            //Monthly
            if (prices[i].getAttribute('class').match(/mobile_msrp/gi)) {
              //Mobile MSRP & Label Adjust

              var mpc = prices[i].parentNode;
              mpc.removeChild(prices[i]);
              var mobileproductlabel = mpc.parentNode;
              mobileproductlabel.style.top = '7px';
              mobileproductlabel.style['border-radius'] = 'unset';
              if (rsidata.lvl == '24') {
                !mobileproductlabel.querySelector('.labelcontain.topper') &&
                  mobileproductlabel.insertAdjacentHTML(
                    'beforebegin',
                    '<div class="labelcontain topper">Best Value</div>'
                  );
                mobileproductlabel.style['margin-top'] = '0';
              } else {
                mobileproductlabel.style['border-top-left-radius'] = '5px';
                mobileproductlabel.style['border-top-right-radius'] = '5px';
              }
              (mobileproductlabel.getAttribute('class') || '').match(
                /mobile_product_label/gi
              ) &&
                !(
                  mobileproductlabel.nextElementSibling.getAttribute('class') ||
                  ''
                ).match(/monthly_mobilebottom/gi) &&
                !mobileproductlabel.style.display.match(/none/gi) &&
                mobileproductlabel.insertAdjacentHTML(
                  'afterend',
                  '<div class="monthly_mobilebottom labelcontain">' +
                    prices[i].outerHTML +
                    '<span class="mobile_msrp js_oct_2016_price">' +
                    rsidata.msrp +
                    '</span><strong style="font-family: GothamBold; display: inline-block; margin: 0 .1em;">$' +
                    rsidata.price +
                    '</strong> due today</div>'
                );
            } else {
              //Desktop
              prices[i].innerHTML = msrp;
              var msrpcontainer = prices[i].parentNode.parentNode;
              var nodes = Array.prototype.slice.call(msrpcontainer.childNodes);
              nodes[0] &&
                nodes[0].nodeName.match(/text/gi) &&
                nodes[0].parentNode.removeChild(nodes[0]);
              if (!msrpcontainer.querySelector('.msrpstrong')) {
                msrpcontainer.insertAdjacentHTML(
                  'beforeend',
                  '<strong class="msrpstrong" style="display: inline-block; margin: 0 .5em; font-family: GothamBold;">$' +
                    rsidata.price +
                    '</strong><span>due today</span>'
                );
              }
            }
          } else {
            //Full
            prices[i].innerHTML = msrp;

            if (msrp === price) {
              if (isMobile) {
                prices[i].style.visibility = 'hidden';
              } else {
                prices[i].parentElement.parentElement.style.visibility =
                  'hidden';
              }
            }
          }
        } else {
          //Reset prices:
          if (
            !window.__showFullPrices &&
            rsidata.lvl in { '24': 1, '12': 1, '06': 1, '03': 1, '01': 1 }
          ) {
            // Math.ceil takes care of the remainder, use parseFloat internally;
            var fn = parseFloat;

            var monthlyprice = (
              Math.ceil(
                fn(rsidata.price, 10) / parseInt(rsidata.lvl, 10) * 100
              ) / 100
            ).toFixed(2);

            //Monthly
            if (prices[i].getAttribute('class').match(/mobile_price/gi)) {
              //Mobile
              var mpc = prices[i].parentNode;
              prices[i].textContent = monthlyprice.split('.')[0];
              prices[i].style['font-size'] = '2.5em';
              !mpc.querySelector('.productcents') &&
                mpc.insertAdjacentHTML(
                  'beforeend',
                  '<div class="productcents" style="display: inline-block; font-size: 1em; vertical-align: top; text-align: left; margin-top: 0.3em"><p>.' +
                    monthlyprice.split('.')[1] +
                    '</p><p>/Month</p></div>'
                );
            } else {
              //Desktop
              prices[i].innerHTML = monthlyprice.split('.')[0];
              prices[i].insertAdjacentHTML(
                'beforeend',
                '<div style="display: inline-block; font-size: 0.385em; vertical-align: top; text-align: left; margin-top: 0.3em; vertical-align: baseline; line-height: 1.2;"><p>.' +
                  monthlyprice.split('.')[1] +
                  '</p><p>/Month</p></div>'
              );
            }
          } else {
            //Full
            prices[i].innerHTML = price;
          }
        }
      }

      if (msrp == price) {
        //console.log(`price: ${price}    msrp: ${msrp}     ${prices[i]}`)
        $(prices[i])
          .parents('.oct_2016_multipay_strikeprice_square')
          .hide();
        if ($(prices[i]).hasClass('mobile_msrp')) {
          $(prices[i]).hide();
        }
      }
      // Hide 24D & egift strikethrough if same as price
      try {
        if (
          RSI({ cat: 'esp', media: 'box', lvl: '24D' })[0].price ==
          RSI({ cat: 'esp', media: 'box', lvl: '24D' })[0].msrp
        ) {
          $('.oct_2016_gold_bg .oct_2016_msrp_square').hide();
        }
      } catch (e) {}
    }
  }