Thu Nov 28 2019
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
var app = app || {}, 
    page = page || {};

page.catalog = (function($, window, document, undefined) {
  var $window = $(window),
      $document = $(document),
      $page = $("body");
  
  var _plansFilter = search => a => Object.keys(search).every(k => a[k] === search[k] || Array.isArray(search[k]) && search[k].includes(a[k]));

  var _init = function() {
    app.start();
    
    $.ajax({
      url: "https://www.rosettastone.com/lp/data-models/us/js/products/catalog.js",
      dataType: "script",
      success: function() {
        var productTemplateDesktop = $("#tmpl-product-desktop").text(),
            productTemplateMobile = $("#tmpl-product-mobile").text(),
            $productsDesktop = $("#products-desktop"),
            $productsMobile = $("#products-mobile");

        var productfilter = pagedata.productfilter || [3, 6, 12, 24]
        productfilter.forEach(function(plan) {          
          var product = window.pagedata.products.filter(_plansFilter({lang: window.lang, type: "subscription", lvl: plan.toString()}))[0];

          if (product) {
            
            var monthlyPrice = (Math.ceil(parseFloat(product.price, 10) / parseInt(plan, 10) * 100) / 100).toFixed(2).split('.');

            var productDetails = {
              fullprice: /lifetime/.test(product.lvl) ? true : false,
              lvl: product.lvl,
              name:  /lifetime/.test(product.lvl) ? 'LIFETIME' : product.lvl + '-MONTH',
              price: product.price,
              monthlyPrice: monthlyPrice,
              monthlyPriceLeft: monthlyPrice[0],
              monthlyPriceRight: monthlyPrice[1],
              msrp: product.msrp,
              isOnMsrp: product.price == product.msrp,
              sku: product.sku,
              cart: product.cart,
              ribbon: window.pagedata.ribbontext[product.lvl] || "",
              offer: window.pagedata.offertext[product.lvl] || ""
            };

            //var _htmlDesktop = app.ui.template(productTemplateDesktop, productDetails);
                //_htmlMobile = app.ui.template(productTemplateMobile, productDetails);
            //_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
            var compiled = _.template(productTemplateDesktop)
            var _htmlDesktop = compiled(productDetails)         
            console.log(compiled.source)
            var c = _.template(productTemplateMobile)
            var _htmlMobile = c(productDetails)   

            $productsDesktop.append(_htmlDesktop);
            $productsMobile.append(_htmlMobile);
          }
        });
        $(function() {
          // tmp fix for WS-4147 - strikethrough fix.
          varl = lang || 'esp'          
          var products = window.pagedata.products.filter(p => p.lang == lang)
          $.each(products, function(i,e) {
            if (e.price == e.msrp) {
      
              $('.product-m-wrap[data-lvl="'+e.lvl+'"] .msrp, .product-d.product[data-lvl="'+e.lvl+'"] .msrp').hide()
            }
          })
      });
      }
    });
  };

  return {
      start: _init
  };

})(jQuery, this, this.document);

page.catalog.start();