Skip to content
This repository
Browse code

Merge branch 'develop' into gh-pages

  • Loading branch information...
commit 4780552b020e6be604009d669957ff88c791ceb7 2 parents 946e437 + a9b1063
javi santana javisantana authored
1  .gitignore
@@ -3,3 +3,4 @@
3 3 node_modules
4 4 themes/css/all.css
5 5 themes/css/cartodb.ie.css
  6 +secrets.json
5 Makefile
@@ -29,8 +29,9 @@ css: $(CSS_FILES)
29 29 release: dist css
30 30 node scripts/release.js
31 31
32   -publish:
33   - ./scripts/publish.sh
  32 +publish: release
  33 + #./scripts/publish.sh
  34 + node scripts/publish.js
34 35
35 36
36 37 PHONY: clean themes dist
3  package.json
@@ -21,6 +21,7 @@
21 21 "type": "BSD"
22 22 }],
23 23 "devDependencies": {
24   - "uglify-js": "1.3.3"
  24 + "uglify-js": "1.3.3",
  25 + "knox": ""
25 26 }
26 27 }
70 scripts/publish.js
... ... @@ -0,0 +1,70 @@
  1 +
  2 +var secrets = require('./secrets.json')
  3 +var fs = require('fs')
  4 +var package_ = require('../package')
  5 +
  6 +
  7 +var knox = require('knox').createClient({
  8 + key: secrets.S3_KEY,
  9 + secret: secrets.S3_SECRET,
  10 + bucket: secrets.S3_BUCKET
  11 +});
  12 +
  13 +
  14 +
  15 +function put_files(files, local_path, remote_path, content_type) {
  16 + var total = files.length;
  17 + var uploaded = 0;
  18 + for(var i in files) {
  19 + var file = files[i];
  20 + console.log(local_path + '/' + file, ' => ', remote_path + '/' + file);
  21 + var content_type = {
  22 + 'png': 'image/png',
  23 + 'gif': 'image/gif',
  24 + 'css': 'text/css',
  25 + 'js': 'application/x-javascript'
  26 + }
  27 + var ext = file.split('.');
  28 + ext = ext[ext.length - 1];
  29 + knox.putFile(local_path + '/' + file, remote_path + '/' + file, {'Content-Type': content_type[ext], 'x-amz-acl': 'public-read' }, function(err, result) {
  30 + if(!err) {
  31 + if (200 == result.statusCode) {
  32 + uploaded++
  33 + }
  34 + }
  35 + else {
  36 + console.log('Failed to upload file to Amazon S3', err);
  37 + }
  38 + total--;
  39 + if(total == 0) {
  40 + if(uploaded == files.length) {
  41 + console.log("files uploaded");
  42 + } else {
  43 + console.log("an error ocurred");
  44 + }
  45 + }
  46 +
  47 + });
  48 + }
  49 +}
  50 +
  51 +
  52 +var JS_FILES = [
  53 + 'cartodb.js',
  54 + 'cartodb.uncompressed.js'
  55 +]
  56 +
  57 +var CSS_FILES = [
  58 + 'cartodb.css',
  59 + 'cartodb.ie.css'
  60 +]
  61 +
  62 +var IMG_FILES = fs.readdirSync('themes/img')
  63 +
  64 +put_files(JS_FILES, 'v2', 'cartodb.js/v2')
  65 +put_files(CSS_FILES, 'v2/themes/css', 'cartodb.js/v2/themes/css')
  66 +put_files(IMG_FILES, 'v2/themes/img', 'cartodb.js/v2/themes/img')
  67 +
  68 +put_files(JS_FILES, 'v2', 'cartodb.js/v2/' + package_.version)
  69 +put_files(CSS_FILES, 'v2/themes/css', 'cartodb.js/v2/' + package_.version + '/themes/css')
  70 +put_files(IMG_FILES, 'v2/themes/img', 'cartodb.js/v2/' + package_.version + '/themes/img')
3  src/geo/gmaps/gmaps_cartodb_layer.js
@@ -41,7 +41,8 @@ var CartoDBLayer = function(opts) {
41 41 tiler_protocol: "http",
42 42 sql_domain: "cartodb.com",
43 43 sql_port: "80",
44   - sql_protocol: "http"
  44 + sql_protocol: "http",
  45 + subdomains: null
45 46 };
46 47
47 48 this.options = _.defaults(opts, default_options);
3  src/geo/leaflet/leaflet_cartodb_layer.js
@@ -31,7 +31,8 @@ L.CartoDBLayer = L.TileLayer.extend({
31 31 sql_port: "80",
32 32 sql_protocol: "http",
33 33 extra_params: {},
34   - cdn_url: null
  34 + cdn_url: null,
  35 + subdomains: null
35 36 },
36 37
37 38
32 src/vis/layers.js
@@ -3,11 +3,38 @@
3 3
4 4 var Layers = cdb.vis.Layers;
5 5
  6 +/*
  7 + * if we are using http and the tiles of base map need to be fetched from
  8 + * https try to fix it
  9 + */
  10 +
  11 +var HTTPS_TO_HTTP = {
  12 + 'https://dnv9my2eseobd.cloudfront.net/': 'http://a.tiles.mapbox.com/',
  13 + 'https://maps.nlp.nokia.com/': 'http://maps.nlp.nokia.com/',
  14 + 'https://tile.stamen.com/': 'http://tile.stamen.com/'
  15 +};
  16 +
  17 +function transformToHTTP(tilesTemplate) {
  18 + for(var url in HTTPS_TO_HTTP) {
  19 + if(tilesTemplate.indexOf(url) !== -1) {
  20 + return tilesTemplate.replace(url, HTTPS_TO_HTTP[url])
  21 + }
  22 + }
  23 + return tilesTemplate;
  24 +}
  25 +
6 26 Layers.register('tilejson', function(vis, data) {
7   - return new cdb.geo.TileLayer({urlTemplate: data.tiles[0]});
  27 + var url = data.tiles[0];
  28 + url = vis.https ? url: transformToHTTP(url);
  29 + return new cdb.geo.TileLayer({
  30 + urlTemplate: url
  31 + });
8 32 });
9 33
10 34 Layers.register('tiled', function(vis, data) {
  35 + var url = data.urlTemplate;
  36 + url = vis.https ? url: transformToHTTP(url);
  37 + data.urlTemplate = url;
11 38 return new cdb.geo.TileLayer(data);
12 39 });
13 40
@@ -36,6 +63,9 @@ var cartoLayer = function(vis, data) {
36 63 data.interactivity = names.join(',');
37 64 }
38 65
  66 + data.tiler_protocol = vis.https ? 'https': 'http';
  67 + data.tiler_port = vis.https ? 443: 80;
  68 +
39 69 return new cdb.geo.CartoDBLayer(data);
40 70 };
41 71
42 src/vis/vis.js
@@ -62,6 +62,8 @@ var Vis = cdb.core.View.extend({
62 62 initialize: function() {
63 63 _.bindAll(this, 'loadingTiles', 'loadTiles');
64 64
  65 + this.https = false;
  66 +
65 67 if(this.options.mapView) {
66 68 this.mapView = this.options.mapView;
67 69 this.map = this.mapView.map;
@@ -72,12 +74,24 @@ var Vis = cdb.core.View.extend({
72 74 load: function(data, options) {
73 75 if(typeof(data) === 'string') {
74 76 var self = this;
75   - $.getJSON(data, function(d) {
  77 + $.getJSON(data + "?callback=?", function(d) {
76 78 self.load(d, options);
77 79 });
  80 + return;
  81 + }
  82 +
  83 + // configure the vis in http or https
  84 + if(window && window.location.protocol && window.location.protocol === 'https:') {
  85 + this.https = true;
78 86 }
79 87
80   - this._applyOptions(data, options);
  88 + if(data.https) {
  89 + this.https = data.https;
  90 + }
  91 +
  92 + if(options) {
  93 + this._applyOptions(data, options);
  94 + }
81 95
82 96 // map
83 97 data.maxZoom || (data.maxZoom = 20);
@@ -168,8 +182,15 @@ var Vis = cdb.core.View.extend({
168 182
169 183 // change vizjson based on options
170 184 _applyOptions: function(vizjson, opt) {
  185 + opt = opt || {};
  186 + opt = _.defaults(opt, {
  187 + search: true,
  188 + title: true,
  189 + description: true
  190 + });
171 191
172 192 function search_overlay(name) {
  193 + if(!vizjson.overlays) return null;
173 194 for(var i = 0; i < vizjson.overlays.length; ++i) {
174 195 if(vizjson.overlays[i].type === name) {
175 196 return vizjson.overlays[i];
@@ -178,6 +199,7 @@ var Vis = cdb.core.View.extend({
178 199 }
179 200
180 201 function remove_overlay(name) {
  202 + if(!vizjson.overlays) return;
181 203 for(var i = 0; i < vizjson.overlays.length; ++i) {
182 204 if(vizjson.overlays[i].type === name) {
183 205 vizjson.overlays.splice(i, 1);
@@ -186,8 +208,12 @@ var Vis = cdb.core.View.extend({
186 208 }
187 209 }
188 210
  211 + if(opt.https) {
  212 + this.https = true;
  213 + }
  214 +
189 215 // remove search if the vizualization does not contain it
190   - if (!opt.search) {
  216 + if (opt.search != undefined && !opt.search) {
191 217 remove_overlay('search');
192 218 }
193 219
@@ -210,6 +236,15 @@ var Vis = cdb.core.View.extend({
210 236 }
211 237 }
212 238
  239 + // if bounds are present zoom and center will not taken into account
  240 + if(opt.zoom !== undefined) {
  241 + vizjson.zoom = parseFloat(opt.zoom);
  242 + }
  243 +
  244 + if(opt.center_lat !== undefined) {
  245 + vizjson.center = [parseFloat(opt.center_lat), parseFloat(opt.center_lon)];
  246 + }
  247 +
213 248 if(opt.sw_lat !== undefined) {
214 249 vizjson.bounds = [
215 250 [parseFloat(opt.sw_lat), parseFloat(opt.sw_lon)],
@@ -217,6 +252,7 @@ var Vis = cdb.core.View.extend({
217 252 ];
218 253 }
219 254
  255 +
220 256 if(opt.sql) {
221 257 vizjson.layers[1].options.query = opt.sql;
222 258 }
14 test/spec/vis/vis.spec.js
@@ -85,4 +85,18 @@ describe("Vis", function() {
85 85 expect(_map).not.toEqual(undefined);
86 86 });
87 87
  88 + it("when https is false all the urls should be transformed to http", function() {
  89 + this.vis.https = false;
  90 + this.mapConfig.layers = [{
  91 + kind: 'tiled',
  92 + options: {
  93 + urlTemplate: 'https://dnv9my2eseobd.cloudfront.net/v3/{z}/{x}/{y}.png'
  94 + }
  95 + }]
  96 + this.vis.load(this.mapConfig);
  97 + expect(this.vis.map.layers.at(0).get('urlTemplate')).toEqual(
  98 + 'http://a.tiles.mapbox.com/v3/{z}/{x}/{y}.png'
  99 + )
  100 + });
  101 +
88 102 })

0 comments on commit 4780552

Please sign in to comment.
Something went wrong with that request. Please try again.