Skip to content

Commit 34791b5

Browse files
committed
Set up the new files from can-util
1 parent 0211db9 commit 34791b5

12 files changed

+40
-79
lines changed

.jshintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"QUnit": true,
77
"System": true,
88
"SimpleDOM": true,
9+
"ActiveXObject": true,
910
"test": true,
1011
"asyncTest": true,
1112
"expect": true,
@@ -29,7 +30,7 @@
2930
"latedef": true,
3031
"noarg": true,
3132
"undef": true,
32-
"unused": true,
33+
"unused": false,
3334
"trailing": true,
3435
"maxdepth": 4,
3536
"boss" : true,
File renamed without changes.
File renamed without changes.

src/ajax-test.js renamed to can-ajax-test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
var ajax = require('can-util/dom/ajax/ajax');
1+
var ajax = require('./can-ajax');
2+
var makeMap = require('can-make-map');
23
var namespace = require("can-namespace");
3-
var makeMap = require('can-util/js/make-map/make-map');
44

55
QUnit = require('steal-qunit');
66

7-
QUnit.module("can-util/dom/ajax");
7+
QUnit.module("can-ajax");
88

99
var makeFixture = function(XHR){
1010

@@ -38,7 +38,7 @@ if (__dirname !== '/') {
3838
QUnit.asyncTest("basic get request", function () {
3939
ajax({
4040
type: "get",
41-
url: __dirname+"/test-result.json"
41+
url: __dirname+"/can-ajax-test-result.json"
4242
}).then(function(resp){
4343
QUnit.equal(resp.message, "VALUE");
4444
start();
@@ -54,7 +54,7 @@ if (__dirname !== '/') {
5454
QUnit.asyncTest("GET requests with dataType parse JSON (#106)", function(){
5555
ajax({
5656
type: "get",
57-
url: __dirname+"/test-result.txt",
57+
url: __dirname+"/can-ajax-test-result.txt",
5858
dataType: "json"
5959
}).then(function(resp){
6060
QUnit.equal(resp.message, "VALUE");
@@ -68,7 +68,7 @@ QUnit.asyncTest("ignores case of type parameter for a post request (#100)", func
6868
CONTENT_TYPE: "Content-Type"
6969
},
7070
restore = makeFixture(function () {
71-
this.open = function (type, url) {
71+
this.open = function () {
7272
};
7373

7474
this.send = function () {
@@ -117,7 +117,7 @@ if(typeof XDomainRequest === 'undefined') {
117117
start();
118118
});
119119
});
120-
120+
121121
// Test simple GET CORS:
122122
QUnit.asyncTest("GET CORS should be a simple request - without a preflight (#187)", function () {
123123

@@ -126,7 +126,7 @@ if(typeof XDomainRequest === 'undefined') {
126126
var isSimpleMethod = makePredicateContains("GET,POST,HEAD");
127127
var isSimpleHeader = makePredicateContains("Accept,Accept-Language,Content-Language,Content-Type,DPR,Downlink,Save-Data,Viewport-Width,Width");
128128
var isSimpleContentType = makePredicateContains("application/x-www-form-urlencoded,multipart/form-data,text/plain");
129-
129+
130130
restore = makeFixture(function () {
131131
this.open = function (type, url) {
132132
if (!isSimpleMethod(type)){
@@ -141,7 +141,7 @@ if(typeof XDomainRequest === 'undefined') {
141141
this.status = 200;
142142
this.onreadystatechange();
143143
};
144-
144+
145145
this.setRequestHeader = function (header, value) {
146146
if (header === "Content-Type" && !isSimpleHeader(value)){
147147
isSimpleRequest = false;
@@ -152,7 +152,7 @@ if(typeof XDomainRequest === 'undefined') {
152152
response[header] = value;
153153
};
154154
});
155-
155+
156156
ajax({
157157
url: "http://query.yahooapis.com/v1/public/yql",
158158
data: {
@@ -176,7 +176,7 @@ if(System.env !== 'canjs-test' && __dirname !== '/') {
176176
QUnit.asyncTest("abort", function () {
177177
var promise = ajax({
178178
type: "get",
179-
url: __dirname+"/test-result.json"
179+
url: __dirname+"/can-ajax-test-result.json"
180180
});
181181
promise.catch(function(xhr) {
182182
if(xhr instanceof Error) {
@@ -237,7 +237,7 @@ if (__dirname !== '/') {
237237
QUnit.asyncTest("correctly serializes null and undefined values (#177)", function () {
238238
ajax({
239239
type: "get",
240-
url: __dirname + "/test-result.txt",
240+
url: __dirname + "/can-ajax-test-result.txt",
241241
data: {
242242
foo: null
243243
}

src/ajax.js renamed to can-ajax.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
var Global = require("../../js/global/global");
2-
var assign = require("../../js/assign/assign");
1+
var Global = require("can-global");
2+
var assign = require("can-assign");
33
var namespace = require("can-namespace");
4-
var parseURI = require('../../js/parse-uri/parse-uri');
5-
var param = require("../../js/param/param");
4+
var parseURI = require('can-parse-uri');
5+
var param = require("can-param");
66

77
/**
8-
* @module {function} can-util/dom/ajax/ajax ajax
9-
* @parent can-util/dom
10-
*
8+
* @module {function} can-ajax can-ajax
9+
* @parent can-infrastructure
10+
*
1111
* Make an asynchronous HTTP (AJAX) request.
12-
*
12+
*
1313
* @signature `ajax( ajaxOptions )`
14-
*
14+
*
1515
* Is used to make an asynchronous HTTP (AJAX) request similar to [http://api.jquery.com/jQuery.ajax/jQuery.ajax].
16-
*
16+
*
1717
* ```
18-
* var ajax = require("can-util/dom/ajax/ajax");
19-
*
18+
* var ajax = require("can-ajax");
19+
*
2020
* ajax({
2121
* url: "http://query.yahooapis.com/v1/public/yql",
2222
* data: {
@@ -27,16 +27,16 @@ var param = require("../../js/param/param");
2727
* console.log( response.query.count ); // => 2
2828
* });
2929
* ```
30-
*
30+
*
3131
* @param {Object} ajaxOptions Configuration options for the AJAX request.
3232
* - __url__ `{String}` The requested url.
3333
* - __type__ `{String}` The method of the request. Ex: `GET`, `PUT`, `POST`, etc. Capitalization is ignored. _Default is `GET`_.
34-
* - __data__ `{Object}` The data of the request. If data needs to be urlencoded (e.g. for GET requests or for CORS) it is serialized with [can-util/js/param].
34+
* - __data__ `{Object}` The data of the request. If data needs to be urlencoded (e.g. for GET requests or for CORS) it is serialized with [can-param].
3535
* - __dataType__ `{String}` Type of data. _Default is `json`_.
3636
* - __crossDomain__ `{Boolean}` If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true. This allows, for example, server-side redirection to another domain. Default: `false` for same-domain requests, `true` for cross-domain requests.
3737
*
3838
* @return {Promise} A Promise that resolves to the data. The Promise instance is abortable and exposes an `abort` method. Invoking abort on the Promise instance indirectly rejects it.
39-
*
39+
*
4040
*/
4141

4242
// from https://gist.github.com/mythz/1334560
@@ -166,7 +166,7 @@ module.exports = namespace.ajax = function (o) {
166166
// For CORS to send a "simple" request (to avoid a preflight check), the following methods are allowed: GET/POST/HEAD,
167167
// see https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests
168168
var isSimpleCors = o.crossDomain && ['GET', 'POST', 'HEAD'].indexOf(type) !== -1;
169-
169+
170170
if (isPost) {
171171
var isJson = o.dataType.indexOf("json") >= 0;
172172
data = (isJson && !isSimpleCors) ?
@@ -176,7 +176,7 @@ module.exports = namespace.ajax = function (o) {
176176
// CORS simple: `Content-Type` has to be `application/x-www-form-urlencoded`:
177177
xhr.setRequestHeader("Content-Type", (isJson && !isSimpleCors) ? "application/json" : "application/x-www-form-urlencoded");
178178
}
179-
179+
180180
// CORS simple: no custom headers, so we don't add `X-Requested-With` header:
181181
if (!isSimpleCors){
182182
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");

package.json

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,14 @@
1818
"postpublish": "git push --tags && git checkout master && git branch -D release && git push",
1919
"testee": "testee test.html --browsers firefox",
2020
"test": "npm run jshint && npm run testee",
21-
"jshint": "jshint ./*.js ./src/ --config",
21+
"jshint": "jshint ./*.js --config",
2222
"release:patch": "npm version patch && npm publish",
2323
"release:minor": "npm version minor && npm publish",
2424
"release:major": "npm version major && npm publish",
2525
"build": "node build.js",
2626
"develop": "done-serve --static --develop --port 8080"
2727
},
2828
"main": "dist/cjs/can-ajax",
29-
"browser": {
30-
"transform": [
31-
"cssify"
32-
]
33-
},
34-
"browserify": {
35-
"transform": [
36-
"cssify"
37-
]
38-
},
3929
"keywords": [
4030
"canjs",
4131
"ajax",
@@ -53,16 +43,15 @@
5343
"generator-donejs",
5444
"donejs-cli",
5545
"steal-tools"
56-
],
57-
"plugins": [
58-
"steal-less",
59-
"steal-stache"
60-
],
61-
"directories": {
62-
"lib": "src"
63-
}
46+
]
6447
},
6548
"dependencies": {
49+
"can-assign": "^1.0.0",
50+
"can-global": "^1.0.0",
51+
"can-make-map": "^1.0.0",
52+
"can-namespace": "^1.0.0",
53+
"can-param": "^1.0.1",
54+
"can-parse-uri": "^1.0.0"
6655
},
6756
"devDependencies": {
6857
"jshint": "^2.9.1",

src/can-ajax-test.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/can-ajax.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/can-ajax.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/test.html

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)