Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  createLegend: function (container, promise, mobileView) {
  2.         var data        = seatcheck.data,
  3.             seats       = seatcheck.layers.seats,
  4.             c           = seatcheck.options.classes,
  5.             s           = seatcheck.options.selectors,
  6.             cache       = { seatsCats: { }},
  7.             indent      = 77, // по макету
  8.             svoge       = window.svoge || new Svoge(),
  9.             height      = 0,
  10.             paddingLeft = 0;
  11.  
  12.  
  13.         // определяем, билеты каких категорий еще можно купить
  14.         var isRelevant = {},
  15.             relevantCats = [];
  16.  
  17.         data.cats.forEach(function (d) {
  18.             isRelevant[d.id] = false;
  19.         });
  20.  
  21.         data.s.forEach(function (d) {
  22.             if (d.status == "ok") {
  23.                 isRelevant[d.catId] = true;
  24.             }
  25.         });
  26.  
  27.         data.cats.forEach(function (d) {
  28.             if (isRelevant[d.id] &&
  29.                 (d.status == "ok" || (d.status == "protected" && options.view == 'manage'))) {
  30.                 relevantCats.push(d);
  31.             }
  32.         });
  33.  
  34.         var legendWrap = d3s(container).append('div')
  35.             .classed(c.legendWrap, true);
  36.  
  37.         if (mobileView) {
  38.             legendWrap.classed(c.horizontal, true);
  39.  
  40.             var legendWrapMobile = legendWrap.append('div')
  41.                 .classed(c.legendWrapMobile, true);
  42.  
  43.             var legend = legendWrapMobile.append('div')
  44.         } else {
  45.             var legend = legendWrap.append('div');
  46.         }
  47.  
  48.         legend.classed(c.legend, true);
  49.  
  50.         var cats = legend.selectAll(c.legendCat)
  51.             .data(relevantCats)
  52.             .enter()
  53.             .append('div')
  54.             .classed(c.legendCat, true)
  55.             .each(function (c) {
  56.                 //кеширование выборок
  57.                 cache.seatsCats[c.id] = seats
  58.                     .selectAll(s.catElement)
  59.                     .filter(function (d) {
  60.                         return d.catId != c.id;
  61.                     });
  62.             });
  63.  
  64.         var prices = cats.append('div')
  65.             .classed(c.legendCatPrice, true)
  66.             .style('background-color', function (c) {
  67.                 return c.color;
  68.             })
  69.             .text(function (c) {
  70.                 return c.price + " ";
  71.             });
  72.  
  73.         var svoges = prices.append('img')
  74.             .classed('svoge', true)
  75.             .classed('svg-i-rouble', true)
  76.             .attr('src', seatcheck.options.host + 'img/svoge-pixel.png')
  77.             .attr('data-svoge', 'svg-i-rouble');
  78.  
  79.         var sv;
  80.         svoges.each(function () {
  81.             sv = svoge.makeSpecificSvoge($(this));
  82.         });
  83.  
  84.         var finishLegend = function () {
  85.             prices.each(function () {
  86.                 var left = $(this).outerWidth();
  87.                 if (paddingLeft < left) paddingLeft = left;
  88.             });
  89.  
  90.             if (!mobileView) {
  91.                 cats.append('div')
  92.                     .classed(c.legendCatName, true)
  93.                     .text(function (c) {
  94.                         return c.name;
  95.                     })
  96.                     .style('padding-left', paddingLeft + 16 + "px");
  97.  
  98.                 cats.append('div')
  99.                     .classed(c.legendCatComment, true)
  100.                     .text(function (c) {
  101.                         return c.comment;
  102.                     });
  103.             }
  104.  
  105.             cats.each(function () {
  106.                 var priceHeight = $(d3s(this).select(s.legendCatPrice).node()).outerHeight(),
  107.                     nameHeight  = $(d3s(this).select(s.legendCatName).node()).outerHeight(),
  108.                     paddingTop  = priceHeight > nameHeight ? "8px" : "4px";
  109.  
  110.                 d3s(this).select(s.legendCatComment).style('padding-top', paddingTop);
  111.                 height += $(this).outerHeight(true);
  112.             });
  113.  
  114.             if (mobileView) {
  115.                 var $w = $(legendWrap.node()),
  116.                     bodyRect = $w.parents('body')[0].getBoundingClientRect(),
  117.                     wrapRect = $w[0].getBoundingClientRect(),
  118.                     $legendWrapMobile  = $(legendWrapMobile.node());
  119.  
  120.                 var arrowLeft = legendWrapMobile.append('div')
  121.                     .classed(c.arrow, true)
  122.                     .classed(c.arrowLeft, true);
  123.  
  124.                 var arrowRight = legendWrapMobile.append('div')
  125.                     .classed(c.arrow, true)
  126.                     .classed(c.arrowRight, true);
  127.  
  128.                 $w.innerWidth(bodyRect.width / seatcheck.scale.outer)
  129.                     .css('bottom', Math.floor(Math.max(bodyRect.bottom - wrapRect.top - height - 1, indent)) + 'px');
  130.  
  131.                 $legendWrapMobile.innerWidth(bodyRect.width - 40);
  132.  
  133.                 if ($(legendWrapMobile.node()).outerWidth(true) >=  Math.floor($(legend.node()).outerWidth(true))) {
  134.                     $(arrowRight.node()).hide();
  135.                 }
  136.                 $(arrowLeft.node()).hide();
  137.             } else {
  138.                 cats
  139.                     .on("mouseenter", function (c) {
  140.                         cache.seatsCats[c.id]
  141.                             .style("opacity", '0.3');
  142.                     })
  143.                     .on("mouseleave", function () {
  144.                         seats.selectAll(s.catElement)
  145.                             .style("opacity", '1');
  146.                     });
  147.             }
  148.             console.log('', $(legend.node()).outerWidth(true));
  149.             console.log('', $(legend.node())[0].getBoundingClientRect().width);
  150.             console.log('2');
  151.         };
  152.  
  153.         var interval = setInterval(function () {
  154.             var w = parseInt(sv.css('width'));
  155.             if (w > 0 && w <= 10) {
  156.                 clearInterval(interval);
  157.                 finishLegend();
  158.                 console.log('3');
  159.                 promise.resolve();
  160.             }
  161.         }, 10);
  162.         return promise;
  163.     },
  164.  
  165.     addEvent: function (handler, callback) {
  166.         seatcheck.events[ handler ] = callback;
  167.         return seatcheck;
  168.     },
  169.  
  170.     events: {}
  171.  
  172. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement