Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- createLegend: function (container, promise, mobileView) {
- var data = seatcheck.data,
- seats = seatcheck.layers.seats,
- c = seatcheck.options.classes,
- s = seatcheck.options.selectors,
- cache = { seatsCats: { }},
- indent = 77, // по макету
- svoge = window.svoge || new Svoge(),
- height = 0,
- paddingLeft = 0;
- // определяем, билеты каких категорий еще можно купить
- var isRelevant = {},
- relevantCats = [];
- data.cats.forEach(function (d) {
- isRelevant[d.id] = false;
- });
- data.s.forEach(function (d) {
- if (d.status == "ok") {
- isRelevant[d.catId] = true;
- }
- });
- data.cats.forEach(function (d) {
- if (isRelevant[d.id] &&
- (d.status == "ok" || (d.status == "protected" && options.view == 'manage'))) {
- relevantCats.push(d);
- }
- });
- var legendWrap = d3s(container).append('div')
- .classed(c.legendWrap, true);
- if (mobileView) {
- legendWrap.classed(c.horizontal, true);
- var legendWrapMobile = legendWrap.append('div')
- .classed(c.legendWrapMobile, true);
- var legend = legendWrapMobile.append('div')
- } else {
- var legend = legendWrap.append('div');
- }
- legend.classed(c.legend, true);
- var cats = legend.selectAll(c.legendCat)
- .data(relevantCats)
- .enter()
- .append('div')
- .classed(c.legendCat, true)
- .each(function (c) {
- //кеширование выборок
- cache.seatsCats[c.id] = seats
- .selectAll(s.catElement)
- .filter(function (d) {
- return d.catId != c.id;
- });
- });
- var prices = cats.append('div')
- .classed(c.legendCatPrice, true)
- .style('background-color', function (c) {
- return c.color;
- })
- .text(function (c) {
- return c.price + " ";
- });
- var svoges = prices.append('img')
- .classed('svoge', true)
- .classed('svg-i-rouble', true)
- .attr('src', seatcheck.options.host + 'img/svoge-pixel.png')
- .attr('data-svoge', 'svg-i-rouble');
- var sv;
- svoges.each(function () {
- sv = svoge.makeSpecificSvoge($(this));
- });
- var finishLegend = function () {
- prices.each(function () {
- var left = $(this).outerWidth();
- if (paddingLeft < left) paddingLeft = left;
- });
- if (!mobileView) {
- cats.append('div')
- .classed(c.legendCatName, true)
- .text(function (c) {
- return c.name;
- })
- .style('padding-left', paddingLeft + 16 + "px");
- cats.append('div')
- .classed(c.legendCatComment, true)
- .text(function (c) {
- return c.comment;
- });
- }
- cats.each(function () {
- var priceHeight = $(d3s(this).select(s.legendCatPrice).node()).outerHeight(),
- nameHeight = $(d3s(this).select(s.legendCatName).node()).outerHeight(),
- paddingTop = priceHeight > nameHeight ? "8px" : "4px";
- d3s(this).select(s.legendCatComment).style('padding-top', paddingTop);
- height += $(this).outerHeight(true);
- });
- if (mobileView) {
- var $w = $(legendWrap.node()),
- bodyRect = $w.parents('body')[0].getBoundingClientRect(),
- wrapRect = $w[0].getBoundingClientRect(),
- $legendWrapMobile = $(legendWrapMobile.node());
- var arrowLeft = legendWrapMobile.append('div')
- .classed(c.arrow, true)
- .classed(c.arrowLeft, true);
- var arrowRight = legendWrapMobile.append('div')
- .classed(c.arrow, true)
- .classed(c.arrowRight, true);
- $w.innerWidth(bodyRect.width / seatcheck.scale.outer)
- .css('bottom', Math.floor(Math.max(bodyRect.bottom - wrapRect.top - height - 1, indent)) + 'px');
- $legendWrapMobile.innerWidth(bodyRect.width - 40);
- if ($(legendWrapMobile.node()).outerWidth(true) >= Math.floor($(legend.node()).outerWidth(true))) {
- $(arrowRight.node()).hide();
- }
- $(arrowLeft.node()).hide();
- } else {
- cats
- .on("mouseenter", function (c) {
- cache.seatsCats[c.id]
- .style("opacity", '0.3');
- })
- .on("mouseleave", function () {
- seats.selectAll(s.catElement)
- .style("opacity", '1');
- });
- }
- console.log('', $(legend.node()).outerWidth(true));
- console.log('', $(legend.node())[0].getBoundingClientRect().width);
- console.log('2');
- };
- var interval = setInterval(function () {
- var w = parseInt(sv.css('width'));
- if (w > 0 && w <= 10) {
- clearInterval(interval);
- finishLegend();
- console.log('3');
- promise.resolve();
- }
- }, 10);
- return promise;
- },
- addEvent: function (handler, callback) {
- seatcheck.events[ handler ] = callback;
- return seatcheck;
- },
- events: {}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement