Sha256: 9476de81e21fcfd280b87a8d53bfffcc64cd6570b21f02397acdc723934f3848

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

// = require jsrender.min
// = require decidim/decidim_awesome/awesome_map/layers
// = require decidim/decidim_awesome/awesome_map/categories

((exports) => {
  const { getCategory, layers } = exports.AwesomeMap;

  const popupMeetingTemplateId = "marker-meeting-popup";
  const popupProposalTemplateId = "marker-proposal-popup";
  const allMarkers = [];

  const drawMarker = (element, marker, component) => {
    let tmpl = component.type === "proposals" ? popupProposalTemplateId : popupMeetingTemplateId,
        node = document.createElement("div");

    $($.templates(`#${tmpl}`).render(element)).appendTo(node);

    marker.bindPopup(node, {
      maxwidth: 640,
      minWidth: 500,
      keepInView: true,
      className: "map-info"
    }).openPopup();

    allMarkers.push({
      marker: marker,
      component: component,
      element: element
    });

    // Add to category layer
    let cat = getCategory(element.category);
    if(layers[cat.id]) {
      $('#awesome_map-categories-control').show();
      marker.addTo(layers[cat.id].group);
      // show category if hidden
      const $label = $(`label.awesome_map-category-${cat.id}`);
      const $parent = $(`label.awesome_map-category-${cat.parent}`);
      $label.show();
      // update number of items
      $label.attr("title", (parseInt($label.attr("title") || 0) + 1) + " " +  window.DecidimAwesome.texts.items);
      // show parent if apply
      $parent.show();
      $parent.attr("title", (parseInt($parent.attr("title") || 0) + 1) + " " +  window.DecidimAwesome.texts.items);
    }

    // update component stats
    const $component = $(`#awesome_map-component_${component.id}`);
    $component.attr("title", parseInt($component.attr("title") || 0) + 1);

    return marker;
  };

  exports.AwesomeMap.allMarkers = allMarkers;
  exports.AwesomeMap.drawMarker = drawMarker;
})(window);

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-decidim_awesome-0.7.2 app/assets/javascripts/decidim/decidim_awesome/awesome_map/markers.js.es6
decidim-decidim_awesome-0.7.0 app/assets/javascripts/decidim/decidim_awesome/awesome_map/markers.js.es6
decidim-decidim_awesome-0.6.7 app/assets/javascripts/decidim/decidim_awesome/awesome_map/markers.js.es6