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({ ...@@ -6,7 +6,7 @@ require.config({
jquery: 'bower_components/jquery/jquery', jquery: 'bower_components/jquery/jquery',
es5shim: 'bower_components/es5-shim/es5-shim', es5shim: 'bower_components/es5-shim/es5-shim',
es5sham: 'bower_components/es5-shim/es5-sham', es5sham: 'bower_components/es5-shim/es5-sham',
text: 'bower_components/requirejs/plugins/text' text: 'bower_components/requirejs-text/text'
}, },
map: { map: {
'*': { '*': {
......
...@@ -93,8 +93,8 @@ define([ ...@@ -93,8 +93,8 @@ define([
this.on('click', { 'toggleSelector': this.toggle }); this.on('click', { 'toggleSelector': this.toggle });
this.on('dblclick', { 'labelSelector': this.edit }); this.on('dblclick', { 'labelSelector': this.edit });
this.$node.on('blur', '.edit', this.bind(this.requestUpdate)); this.$node.on('blur', '.edit', this.requestUpdate.bind(this));
this.$node.on('keydown', '.edit', this.bind(this.requestUpdateOnEnter)); this.$node.on('keydown', '.edit', this.requestUpdateOnEnter.bind(this));
// these don't work // these don't work
// this.on(this.attr.editSelector, 'blur', this.requestUpdate); // this.on(this.attr.editSelector, 'blur', this.requestUpdate);
......
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
"dependencies": { "dependencies": {
"depot": "~0.1.4", "depot": "~0.1.4",
"es5-shim": "git://github.com/kriskowal/es5-shim.git#2.0.0", "es5-shim": "git://github.com/kriskowal/es5-shim.git#2.0.0",
"flight": "~1.0.3", "flight": "~1.0.4",
"jquery": "1.8.3", "jquery": "1.8.3",
"requirejs": "~2.1.5", "requirejs": "~2.1.5",
"todomvc-common": "~0.1.4" "todomvc-common": "~0.1.4",
"requirejs-text": "~2.0.10"
} }
} }
/* ---------------------------------- // depot.js v0.1.6
* depot.js v0.1.0
* Licensed under The MIT License // (c) 2013 Michal Kuklis
* http://opensource.org/licenses/MIT // Licensed under The MIT License
* ---------------------------------- */ // http://opensource.org/licenses/MIT
// commonjs, amd, global
(function (name, root, factory) { (function (name, root, factory) {
if (typeof exports === 'object') { if (typeof exports == 'object') {
module.exports = factory(); module.exports = factory();
} else if (typeof define === 'function' && define.amd) { } else if (typeof define == 'function' && define.amd) {
define(factory); define(factory);
} else { } else {
root[name] = factory(); root[name] = factory();
...@@ -28,17 +27,30 @@ ...@@ -28,17 +27,30 @@
record[this.idAttribute] = guid(); record[this.idAttribute] = guid();
} }
id = record[this.idAttribute]; id = record[this.idAttribute] + '';
if (this.ids.indexOf(id) >= 0) { if (this.ids.indexOf(id) < 0) {
record = extend(this.get(id), record);
}
else {
this.ids.push(id); 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; return record;
}, },
...@@ -57,11 +69,12 @@ ...@@ -57,11 +69,12 @@
find: function (criteria) { find: function (criteria) {
var key, match, record; var key, match, record;
var name = this.name; var name = this.name;
var self = this;
if (!criteria) return this.all(); if (!criteria) return this.all();
return this.ids.reduce(function (memo, id) { 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); match = findMatch(criteria, record);
if (match) { if (match) {
...@@ -73,14 +86,14 @@ ...@@ -73,14 +86,14 @@
}, },
get: function (id) { get: function (id) {
return jsonData(localStorage.getItem(getKey(this.name, id))); return jsonData(this.storageAdaptor.getItem(getKey(this.name, id)));
}, },
all: function () { all: function () {
var record, name = this.name; var record, self = this, name = this.name;
return this.ids.reduce(function (memo, id) { return this.ids.reduce(function (memo, id) {
record = localStorage.getItem(getKey(name, id)); record = self.storageAdaptor.getItem(getKey(name, id));
if (record) { if (record) {
memo.push(jsonData(record)); memo.push(jsonData(record));
...@@ -95,12 +108,12 @@ ...@@ -95,12 +108,12 @@
var id = (record[this.idAttribute]) ? record[this.idAttribute] : record; var id = (record[this.idAttribute]) ? record[this.idAttribute] : record;
var key = getKey(this.name, id); var key = getKey(this.name, id);
record = jsonData(localStorage.getItem(key)); record = jsonData(this.storageAdaptor.getItem(key));
localStorage.removeItem(key); this.storageAdaptor.removeItem(key);
index = this.ids.indexOf(id); index = this.ids.indexOf(id);
if (index != -1) this.ids.splice(index, 1); if (index != -1) this.ids.splice(index, 1);
localStorage.setItem(this.name, this.ids.join(",")); this.storageAdaptor.setItem(this.name, this.ids.join(","));
return record; return record;
}, },
...@@ -114,27 +127,31 @@ ...@@ -114,27 +127,31 @@
if (criteria) { if (criteria) {
record = jsonData(localStorage.getItem(key)); record = jsonData(this.storageAdaptor.getItem(key));
match = findMatch(criteria, record); match = findMatch(criteria, record);
if (match) { if (match) {
localStorage.removeItem(key); this.storageAdaptor.removeItem(key);
this.ids.splice(i, 1); this.ids.splice(i, 1);
} }
} }
else { else {
localStorage.removeItem(key); this.storageAdaptor.removeItem(key);
} }
} }
if (criteria) { if (criteria) {
localStorage.setItem(this.name, this.ids.join(",")); this.storageAdaptor.setItem(this.name, this.ids.join(","));
} }
else { else {
localStorage.removeItem(this.name); this.storageAdaptor.removeItem(this.name);
this.ids = []; this.ids = [];
} }
},
size: function () {
return this.ids.length;
} }
}; };
...@@ -187,17 +204,22 @@ ...@@ -187,17 +204,22 @@
function depot(name, options) { function depot(name, options) {
var store, ids; 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(",")) || []; ids = (store && store.split(",")) || [];
options = options || {};
return Object.create(api, { return Object.create(api, {
name: { value: name }, name: { value: name },
store: { value: store }, store: { value: store },
ids: { value: ids, writable: true }, 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 // Copyright 2009-2012 by contributors, MIT License
// vim: ts=4 sts=4 sw=4 expandtab // vim: ts=4 sts=4 sw=4 expandtab
// Module systems magic dance // Module systems magic dance
(function (definition) { (function (definition) {
// RequireJS // RequireJS
...@@ -95,63 +96,15 @@ if (!Object.getOwnPropertyNames) { ...@@ -95,63 +96,15 @@ if (!Object.getOwnPropertyNames) {
// ES5 15.2.3.5 // ES5 15.2.3.5
// http://es5.github.com/#x15.2.3.5 // http://es5.github.com/#x15.2.3.5
if (!Object.create) { 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) { Object.create = function create(prototype, properties) {
var object; var object;
function Type() {} // An empty constructor.
if (prototype === null) { if (prototype === null) {
object = createEmpty(); object = { "__proto__": null };
} else { } else {
if (typeof prototype !== "object" && typeof prototype !== "function") { if (typeof prototype != "object") {
// In the native implementation `parent` can be `null` throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
// 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
} }
var Type = function () {};
Type.prototype = prototype; Type.prototype = prototype;
object = new Type(); object = new Type();
// IE has no built-in implementation of `Object.getPrototypeOf` // IE has no built-in implementation of `Object.getPrototypeOf`
...@@ -160,11 +113,9 @@ if (!Object.create) { ...@@ -160,11 +113,9 @@ if (!Object.create) {
// objects created using `Object.create` // objects created using `Object.create`
object.__proto__ = prototype; object.__proto__ = prototype;
} }
if (properties !== void 0) { if (properties !== void 0) {
Object.defineProperties(object, properties); Object.defineProperties(object, properties);
} }
return object; return object;
}; };
} }
...@@ -197,8 +148,7 @@ if (Object.defineProperty) { ...@@ -197,8 +148,7 @@ if (Object.defineProperty) {
var definePropertyWorksOnDom = typeof document == "undefined" || var definePropertyWorksOnDom = typeof document == "undefined" ||
doesDefinePropertyWork(document.createElement("div")); doesDefinePropertyWork(document.createElement("div"));
if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) { if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
var definePropertyFallback = Object.defineProperty, var definePropertyFallback = Object.defineProperty;
definePropertiesFallback = Object.defineProperties;
} }
} }
...@@ -278,17 +228,8 @@ if (!Object.defineProperty || definePropertyFallback) { ...@@ -278,17 +228,8 @@ if (!Object.defineProperty || definePropertyFallback) {
// ES5 15.2.3.7 // ES5 15.2.3.7
// http://es5.github.com/#x15.2.3.7 // http://es5.github.com/#x15.2.3.7
if (!Object.defineProperties || definePropertiesFallback) { if (!Object.defineProperties) {
Object.defineProperties = function defineProperties(object, properties) { 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) { for (var property in properties) {
if (owns(properties, property) && property != "__proto__") { if (owns(properties, property) && property != "__proto__") {
Object.defineProperty(object, property, properties[property]); Object.defineProperty(object, property, properties[property]);
......
...@@ -18,37 +18,31 @@ define( ...@@ -18,37 +18,31 @@ define(
var advice = { var advice = {
around: function(base, wrapped) { around: function(base, wrapped) {
return function() { return function composedAround() {
var args = util.toArray(arguments); // unpacking arguments by hand benchmarked faster
return wrapped.apply(this, [base.bind(this)].concat(args)); 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) { before: function(base, before) {
return this.around(base, function() { var beforeFn = (typeof before == 'function') ? before : before.obj[before.fnName];
var args = util.toArray(arguments), return function composedBefore() {
orig = args.shift(), beforeFn.apply(this, arguments);
beforeFn; return base.apply(this, arguments);
}
beforeFn = (typeof before == 'function') ? before : before.obj[before.fnName];
beforeFn.apply(this, args);
return (orig).apply(this, args);
});
}, },
after: function(base, after) { after: function(base, after) {
return this.around(base, function() { var afterFn = (typeof after == 'function') ? after : after.obj[after.fnName];
var args = util.toArray(arguments), return function composedAfter() {
orig = args.shift(), var res = (base.unbound || base).apply(this, arguments);
afterFn; afterFn.apply(this, arguments);
// 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);
return res; return res;
}); }
}, },
// a mixin that allows other mixins to augment existing functions by adding additional // 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( ...@@ -49,7 +49,7 @@ define(
name = eventArgs[0]; name = eventArgs[0];
} }
if (window.DEBUG) { if (window.DEBUG && window.DEBUG.enabled) {
logFilter = DEBUG.events.logFilter; logFilter = DEBUG.events.logFilter;
// no regex for you, actions... // no regex for you, actions...
...@@ -68,14 +68,12 @@ define( ...@@ -68,14 +68,12 @@ define(
action, action,
'[' + name + ']', '[' + name + ']',
elemToString(elem), elemToString(elem),
component.constructor.describe, component.constructor.describe.split(' ').slice(0,3).join(' ') //two mixins only
fn && (fnName = fn.name || fn.displayName) && '-> ' + fnName
); );
} }
} }
} }
function withLogging() { function withLogging() {
this.before('trigger', function() { this.before('trigger', function() {
log('trigger', this, util.toArray(arguments)); log('trigger', this, util.toArray(arguments));
......
...@@ -16,18 +16,18 @@ define( ...@@ -16,18 +16,18 @@ define(
function parseEventArgs(instance, args) { function parseEventArgs(instance, args) {
var element, type, callback; var element, type, callback;
var end = args.length;
args = util.toArray(args); if (typeof args[end - 1] === 'function') {
end -= 1;
if (typeof args[args.length-1] === 'function') { callback = args[end];
callback = args.pop();
} }
if (typeof args[args.length-1] === 'object') { if (typeof args[end - 1] === 'object') {
args.pop(); end -= 1;
} }
if (args.length == 2) { if (end == 2) {
element = args[0]; element = args[0];
type = args[1]; type = args[1];
} else { } else {
...@@ -56,53 +56,43 @@ define( ...@@ -56,53 +56,43 @@ define(
(this.reset = function() { (this.reset = function() {
this.components = []; this.components = [];
this.allInstances = []; this.allInstances = {};
this.events = []; this.events = [];
}).call(this); }).call(this);
function ComponentInfo(component) { function ComponentInfo(component) {
this.component = component; this.component = component;
this.instances = []; this.attachedTo = [];
this.instances = {};
this.addInstance = function(instance) { this.addInstance = function(instance) {
this.throwIfInstanceExistsOnNode(instance);
var instanceInfo = new InstanceInfo(instance); var instanceInfo = new InstanceInfo(instance);
this.instances.push(instanceInfo); this.instances[instance.identity] = instanceInfo;
this.attachedTo.push(instance.node);
return instanceInfo; 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) { this.removeInstance = function(instance) {
var instanceInfo = this.instances.filter(function(instanceInfo) { delete this.instances[instance.identity];
return instanceInfo.instance == instance; var indexOfNode = this.attachedTo.indexOf(instance.node);
})[0]; (indexOfNode > -1) && this.attachedTo.splice(indexOfNode, 1);
var index = this.instances.indexOf(instanceInfo);
(index > -1) && this.instances.splice(index, 1); if (!Object.keys(this.instances).length) {
if (!this.instances.length) {
//if I hold no more instances remove me from registry //if I hold no more instances remove me from registry
registry.removeComponentInfo(this); registry.removeComponentInfo(this);
} }
} }
this.isAttachedTo = function(node) {
return this.attachedTo.indexOf(node) > -1;
}
} }
function InstanceInfo(instance) { function InstanceInfo(instance) {
this.instance = instance; this.instance = instance;
this.events = []; this.events = [];
this.addTrigger = function() {};
this.addBind = function(event) { this.addBind = function(event) {
this.events.push(event); this.events.push(event);
registry.events.push(event); registry.events.push(event);
...@@ -127,7 +117,7 @@ define( ...@@ -127,7 +117,7 @@ define(
var inst = component.addInstance(instance); var inst = component.addInstance(instance);
this.allInstances.push(inst); this.allInstances[instance.identity] = inst;
return component; return component;
}; };
...@@ -137,11 +127,10 @@ define( ...@@ -137,11 +127,10 @@ define(
//remove from component info //remove from component info
var componentInfo = this.findComponentInfo(instance); var componentInfo = this.findComponentInfo(instance);
componentInfo.removeInstance(instance); componentInfo && componentInfo.removeInstance(instance);
//remove from registry //remove from registry
var index = this.allInstances.indexOf(instInfo); delete this.allInstances[instance.identity];
(index > -1) && this.allInstances.splice(index, 1);
}; };
this.removeComponentInfo = function(componentInfo) { this.removeComponentInfo = function(componentInfo) {
...@@ -161,41 +150,32 @@ define( ...@@ -161,41 +150,32 @@ define(
return null; return null;
}; };
this.findInstanceInfo = function(which) { this.findInstanceInfo = function(instance) {
var testFn; return this.allInstances[instance.identity] || null;
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.trigger = function() { this.findInstanceInfoByNode = function(node) {
var event = parseEventArgs(this, arguments), var result = [];
instance = registry.findInstanceInfo(this); Object.keys(this.allInstances).forEach(function(k) {
var thisInstanceInfo = this.allInstances[k];
if (instance) { if(thisInstanceInfo.instance.node === node) {
instance.addTrigger(event); result.push(thisInstanceInfo);
} }
}, this);
return result;
}; };
this.on = function(componentOn) { this.on = function(componentOn) {
var otherArgs = util.toArray(arguments, 1); var instance = registry.findInstanceInfo(this), boundCallback;
var instance = registry.findInstanceInfo(this);
var 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) { if (instance) {
boundCallback = componentOn.apply(null, otherArgs); boundCallback = componentOn.apply(null, otherArgs);
if(boundCallback) { if (boundCallback) {
otherArgs[otherArgs.length-1] = boundCallback; otherArgs[otherArgs.length-1] = boundCallback;
} }
var event = parseEventArgs(this, otherArgs); var event = parseEventArgs(this, otherArgs);
...@@ -210,8 +190,18 @@ define( ...@@ -210,8 +190,18 @@ define(
if (instance) { if (instance) {
instance.removeBind(event); 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() { this.teardown = function() {
registry.removeInstance(this); registry.removeInstance(this);
}; };
...@@ -221,9 +211,10 @@ define( ...@@ -221,9 +211,10 @@ define(
registry.addInstance(this); registry.addInstance(this);
}); });
this.after('trigger', registry.trigger);
this.around('on', registry.on); this.around('on', registry.on);
this.after('off', registry.off); 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'}); this.after('teardown', {obj:registry, fnName:'teardown'});
}; };
......
...@@ -47,10 +47,18 @@ define( ...@@ -47,10 +47,18 @@ define(
// base; //{a:2, b:6} // base; //{a:2, b:6}
merge: function(/*obj1, obj2,....deepCopy*/) { 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 //start with empty object so a copy is created
args.unshift({}); args[0] = {};
if (args[args.length - 1] === true) { if (args[args.length - 1] === true) {
//jquery extend requires deep copy as first arg //jquery extend requires deep copy as first arg
......
...@@ -56,31 +56,63 @@ define( ...@@ -56,31 +56,63 @@ define(
//****************************************************************************************** //******************************************************************************************
// Event logging // 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*/) { function filterEventLogsByAction(/*actions*/) {
var actions = [].slice.call(arguments, 0); var actions = [].slice.call(arguments);
logFilter.eventNames.length || (logFilter.eventNames = 'all'); logFilter.eventNames.length || (logFilter.eventNames = ALL);
logFilter.actions = actions.length ? actions : 'all'; logFilter.actions = actions.length ? actions : ALL;
saveLogFilter();
} }
function filterEventLogsByName(/*eventNames*/) { function filterEventLogsByName(/*eventNames*/) {
var eventNames = [].slice.call(arguments, 0); var eventNames = [].slice.call(arguments);
logFilter.actions.length || (logFilter.actions = 'all'); logFilter.actions.length || (logFilter.actions = ALL);
logFilter.eventNames = eventNames.length ? eventNames : 'all'; logFilter.eventNames = eventNames.length ? eventNames : ALL;
saveLogFilter();
} }
function hideAllEventLogs() { function hideAllEventLogs() {
logFilter.actions = []; logFilter.actions = [];
logFilter.eventNames = []; logFilter.eventNames = [];
saveLogFilter();
} }
function showAllEventLogs() { function showAllEventLogs() {
logFilter.actions = 'all'; logFilter.actions = ALL;
logFilter.eventNames = '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 { return {
...@@ -90,7 +122,7 @@ define( ...@@ -90,7 +122,7 @@ define(
if (enable && window.console) { if (enable && window.console) {
console.info('Booting in DEBUG mode'); 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; 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. * Available via the MIT or new BSD license.
* see: http://github.com/requirejs/text for details * see: http://github.com/requirejs/text for details
*/ */
/*jslint regexp: true */ /*jslint regexp: true */
/*global require: false, XMLHttpRequest: false, ActiveXObject: false, /*global require, XMLHttpRequest, ActiveXObject,
define: false, window: false, process: false, Packages: false, define, window, process, Packages,
java: false, location: false */ java, location, Components, FileUtils */
define(['module'], function (module) { define(['module'], function (module) {
'use strict'; 'use strict';
var text, fs, var text, fs, Cc, Ci, xpcIsWindows,
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'], progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im, xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im, bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
...@@ -19,11 +19,11 @@ define(['module'], function (module) { ...@@ -19,11 +19,11 @@ define(['module'], function (module) {
defaultProtocol = hasLocation && location.protocol && location.protocol.replace(/\:/, ''), defaultProtocol = hasLocation && location.protocol && location.protocol.replace(/\:/, ''),
defaultHostName = hasLocation && location.hostname, defaultHostName = hasLocation && location.hostname,
defaultPort = hasLocation && (location.port || undefined), defaultPort = hasLocation && (location.port || undefined),
buildMap = [], buildMap = {},
masterConfig = (module.config && module.config()) || {}; masterConfig = (module.config && module.config()) || {};
text = { text = {
version: '2.0.3', version: '2.0.10',
strip: function (content) { strip: function (content) {
//Strips <?xml ...?> declarations so that external SVG and XML //Strips <?xml ...?> declarations so that external SVG and XML
...@@ -83,16 +83,30 @@ define(['module'], function (module) { ...@@ -83,16 +83,30 @@ define(['module'], function (module) {
* where strip is a boolean. * where strip is a boolean.
*/ */
parseName: function (name) { parseName: function (name) {
var strip = false, index = name.indexOf("."), var modName, ext, temp,
modName = name.substring(0, index), 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); ext = name.substring(index + 1, name.length);
} else {
modName = name;
}
index = ext.indexOf("!"); temp = ext || modName;
index = temp.indexOf("!");
if (index !== -1) { if (index !== -1) {
//Pull off the strip arg. //Pull off the strip arg.
strip = ext.substring(index + 1, ext.length); strip = temp.substring(index + 1) === "strip";
strip = strip === "strip"; temp = temp.substring(0, index);
ext = ext.substring(0, index); if (ext) {
ext = temp;
} else {
modName = temp;
}
} }
return { return {
...@@ -156,11 +170,18 @@ define(['module'], function (module) { ...@@ -156,11 +170,18 @@ define(['module'], function (module) {
masterConfig.isBuild = config.isBuild; masterConfig.isBuild = config.isBuild;
var parsed = text.parseName(name), var parsed = text.parseName(name),
nonStripName = parsed.moduleName + '.' + parsed.ext, nonStripName = parsed.moduleName +
(parsed.ext ? '.' + parsed.ext : ''),
url = req.toUrl(nonStripName), url = req.toUrl(nonStripName),
useXhr = (masterConfig.useXhr) || useXhr = (masterConfig.useXhr) ||
text.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. //Load the text. Use XHR if possible and in a browser.
if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) { if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) {
text.get(url, function (content) { text.get(url, function (content) {
...@@ -194,11 +215,11 @@ define(['module'], function (module) { ...@@ -194,11 +215,11 @@ define(['module'], function (module) {
writeFile: function (pluginName, moduleName, req, write, config) { writeFile: function (pluginName, moduleName, req, write, config) {
var parsed = text.parseName(moduleName), 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 //Use a '.js' file name so that it indicates it is a
//script that can be loaded across domains. //script that can be loaded across domains.
fileName = req.toUrl(parsed.moduleName + '.' + fileName = req.toUrl(parsed.moduleName + extPart) + '.js';
parsed.ext) + '.js';
//Leverage own load() method to load plugin value, but only //Leverage own load() method to load plugin value, but only
//write out values that do not have the strip argument, //write out values that do not have the strip argument,
...@@ -222,24 +243,38 @@ define(['module'], function (module) { ...@@ -222,24 +243,38 @@ define(['module'], function (module) {
if (masterConfig.env === 'node' || (!masterConfig.env && if (masterConfig.env === 'node' || (!masterConfig.env &&
typeof process !== "undefined" && typeof process !== "undefined" &&
process.versions && process.versions &&
!!process.versions.node)) { !!process.versions.node &&
!process.versions['node-webkit'])) {
//Using special require.nodeRequire, something added by r.js. //Using special require.nodeRequire, something added by r.js.
fs = require.nodeRequire('fs'); fs = require.nodeRequire('fs');
text.get = function (url, callback) { text.get = function (url, callback, errback) {
try {
var file = fs.readFileSync(url, 'utf8'); var file = fs.readFileSync(url, 'utf8');
//Remove BOM (Byte Mark Order) from utf8 files if it is there. //Remove BOM (Byte Mark Order) from utf8 files if it is there.
if (file.indexOf('\uFEFF') === 0) { if (file.indexOf('\uFEFF') === 0) {
file = file.substring(1); file = file.substring(1);
} }
callback(file); callback(file);
} catch (e) {
errback(e);
}
}; };
} else if (masterConfig.env === 'xhr' || (!masterConfig.env && } else if (masterConfig.env === 'xhr' || (!masterConfig.env &&
text.createXhr())) { text.createXhr())) {
text.get = function (url, callback, errback) { text.get = function (url, callback, errback, headers) {
var xhr = text.createXhr(); var xhr = text.createXhr(), header;
xhr.open('GET', url, true); 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 //Allow overrides specified in config
if (masterConfig.onXhr) { if (masterConfig.onXhr) {
masterConfig.onXhr(xhr, url); masterConfig.onXhr(xhr, url);
...@@ -259,6 +294,10 @@ define(['module'], function (module) { ...@@ -259,6 +294,10 @@ define(['module'], function (module) {
} else { } else {
callback(xhr.responseText); callback(xhr.responseText);
} }
if (masterConfig.onXhrComplete) {
masterConfig.onXhrComplete(xhr, url);
}
} }
}; };
xhr.send(null); xhr.send(null);
...@@ -289,7 +328,9 @@ define(['module'], function (module) { ...@@ -289,7 +328,9 @@ define(['module'], function (module) {
line = line.substring(1); line = line.substring(1);
} }
if (line !== null) {
stringBuffer.append(line); stringBuffer.append(line);
}
while ((line = input.readLine()) !== null) { while ((line = input.readLine()) !== null) {
stringBuffer.append(lineSeparator); stringBuffer.append(lineSeparator);
...@@ -302,7 +343,44 @@ define(['module'], function (module) { ...@@ -302,7 +343,44 @@ define(['module'], function (module) {
} }
callback(content); 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; return text;
}); });
...@@ -25,6 +25,6 @@ ...@@ -25,6 +25,6 @@
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p> <p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer> </footer>
<script src="bower_components/todomvc-common/base.js"></script> <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> </body>
</html> </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