diff options
author | Valerio Virgillito | 2012-02-01 00:09:27 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-01 00:09:27 -0800 |
commit | 8592cfb89db05f0e52d8c1b8c7046e6f49e3522d (patch) | |
tree | a6f9b5adfe16fd6232708f8a2345cd79056caca9 /node_modules/montage-user/require | |
parent | c6d1a1da9e7cdf477daf32410d80691eb1e828d5 (diff) | |
download | ninja-8592cfb89db05f0e52d8c1b8c7046e6f49e3522d.tar.gz |
Adding a montage framework copy for the user document
Adding a new montage copy containing the latest version of montage to use the new native widgets
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'node_modules/montage-user/require')
-rwxr-xr-x | node_modules/montage-user/require/browser.js | 112 | ||||
-rw-r--r-- | node_modules/montage-user/require/node.js | 101 | ||||
-rwxr-xr-x | node_modules/montage-user/require/require.js | 698 |
3 files changed, 911 insertions, 0 deletions
diff --git a/node_modules/montage-user/require/browser.js b/node_modules/montage-user/require/browser.js new file mode 100755 index 00000000..e249d355 --- /dev/null +++ b/node_modules/montage-user/require/browser.js | |||
@@ -0,0 +1,112 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | bootstrap("require/browser", function (require) { | ||
7 | |||
8 | var Require = require("require/require"); | ||
9 | var Promise = require("core/promise").Promise; | ||
10 | var URL = require("core/mini-url"); | ||
11 | |||
12 | var global = typeof global !== "undefined" ? global : window; | ||
13 | |||
14 | Require.getLocation = function() { | ||
15 | return URL.resolve(window.location, "."); | ||
16 | }; | ||
17 | |||
18 | Require.overlays = ["browser", "montage"]; | ||
19 | |||
20 | // Due to crazy variabile availability of new and old XHR APIs across | ||
21 | // platforms, this implementation registers every known name for the event | ||
22 | // listeners. The promise library ascertains that the returned promise | ||
23 | // is resolved only by the first event. | ||
24 | // http://dl.dropbox.com/u/131998/yui/misc/get/browser-capabilities.html | ||
25 | Require.read = function (url) { | ||
26 | |||
27 | if (URL.resolve(window.location, url).indexOf("file:") === 0) { | ||
28 | throw new Error("XHR does not function for file: protocol"); | ||
29 | } | ||
30 | |||
31 | var request = new XMLHttpRequest(); | ||
32 | var response = Promise.defer(); | ||
33 | |||
34 | function onload() { | ||
35 | if (xhrSuccess(request)) { | ||
36 | response.resolve(request.responseText); | ||
37 | } else { | ||
38 | onerror(); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | function onerror() { | ||
43 | response.reject("Can't XHR " + JSON.stringify(url)); | ||
44 | } | ||
45 | |||
46 | try { | ||
47 | request.open("GET", url, true); | ||
48 | request.overrideMimeType("application/javascript"); | ||
49 | request.onreadystatechange = function () { | ||
50 | if (request.readyState === 4) { | ||
51 | onload(); | ||
52 | } | ||
53 | }; | ||
54 | request.onload = request.load = onload; | ||
55 | request.onerror = request.error = onerror; | ||
56 | } catch (exception) { | ||
57 | response.reject(exception.message, exception); | ||
58 | } | ||
59 | |||
60 | request.send(); | ||
61 | return response.promise; | ||
62 | }; | ||
63 | |||
64 | // Determine if an XMLHttpRequest was successful | ||
65 | // Some versions of WebKit return 0 for successful file:// URLs | ||
66 | function xhrSuccess(req) { | ||
67 | return (req.status === 200 || (req.status === 0 && req.responseText)); | ||
68 | } | ||
69 | |||
70 | // By using a named "eval" most browsers will execute in the global scope. | ||
71 | // http://www.davidflanagan.com/2010/12/global-eval-in.html | ||
72 | // Unfortunately execScript doesn't always return the value of the evaluated expression (at least in Chrome) | ||
73 | var globalEval = /*this.execScript ||*/eval; | ||
74 | // For Firebug evaled code isn't debuggable otherwise | ||
75 | // http://code.google.com/p/fbug/issues/detail?id=2198 | ||
76 | if (global.navigator && global.navigator.userAgent.indexOf("Firefox") >= 0) { | ||
77 | globalEval = new Function("evalString", "return eval(evalString)"); | ||
78 | } | ||
79 | |||
80 | Require.Compiler = function (config) { | ||
81 | return function(module) { | ||
82 | if (module.factory || module.text === void 0) | ||
83 | return module; | ||
84 | |||
85 | // Here we use a couple tricks to make debugging better in various browsers: | ||
86 | // TODO: determine if these are all necessary / the best options | ||
87 | // 1. name the function with something inteligible since some debuggers display the first part of each eval (Firebug) | ||
88 | // 2. append the "//@ sourceURL=location" hack (Safari, Chrome, Firebug) | ||
89 | // * http://pmuellr.blogspot.com/2009/06/debugger-friendly.html | ||
90 | // * http://blog.getfirebug.com/2009/08/11/give-your-eval-a-name-with-sourceurl/ | ||
91 | // TODO: investigate why this isn't working in Firebug. | ||
92 | // 3. set displayName property on the factory function (Safari, Chrome) | ||
93 | |||
94 | var displayName = "__FILE__"+module.location.replace(/\.\w+$|\W/g, "__"); | ||
95 | |||
96 | try { | ||
97 | module.factory = globalEval("(function "+displayName+"(require, exports, module) {"+module.text+"//*/\n})"+"\n//@ sourceURL="+module.location); | ||
98 | } catch (exception) { | ||
99 | throw new SyntaxError("in " + module.location + ": " + exception.message); | ||
100 | } | ||
101 | |||
102 | // This should work and would be simpler, but Firebug does not show scripts executed via "new Function()" constructor. | ||
103 | // TODO: sniff browser? | ||
104 | // module.factory = new Function("require", "exports", "module", module.text + "\n//*/"+sourceURLComment); | ||
105 | |||
106 | module.factory.displayName = displayName; | ||
107 | |||
108 | return module; | ||
109 | } | ||
110 | }; | ||
111 | |||
112 | }); | ||
diff --git a/node_modules/montage-user/require/node.js b/node_modules/montage-user/require/node.js new file mode 100644 index 00000000..568410cf --- /dev/null +++ b/node_modules/montage-user/require/node.js | |||
@@ -0,0 +1,101 @@ | |||
1 | |||
2 | var Require = require("./require"); | ||
3 | var URL = require("../core/url"); | ||
4 | var Promise = require("../core/promise").Promise; | ||
5 | var FS = require("fs"); | ||
6 | |||
7 | var globalEval = eval; | ||
8 | |||
9 | Require.getLocation = function () { | ||
10 | return URL.resolve("file:///", process.cwd() + "/"); | ||
11 | }; | ||
12 | |||
13 | var urlToPath = function (url) { | ||
14 | var parsed = URL.parse(url); | ||
15 | return parsed.path; | ||
16 | }; | ||
17 | |||
18 | Require.read = function (url) { | ||
19 | var deferred = Promise.defer(); | ||
20 | var path = urlToPath(url); | ||
21 | FS.readFile(path, "utf-8", function (error, text) { | ||
22 | if (error) { | ||
23 | deferred.reject(new Error(error)); | ||
24 | } else { | ||
25 | deferred.resolve(text); | ||
26 | } | ||
27 | }); | ||
28 | return deferred.promise; | ||
29 | }; | ||
30 | |||
31 | // Compiles module text into a function. | ||
32 | // Can be overriden by the platform to make the engine aware of the source path. Uses sourceURL hack by default. | ||
33 | Require.Compiler = function (config) { | ||
34 | config.scope = config.scope || {}; | ||
35 | var names = ["require", "exports", "module"]; | ||
36 | var scopeNames = Object.keys(config.scope); | ||
37 | names.push.apply(names, scopeNames); | ||
38 | return function(module) { | ||
39 | if (module.factory) | ||
40 | return module; | ||
41 | if (!module.factory && module.text !== void 0) { | ||
42 | var factory = globalEval( | ||
43 | "(function(" + names.join(",") + "){" + | ||
44 | module.text + | ||
45 | "\n//*/\n})\n//@ sourceURL=" + module.location | ||
46 | ); | ||
47 | module.factory = function (require, exports, module) { | ||
48 | Array.prototype.push.apply(arguments, scopeNames.map(function (name) { | ||
49 | return config.scope[name]; | ||
50 | })); | ||
51 | return factory.apply(this, arguments); | ||
52 | }; | ||
53 | // new Function will have its body reevaluated at every call, hence using eval instead | ||
54 | // https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope | ||
55 | //module.factory = new Function("require", "exports", "module", module.text + "\n//*/\n//@ sourceURL="+module.path); | ||
56 | } | ||
57 | return module; | ||
58 | }; | ||
59 | }; | ||
60 | |||
61 | Require.DefaultLoaderConstructor = function(config) { | ||
62 | return Require.MappingsLoader( | ||
63 | config, | ||
64 | Require.ExtensionsLoader( | ||
65 | config, | ||
66 | Require.PathsLoader( | ||
67 | config, | ||
68 | Require.CachingLoader( | ||
69 | config, | ||
70 | Require.Loader( | ||
71 | config, | ||
72 | Require.NodeLoader(config) | ||
73 | ) | ||
74 | ) | ||
75 | ) | ||
76 | ) | ||
77 | ); | ||
78 | }; | ||
79 | |||
80 | Require.NodeLoader = function (config) { | ||
81 | return function (url, module) { | ||
82 | var id = url.slice(config.location.length); | ||
83 | return { | ||
84 | type: "native", | ||
85 | exports: require(id), | ||
86 | location: url | ||
87 | } | ||
88 | }; | ||
89 | } | ||
90 | |||
91 | Require.main = function () { | ||
92 | var require = Require.Sandbox(); | ||
93 | require.async(process.argv[2]).end(); | ||
94 | }; | ||
95 | |||
96 | Require.overlays = ["node", "server", "montage"]; | ||
97 | |||
98 | if (require.main === module) { | ||
99 | Require.main(); | ||
100 | } | ||
101 | |||
diff --git a/node_modules/montage-user/require/require.js b/node_modules/montage-user/require/require.js new file mode 100755 index 00000000..8273b660 --- /dev/null +++ b/node_modules/montage-user/require/require.js | |||
@@ -0,0 +1,698 @@ | |||
1 | /* <copyright> | ||
2 | This |