Skip to content

Commit 915f52b

Browse files
committed
various fixes for browser
1 parent 22ea04c commit 915f52b

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

.gitignore

+1-5
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,4 @@ tests/
8787
doc/
8888

8989

90-
91-
92-
93-
94-
90+
.vscode/launch.json

dist/hwc-kernel.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/hwc-kernel.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
'use strict';
22
/*
3-
* VERY FIRST DEFINES AND LEGACY
3+
* VERY FIRST DEFINES AND POLYFILLS
44
*/
55

6+
if (typeof document !== "undefined" && !document.currentScript) {
7+
document.currentScript = (function () {
8+
var scripts = document.getElementsByTagName('script');
9+
return scripts[scripts.length - 1];
10+
})();
11+
}
12+
613
var __global = typeof window === 'object' ? window : global;
714

815
var hwc_conf = { paths: {} };
916

10-
hwc_conf.path_core = __global.hwc_path ? __global.hwc_path : "modules/hw-code";
17+
function retrieveCorePath() {
18+
// TODO: implement without hacks
19+
// for now set hwc_path global variable
20+
var hwc_path = document.currentScript.getAttribute('data-hwc-path');
21+
return hwc_path ? hwc_path : "module/hw-core"
22+
}
23+
24+
hwc_conf.path_core = __global.hwc_path ? __global.hwc_path : retrieveCorePath();
1125

1226
hwc_conf.paths.hwc_js_kernel = hwc_conf.path_core + "js-kernel/index";
1327
hwc_conf.paths.hwc_js_modules_path = hwc_conf.path_core + "js-modules/";
@@ -17,14 +31,8 @@ hwc_conf.paths.hwc_js_modules_jquery = hwc_conf.paths.hwc_js_modules_path + "jqu
1731
hwc_conf.paths.hwc_js_modules_requirenode = hwc_conf.paths.hwc_js_modules_path + "requirejs/r/index";
1832
hwc_conf.paths.hwc_js_modules_requirejs = hwc_conf.paths.hwc_js_modules_path + "requirejs/requirejs/index";
1933

20-
2134
__global.hwc_conf = hwc_conf;
2235

23-
24-
//if (typeof __webpack_require__ === "function") {
25-
// require("../js-modules/requirejs/requirejs/require.js");
26-
//}
27-
2836
// ONLY FOR IE8-
2937
if (!Array.prototype.indexOf) {
3038
Array.prototype.indexOf = function (what, i) {
@@ -403,16 +411,12 @@ if (!Function.prototype.bind) {
403411
_loadSync(hwc_conf.paths.hwc_js_modules_requirejs + '.js');
404412
}
405413

406-
hwc.__requirejs = requirejs;
407-
408-
hwc.__requirejs.config({
414+
requirejs.config({
409415
paths: hwc_conf.paths
410416
});
411417
};
412418

413419
pub.initNode = function () {
414-
hwc.__requirejs = global.requirejs;
415-
416420
setGlobals(global, true);
417421
}
418422

@@ -427,12 +431,17 @@ if (!Function.prototype.bind) {
427431

428432
hwc.Core = HWCore;
429433

434+
// some aliases for requirejs
430435
if (this.defines.IN_BROWSER) {
431436
this.initBrowser();
432437
} else {
433438
this.initNode();
434439
}
435440

441+
hwc.require = hwc.include = hwc.module = hwc.__requirejs = requirejs;
442+
443+
hwc.define = define;
444+
436445
HWCore.const = hwc.const = this.defines;
437446

438447
hwc.__core = hwc.Core.I(callback);
@@ -445,7 +454,7 @@ if (!Function.prototype.bind) {
445454

446455
function _loadSync(url) {
447456
// get some kind of XMLHttpRequest
448-
var xhrObj = createXMLHTTPObject();
457+
var xhrObj = new XMLHttpRequest();
449458
// open and send a synchronous request
450459
xhrObj.open('GET', url, false);
451460
xhrObj.send('');
@@ -535,7 +544,7 @@ if (!Function.prototype.bind) {
535544

536545
})();
537546

538-
define(["hwc_js_modules_rsvp"], function (RSVP) {
547+
define("hwc_js_kernel", ["hwc_js_modules_rsvp"], function (RSVP) {
539548
hwc.__core.loading = false;
540549
hwc.__defineLoader(hwc, RSVP);
541550

0 commit comments

Comments
 (0)