Commit 28e16092 authored by Pascal Hartig's avatar Pascal Hartig

flight: upgrade libraries

Upgraded to flight 1.0.4 which removed `Component#bind` in favor of the native
or polyfilled `Function#bind` and used the new require.js bower format.

Waiting for @phuu to upgrade to Flight 1.1. :)
parent 49d9a24f
......@@ -6,7 +6,7 @@ require.config({
jquery: 'bower_components/jquery/jquery',
es5shim: 'bower_components/es5-shim/es5-shim',
es5sham: 'bower_components/es5-shim/es5-sham',
text: 'bower_components/requirejs/plugins/text'
text: 'bower_components/requirejs-text/text'
},
map: {
'*': {
......
......@@ -93,8 +93,8 @@ define([
this.on('click', { 'toggleSelector': this.toggle });
this.on('dblclick', { 'labelSelector': this.edit });
this.$node.on('blur', '.edit', this.bind(this.requestUpdate));
this.$node.on('keydown', '.edit', this.bind(this.requestUpdateOnEnter));
this.$node.on('blur', '.edit', this.requestUpdate.bind(this));
this.$node.on('keydown', '.edit', this.requestUpdateOnEnter.bind(this));
// these don't work
// this.on(this.attr.editSelector, 'blur', this.requestUpdate);
......
......@@ -4,9 +4,10 @@
"dependencies": {
"depot": "~0.1.4",
"es5-shim": "git://github.com/kriskowal/es5-shim.git#2.0.0",
"flight": "~1.0.3",
"flight": "~1.0.4",
"jquery": "1.8.3",
"requirejs": "~2.1.5",
"todomvc-common": "~0.1.4"
"todomvc-common": "~0.1.4",
"requirejs-text": "~2.0.10"
}
}
/* ----------------------------------
* depot.js v0.1.0
* Licensed under The MIT License
* http://opensource.org/licenses/MIT
* ---------------------------------- */
// depot.js v0.1.6
// (c) 2013 Michal Kuklis
// Licensed under The MIT License
// http://opensource.org/licenses/MIT
// commonjs, amd, global
(function (name, root, factory) {
if (typeof exports === 'object') {
if (typeof exports == 'object') {
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
} else if (typeof define == 'function' && define.amd) {
define(factory);
} else {
root[name] = factory();
}
}("depot", this, function () {
"use strict";
// depot api
......@@ -28,17 +27,30 @@
record[this.idAttribute] = guid();
}
id = record[this.idAttribute];
id = record[this.idAttribute] + '';
if (this.ids.indexOf(id) >= 0) {
record = extend(this.get(id), record);
}
else {
if (this.ids.indexOf(id) < 0) {
this.ids.push(id);
localStorage.setItem(this.name, this.ids.join(","));
this.storageAdaptor.setItem(this.name, this.ids.join(","));
}
localStorage.setItem(getKey(this.name, id), JSON.stringify(record));
this.storageAdaptor.setItem(getKey(this.name, id), JSON.stringify(record));
return record;
},
update: function (id, data) {
if (typeof data == 'undefined') {
data = id;
id = data[this.idAttribute];
}
var record = this.get(id);
if (record) {
record = extend(record, data);
this.save(record);
}
return record;
},
......@@ -57,11 +69,12 @@
find: function (criteria) {
var key, match, record;
var name = this.name;
var self = this;
if (!criteria) return this.all();
return this.ids.reduce(function (memo, id) {
record = jsonData(localStorage.getItem(getKey(name, id)));
record = jsonData(self.storageAdaptor.getItem(getKey(name, id)));
match = findMatch(criteria, record);
if (match) {
......@@ -73,14 +86,14 @@
},
get: function (id) {
return jsonData(localStorage.getItem(getKey(this.name, id)));
return jsonData(this.storageAdaptor.getItem(getKey(this.name, id)));
},
all: function () {
var record, name = this.name;
var record, self = this, name = this.name;
return this.ids.reduce(function (memo, id) {
record = localStorage.getItem(getKey(name, id));
record = self.storageAdaptor.getItem(getKey(name, id));
if (record) {
memo.push(jsonData(record));
......@@ -95,12 +108,12 @@
var id = (record[this.idAttribute]) ? record[this.idAttribute] : record;
var key = getKey(this.name, id);
record = jsonData(localStorage.getItem(key));
localStorage.removeItem(key);
record = jsonData(this.storageAdaptor.getItem(key));
this.storageAdaptor.removeItem(key);
index = this.ids.indexOf(id);
if (index != -1) this.ids.splice(index, 1);
localStorage.setItem(this.name, this.ids.join(","));
if (index != -1) this.ids.splice(index, 1);
this.storageAdaptor.setItem(this.name, this.ids.join(","));
return record;
},
......@@ -114,27 +127,31 @@
if (criteria) {
record = jsonData(localStorage.getItem(key));
record = jsonData(this.storageAdaptor.getItem(key));
match = findMatch(criteria, record);
if (match) {
localStorage.removeItem(key);
this.storageAdaptor.removeItem(key);
this.ids.splice(i, 1);
}
}
else {
localStorage.removeItem(key);
this.storageAdaptor.removeItem(key);
}
}
if (criteria) {
localStorage.setItem(this.name, this.ids.join(","));
this.storageAdaptor.setItem(this.name, this.ids.join(","));
}
else {
localStorage.removeItem(this.name);
this.storageAdaptor.removeItem(this.name);
this.ids = [];
}
},
size: function () {
return this.ids.length;
}
};
......@@ -170,7 +187,7 @@
}
function guid() {
return s4() + s4() + '-' + s4() + '-' + s4() +
return s4() + s4() + '-' + s4() + '-' + s4() +
'-' +s4() + '-' + s4() + s4() + s4();
}
......@@ -187,17 +204,22 @@
function depot(name, options) {
var store, ids;
if (!localStorage) throw new Error("localStorage not found");
options = extend({
idAttribute: '_id',
storageAdaptor: localStorage
}, options);
if (!options.storageAdaptor) throw new Error("No storage adaptor was found");
store = localStorage.getItem(name);
store = options.storageAdaptor.getItem(name);
ids = (store && store.split(",")) || [];
options = options || {};
return Object.create(api, {
return Object.create(api, {
name: { value: name },
store: { value: store },
ids: { value: ids, writable: true },
idAttribute: { value: options.idAttribute || '_id' }
idAttribute: { value: options.idAttribute },
storageAdaptor: { value: options.storageAdaptor }
});
}
......
// Copyright 2009-2012 by contributors, MIT License
// vim: ts=4 sts=4 sw=4 expandtab
// Module systems magic dance
(function (definition) {
// RequireJS
......@@ -95,63 +96,15 @@ if (!Object.getOwnPropertyNames) {
// ES5 15.2.3.5
// http://es5.github.com/#x15.2.3.5
if (!Object.create) {
// Contributed by Brandon Benvie, October, 2012
var createEmpty;
var supportsProto = Object.prototype.__proto__ === null;
if (supportsProto || typeof document == 'undefined') {
createEmpty = function () {
return { "__proto__": null };
};
} else {
// In old IE __proto__ can't be used to manually set `null`, nor does
// any other method exist to make an object that inherits from nothing,
// aside from Object.prototype itself. Instead, create a new global
// object and *steal* its Object.prototype and strip it bare. This is
// used as the prototype to create nullary objects.
createEmpty = (function () {
var iframe = document.createElement('iframe');
var parent = document.body || document.documentElement;
iframe.style.display = 'none';
parent.appendChild(iframe);
iframe.src = 'javascript:';
var empty = iframe.contentWindow.Object.prototype;
parent.removeChild(iframe);
iframe = null;
delete empty.constructor;
delete empty.hasOwnProperty;
delete empty.propertyIsEnumerable;
delete empty.isPrototypeOf;
delete empty.toLocaleString;
delete empty.toString;
delete empty.valueOf;
empty.__proto__ = null;
function Empty() {}
Empty.prototype = empty;
return function () {
return new Empty();
};
})();
}
Object.create = function create(prototype, properties) {
var object;
function Type() {} // An empty constructor.
if (prototype === null) {
object = createEmpty();
object = { "__proto__": null };
} else {
if (typeof prototype !== "object" && typeof prototype !== "function") {
// In the native implementation `parent` can be `null`
// OR *any* `instanceof Object` (Object|Function|Array|RegExp|etc)
// Use `typeof` tho, b/c in old IE, DOM elements are not `instanceof Object`
// like they are in modern browsers. Using `Object.create` on DOM elements
// is...err...probably inappropriate, but the native version allows for it.
throw new TypeError("Object prototype may only be an Object or null"); // same msg as Chrome
if (typeof prototype != "object") {
throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
}
var Type = function () {};
Type.prototype = prototype;
object = new Type();
// IE has no built-in implementation of `Object.getPrototypeOf`
......@@ -160,11 +113,9 @@ if (!Object.create) {
// objects created using `Object.create`
object.__proto__ = prototype;
}
if (properties !== void 0) {
Object.defineProperties(object, properties);
}
return object;
};
}
......@@ -197,8 +148,7 @@ if (Object.defineProperty) {
var definePropertyWorksOnDom = typeof document == "undefined" ||
doesDefinePropertyWork(document.createElement("div"));
if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
var definePropertyFallback = Object.defineProperty,
definePropertiesFallback = Object.defineProperties;
var definePropertyFallback = Object.defineProperty;
}
}
......@@ -278,17 +228,8 @@ if (!Object.defineProperty || definePropertyFallback) {
// ES5 15.2.3.7
// http://es5.github.com/#x15.2.3.7
if (!Object.defineProperties || definePropertiesFallback) {
if (!Object.defineProperties) {
Object.defineProperties = function defineProperties(object, properties) {
// make a valiant attempt to use the real defineProperties
if (definePropertiesFallback) {
try {
return definePropertiesFallback.call(Object, object, properties);
} catch (exception) {
// try the shim if the real one doesn't work
}
}
for (var property in properties) {
if (owns(properties, property) && property != "__proto__") {
Object.defineProperty(object, property, properties[property]);
......
......@@ -18,37 +18,31 @@ define(
var advice = {
around: function(base, wrapped) {
return function() {
var args = util.toArray(arguments);
return wrapped.apply(this, [base.bind(this)].concat(args));
return function composedAround() {
// unpacking arguments by hand benchmarked faster
var i = 0, l = arguments.length, args = new Array(l + 1);
args[0] = base.bind(this);
for (; i < l; i++) args[i + 1] = arguments[i];
return wrapped.apply(this, args);
}
},
before: function(base, before) {
return this.around(base, function() {
var args = util.toArray(arguments),
orig = args.shift(),
beforeFn;
beforeFn = (typeof before == 'function') ? before : before.obj[before.fnName];
beforeFn.apply(this, args);
return (orig).apply(this, args);
});
var beforeFn = (typeof before == 'function') ? before : before.obj[before.fnName];
return function composedBefore() {
beforeFn.apply(this, arguments);
return base.apply(this, arguments);
}
},
after: function(base, after) {
return this.around(base, function() {
var args = util.toArray(arguments),
orig = args.shift(),
afterFn;
// this is a separate statement for debugging purposes.
var res = (orig.unbound || orig).apply(this, args);
afterFn = (typeof after == 'function') ? after : after.obj[after.fnName];
afterFn.apply(this, args);
var afterFn = (typeof after == 'function') ? after : after.obj[after.fnName];
return function composedAfter() {
var res = (base.unbound || base).apply(this, arguments);
afterFn.apply(this, arguments);
return res;
});
}
},
// a mixin that allows other mixins to augment existing functions by adding additional
......
This diff is collapsed.
File mode changed from 100755 to 100644
......@@ -49,7 +49,7 @@ define(
name = eventArgs[0];
}
if (window.DEBUG) {
if (window.DEBUG && window.DEBUG.enabled) {
logFilter = DEBUG.events.logFilter;
// no regex for you, actions...
......@@ -68,14 +68,12 @@ define(
action,
'[' + name + ']',
elemToString(elem),
component.constructor.describe,
fn && (fnName = fn.name || fn.displayName) && '-> ' + fnName
component.constructor.describe.split(' ').slice(0,3).join(' ') //two mixins only
);
}
}
}
function withLogging() {
this.before('trigger', function() {
log('trigger', this, util.toArray(arguments));
......
......@@ -16,18 +16,18 @@ define(
function parseEventArgs(instance, args) {
var element, type, callback;
var end = args.length;
args = util.toArray(args);
if (typeof args[args.length-1] === 'function') {
callback = args.pop();
if (typeof args[end - 1] === 'function') {
end -= 1;
callback = args[end];
}
if (typeof args[args.length-1] === 'object') {
args.pop();
if (typeof args[end - 1] === 'object') {
end -= 1;
}
if (args.length == 2) {
if (end == 2) {
element = args[0];
type = args[1];
} else {
......@@ -56,53 +56,43 @@ define(
(this.reset = function() {
this.components = [];
this.allInstances = [];
this.allInstances = {};
this.events = [];
}).call(this);
function ComponentInfo(component) {
this.component = component;
this.instances = [];
this.attachedTo = [];
this.instances = {};
this.addInstance = function(instance) {
this.throwIfInstanceExistsOnNode(instance);
var instanceInfo = new InstanceInfo(instance);
this.instances.push(instanceInfo);
this.instances[instance.identity] = instanceInfo;
this.attachedTo.push(instance.node);
return instanceInfo;
}
this.throwIfInstanceExistsOnNode = function(instance) {
this.instances.forEach(function (instanceInfo) {
if (instanceInfo.instance.$node[0] === instance.$node[0]) {
throw new Error('Instance of ' + instance.constructor + ' already exists on node ' + instance.$node[0]);
}
});
}
this.removeInstance = function(instance) {
var instanceInfo = this.instances.filter(function(instanceInfo) {
return instanceInfo.instance == instance;
})[0];
var index = this.instances.indexOf(instanceInfo);
(index > -1) && this.instances.splice(index, 1);
delete this.instances[instance.identity];
var indexOfNode = this.attachedTo.indexOf(instance.node);
(indexOfNode > -1) && this.attachedTo.splice(indexOfNode, 1);
if (!this.instances.length) {
if (!Object.keys(this.instances).length) {
//if I hold no more instances remove me from registry
registry.removeComponentInfo(this);
}
}
this.isAttachedTo = function(node) {
return this.attachedTo.indexOf(node) > -1;
}
}
function InstanceInfo(instance) {
this.instance = instance;
this.events = [];
this.addTrigger = function() {};
this.addBind = function(event) {
this.events.push(event);
registry.events.push(event);
......@@ -127,7 +117,7 @@ define(
var inst = component.addInstance(instance);
this.allInstances.push(inst);
this.allInstances[instance.identity] = inst;
return component;
};
......@@ -137,11 +127,10 @@ define(
//remove from component info
var componentInfo = this.findComponentInfo(instance);
componentInfo.removeInstance(instance);
componentInfo && componentInfo.removeInstance(instance);
//remove from registry
var index = this.allInstances.indexOf(instInfo);
(index > -1) && this.allInstances.splice(index, 1);
delete this.allInstances[instance.identity];
};
this.removeComponentInfo = function(componentInfo) {
......@@ -161,41 +150,32 @@ define(
return null;
};
this.findInstanceInfo = function(which) {
var testFn;
if (which.node) {
//by instance (returns matched instance)
testFn = function(inst) {return inst.instance === which};
} else {
//by node (returns array of matches)
testFn = function(inst) {return inst.instance.node === which};
}
var matches = this.allInstances.filter(testFn);
if (!matches.length) {
return which.node ? null : [];
}
return which.node ? matches[0] : matches;
this.findInstanceInfo = function(instance) {
return this.allInstances[instance.identity] || null;
};
this.trigger = function() {
var event = parseEventArgs(this, arguments),
instance = registry.findInstanceInfo(this);
if (instance) {
instance.addTrigger(event);
}
this.findInstanceInfoByNode = function(node) {
var result = [];
Object.keys(this.allInstances).forEach(function(k) {
var thisInstanceInfo = this.allInstances[k];
if(thisInstanceInfo.instance.node === node) {
result.push(thisInstanceInfo);
}
}, this);
return result;
};
this.on = function(componentOn) {
var otherArgs = util.toArray(arguments, 1);
var instance = registry.findInstanceInfo(this);
var boundCallback;
var instance = registry.findInstanceInfo(this), boundCallback;
// unpacking arguments by hand benchmarked faster
var l = arguments.length, i = 1;
var otherArgs = new Array(l - 1);
for (; i < l; i++) otherArgs[i - 1] = arguments[i];
if (instance) {
boundCallback = componentOn.apply(null, otherArgs);
if(boundCallback) {
if (boundCallback) {
otherArgs[otherArgs.length-1] = boundCallback;
}
var event = parseEventArgs(this, otherArgs);
......@@ -210,8 +190,18 @@ define(
if (instance) {
instance.removeBind(event);
}
//remove from global event registry
for (var i = 0, e; e = registry.events[i]; i++) {
if (matchEvent(e, event)) {
registry.events.splice(i, 1);
}
}
};
//debug tools may want to add advice to trigger
registry.trigger = new Function;
this.teardown = function() {
registry.removeInstance(this);
};
......@@ -221,9 +211,10 @@ define(
registry.addInstance(this);
});
this.after('trigger', registry.trigger);
this.around('on', registry.on);
this.after('off', registry.off);
//debug tools may want to add advice to trigger
window.DEBUG && DEBUG.enabled && this.after('trigger', registry.trigger);
this.after('teardown', {obj:registry, fnName:'teardown'});
};
......
......@@ -47,10 +47,18 @@ define(
// base; //{a:2, b:6}
merge: function(/*obj1, obj2,....deepCopy*/) {
var args = this.toArray(arguments);
// unpacking arguments by hand benchmarked faster
var l = arguments.length,
i = 0,
args = new Array(l + 1);
for (; i < l; i++) args[i + 1] = arguments[i];
if (l === 0) {
return {};
}
//start with empty object so a copy is created
args.unshift({});
args[0] = {};
if (args[args.length - 1] === true) {
//jquery extend requires deep copy as first arg
......
......@@ -56,31 +56,63 @@ define(
//******************************************************************************************
// Event logging
//******************************************************************************************
var logLevel = 'all';
logFilter = {actions: logLevel, eventNames: logLevel}; //no filter by default
var ALL = 'all'; //no filter
//no logging by default
var defaultEventNamesFilter = [];
var defaultActionsFilter = [];
var logFilter = retrieveLogFilter();
function filterEventLogsByAction(/*actions*/) {
var actions = [].slice.call(arguments, 0);
var actions = [].slice.call(arguments);
logFilter.eventNames.length || (logFilter.eventNames = 'all');
logFilter.actions = actions.length ? actions : 'all';
logFilter.eventNames.length || (logFilter.eventNames = ALL);
logFilter.actions = actions.length ? actions : ALL;
saveLogFilter();
}
function filterEventLogsByName(/*eventNames*/) {
var eventNames = [].slice.call(arguments, 0);
var eventNames = [].slice.call(arguments);
logFilter.actions.length || (logFilter.actions = 'all');
logFilter.eventNames = eventNames.length ? eventNames : 'all';
logFilter.actions.length || (logFilter.actions = ALL);
logFilter.eventNames = eventNames.length ? eventNames : ALL;
saveLogFilter();
}
function hideAllEventLogs() {
logFilter.actions = [];
logFilter.eventNames = [];
saveLogFilter();
}
function showAllEventLogs() {
logFilter.actions = 'all';
logFilter.eventNames = 'all';
logFilter.actions = ALL;
logFilter.eventNames = ALL;
saveLogFilter();
}
function saveLogFilter() {
if (window.localStorage) {
localStorage.setItem('logFilter_eventNames', logFilter.eventNames);
localStorage.setItem('logFilter_actions', logFilter.actions);
}
}
function retrieveLogFilter() {
var result = {
eventNames: (window.localStorage && localStorage.getItem('logFilter_eventNames')) || defaultEventNamesFilter,
actions: (window.localStorage && localStorage.getItem('logFilter_actions')) || defaultActionsFilter
};
//reconstitute arrays
Object.keys(result).forEach(function(k) {
var thisProp = result[k];
if (typeof thisProp == 'string' && thisProp !== ALL) {
result[k] = thisProp.split(',');
}
});
return result;
}
return {
......@@ -90,7 +122,7 @@ define(
if (enable && window.console) {
console.info('Booting in DEBUG mode');
console.info('You can filter event logging with DEBUG.events.logAll/logNone/logByName/logByAction');
console.info('You can configure event logging with DEBUG.events.logAll()/logNone()/logByName()/logByAction()');
}
window.DEBUG = this;
......
/**
* @license RequireJS text 2.0.3 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
* @license RequireJS text 2.0.10 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/requirejs/text for details
*/
/*jslint regexp: true */
/*global require: false, XMLHttpRequest: false, ActiveXObject: false,
define: false, window: false, process: false, Packages: false,
java: false, location: false */
/*global require, XMLHttpRequest, ActiveXObject,
define, window, process, Packages,
java, location, Components, FileUtils */
define(['module'], function (module) {
'use strict';
var text, fs,
var text, fs, Cc, Ci, xpcIsWindows,
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
......@@ -19,11 +19,11 @@ define(['module'], function (module) {
defaultProtocol = hasLocation && location.protocol && location.protocol.replace(/\:/, ''),
defaultHostName = hasLocation && location.hostname,
defaultPort = hasLocation && (location.port || undefined),
buildMap = [],
buildMap = {},
masterConfig = (module.config && module.config()) || {};
text = {
version: '2.0.3',
version: '2.0.10',
strip: function (content) {
//Strips <?xml ...?> declarations so that external SVG and XML
......@@ -83,16 +83,30 @@ define(['module'], function (module) {
* where strip is a boolean.
*/
parseName: function (name) {
var strip = false, index = name.indexOf("."),
modName = name.substring(0, index),
var modName, ext, temp,
strip = false,
index = name.indexOf("."),
isRelative = name.indexOf('./') === 0 ||
name.indexOf('../') === 0;
if (index !== -1 && (!isRelative || index > 1)) {
modName = name.substring(0, index);
ext = name.substring(index + 1, name.length);
} else {
modName = name;
}
index = ext.indexOf("!");
temp = ext || modName;
index = temp.indexOf("!");
if (index !== -1) {
//Pull off the strip arg.
strip = ext.substring(index + 1, ext.length);
strip = strip === "strip";
ext = ext.substring(0, index);
strip = temp.substring(index + 1) === "strip";
temp = temp.substring(0, index);
if (ext) {
ext = temp;
} else {
modName = temp;
}
}
return {
......@@ -156,11 +170,18 @@ define(['module'], function (module) {
masterConfig.isBuild = config.isBuild;
var parsed = text.parseName(name),
nonStripName = parsed.moduleName + '.' + parsed.ext,
nonStripName = parsed.moduleName +
(parsed.ext ? '.' + parsed.ext : ''),
url = req.toUrl(nonStripName),
useXhr = (masterConfig.useXhr) ||
text.useXhr;
// Do not load if it is an empty: url
if (url.indexOf('empty:') === 0) {
onLoad();
return;
}
//Load the text. Use XHR if possible and in a browser.
if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) {
text.get(url, function (content) {
......@@ -194,11 +215,11 @@ define(['module'], function (module) {
writeFile: function (pluginName, moduleName, req, write, config) {
var parsed = text.parseName(moduleName),
nonStripName = parsed.moduleName + '.' + parsed.ext,
extPart = parsed.ext ? '.' + parsed.ext : '',
nonStripName = parsed.moduleName + extPart,
//Use a '.js' file name so that it indicates it is a
//script that can be loaded across domains.
fileName = req.toUrl(parsed.moduleName + '.' +
parsed.ext) + '.js';
fileName = req.toUrl(parsed.moduleName + extPart) + '.js';
//Leverage own load() method to load plugin value, but only
//write out values that do not have the strip argument,
......@@ -222,24 +243,38 @@ define(['module'], function (module) {
if (masterConfig.env === 'node' || (!masterConfig.env &&
typeof process !== "undefined" &&
process.versions &&
!!process.versions.node)) {
!!process.versions.node &&
!process.versions['node-webkit'])) {
//Using special require.nodeRequire, something added by r.js.
fs = require.nodeRequire('fs');
text.get = function (url, callback) {
var file = fs.readFileSync(url, 'utf8');
//Remove BOM (Byte Mark Order) from utf8 files if it is there.
if (file.indexOf('\uFEFF') === 0) {
file = file.substring(1);
text.get = function (url, callback, errback) {
try {
var file = fs.readFileSync(url, 'utf8');
//Remove BOM (Byte Mark Order) from utf8 files if it is there.
if (file.indexOf('\uFEFF') === 0) {
file = file.substring(1);
}
callback(file);
} catch (e) {
errback(e);
}
callback(file);
};
} else if (masterConfig.env === 'xhr' || (!masterConfig.env &&
text.createXhr())) {
text.get = function (url, callback, errback) {
var xhr = text.createXhr();
text.get = function (url, callback, errback, headers) {
var xhr = text.createXhr(), header;
xhr.open('GET', url, true);
//Allow plugins direct access to xhr headers
if (headers) {
for (header in headers) {
if (headers.hasOwnProperty(header)) {
xhr.setRequestHeader(header.toLowerCase(), headers[header]);
}
}
}
//Allow overrides specified in config
if (masterConfig.onXhr) {
masterConfig.onXhr(xhr, url);
......@@ -259,6 +294,10 @@ define(['module'], function (module) {
} else {
callback(xhr.responseText);
}
if (masterConfig.onXhrComplete) {
masterConfig.onXhrComplete(xhr, url);
}
}
};
xhr.send(null);
......@@ -289,7 +328,9 @@ define(['module'], function (module) {
line = line.substring(1);
}
stringBuffer.append(line);
if (line !== null) {
stringBuffer.append(line);
}
while ((line = input.readLine()) !== null) {
stringBuffer.append(lineSeparator);
......@@ -302,7 +343,44 @@ define(['module'], function (module) {
}
callback(content);
};
}
} else if (masterConfig.env === 'xpconnect' || (!masterConfig.env &&
typeof Components !== 'undefined' && Components.classes &&
Components.interfaces)) {
//Avert your gaze!
Cc = Components.classes,
Ci = Components.interfaces;
Components.utils['import']('resource://gre/modules/FileUtils.jsm');
xpcIsWindows = ('@mozilla.org/windows-registry-key;1' in Cc);
text.get = function (url, callback) {
var inStream, convertStream, fileObj,
readData = {};
if (xpcIsWindows) {
url = url.replace(/\//g, '\\');
}
fileObj = new FileUtils.File(url);
//XPCOM, you so crazy
try {
inStream = Cc['@mozilla.org/network/file-input-stream;1']
.createInstance(Ci.nsIFileInputStream);
inStream.init(fileObj, 1, 0, false);
convertStream = Cc['@mozilla.org/intl/converter-input-stream;1']
.createInstance(Ci.nsIConverterInputStream);
convertStream.init(inStream, "utf-8", inStream.available(),
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
convertStream.readString(inStream.available(), readData);
convertStream.close();
inStream.close();
callback(readData.value);
} catch (e) {
throw new Error((fileObj && fileObj.path || '') + ': ' + e);
}
};
}
return text;
});
......@@ -25,6 +25,6 @@
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
<script src="bower_components/todomvc-common/base.js"></script>
<script data-main="app/js/main" src="bower_components/requirejs/requirejs.js"></script>
<script data-main="app/js/main" src="bower_components/requirejs/require.js"></script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment