A lot of projects ported from the old metanohi site.

This commit is contained in:
Niels Serup
2011-08-02 23:08:13 +02:00
parent d1b8234f78
commit a63b3ad10d
261 changed files with 12435 additions and 28 deletions

View File

@@ -0,0 +1,21 @@
#+title: wontofor
#&summary
A small JavaScript library
#&
#+license: bysa, page
#+license: gpl 3+, program
* wontofor
Wontofor is a JavaScript shortcut system. It allows for easier use of JS and is
not at all finished. It's a bit like jQuery.
It's very easy to create a module in wontofor. Two examples: [[parts/ajax.js][ajax.js]] and
[[parts/html.js][html.js]].
I've put a test up [[test1.html][here]].
The main JS file can be found [[wontofor.js][here]].
Wontofor is licensed under the [[http://www.gnu.org/licenses/gpl.html][GNU General Public License]], version 3 or any
later version.

View File

@@ -0,0 +1,13 @@
CHAPTER I. Down the Rabbit-Hole
Alice was beginning to get very tired of sitting by her sister on the
bank, and of having nothing to do: once or twice she had peeped into the
book her sister was reading, but it had no pictures or conversations in
it, 'and what is the use of a book,' thought Alice 'without pictures or
conversation?'
So she was considering in her own mind (as well as she could, for the
hot day made her feel very sleepy and stupid), whether the pleasure
of making a daisy-chain would be worth the trouble of getting up and
picking the daisies, when suddenly a White Rabbit with pink eyes ran
close by her.

View File

@@ -0,0 +1,23 @@
ADVENTURE I. A SCANDAL IN BOHEMIA
I.
To Sherlock Holmes she is always THE woman. I have seldom heard
him mention her under any other name. In his eyes she eclipses
and predominates the whole of her sex. It was not that he felt
any emotion akin to love for Irene Adler. All emotions, and that
one particularly, were abhorrent to his cold, precise but
admirably balanced mind. He was, I take it, the most perfect
reasoning and observing machine that the world has seen, but as a
lover he would have placed himself in a false position. He never
spoke of the softer passions, save with a gibe and a sneer. They
were admirable things for the observer--excellent for drawing the
veil from men's motives and actions. But for the trained reasoner
to admit such intrusions into his own delicate and finely
adjusted temperament was to introduce a distracting factor which
might throw a doubt upon all his mental results. Grit in a
sensitive instrument, or a crack in one of his own high-power
lenses, would not be more disturbing than a strong emotion in a
nature such as his. And yet there was but one woman to him, and
that woman was the late Irene Adler, of dubious and questionable
memory.

View File

@@ -0,0 +1,35 @@
/* wontofor: A JavaScript shortcut system
* Copyright (C) 2010 Niels Serup
*
* This file is part of wontofor.
*
* wontofor 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.
*
* wontofor 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 wontofor. If not, see <http://www.gnu.org/licenses/>.
*
* Maintained by Niels Serup <ns@metanohi.org>
* See <http://metanohi.org/projects/wontofor/>
*/
wontofor.ajax.getWeb = function(url, func, args, method) {
var req = new XMLHttpRequest()
req.open(method, url, true)
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200)
func(req.responseText, true)
else
func(req.status, false)
}
}
req.send(null)
}.base('.', alert, [], 'GET')

View File

@@ -0,0 +1,48 @@
/* wontofor: A JavaScript shortcut system
* Copyright (C) 2010 Niels Serup
*
* This file is part of wontofor.
*
* wontofor 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.
*
* wontofor 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 wontofor. If not, see <http://www.gnu.org/licenses/>.
*
* Maintained by Niels Serup <ns@metanohi.org>
* See <http://metanohi.org/projects/wontofor/>
*/
wontofor.html.body = document.body
HTMLElement.prototype.set_opacity = function(val) {
this.style.opacity = val
this.style.filter = 'alpha(opacity=' + val*100 + ')'
}
HTMLElement.prototype.remove = function() {
this.parentNode.removeChild(this)
}
HTMLElement.prototype.setText = function(text) {
this.innerHTML = text
}
HTMLElement.prototype.append = function(elem) {
this.appendChild(elem)
}
wontofor.html.create = function(tag) {
return document.createElement(tag)
}
wontofor.html.setTitle = function(title) {
document.title = title
}

View File

@@ -0,0 +1,30 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3c.org/1999/xhtml">
<head>
<title>wontofor test 1</title>
<style type='text/css'>
</style>
<script type='text/javascript' src='wontofor.js'></script>
<script type='text/javascript'>
function go_on() {
w.html.setTitle('Testing...')
w.ajax.getWeb('material/alice.txt', function(txt) {
par = w.html.create('p')
par.setText(txt)
w.html.body.append(par)
})
}
window.onload = function() {
w = wontofor
w.setInclusionPath('parts')
w.include('ajax', 'html', go_on)
}
</script>
</head>
<body>
</body>
</html>

View File

@@ -0,0 +1,152 @@
/* wontofor: A JavaScript shortcut system
* Copyright (C) 2010 Niels Serup
*
* This file is part of wontofor.
*
* wontofor 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.
*
* wontofor 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 wontofor. If not, see <http://www.gnu.org/licenses/>.
*
* Maintained by Niels Serup <ns@metanohi.org>
* See <http://metanohi.org/projects/wontofor/>
*/
wontofor = function() {
this.headElement = document.getElementsByTagName('head')[0]
this.inclusions = []
this.inclusionPath = ''
this.inclusionsInProgress = []
this.temp = {}
}
wontofor.prototype.dump = function(text) {
alert(text)
}
wontofor.prototype.setInclusionPath = function(path) {
if (path.length > 0 && path.substr(path.length-1) != '/')
path += '/'
this.inclusionPath = path
}
wontofor.prototype.include = function() {
if (arguments.length < 1) return
var func = arguments[arguments.length-1]
this.clearCompletedInclusions()
var i
this.inclusionsInProgress.push([0, -1, null])
var include_id = this.inclusionsInProgress.length-1
var num = 0
var to_be_included = []
for (i = 0; i < arguments.length-1; i++) {
if (this.inclusions.has(name)) continue
to_be_included.push(i)
num++
}
if (num == 0)
return
this.inclusionsInProgress[include_id] = [num, 0, func]
for (i = 0; i < num; i++) {
this.includeOne(arguments[to_be_included[i]], include_id)
}
}
wontofor.prototype.includeOne = function(name, id) {
this.temp[name] = function() {}
this[name] = this.temp[name].prototype
this[name].root = this
this[name].name = name
var _this = this
var elem = document.createElement('script')
elem.type = 'text/javascript'
elem.onload = function (event) {
_this.endInclusion(name, id)
}
elem.onreadystatechange = function (event) {
if (js.readyState == 'complete')
_this.endInclusion(name, id)
}
elem.src = this.inclusionPath + name + '.js'
this.headElement.appendChild(elem)
}
wontofor.prototype.endInclusion = function(name, id) {
if (this.inclusions.has(name)) return
this[name] = new this.temp[name]()
delete this.temp[name]
this.inclusions.push(name)
if (this.inclusionsInProgress[id][0] == this.inclusionsInProgress[id][1]+1)
this.inclusionsInProgress[id][2]()
this.inclusionsInProgress[id][1]++
}
wontofor.prototype.clearCompletedInclusions = function() {
var i
var last_unfinished = -1
for (i = 0; i < this.inclusionsInProgress.length; i++) {
if (this.inclusionsInProgress[i][0] != this.inclusionsInProgress[i][1])
last_unfinished = i
}
for (i = last_unfinished+1; i < this.inclusionsInProgress.length; i++) {
this.inclusionsInProgress.pop()
}
}
Function.prototype.base = function() {
var _this = this
var _arguments = arguments
var _arguments_length = _arguments.length
return function() {
var mixed_args = []
var i = 0
var arg
while (i < arguments.length) {
arg = arguments[i]
if (arg != null)
mixed_args.push(arg)
else if (_arguments_length > i)
mixed_args.push(_arguments[i])
else
mixed_args.push(null)
i++
}
while (i < _arguments.length) {
mixed_args.push(_arguments[i])
i++
}
return _this.apply(this, mixed_args)
}
}
Array.prototype.has = function(obj) {
for (var i = 0; i < this.length; i++) {
if (this[i] == obj)
return true
}
return false
}
wontofor = new wontofor()