diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..d0f7923 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,42 @@ +These installation instructions are not meant for novices. Improvements are welcome. + +### Quick and Simple (Demo purposes) Installation + +If you're looking to demo Avocadojs, your best bet is to go to +avocadojs.com and demo it from there. +Unless you want the most up-to-date version of the code for some +reason, or you're playing with Avocadojs and you want to quickly demo +what you've done. In which case, throw the public directory somewhere +where a webserver can see its contents. For example, on Mac OS X, +start up your webserver, and then copy the "public" folder to the "Sites" directory. + +Remember, for the newer versions of OS X you'll have to start apache from the commandline, like so: + +>sudo apachectl start +>sudo apachectl stop +>sudo apachectl restart + +and you might have to do things like play with your user config file, ie: + +>sudo vim /etc/apache2/users/USERNAME.conf + +possibly writing something like this in there: + +> \ +> Options Indexes Multiviews +> Options FollowSymLinks +> AllowOverride AuthConfig Limit +> Order deny,allow +> Deny from all +> Allow from 127.0.0.1 +> \ + +### More complicated, development installation + +I run Apache with WebDav, and serve the public +directory through there. + +Don't do this alone, unless you're fairly confident you know what +you're doing. Enabling WebDav while Apache is running, without knowing +how to properly secure things, is probably a bad idea. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..7be22c1 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +A fork of [Adam](https://github.com/AdamSpitz)'s [Avocadojs](https://github.com/AdamSpitz/Avocado). + +Why? Because [forks are easier than direct contributions](http://www.youtube.com/watch?feature=player_detailpage&v=0SARbwvhupQ#t=1697s). + +This project doesn't (yet) have any documentation - contributions are welcome. + +See [here](http://avocadojs.com/ "avocadojs.com") for more project information. diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..2b4bab1 --- /dev/null +++ b/public/index.html @@ -0,0 +1,16 @@ + + + + + + + Page Redirection + + + + If you are not redirected automatically, follow the link to example + + \ No newline at end of file diff --git a/public/javascripts/bootstrap.js b/public/javascripts/bootstrap.js index 62a45df..40f7bbb 100644 --- a/public/javascripts/bootstrap.js +++ b/public/javascripts/bootstrap.js @@ -1215,10 +1215,7 @@ thisModule.addSlots(avocado.transporter, function(add) { var repoURL = baseURL + "javascripts/"; // aaa - hack because I want saving to keep working on my local machine - if (repoURL.indexOf("http://localhost") === 0) { avocado.kernelModuleSupportsWebDAV = true; } - - // aaa - hack because I haven't managed to get WebDAV working on the real server yet - if (repoURL.indexOf("coolfridgesoftware.com") >= 0) { window.kernelModuleSavingScriptURL = "http://coolfridgesoftware.com/cgi-bin/savefile.cgi"; } + if (repoURL.indexOf("http://localhost") === 0 || repoURL.indexOf("http://127.0.0.1") === 0) { avocado.kernelModuleSupportsWebDAV = true; } var kernelRepo; if (window.kernelModuleSavingScriptURL) { diff --git a/public/javascripts/bootstrap_lk.js b/public/javascripts/bootstrap_lk.js index db5d99d..5afdd7c 100644 --- a/public/javascripts/bootstrap_lk.js +++ b/public/javascripts/bootstrap_lk.js @@ -98,7 +98,6 @@ thisModule.addSlots(avocado.transporter.livelyKernelInitializer, function(add) { // Loading LK modules dynamically, in the same order that they are loaded in the xhtml file. avocado.transporter.loadExternal( ["prototype/prototype", - "lk/JSON", "lk/defaultconfig", "local-LK-config", "lk/Base", diff --git a/public/javascripts/core/collections/hash_table.js b/public/javascripts/core/collections/hash_table.js index 13456d0..6c9b134 100644 --- a/public/javascripts/core/collections/hash_table.js +++ b/public/javascripts/core/collections/hash_table.js @@ -167,14 +167,14 @@ thisModule.addSlots(avocado.hashTable, function(add) { }, {category: ['accessing']}); add.method('_each', function (iterator) { - for (var h in this._buckets) { - if (this._buckets.hasOwnProperty(h)) { - var b = this._buckets[h]; - if (b instanceof Array) { - for (var i = 0, n = b.length; i < n; ++i) { - var entry = b[i]; - iterator(entry); - } + var keys = Object.native_keys(this._buckets); + var length = keys.length; + for (var i = 0; i < length; i++) { + var b = this._buckets[keys[i]]; + if(b && b instanceof Array) { + for (var j = 0, n = b.length; j < n; ++j) { + var entry = b[j]; + iterator(entry); } } } diff --git a/public/javascripts/core/deep_copy.js b/public/javascripts/core/deep_copy.js index d4a31cb..9e77e01 100644 --- a/public/javascripts/core/deep_copy.js +++ b/public/javascripts/core/deep_copy.js @@ -42,20 +42,21 @@ thisModule.addSlots(avocado.deepCopier, function(add) { var isArray = isObj && (o instanceof Array); c = isObj ? (isArray ? [] : Object.create(o['__proto__'])) : eval("(" + o.toString() + ")"); var thisCopier = this; - for (var n in o) { - if (o.hasOwnProperty(n)) { - var contents = o[n]; - if (n === '__annotation__') { - c[n] = contents.copy(); + var keys = Object.native_keys(o); + var length = keys.length; + for (var j = 0; j < length; ++j){ + var n = keys[j]; + var contents = o[n]; + if (n === '__annotation__') { + c[n] = contents.copy(); + } else if (contents) { + var contentsType = typeof(contents); + var contentsCreatorSlot = (contentsType === 'object' || contentsType === 'function') && avocado.annotator.theCreatorSlotOf(contents); + if (contentsCreatorSlot && contentsCreatorSlot.name === n && contentsCreatorSlot.holder === o) { + c[n] = thisCopier.createCopyOf(contents); + avocado.annotator.annotationOf(c[n]).setCreatorSlot(n, c); } else { - var contentsType = typeof(contents); - var contentsCreatorSlot = (contentsType === 'object' || contentsType === 'function') && avocado.annotator.theCreatorSlotOf(contents); - if (contentsCreatorSlot && contentsCreatorSlot.name === n && contentsCreatorSlot.holder === o) { - c[n] = thisCopier.createCopyOf(contents); - avocado.annotator.annotationOf(c[n]).setCreatorSlot(n, c); - } else { - c[n] = contents; - } + c[n] = contents; } } } @@ -87,12 +88,15 @@ thisModule.addSlots(avocado.deepCopier, function(add) { var thisCopier = this; var originalsAndCopies = this._originalsAndCopies; var originalsAndCopiesCount = originalsAndCopies.length; - for (var n in c) { - if (c.hasOwnProperty(n)) { + var keys = Object.native_keys(c); + var length = keys.length; + for (var j = 0; j < length; ++j){ + var n = keys[j]; + var contents = c[n]; + if (contents) { if (n === '__annotation__') { // just ignore it, no refs to fix up, I think - oh, actually, could do the creator slot, but we've already done it up above - } else { - var contents = c[n]; + } else { var contentsType = typeof(contents); if (contentsType === 'object' || contentsType === 'function') { var wasInternalRef = false; diff --git a/public/javascripts/general_ui/wheel_menus.js b/public/javascripts/general_ui/wheel_menus.js index 212b028..3efd0ee 100644 --- a/public/javascripts/general_ui/wheel_menus.js +++ b/public/javascripts/general_ui/wheel_menus.js @@ -514,7 +514,7 @@ thisModule.addSlots(avocado.morphMixins.WorldMorph, function(add) { return commandMorph._cachedArgumentMorphLabels; }, {category: ['commands', 'feedback']}); - add.method('findArgumentMorphsAndShowLabels', function (argMorphLabels, partialCommand) { + add.method('findArgumentMorphsAndShowLabels', function (evt, argMorphLabels, partialCommand) { var context = partialCommand.command().contextOrDefault(); argMorphLabels.each(function(m, i) { var argHolder = partialCommand.argumentHolders()[i]; @@ -531,7 +531,7 @@ thisModule.addSlots(avocado.morphMixins.WorldMorph, function(add) { add.method('showWhatWillHappenIfThisCommandRuns', function (evt, commandMorph) { var pc = commandMorph._model.createPartialCommand(); - this.findArgumentMorphsAndShowLabels(this.argumentMorphLabelsFor(commandMorph), pc); + this.findArgumentMorphsAndShowLabels(evt, this.argumentMorphLabelsFor(commandMorph), pc); var world = avocado.ui.worldFor(evt); world.removeAllPartialCommandMorphs(); world.showPartialCommandMorph(world.morphFor(pc).setFillOpacity(0.5)); diff --git a/public/javascripts/lk/Base.js b/public/javascripts/lk/Base.js index 5964d25..d2c0199 100644 --- a/public/javascripts/lk/Base.js +++ b/public/javascripts/lk/Base.js @@ -47,7 +47,8 @@ Object.defineProperties = function(object, descriptorSet) { } return object; } - + +Object.native_keys = Object.keys; Object.defineProperties(Object, { // I like mine better. -- Adam /* @@ -62,12 +63,15 @@ Object.defineProperties(Object, { */ keys: { - value: function(object, optFast) { - if (typeof object !== 'object') throw new TypeError('not an object'); - var names = []; // check behavior wrt arrays - for (var name in object) { - if (object.hasOwnProperty(name)) - names.push(name); + value: function(object, optFast) { + if (typeof object !== 'object' && typeof object !== 'function') throw new TypeError('not an object'); + var names = []; // check behavior wrt arrays + var keys = Object.native_keys(object); + var length = keys.length; + for (var i = 0; i < length; ++i) { + var name = keys[i]; + if (object[name]) + names.push(name); } if (!optFast) names.sort(); return names; diff --git a/public/javascripts/lk/JSON.js b/public/javascripts/lk/JSON.js deleted file mode 100644 index 08dab4b..0000000 --- a/public/javascripts/lk/JSON.js +++ /dev/null @@ -1,310 +0,0 @@ -/* - JSON.js - 2007-10-02 - - Based on Doug Crockford's Public Domain - json.js - 2007-09-27 - -............................................................................... - -This file adds these methods to JavaScript: - - JSON.serialize(value, optFilter) - - JSON.serialize(value) does much the same job that - value.toJSONString() is supposed to do in the original - json.js library on normal JSON objects. However, they - provide different hooks for having their behavior extended. - - For json.js, other objects can provide their own - implementation of toJSONString(), in which case JSON - serialization relies on these objects to return a correct - JSON string. But if one object instead returns an - unbalanced part of a JSON string and another object - returns a compensating unbalanced string, then an outer - toJSONString() can produce quoting confusions that invite - XSS-like attacks. The primary purpose of JSON.js is - to prevent such attacks. - - The design of JSON.js borrows ideas from Java's object - serialization streams. - - JSON.unserialize(string, optFilter) - - JSON.unserialize(string, optFilter) acts like json.js's - string.parseJSON(optFilter). This version also fixes a bug - in the original: json.js specifies "If [the optional filter] - returns undefined then the member is deleted." However, - the implemenation in json.js instead defines the property to - have the value undefined. JSON.unserialize() does indeed - delete the property in this case. - - Bug: If the JSON expression to be unserialized contains - the key "__proto__", this will be silently ignored on - Firefox independent of the behavior of optFilter. json.js - exhibits the same bug on Firefox. Whether this is a bug in - these JSON libraries, in the Javascript spec, or in the - Firefox implementation of Javascript is open to debate. In - any case, this problem is unlikely to be fixed. - - JSON.defaultFilter(baseObj, key) - - A filter is a function that takes a baseObj and a key for - indexing into that baseObj -- the name of one of its - properties. A filter can: - * return baseObj[key], in which case serialization - or unserialization proceeds normally. - * return undefined, suppressing the apparent existence - of this property on this baseObj. - * return something else, in which case it will be used - instead of baseObj[key]. - * throw, terminating serialization or unserialization. - - If a filter is provided to serialize(), it is applied in - top-down order, so traversal proceeds only into the - results of filtering. If a filter is provided to - unserialize(), it is applied in bottom-up order, so that - reconstructed parts are available for building - reconstructed wholes. - - If no optFilter argument is provided to serialize(), - this defaultFilter is used. It is part of the API so that - other filters can be built by composing with it. - This default filter will return undefined unless key is a - string and an own-property of baseObj, or if key is a - number and baseObj is an array. If baseObj[key] - implements toJSON(), the default filter will return - baseObj[key].toJSON(), enabling individual objects (such - as dates) to offer replacements for themselves. Otherwise, - it returns baseObj[key]. - - If no optFilter argument is provided to unserialize(), - then the result is just the literal tree of JSON objects. - - Date.toJSON() - - Returns an ISO string encoding the date. When serializing - with the default filter, this brings about the same effect - as json.js's Date.toJSONString(). - -Use your own copy. It is extremely unwise to load untrusted third -party code into your pages. -*/ - - -/** - * Like the date.toJSONString() method defined in json.js, except - * without the surrounding quotes. This should be identical to - * Date.prototype.toISOString when that is defined, as it is in caja.js - */ -Date.prototype.toJSON = function () { - function f(n) { - return n < 10 ? '0' + n : n; - } - return (this.getUTCFullYear() + '-' + - f(this.getUTCMonth() + 1) + '-' + - f(this.getUTCDate()) + 'T' + - f(this.getUTCHours()) + ':' + - f(this.getUTCMinutes()) + ':' + - f(this.getUTCSeconds()) + 'Z'); -}; - - -CustomJSON = (function () { - - function defaultFilter(baseObj, key) { - var result; - - if (typeof key === 'string') { - if (!Object.prototype.hasOwnProperty.call(baseObj, key)) { - return undefined; - } - } else if (typeof key === 'number') { - if (!(baseObj instanceof Array)) { - return undefined; - } - } else { - return undefined; - } - result = baseObj[key]; - if (result && typeof result.toJSON === 'function') { - return result.toJSON(); - } else { - return result; - } - } - - /** m is a table of character substitutions. */ - var m = { - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '"' : '\\"', - '\\': '\\\\' - }; - - return { - defaultFilter: defaultFilter, - - serialize: function(value, optFilter) { - var out = []; // array holding partial texts - // var stack = []; // for diagnosing cycles - var filter = optFilter || defaultFilter; - - /** - * The internal recursive serialization function. - */ - function serialize(value) { - var i,j; // loop counters - var len; // array lengths; - var needComma = false; - var k,v; // property key and value - - // stack.push(value); - - switch (typeof value) { - case 'object': - if (value === null) { - out.push('null'); - - } else if (value instanceof Array) { - len = value.length; - out.push('['); - for (i = 0; i < len; i += 1) { - v = filter(value, i); - if (v !== undefined) { - if (needComma) { - out.push(','); - } else { - needComma = true; - } - serialize(v); - } - } - out.push(']'); - - } else { - out.push('{'); - for (k in value) { - v = filter(value, k); - if (v !== undefined) { - if (needComma) { - out.push(','); - } else { - needComma = true; - } - serialize(k); - out.push(':'); - serialize(v); - } - } - out.push('}'); - } - break; - - case 'string': - // If the string contains no control characters, no quote - // characters, and no backslash characters, then we can - // simply slap some quotes around it. Otherwise we must - // also replace the offending characters with safe - // sequences. - if ((/["\\\x00-\x1f]/).test(value)) { //"])){ - out.push('"' + - value.replace((/[\x00-\x1f\\"]/g), //"]), - function (a) { - var c = m[a]; - if (c) { - return c; - } - c = a.charCodeAt(); - return '\\u00' + Math.floor(c / 16).toString(16) + - (c % 16).toString(16); - }) + '"'); - } else { - out.push('"' + value + '"'); - } - break; - - case 'number': - // JSON numbers must be finite. Encode non-finite numbers - // as null. - out.push(isFinite(value) ? String(value) : 'null'); - break; - - case 'boolean': - out.push(String(value)); - break; - - default: - out.push('null'); - } - // stack.pop(); - } - - var fakeRoot = [value]; - serialize(filter(fakeRoot, 0)); - return out.join(''); - }, - - unserialize: function(str, optFilter) { - - var result; - - function walk(value) { - var i,len,k,v; - - if (value && typeof value === 'object') { - if (value instanceof Array) { - len = value.length; - for (i = 0; i < len; i += 1) { - walk(value[i]); - v = optFilter(value, i); - if (v === undefined) { - delete value[i]; - } else { - value[i] = v; - } - } - } else { - for (k in value) { - walk(value[k]); - v = optFilter(value, k); - if (v === undefined) { - delete value[k]; - } else { - value[k] = v; - } - } - } - } - - } - - if ((/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/). - test(str. - replace((/\\./g), '@'). - replace((/"[^"\\\n\r]*"/g), ''))) { //"))) { - result = eval('(' + str + ')'); - if (optFilter) { - var fakeRoot = [result]; - walk(fakeRoot); - return fakeRoot[0]; - } else { - return result; - } - } - throw new SyntaxError('parseJSON'); - } - }; -})(); - -// reuse existing JSON implementation -if (window.JSON) { // "window" added by Adam - seems to break otherwise - for (var name in CustomJSON) - JSON[name] = CustomJSON[name]; -} else { - JSON = CustomJSON -} diff --git a/public/javascripts/prototype/prototype.js b/public/javascripts/prototype/prototype.js index 252dc91..8236fe0 100644 --- a/public/javascripts/prototype/prototype.js +++ b/public/javascripts/prototype/prototype.js @@ -170,31 +170,6 @@ var Class = (function() { } } - function toJSON(object) { - var type = typeof object; - switch (type) { - case 'undefined': - case 'function': - case 'unknown': return; - case 'boolean': return object.toString(); - } - - if (object === null) return 'null'; - if (object.toJSON) return object.toJSON(); - if (isElement(object)) return; - - var results = []; - for (var property in object) { - if (property !== '__annotation__') { // added by Adam to prevent infinite recursion - var value = toJSON(object[property]); - if (!isUndefined(value)) - results.push(property.toJSON() + ': ' + value); - } - } - - return '{' + results.join(', ') + '}'; - } - function toQueryString(object) { return $H(object).toQueryString(); } @@ -253,7 +228,6 @@ var Class = (function() { extend(Object, { extend: extend, inspect: inspect, - toJSON: toJSON, toQueryString: toQueryString, toHTML: toHTML, keys: keys, @@ -358,16 +332,6 @@ Object.extend(Function.prototype, (function() { })()); -Date.prototype.toJSON = function() { - return '"' + this.getUTCFullYear() + '-' + - (this.getUTCMonth() + 1).toPaddedString(2) + '-' + - this.getUTCDate().toPaddedString(2) + 'T' + - this.getUTCHours().toPaddedString(2) + ':' + - this.getUTCMinutes().toPaddedString(2) + ':' + - this.getUTCSeconds().toPaddedString(2) + 'Z"'; -}; - - RegExp.prototype.match = RegExp.prototype.test; RegExp.escape = function(str) { @@ -584,10 +548,6 @@ Object.extend(String.prototype, (function() { return "'" + escapedString.replace(/'/g, '\\\'') + "'"; } - function toJSON() { - return this.inspect(true); - } - function unfilterJSON(filter) { return this.replace(filter || Prototype.JSONFilter, '$1'); } @@ -654,7 +614,6 @@ Object.extend(String.prototype, (function() { underscore: underscore, dasherize: dasherize, inspect: inspect, - toJSON: toJSON, unfilterJSON: unfilterJSON, isJSON: isJSON, evalJSON: evalJSON, @@ -1043,15 +1002,6 @@ Array.from = $A; return '[' + this.map(Object.inspect).join(', ') + ']'; } - function toJSON() { - var results = []; - this.each(function(object) { - var value = Object.toJSON(object); - if (!Object.isUndefined(value)) results.push(value); - }); - return '[' + results.join(', ') + ']'; - } - function indexOf(item, i) { i || (i = 0); var length = this.length; @@ -1100,8 +1050,7 @@ Array.from = $A; clone: clone, toArray: clone, size: size, - inspect: inspect, - toJSON: toJSON + inspect: inspect }); var CONCAT_ARGUMENTS_BUGGY = (function() { @@ -1199,10 +1148,6 @@ var Hash = Class.create(Enumerable, (function() { }).join(', ') + '}>'; } - function toJSON() { - return Object.toJSON(this.toObject()); - } - function clone() { return new Hash(this); } @@ -1222,7 +1167,6 @@ var Hash = Class.create(Enumerable, (function() { update: update, toQueryString: toQueryString, inspect: inspect, - toJSON: toJSON, clone: clone }; })()); @@ -1247,10 +1191,6 @@ Object.extend(Number.prototype, (function() { return '0'.times(length - string.length) + string; } - function toJSON() { - return isFinite(this) ? this.toString() : 'null'; - } - function abs() { return Math.abs(this); } @@ -1272,7 +1212,6 @@ Object.extend(Number.prototype, (function() { succ: succ, times: times, toPaddedString: toPaddedString, - toJSON: toJSON, abs: abs, round: round, ceil: ceil, diff --git a/test b/test new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/test @@ -0,0 +1 @@ +test \ No newline at end of file