Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
205 lines (172 sloc) 5.5 KB
////////////////////////////////////////////////////////////////////////////////////////////////////
// Phos
//
// Copyright (C) 2009,2010,2011,2012 David J. Goehrig
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////////////////////////
global = window
document.goto = function(x) { document.location.href = x }
var _doc = document
var _root = window
var _body = null
window.onload = function() {
_body = document.querySelector('body');
'/object/'.use(navigator.userAgent.match(/AppleWebKit\/534/) ? 'Safari' :
navigator.userAgent.match(/Safari/) ? 'Safari' :
navigator.userAgent.match(/Chrome/) ? 'Chrome' :
navigator.userAgent.match(/Firefox/) ? 'Firefox' :
'Opera')
Display.init()
}
var here; // the last mouse position
var that; // the last thing selected
var these; // the targets of a selection
var editing; // the block we're editing
var clipboard; // the last object we cut or copied
var A;
var An = A = {
object: function() { return a({}) },
string: function() { return '' },
array: function() { return [] },
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// Event Functions
_doc.onkeypress = function() { return false }; // Hack to break backspace
_doc.oncontextmenu = function(e) { return false }; // Hack to remove popup menu
_root.onresize = function() { _doc.location.href = _doc.location.href };
function nop() {}
Object.prototype.a = Object.prototype.an = function(I,V) {
return I.can('init') ?
I.init(V):
I.clone()
}
Object.prototype.the = function(I) { return I }
Object.prototype.has = function(K,X) {
this[K] = function() { return X }
this[K].dynamic = false
return this
}
Object.prototype.does = function(V,F) {
F.dynamic = true
F.params = F.parameters()
this[V] = F
return this
}
Object.prototype.clone = function() {
var Proto = function() {}
Proto.prototype = this
return new Proto()
}
Object.prototype.copy = function(O) {
var I = this
O.each(function(V,K) { I[K] = V })
return this
}
Object.prototype.from = function() {
this['init'] = function() { return this }
for (var J = 0; J < arguments.length; ++J)
this.copy(arguments[J])
return this
}
Object.prototype.each = function(F) {
for (var K in this) if (this.hasOwnProperty(K) && K != 'prototype') F(this[K],K)
return this
}
Object.prototype.all = function(F) {
for (var K in this) if (K != 'prototype') F(this[K],K)
return this
}
Object.prototype.which = function(F) {
var W = []
this.each(function(V,K) { if (F(V,K)) W.push(V) })
return W
}
Object.prototype.can = function(K) {
return (typeof(this[K]) == "function")
}
Object.prototype.slots = function() {
var J = 0
this.each(function(V,K) { if (K && V) ++J })
return J
}
Object.prototype.slot = function(P,K,X,Y) {
return [ a(Block).says(this).at(X,Y).by(200,20).has('parent',c).has('valueOf', K.deparameterized()) ];
}
Object.prototype.names = function() {
var R = []
var I = this
window.each(function(V,K) { if (V === I) R.push(K) })
return R
}
Object.prototype.name = function() {
if (this.names()[0]) return this.names()[0]
var Kind = this.__proto__.name()
return (['A','E','I','O','U','Y'].contains(Kind.charAt(0)) ? 'an '.append(Kind) : 'a '.append(Kind))
}
Object.prototype.plural = function(I) { return window[I] = this }
Object.prototype.named = function(N) {
var I = this
An[N.name().toLowerCase()]= function(Y) { return a(I,Y) }
return window[N.name()] = this
}
Object.prototype.is = function(O) {
var I = this
var R = true
O.all(function(V,K) {
if (O.can(K) && !I.can(K)) return R = false
})
return R
}
Object.prototype.implements = function() {
var I = this
var R = []
Objects.each(function(O,K) { if (I.is(O)) R.push(K) })
return R
}
Object.prototype.any = function(F) {
var R = null
this.each(function(O,K) { if (F(O,K)) return R = O })
return R
}
Object.prototype.module = function() {
var Ots = Object.prototype.toString
Object.prototype.toString = function() {
var R = '{ '
this.each(function(V,K) {
if (typeof(V) == 'function') R = R.append(K,': ',V,', ')
if (typeof(V) == 'string') R = R.append(K,': "', V, '", ')
if (typeof(V) == 'number') R = R.append(K,': ', V, ', ')
if (typeof(V) == 'boolean') R = R.append(K,': ', V, ', ')
if (typeof(V) == 'object') R = R.append(K, ': ', V.name(), ', ')
})
return R.append('}') }
var R = 'function() { return '.append( this.toString(), ' }')
Object.prototype.toString = Ots
return R
}
Object.prototype.download = function() {
document.goto("data:application/json,".append(this.toString().encode()))
return this
}
Object.prototype.when = HTMLElement.prototype.when = function(E,F) {
this.addEventListener(E,F,false)
return this
}
Object.prototype.value = function() { return this }
Object.prototype.parameters = function() {
var m = /function (\([^)]*\))/.exec(this.toString());
return m ? m[1] : "";
}