P
P
Pavel Voronyuk2015-04-08 18:46:19
JavaScript
Pavel Voronyuk, 2015-04-08 18:46:19

How to collect 3 files in one js?

there is such a code to draw an interactive map using Raphael:

it is in the init.js file

$(function(){
  
  var wmap = Raphael('map', 1200, 1000),
    attributes = {
            fill: '#acacac',
            stroke: '#fff',
            'stroke-width': 1,
            'stroke-linejoin': 'round'
        },
    arr = new Array();
  
  for (var country in info.provinces) {
    
    var province = wmap.path(info.provinces[country].border);
    
    province.attr(attributes);
    
    arr[province.id] = country;
    
    province
    .hover(function(){
      this.animate({
        fill: '#1669AD'
      }, 10);
    }, function(){
      this.animate({
        fill: attributes.fill
      }, 10);
    })
    .click(function(){
      document.location.hash = arr[this.id];
      
      var point = this.getBBox(0);
      
      $('#map').next('.point').remove();
      
      $('#map').after($('<div />').addClass('point'));
      
      $('.point')
      .html(info.provinces[arr[this.id]].name)
      .fadeIn();
    });
  }
});


cw1.worldoftanks.ru/static/551254/wgcw/regions/reg... is connected in the index.html header before init.js

and this whole thing is beautifully displayed.

But there is also
cw1.worldoftanks.ru/static/551254/wgcw/regions/reg...
cw1.worldoftanks.ru/static/551254/wgcw/regions/reg...
cw1.worldoftanks.ru/static/551254/wgcw /regions/reg... ...

which also need to be included..

The essence of the question is how to include all such files, and so that one big map is drawn? Because if you insert 3 files in the header, only the last one will be displayed.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dtestyk, 2015-04-08
@dtestyk

I think you are redefining info

A
Alexander Rulev, 2015-04-08
@Rulexec

The info variable is overridden , so you can do this:

<script src='http://cw1.worldoftanks.ru/static/551254/wgcw/regions/reg_01/map.js'></script>
<script>var info1 = info;</script>
<script src='http://cw1.worldoftanks.ru/static/551254/wgcw/regions/reg_02/map.js'></script>
<script>var info2 = info;</script>
...

And then wrap the code that draws in a function to pass it different info (info1, info2, ...) and elements where to draw.

M
Makito, 2015-04-10
@Makito

And you generally can not influence the code in these included data files in any way?
That is, rewrite them into one file, for example.
If not, then Alexander Rulev speaks sensibly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question