Skip to content

Commit 01038f8

Browse files
committedOct 8, 2015
jsonp, cors, jsapi in ie9
1 parent 090aa28 commit 01038f8

File tree

9 files changed

+166
-31
lines changed

9 files changed

+166
-31
lines changed
 

‎app/components/download-button.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export default Ember.Component.extend({
99
let url = ENV.APP.API;
1010
url += DS.JSONAPIAdapter.prototype.buildURL('dataset', model.get('id'));
1111
return url;
12-
}.property()
12+
}.property('model.id')
1313

1414
});

‎app/components/esri-map.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ export default Ember.Component.extend({
2222
this.set('map', map);
2323

2424
let mapViewOpts = {
25-
container: 'map-div', //reference to the DOM node that will contain the view
25+
container: this.element, //reference to the DOM node that will contain the view
2626
map: map, //references the map object created in step 3
27-
height: this.element.clientHeight,
28-
width: this.element.clientWidth
27+
height: this.element.clientHeight + 'px',//ie9 needs it expressed this way
28+
width: this.element.clientWidth + 'px'
2929
};
3030

3131
let extent, ext = dataset.get('extent');
@@ -93,7 +93,7 @@ export default Ember.Component.extend({
9393
case 'esriGeometryLine':
9494
renderer = this._createRendererFromJson(this._defaultLineRenderer);
9595
break;
96-
default:
96+
default:
9797
renderer = this._createRendererFromJson(this._defaultPolygonRenderer);
9898
}
9999
return renderer;
@@ -107,7 +107,7 @@ export default Ember.Component.extend({
107107
popupTemplate: this._getDatasetInfoTemplate(dataset),
108108
renderer: this._getRenderer(dataset, opts)
109109
};
110-
110+
111111
return opts;
112112
},
113113

‎app/controllers/dataset.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ export default Ember.Controller.extend({
1010
let groupThumbnailUrl = model.get('mainGroupThumbnailUrl');
1111
let defaultThumbnailUrl = 'images/default-dataset-thumb.png';
1212
return thumbnailUrl || groupThumbnailUrl || defaultThumbnailUrl;
13-
}.property(),
13+
}.property('model.thumbnailUrl', 'model.mainGroupThumbnailUrl'),
1414

1515
baseUrl: function () {
1616
let model = this.get('model');
1717
let url = ENV.APP.API;
1818
url += DS.JSONAPIAdapter.prototype.buildURL('dataset', model.get('id'));
1919
return url;
20-
}.property(),
20+
}.property('model.id'),
2121

2222
tagsString: function () {
2323
let model = this.get('model');
2424
return model.get('tags').join(' | ');
25-
}.property()
25+
}.property('model.tags')
2626

2727
});

‎app/services/feature-service.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Ember from 'ember';
2-
import ajax from 'ic-ajax';
3-
//import FeatureService from '';
2+
import esriRequest from 'esri/request';
43

54
export default Ember.Service.extend({
65

@@ -14,17 +13,17 @@ export default Ember.Service.extend({
1413
let perPage = params.perPage;
1514
url += '&resultOffset=' + (params.page - 1) * perPage;
1615
url += '&resultRecordCount=' + perPage;
17-
//NOTE: when you pass in one of the above two parameters and orderByFields is left empty,
18-
//map service uses the object-id field to sort the result.
19-
//For a query layer with a pseudo column as the object-id field (e.g., FID),
16+
//NOTE: when you pass in one of the above two parameters and orderByFields is left empty,
17+
//map service uses the object-id field to sort the result.
18+
//For a query layer with a pseudo column as the object-id field (e.g., FID),
2019
//you must provide orderByFields; otherwise the query fails
2120
}
2221

2322
let orderBy = params.orderBy;
2423
if (!params.orderByAsc) {
2524
orderBy += ' desc';
2625
}
27-
//NOTE: this still could fail
26+
//NOTE: this still could fail
2827
//if the oid field has changed since it was harvested by open data
2928
//or it is null (which should not happen...)
3029
url += '&orderByFields=' + orderBy;
@@ -33,14 +32,23 @@ export default Ember.Service.extend({
3332
},
3433

3534
fetchPage: function (dataset, params) {
36-
3735
let url = this._getQueryUrl(dataset, params);
36+
return this._request(url);
37+
},
3838

39-
return ajax({
40-
url: url,
41-
dataType: 'json',
39+
_request(url) {
40+
// use esri.request so it handles cors/jsonp but wrap it in an ember promise
41+
return new Ember.RSVP.Promise(function (resolve, reject) {
42+
let req = {
43+
url: url,
44+
callbackParamName: 'callback' //use jsonp in downlevel ie
45+
};
46+
let opts = {
47+
disableIdentityLookup: true
48+
};
49+
let reqHandle = new esriRequest(req, opts);
50+
reqHandle.then(resolve, reject);
4251
});
43-
4452
}
4553

4654
});

‎app/styles/dataset.scss

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
margin-right: 10px;
66
}
77
}
8-
#map-div {
8+
.map-container {
99
height: 600px;
10-
background-color:#474747;
1110
}
11+
.esri-map-component {
12+
height: 100%;
13+
background-color:#474747;
14+
width: 100%;
15+
}
1216

1317
#table-container {
1418
margin-top: 25px;

‎app/templates/components/esri-map.hbs

-1
This file was deleted.

‎app/templates/dataset.hbs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
<div class="col-lg-6 col-md-6">
99
<h4>Description</h4>
1010
<p>{{{model.description}}}</p>
11-
11+
1212
</div>
1313
<div class="col-lg-6 col-md-6">
1414
<dl class="dl-horizontal">
15-
15+
1616
<dt>Owner:</dt>
1717
<dd>{{model.owner}}</dd>
1818

1919
<dt>Created:</dt>
2020
<dd>{{moment-from-now model.createdAt}}</dd>
21-
21+
2222
<dt>Updated:</dt>
2323
<dd>{{moment-from-now model.createdAt}}</dd>
2424

2525
<dt>Tags:</dt>
2626
<dd>{{tagsString}}</dd>
27-
27+
2828
<dt>Views:</dt>
2929
<dd>{{model.views}}</dd>
3030

@@ -33,7 +33,7 @@
3333
</div>
3434
</div>
3535

36-
<div class="container">
36+
<div class="container map-container">
3737
{{esri-map model=model}}
3838
</div>
3939

‎ember-cli-build.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ module.exports = function(defaults) {
2222
// please specify an object with the list of modules as keys
2323
// along with the exports of each module as its value.
2424

25-
app.import('bower_components/bootstrap-sass-official/assets/fonts/bootstrap/glyphicons-halflings-regular.woff', {
26-
destDir: 'fonts/bootstrap/'
27-
});
25+
app.import('vendor/scripts/jQuery.XDomainRequest.js');
26+
27+
//app.import('bower_components/bootstrap-sass-official/assets/fonts/bootstrap/glyphicons-halflings-regular.woff', {destDir: 'fonts/bootstrap/'});
28+
app.import('bower_components/bootstrap-sass-official/assets/fonts/bootstrap/glyphicons-halflings-regular.eot', { destDir'fonts/bootstrap/' });
29+
app.import('bower_components/bootstrap-sass-official/assets/fonts/bootstrap/glyphicons-halflings-regular.svg', { destDir'fonts/bootstrap/' });
30+
app.import('bower_components/bootstrap-sass-official/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf', { destDir'fonts/bootstrap/' });
31+
app.import('bower_components/bootstrap-sass-official/assets/fonts/bootstrap/glyphicons-halflings-regular.woff', { destDir'fonts/bootstrap/' });
32+
app.import('bower_components/bootstrap-sass-official/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2', { destDir'fonts/bootstrap/' });
2833

2934
app.import('bower_components/bootstrap-sass-official/assets/javascripts/bootstrap.js');
3035

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*!
2+
* jQuery-ajaxTransport-XDomainRequest - v1.0.4 - 2015-03-05
3+
* https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest
4+
* Copyright (c) 2015 Jason Moon (@JSONMOON)
5+
* Licensed MIT (/blob/master/LICENSE.txt)
6+
*/
7+
(function(factory) {
8+
if (typeof define === 'function' && define.amd) {
9+
// AMD. Register as anonymous module.
10+
define(['jquery'], factory);
11+
} else if (typeof exports === 'object') {
12+
// CommonJS
13+
module.exports = factory(require('jquery'));
14+
} else {
15+
// Browser globals.
16+
factory(jQuery);
17+
}
18+
}(function($) {
19+
20+
// Only continue if we're on IE8/IE9 with jQuery 1.5+ (contains the ajaxTransport function)
21+
if ($.support.cors || !$.ajaxTransport || !window.XDomainRequest) {
22+
return $;
23+
}
24+
25+
var httpRegEx = /^(https?:)?\/\//i;
26+
var getOrPostRegEx = /^get|post$/i;
27+
var sameSchemeRegEx = new RegExp('^(\/\/|' + location.protocol + ')', 'i');
28+
29+
// ajaxTransport exists in jQuery 1.5+
30+
$.ajaxTransport('* text html xml json', function(options, userOptions, jqXHR) {
31+
32+
// Only continue if the request is: asynchronous, uses GET or POST method, has HTTP or HTTPS protocol, and has the same scheme as the calling page
33+
if (!options.crossDomain || !options.async || !getOrPostRegEx.test(options.type) || !httpRegEx.test(options.url) || !sameSchemeRegEx.test(options.url)) {
34+
return;
35+
}
36+
37+
var xdr = null;
38+
39+
return {
40+
send: function(headers, complete) {
41+
var postData = '';
42+
var userType = (userOptions.dataType || '').toLowerCase();
43+
44+
xdr = new XDomainRequest();
45+
if (/^\d+$/.test(userOptions.timeout)) {
46+
xdr.timeout = userOptions.timeout;
47+
}
48+
49+
xdr.ontimeout = function() {
50+
complete(500, 'timeout');
51+
};
52+
53+
xdr.onload = function() {
54+
var allResponseHeaders = 'Content-Length: ' + xdr.responseText.length + '\r\nContent-Type: ' + xdr.contentType;
55+
var status = {
56+
code: 200,
57+
message: 'success'
58+
};
59+
var responses = {
60+
text: xdr.responseText
61+
};
62+
try {
63+
if (userType === 'html' || /text\/html/i.test(xdr.contentType)) {
64+
responses.html = xdr.responseText;
65+
} else if (userType === 'json' || (userType !== 'text' && /\/json/i.test(xdr.contentType))) {
66+
try {
67+
responses.json = $.parseJSON(xdr.responseText);
68+
} catch(e) {
69+
status.code = 500;
70+
status.message = 'parseerror';
71+
//throw 'Invalid JSON: ' + xdr.responseText;
72+
}
73+
} else if (userType === 'xml' || (userType !== 'text' && /\/xml/i.test(xdr.contentType))) {
74+
var doc = new ActiveXObject('Microsoft.XMLDOM');
75+
doc.async = false;
76+
try {
77+
doc.loadXML(xdr.responseText);
78+
} catch(e) {
79+
doc = undefined;
80+
}
81+
if (!doc || !doc.documentElement || doc.getElementsByTagName('parsererror').length) {
82+
status.code = 500;
83+
status.message = 'parseerror';
84+
throw 'Invalid XML: ' + xdr.responseText;
85+
}
86+
responses.xml = doc;
87+
}
88+
} catch(parseMessage) {
89+
throw parseMessage;
90+
} finally {
91+
complete(status.code, status.message, responses, allResponseHeaders);
92+
}
93+
};
94+
95+
// set an empty handler for 'onprogress' so requests don't get aborted
96+
xdr.onprogress = function(){};
97+
xdr.onerror = function() {
98+
complete(500, 'error', {
99+
text: xdr.responseText
100+
});
101+
};
102+
103+
if (userOptions.data) {
104+
postData = ($.type(userOptions.data) === 'string') ? userOptions.data : $.param(userOptions.data);
105+
}
106+
xdr.open(options.type, options.url);
107+
xdr.send(postData);
108+
},
109+
abort: function() {
110+
if (xdr) {
111+
xdr.abort();
112+
}
113+
}
114+
};
115+
});
116+
117+
return $;
118+
119+
}));

0 commit comments

Comments
 (0)
Please sign in to comment.