Skip to content

Commit 389c3ae

Browse files
committed
better import XMLHttpRequest and localStorage; use dist/av.js in node
1 parent d260a20 commit 389c3ae

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

dist/localStorage.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function Storage(){
2+
this.length = 0;
3+
}
4+
Storage.prototype.getItem = function (key) {
5+
return null;
6+
};
7+
8+
Storage.prototype.setItem = function (key, val) {
9+
};
10+
11+
Storage.prototype.removeItem = function (key) {
12+
};
13+
14+
Storage.prototype.clear = function () {
15+
};
16+
17+
Storage.prototype.key = function (i) {
18+
};
19+
20+
exports.localStorage = new Storage();

gulpfile.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ getAVVersion = function() {
4747
return require('./lib/AV.js').AV.VERSION.replace('js', '');
4848
};
4949

50+
gulp.task('localstorage', function() {
51+
gulp.src(['lib/localstorage.js']).pipe(gulp.dest('dist'));
52+
});
53+
5054
gulp.task('pack', shell.task([
51-
'rm -rf dist/',
5255
'rm -rf node_modules/',
5356
'rm -rf ./*.tgz',
5457
'rm -rf ./tools',
@@ -127,4 +130,4 @@ gulp.task('clean', function() {
127130
.pipe(clean({force: true}));
128131
});
129132

130-
gulp.task('release', ['concat', 'concat_core', 'uglify', 'compress-scripts', 'docs', 'compress-docs']);
133+
gulp.task('release', ['concat', 'concat_core', 'uglify', 'compress-scripts', 'localstorage', 'docs', 'compress-docs']);

lib/utils.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,31 @@
1212
*/
1313
var AV = root.AV;
1414

15+
// Import XMLHttpRequest
16+
if (typeof(XMLHttpRequest) !== 'undefined') {
17+
AV.XMLHttpRequest = XMLHttpRequest;
18+
} else if (typeof(require) === 'function' && typeof(require.ensure) === 'undefined') {
19+
AV.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
20+
}
21+
22+
// Import localStorage
23+
if (typeof(localStorage) !== 'undefined') {
24+
AV.localStorage= localStorage;
25+
} else if (typeof(require) === 'function' && typeof(require.ensure) === 'undefined') {
26+
try{
27+
AV.localStorage = require('localStorage');
28+
}catch(error){
29+
AV.localStorage = require('./localStorage.js').localStorage;
30+
}
31+
}
32+
1533
// Import AV's local copy of underscore.
1634
if (typeof(exports) !== "undefined" && exports._) {
1735
// We're running in Node.js. Pull in the dependencies.
1836
AV._ = exports._.noConflict();
19-
try{
20-
AV.localStorage = require('localStorage');
21-
}catch(error){
22-
AV.localStorage = require('./localStorage.js').localStorage;
23-
}
24-
AV.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
2537
exports.AV = AV;
2638
} else {
2739
AV._ = _.noConflict();
28-
if (typeof(localStorage) !== "undefined") {
29-
AV.localStorage = localStorage;
30-
}
31-
if (typeof(XMLHttpRequest) !== "undefined") {
32-
AV.XMLHttpRequest = XMLHttpRequest;
33-
}
3440
}
3541

3642
// If jQuery or Zepto has been included, grab a reference to it.

0 commit comments

Comments
 (0)