1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-12-01 14:28:07 +00:00

Revised test data

Testing against the output of cook.rb isn't satisfactory because of the
bugs in it; instead we're now going to test against the tiddlywiki.com
build products
This commit is contained in:
Jeremy Ruston
2011-12-03 11:41:25 +00:00
parent db2fafb0ab
commit 07df513140
531 changed files with 34826 additions and 4951 deletions

View File

@@ -0,0 +1,43 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery.encoding.digests.sha1</title>
<link rel="stylesheet" type="text/css" href="styles/main.css">
</head>
<body>
<h1>jQuery.encoding.digests.sha1</h1>
<p>
This <a href="http://jquery.com">jQuery</a> plugin implements the SHA-1 cryptographic hash function.
</p>
<h2>Source</h2>
<p>
The source code is currently hosted in TiddlyWiki's
<a href="http://svn.tiddlywiki.org/Trunk/core/jquery/plugins/jQuery.encoding.digests.sha1.js">Subversion repository</a>.
</p>
<p>
<a href="http://groups.google.com/group/TiddlyWikiDev/">Feedback</a> is welcome.
</p>
<h2>API</h2>
<ul>
<li>
<p><code>$.encoding.digests.hexSha1Str(str)</code>: Return, in hex, the SHA-1 hash of a string</p>
</li>
<li>
<p><code>$.encoding.digests.sha1Str(str)</code>: Return the SHA-1 hash of a string</p>
</li>
<li>
<p><code>$.encoding.digests.sha1(x,blen)</code>: Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words</p>
</li>
</ul>
<p>(full documentation in the code comments)</p>
<h2>Demo</h2>
[TBD]
</body>
</html>

View File

@@ -0,0 +1,31 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TiddlyWiki jQuery plugins</title>
<link rel="stylesheet" type="text/css" href="styles/main.css">
</head>
<body>
<h1>TiddlyWiki jQuery plugins</h1>
<p>
With <a href="http://jquery.com">jQuery</a> being integrated into the
<a href="http://tiddlywiki.com">TiddlyWiki</a> core, the community has
begun extracting TiddlyWiki functionality into generic components in
the form of jQuery plugins:
</p>
<ul>
<li>
<a href="twFile.html">jQuery.twFile</a>
</li>
<li>
<a href="twStylesheet.html">jQuery.twStylesheet</a>
</li>
<li>
<a href="encoding.digests.sha1.html">jQuery.encoding.digests.sha1.html</a>
</li>
</ul>
</body>
</html>

View File

@@ -0,0 +1,78 @@
* {
margin: 0;
padding: 0;
}
html {
background-color: #000;
}
body {
width: 50%;
margin: 0 auto;
padding: 10px;
background-color: #FFF;
}
h1,
h2 {
margin-bottom: 10px;
}
h2 {
margin-top: 20px;
}
p,
ul {
margin-bottom: 0.5em;
}
ul {
margin-left: 1em;
}
ul ul {
margin-bottom: 0;
}
li p {
margin-bottom: 0.2em;
}
code {
color: #0A0;
}
fieldset,
legend {
border: 1px solid #AAA;
}
fieldset {
margin: 30px 10px 10px;
padding: 10px 5px 5px 10px;
}
legend,
.editor {
background-color: #EEE;
}
legend {
margin-top: -1em;
border-bottom: none;
padding: 1px 3px 0;
line-height: 1em;
}
fieldset textarea {
display: block;
width: 98%;
}
fieldset input {
width: 5em;
margin: 10px 10px 5px 0;
font-size: 1.1em;
}

View File

@@ -0,0 +1,124 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery.twFile</title>
<link rel="stylesheet" type="text/css" href="styles/main.css">
</head>
<body>
<h1>jQuery.twFile</h1>
<p>
This <a href="http://jquery.com">jQuery</a> plugin provides access to
the local file system (for documents loaded from a <code>file://</code>
URI) to load and save file contents from the browser.
</p>
<p>
The code is based on <a href="http://tiddlywiki.com">TiddlyWiki</a>'s
self-saving capabilities.
</p>
<p id="TiddlySaver">
Note that the <a href="http://www.tiddlywiki.com/TiddlySaver.jar">TiddlySaver</a>
applet is required on Opera and WebKit-based browsers (Safari, Chrome).
The applet has to be present in the same folder as the respective HTML document.
</p>
<h2>Source</h2>
<p>
The source code is currently hosted in TiddlyWiki's
<a href="http://svn.tiddlywiki.org/Trunk/core/jquery/plugins/jQuery.twFile.js">Subversion repository</a>.
</p>
<p>
<a href="http://groups.google.com/group/TiddlyWikiDev/">Feedback</a> is welcome.
</p>
<h2>API Summary</h2>
<ul>
<li>
<p><code>$.twFile.load(filePath)</code>: load contents from file</p>
</li>
<li>
<p><code>$.twFile.save(filePath, content)</code>: save contents to file</p>
</li>
<li>
<p><code>$.twFile.copy(dest, source)</code>: duplicate existing file</p>
<p><strong>N.B.:</strong> This is not supported on all browsers.</p>
</li>
<li>
<p>
<code>$.twFile.convertUriToLocalPath(filePath)</code>:
normalizes specified absolute file path
</p>
</li>
</ul>
<p>
<strong>N.B.:</strong> All file paths must be absolute (e.g.
<code>/tmp/foo.txt</code> or <code>C:\temp\foo.txt</code>).
</p>
<p>(full documentation in the code comments)</p>
<h2>Limitations</h2>
<ul>
<li>
plugin unavailable until
<a href="http://docs.jquery.com/Events/ready">document.ready</a>
handlers have completed
<p>
Since the TiddlySaver applet cannot be injected synchronously
into the document, this is done asynchronously during
<code>document.ready</code> processing.
</p>
<p>
This means that the plugin is not guaranteed to work properly
until after all these handlers have completed.
</p>
</li>
<li>
currently unreliable UTF-8 support on Internet Explorer
<p>
The plugin is designed to work with UTF-8 encoded text files.
However, support in Internet Explorer is broken, and can only
reliably save files that are encoded with the ANSI subset of
UTF-8. In the case of HTML files, this problem can often be
avoided by using HTML entity encodings.
</p>
</li>
</ul>
<h2>Internals</h2>
<p>
Internally, the plugin uses four separate drivers to implement the functionality on different browsers:
<ul>
<li>
<code>activeX</code>: uses the <code>FileSystemObject</code> built into Internet Explorer 5 and above
</li>
<li>
<code>mozilla</code>: uses the XUL libraries built into Firefox
</li>
<li>
<code>tiddlySaver</code>: uses a custom Java applet that works on Safari, Chrome and Opera
</li>
<li>
<code>javaLiveConnect</code>: uses an ancient (and slow) binding technology to call Java runtime library routines directly - only works on Opera
</li>
</ul>
</p>
<h2>Demo</h2>
<p>
Download <a href="twFileDemo.html">this document</a> (and
<a href="#TiddlySaver">TiddlySaver</a> if necessary) and open it from
the local disk.
</p>
<p>
This demo illustrates self-saving capabilities by passing
<code>document.location.href</code> to <code>$.twFile.convertUriToLocalPath</code>,
using the return value in load and save functions.
</p>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,94 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery.twStylesheet</title>
<link rel="stylesheet" type="text/css" href="styles/main.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script src="http://svn.tiddlywiki.org/Trunk/core/jquery/plugins/jQuery.twStylesheet.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
var applyCSS = function() {
var css = $("#css_code").val();
$.twStylesheet(css);
};
var resetCSS = function() {
$.twStylesheet.remove();
};
$("#css_apply").click(applyCSS);
$("#css_reset").click(resetCSS);
// initialize
$("#css_code").val(
"html { background-color: #EEE; }\n" +
"body { color: #FFF; background-color: #000; }\n" +
"h1, h2 { font-variant: small-caps; }\n" +
"ul { list-style-type: square; }\n" +
"code { padding: 1px 2px; background-color: #EEE; }\n" +
"#css_editor, #css_editor legend { background-color: #888; }\n"
);
});
</script>
</head>
<body>
<h1>jQuery.twStylesheet</h1>
<p>
This <a href="http://jquery.com">jQuery</a> plugin allows the application
of CSS rule sets to the document.
</p>
<p>
In contrast to jQuery's <a href="http://docs.jquery.com/CSS">CSS methods</a>,
it applies styles to the document rather than to individual elements (just
like defining a static style sheet in the document head).
</p>
<p>
The code is based on <a href="http://tiddlywiki.com">TiddlyWiki</a>'s dynamic
style-sheet capabilities, where it is used to allow users to customize their
documents on the fly.
</p>
<h2>Source</h2>
<p>
The source code is currently hosted in TiddlyWiki's
<a href="http://svn.tiddlywiki.org/Trunk/core/jquery/plugins/jQuery.twStylesheet.js">Subversion repository</a>.
</p>
<p>
<a href="http://groups.google.com/group/TiddlyWikiDev/">Feedback</a> is welcome.
</p>
<h2>API Summary</h2>
<ul>
<li>
<p><code>$.twStylesheet(css[, options])</code>: adds or replaces a style sheet</p>
<p>
<code>css</code> is a string containing the CSS rule sets, while
<code>options.id</code> is an optional name identifying the style sheet, allowing
co-existence of multiple style sheets
</p>
</li>
<li>
<p>
<code>$.twStylesheet.remove([options])</code>: delete an existing style sheet
</p>
<p>
The <code>options</code> argument is identical to <code>$.twStylesheet</code>'s.
</p>
</li>
</ul>
<p>(full documentation in the code comments)</p>
<h2>Demo</h2>
This will apply the CSS rule sets below to the entire document.
<fieldset id="css_editor" class="editor">
<legend>CSS</legend>
<textarea id="css_code" rows="10" cols="70"></textarea>
<input id="css_apply" type="button" value="Apply">
<input id="css_reset" type="button" value="Reset">
</fieldset>
</body>
</html>

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Usage:
# upload [user]
REMOTE_USER=${1:-$USER}
HOST="jquery.tiddlywiki.org"
DIR="/var/www/www.jquery.tiddlywiki.org/htdocs/"
COMMANDS="ssh $REMOTE_USER@$HOST"
COMMANDS="$COMMANDS cd $DIR;"
COMMANDS="$COMMANDS sudo svn update;"
$COMMANDS

View File

@@ -0,0 +1,155 @@
/*
jQuery.encoding.digests.sha1.js
SHA-1 digest and associated utility functions
Copyright (c) UnaMesa Association 2009
Dual licensed under the MIT and GPL licenses:
http://www.opensource.org/licenses/mit-license.php
http://www.gnu.org/licenses/gpl.html
*/
(function($) {
if(!$.encoding)
$.encoding = {};
$.extend($.encoding,{
strToBe32s: function(str) {
// Convert a string to an array of big-endian 32-bit words
var be=[];
var len=Math.floor(str.length/4);
var i, j;
for(i=0, j=0; i<len; i++, j+=4) {
be[i]=((str.charCodeAt(j)&0xff) << 24)|((str.charCodeAt(j+1)&0xff) << 16)|((str.charCodeAt(j+2)&0xff) << 8)|(str.charCodeAt(j+3)&0xff);
}
while(j<str.length) {
be[j>>2] |= (str.charCodeAt(j)&0xff)<<(24-(j*8)%32);
j++;
}
return be;
},
be32sToStr: function(be) {
// Convert an array of big-endian 32-bit words to a string
var str='';
for(var i=0;i<be.length*32;i+=8) {
str += String.fromCharCode((be[i>>5]>>>(24-i%32)) & 0xff);
}
return str;
},
be32sToHex: function(be) {
// Convert an array of big-endian 32-bit words to a hex string
var hex='0123456789ABCDEF';
var str='';
for(var i=0;i<be.length*4;i++) {
str += hex.charAt((be[i>>2]>>((3-i%4)*8+4))&0xF) + hex.charAt((be[i>>2]>>((3-i%4)*8))&0xF);
}
return str;
}
});
})(jQuery);
(function($) {
if(!$.encoding.digests)
$.encoding.digests = {};
$.extend($.encoding.digests,{
hexSha1Str: function(str) {
// Return, in hex, the SHA-1 hash of a string
return $.encoding.be32sToHex($.encoding.digests.sha1Str(str));
},
sha1Str: function(str) {
// Return the SHA-1 hash of a string
return sha1($.encoding.strToBe32s(str),str.length);
},
sha1: function(x,blen) {
// Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words
return sha1($.encoding.strToBe32s(str),str.length);
}
});
// Private functions.
function sha1(x,blen) {
// Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words
function add32(a,b) {
// Add 32-bit integers, wrapping at 32 bits
// Uses 16-bit operations internally to work around bugs in some JavaScript interpreters.
var lsw=(a&0xFFFF)+(b&0xFFFF);
var msw=(a>>16)+(b>>16)+(lsw>>16);
return (msw<<16)|(lsw&0xFFFF);
}
function AA(a,b,c,d,e) {
// Cryptographic round helper function. Add five 32-bit integers, wrapping at 32 bits, second parameter is rotated left 5 bits before the addition
// Uses 16-bit operations internally to work around bugs in some JavaScript interpreters.
b=(b>>>27)|(b<<5);
var lsw=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF);
var msw=(a>>16)+(b>>16)+(c>>16)+(d>>16)+(e>>16)+(lsw>>16);
return (msw<<16)|(lsw&0xFFFF);
}
function RR(w,j) {
// Cryptographic round helper function.
var n=w[j-3]^w[j-8]^w[j-14]^w[j-16];
return (n>>>31)|(n<<1);
}
var len=blen*8;
//# Append padding so length in bits is 448 mod 512
x[len>>5] |= 0x80 << (24-len%32);
//# Append length
x[((len+64>>9)<<4)+15]=len;
var w=new Array(80);
var k1=0x5A827999;
var k2=0x6ED9EBA1;
var k3=0x8F1BBCDC;
var k4=0xCA62C1D6;
var h0=0x67452301;
var h1=0xEFCDAB89;
var h2=0x98BADCFE;
var h3=0x10325476;
var h4=0xC3D2E1F0;
for(var i=0;i<x.length;i+=16) {
var j=0;
var t;
var a=h0;
var b=h1;
var c=h2;
var d=h3;
var e=h4;
while(j<16) {
w[j]=x[i+j];
t=AA(e,a,d^(b&(c^d)),w[j],k1);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
while(j<20) {
w[j]=RR(w,j);
t=AA(e,a,d^(b&(c^d)),w[j],k1);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
while(j<40) {
w[j]=RR(w,j);
t=AA(e,a,b^c^d,w[j],k2);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
while(j<60) {
w[j]=RR(w,j);
t=AA(e,a,(b&c)|(d&(b|c)),w[j],k3);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
while(j<80) {
w[j]=RR(w,j);
t=AA(e,a,b^c^d,w[j],k4);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
h0=add32(h0,a);
h1=add32(h1,b);
h2=add32(h2,c);
h3=add32(h3,d);
h4=add32(h4,e);
}
return [h0,h1,h2,h3,h4];
}
})(jQuery);

View File

@@ -0,0 +1,333 @@
/*
jQuery.twFile.js
jQuery plugin for loading a file and saving data to a file
Copyright (c) UnaMesa Association 2009
Triple licensed under the BSD, MIT and GPL licenses:
http://www.opensource.org/licenses/bsd-license.php
http://www.opensource.org/licenses/mit-license.php
http://www.gnu.org/licenses/gpl.html
*/
(function($) {
if(!$.twFile) {
$.twFile = {};
}
$.extend($.twFile,{
currentDriver: null,
driverList: ["tiddlySaver", "activeX","javaLiveConnect", "mozilla"],
// Loads the contents of a text file from the local file system
// filePath is the path to the file in these formats:
// x:\path\path\path\filename - PC local file
// \\server\share\path\path\path\filename - PC network file
// /path/path/path/filename - Mac/Unix local file
// returns the text of the file, or null if the operation cannot be performed or false if there was an error
load: function(filePath) {
var d = this.getDriver();
return d ? d.loadFile(filePath) : null;
},
// Saves a string to a text file on the local file system
// filePath is the path to the file in the format described above
// content is the string to save
// returns true if the file was saved successfully, or null if the operation cannot be performed or false if there was an error
save: function(filePath,content) {
var d = this.getDriver();
return d ? d.saveFile(filePath,content) : null;
},
// Copies a file on the local file system
// dest is the path to the destination file in the format described above
// source is the path to the source file in the format described above
// returns true if the file was copied successfully, or null if the operation cannot be performed or false if there was an error
copy: function(dest,source) {
var d = this.getDriver();
if(d && d.copyFile)
return d.copyFile(dest,source);
else
return null;
},
// Converts a local file path from the format returned by document.location into the format expected by this plugin
// url is the original URL of the file
// returns the equivalent local file path
convertUriToLocalPath: function (url) {
// Remove any location or query part of the URL
var originalPath = url.split("#")[0].split("?")[0];
// Convert file://localhost/ to file:///
if(originalPath.indexOf("file://localhost/") == 0)
originalPath = "file://" + originalPath.substr(16);
// Convert to a native file format
//# "file:///x:/path/path/path..." - pc local file --> "x:\path\path\path..."
//# "file://///server/share/path/path/path..." - FireFox pc network file --> "\\server\share\path\path\path..."
//# "file:///path/path/path..." - mac/unix local file --> "/path/path/path..."
//# "file://server/share/path/path/path..." - pc network file --> "\\server\share\path\path\path..."
var localPath;
if(originalPath.charAt(9) == ":") // PC local file
localPath = unescape(originalPath.substr(8)).replace(new RegExp("/","g"),"\\");
else if(originalPath.indexOf("file://///") == 0) // Firefox PC network file
localPath = "\\\\" + unescape(originalPath.substr(10)).replace(new RegExp("/","g"),"\\");
else if(originalPath.indexOf("file:///") == 0) // Mac/UNIX local file
localPath = unescape(originalPath.substr(7));
else if(originalPath.indexOf("file:/") == 0) // Mac/UNIX local file
localPath = unescape(originalPath.substr(5));
else if(originalPath.indexOf("//") == 0) // PC network file
localPath = "\\\\" + unescape(originalPath.substr(7)).replace(new RegExp("/","g"),"\\");
return localPath || originalPath;
},
// Deferred initialization for any drivers that need it
// returns a Deferred object so callback that executes as soon
// as twFile is ready can be attached
initialize: function() {
return $.Deferred(function(dfd) {
for(var t in drivers) {
if(drivers[t].deferredInit)
drivers[t].deferredInit();
}
// Kludge: give the <applet> some time to load
setTimeout(dfd.resolve, 0);
});
},
// Private functions
// Returns a reference to the current driver
getDriver: function() {
if(this.currentDriver === null) {
for(var t=0; t<this.driverList.length; t++) {
if(this.currentDriver === null && drivers[this.driverList[t]].isAvailable && drivers[this.driverList[t]].isAvailable())
this.currentDriver = drivers[this.driverList[t]];
}
}
return this.currentDriver;
}
});
// Automatically initialize on document.ready()
$(function() {
$.twFile.initialize();
});
// Private driver implementations for each browser
var drivers = {};
// Internet Explorer driver
drivers.activeX = {
name: "activeX",
isAvailable: function() {
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
} catch(ex) {
return false;
}
return true;
},
loadFile: function(filePath) {
// Returns null if it can't do it, false if there's an error, or a string of the content if successful
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(filePath,1);
var content = file.ReadAll();
file.Close();
} catch(ex) {
//# alert("Exception while attempting to load\n\n" + ex.toString());
return null;
}
return content;
},
createPath: function(path) {
//# Remove the filename, if present. Use trailing slash (i.e. "foo\bar\") if no filename.
var pos = path.lastIndexOf("\\");
if(pos!=-1)
path = path.substring(0,pos+1);
//# Walk up the path until we find a folder that exists
var scan = [path];
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var parent = fso.GetParentFolderName(path);
while(parent && !fso.FolderExists(parent)) {
scan.push(parent);
parent = fso.GetParentFolderName(parent);
}
//# Walk back down the path, creating folders
for(i=scan.length-1;i>=0;i--) {
if(!fso.FolderExists(scan[i])) {
fso.CreateFolder(scan[i]);
}
}
return true;
} catch(ex) {
}
return false;
},
copyFile: function(dest,source) {
drivers.activeX.createPath(dest);
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.GetFile(source).Copy(dest);
} catch(ex) {
return false;
}
return true;
},
saveFile: function(filePath,content) {
// Returns null if it can't do it, false if there's an error, true if it saved OK
drivers.activeX.createPath(filePath);
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(filePath,2,-1,0);
file.Write(content);
file.Close();
} catch (ex) {
return null;
}
return true;
}
};
// Mozilla driver
drivers.mozilla = {
name: "mozilla",
isAvailable: function() {
return !!window.Components;
},
loadFile: function(filePath) {
// Returns null if it can't do it, false if there's an error, or a string of the content if successful
if(window.Components) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if(!file.exists())
return null;
var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
inputStream.init(file,0x01,00004,null);
var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
sInputStream.init(inputStream);
var contents = sInputStream.read(sInputStream.available());
sInputStream.close();
inputStream.close();
return contents;
} catch(ex) {
//# alert("Exception while attempting to load\n\n" + ex);
return false;
}
}
return null;
},
saveFile: function(filePath,content) {
// Returns null if it can't do it, false if there's an error, true if it saved OK
if(window.Components) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if(!file.exists())
file.create(0,0664);
var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
out.init(file,0x20|0x02,00004,null);
out.write(content,content.length);
out.flush();
out.close();
return true;
} catch(ex) {
alert("Exception while attempting to save\n\n" + ex);
return false;
}
}
return null;
}
};
// TiddlySaver driver
drivers.tiddlySaver = {
name: "tiddlySaver",
deferredInit: function() {
if(!document.applets["TiddlySaver"] && /* !$.browser.mozilla && !$.browser.msie && */ document.location.toString().substr(0,5) == "file:") {
$(document.body).append("<applet style='position:absolute;left:-1px' name='TiddlySaver' code='TiddlySaver.class' archive='TiddlySaver.jar' width='1'height='1'></applet>");
}
},
isAvailable: function() {
var isReady = false;
try {
isReady = !!document.applets["TiddlySaver"] &&
($.browser.msie || document.applets["TiddlySaver"].isActive) &&
( document.applets["TiddlySaver"].isActive() );
} catch (ex) {
isReady = false;
}
return isReady;
},
loadFile: function(filePath) {
var r;
try {
if(document.applets["TiddlySaver"]) {
r = document.applets["TiddlySaver"].loadFile(javaUrlToFilename(filePath),"UTF-8");
return (r === undefined || r === null) ? null : String(r);
}
} catch(ex) {
}
return null;
},
saveFile: function(filePath,content) {
try {
if(document.applets["TiddlySaver"])
return document.applets["TiddlySaver"].saveFile(javaUrlToFilename(filePath),"UTF-8",content);
} catch(ex) {
}
return null;
}
};
// Java LiveConnect driver
drivers.javaLiveConnect = {
name: "javaLiveConnect",
isAvailable: function() {
return !!window.java && !!window.java.io && !!window.java.io.FileReader;
},
loadFile: function(filePath) {
var r;
var content = [];
try {
r = new java.io.BufferedReader(new java.io.FileReader(javaUrlToFilename(filePath)));
var line;
while((line = r.readLine()) != null)
content.push(new String(line));
r.close();
} catch(ex) {
return null;
}
return content.join("\n") + "\n";
},
saveFile: function(filePath,content) {
try {
var s = new java.io.PrintStream(new java.io.FileOutputStream(javaUrlToFilename(filePath)));
s.print(content);
s.close();
} catch(ex) {
return null;
}
return true;
}
};
// Private utilities
function javaUrlToFilename(url) {
var f = "//localhost";
if(url.indexOf(f) == 0)
return url.substring(f.length);
var i = url.indexOf(":");
return i > 0 ? url.substring(i-1) : url;
}
})(jQuery);

View File

@@ -0,0 +1,64 @@
/*
jQuery.twStylesheet.js
jQuery plugin to dynamically insert CSS rules into a document
Usage:
jQuery.twStylesheet applies style definitions
jQuery.twStylesheet.remove neutralizes style definitions
Copyright (c) UnaMesa Association 2009
Triple licensed under the BSD, MIT and GPL licenses:
http://www.opensource.org/licenses/bsd-license.php
http://www.opensource.org/licenses/mit-license.php
http://www.gnu.org/licenses/gpl.html
*/
(function($) {
var defaultId = "customStyleSheet"; // XXX: rename to dynamicStyleSheet?
// Add or replace a style sheet
// css argument is a string of CSS rule sets
// options.id is an optional name identifying the style sheet
// options.doc is an optional document reference
// N.B.: Uses DOM methods instead of jQuery to ensure cross-browser comaptibility.
$.twStylesheet = function(css, options) {
options = options || {};
var id = options.id || defaultId;
var doc = options.doc || document;
var el = doc.getElementById(id);
if(doc.createStyleSheet) { // IE-specific handling
if(el) {
el.parentNode.removeChild(el);
}
doc.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd",
'&nbsp;<style id="' + id + '" type="text/css">' + css + '</style>'); // fails without &nbsp;
} else { // modern browsers
if(el) {
el.replaceChild(doc.createTextNode(css), el.firstChild);
} else {
el = doc.createElement("style");
el.type = "text/css";
el.id = id;
el.appendChild(doc.createTextNode(css));
doc.getElementsByTagName("head")[0].appendChild(el);
}
}
};
// Remove existing style sheet
// options.id is an optional name identifying the style sheet
// options.doc is an optional document reference
$.twStylesheet.remove = function(options) {
options = options || {};
var id = options.id || defaultId;
var doc = options.doc || document;
var el = doc.getElementById(id);
if(el) {
el.parentNode.removeChild(el);
}
};
})(jQuery);

View File

@@ -0,0 +1,139 @@
/**
* gettext for jQuery
*
* Copyright (c) 2008 Sabin Iacob (m0n5t3r) <iacobs@m0n5t3r.info>
* 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.
*
* @license http://www.gnu.org/licenses/gpl.html
* @project jquery.gettext
*
* Usage:
*
* This plugin expects its input data to be a JSON object like
* {"": header, "string": "translation", ...}
*
* After getting the server side set up (either as a static file - my choice - or
* as a web service), the client side is simple:
* * add to the head section of the page something like
* <link href="path/to/translation.json" lang="ro" rel="gettext"/>
* * in your script, use $.gt.gettext(string) or _(string); for plural forms, use
* $.gt.ngettext(sg, pl1[, pl2, ...], count) or n_(sg, pl1[, pl2, ...], count)
* * to extract strings to a .po file, you can use standard gettext utilities like
* xgettext and msgfmt; to generate the JSON, one could use the following Python
* snippet, assuming a domain.mo file exists under path/lang/LC_MESSAGES:
*
* import simplejson as enc
*
* def gettext_json(domain, path, lang = [], indent = False):
* try:
* tr = gettext.translation(domain, path, lang)
* return enc.dumps(tr._catalog, ensure_ascii = False, indent = indent)
* except IOError:
* return None
*
* why go through the additional hassle of gettext? well, it's a matter of
* preference, the main advantags I see are:
* * well known editing tools like KBabel, poEdit, gtranslator, Emacs PO mode,
* etc.
* * translation memory, fuzzy matches and other features that get really
* helpful when your application is big and you have hundreds of strings
*/
(function($) {
$.gt = $.gt || {};
$.extend($.gt, {
messages: {},
lang: 'C',
setLang: function(code) { $.gt.lang = typeof code == 'string' && code != ' ' ? code : 'C'; },
pl_re: /^Plural-Forms:\s*nplurals\s*=\s*(\d+);\s*plural\s*=\s*([^a-zA-Z0-9\$]*([a-zA-Z0-9\$]+).+)$/m,
plural: function(n) {return n != 1;},
load: function() {
$('link[rel=gettext]').each(function(){
var lang = this.lang;
$.get(this.href, function(data){
$.gt.messages[lang] = $.gt.messages[lang] || {};
try {
var messages = eval('(' + data + ')');
} catch(e) {
return;
}
$.extend($.gt.messages[lang], messages);
var pl = $.gt.pl_re.exec($.gt.messages[lang]['']);
if(pl){
var expr = pl[2];
var np = pl[1];
var v = pl[3];
try {
var fn = eval('(function(' + v + ') {return ' + expr + ';})');
} catch(e) {
return;
}
$.gt.plural = fn;
}
});
});
$.gt.setLang($('html').attr('lang'));
},
gettext: function(msgstr) {
var lang = $.gt.lang;
if(lang == 'C' || typeof $.gt.messages[lang] == 'undefined') {
return msgstr;
}
var trans = $.gt.messages[lang][msgstr];
if(typeof trans == 'string') { // regular action
return trans;
} else if(typeof trans == 'object' && trans.constructor == Array) { // the translation contains plural(s), yet gettext was called
return trans[0];
}
return msgstr;
},
ngettext: function() {
var lang = $.gt.lang;
var argv = Array.apply(null, arguments);
var cnt = argv[argv.length - 1];
var sg = argv[0];
var pls = argv.slice(0, -1);
var trans = pls;
if(lang != 'C' && typeof $.gt.messages[lang] != 'undefined') {
trans = $.gt.messages[lang][sg];
}
if(typeof trans == 'string') { // called ngettext, but no plural forms available :-?
return trans;
} else if(typeof trans == 'object' && trans.constructor == Array) {
var pl = $.gt.plural(cnt);
if(typeof pl == 'boolean' && pls.length == 2) {
pl = pl ? 1 : 0;
}
if(typeof pl == 'number' && pl < trans.length) {
return trans[pl];
}
}
return sg;
}
});
$('document').ready($.gt.load);
})(jQuery);
if(typeof _ == 'undefined') {
var _ = jQuery.gt.gettext;
}
if(typeof n_ == 'undefined') {
var n_ = jQuery.gt.ngettext;
}

View File

@@ -0,0 +1,10 @@
/*
jquery.tw.js
addition of tw 'namespace'
*/
(function($) {
if(!$.tw) {
$.tw = {};
$.tw.extend = $.extend;
}
})(jQuery);

View File

@@ -0,0 +1,58 @@
/*
jquery.tw.macro.js
macro parameter expansion
*/
(function($) {
$.tw.extend({
expandMacroParams: function(params) {
// expand the macro parameters into a name:value hash
// all parameters are also given a numeric name, starting at 1
var opts = {};
var unnamed = 1;
var name,val;
var t = $.trim(params);
var s = 0;
var i = findNakedSpace(t,s);
var param = i==-1 ? t.substr(s) : t.substring(s,i);
while(true) {
var ci = param.indexOf(':');
if(ci==-1) {
// parameter is unnamed
name = param ? unnamed++ : null;
val = param;
} else {
name = param.substr(0,ci);
val = param.substr(ci+1);
}
val = $.trim(val);
if(val.charAt(0)=='"' && val.charAt(val.length-1)=='"') {
val = val.substr(1,val.length-2);
}
if(name)
opts[name] = val;
if(i==-1)
break;
s = i+1;
i = findNakedSpace(t,s);
param = i==-1 ? t.substr(s) : t.substring(s,i);
}
return opts;
}
});
// Private functions.
function findNakedSpace(text,start) {
// find the next space not surrounded by quotes
var d = text.indexOf(' ',start);
if(d==-1)
return -1;
var qs = text.indexOf('"',start);
if(qs==-1 || qs > d)
return d;
var qe = text.indexOf('"',qs+1);
if(qe==-1)
return d;
return findNakedSpace(text,qe+1);
}
})(jQuery);

View File

@@ -0,0 +1,15 @@
/*
jquery.tw.macro.today.js
jQuery TiddlyWiki <<today>> macro
*/
(function($) {
$.fn.tw_today = function(args) {
args.format = args.format || args[1];
var opts = $.extend({},$.fn.tw_today.defaults,args);
var now = new Date();
var text = now.formatString(opts.format.trim());
this.append("<span>"+text+"</span>");
return this;
};
$.fn.tw_today.defaults = {format:"ddd mmm 0DD 0hh:0mm:0ss YYYY"};
})(jQuery);

View File

@@ -0,0 +1,2 @@
jquery: jQuery.encoding.digests.sha1.js
jquery: jQuery.twStylesheet.js

View File

@@ -0,0 +1,25 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tests</title>
<link rel="stylesheet" type="text/css" href="../../../test/qunit/testsuite.css">
<script src="../../jquery-1.3.2.min.js" type="text/javascript"></script>
<!-- test suite -->
<script src="../../../test/qunit/testrunner.js" type="text/javascript"></script>
<script src="../../../test/qunit/raiseAssertion.js" type="text/javascript"></script>
<!-- plugin -->
<script src="../jQuery.twFile.js" type="text/javascript"></script>
<!-- test code -->
<script src="js/jQuery.twFile.js" type="text/javascript"></script>
</head>
<body>
<h2 id="banner"></h2>
<h2 id="userAgent"></h2>
<ol id="tests"></ol>
<div id="main"></div>
</body>
</html>

View File

@@ -0,0 +1,25 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tests</title>
<link rel="stylesheet" type="text/css" href="../../../test/qunit/testsuite.css">
<script src="../../jquery-1.3.2.min.js" type="text/javascript"></script>
<!-- test suite -->
<script src="../../../test/qunit/testrunner.js" type="text/javascript"></script>
<script src="../../../test/qunit/raiseAssertion.js" type="text/javascript"></script>
<!-- plugin -->
<script src="../jQuery.twStylesheet.js" type="text/javascript"></script>
<!-- test code -->
<script src="js/jQuery.twStylesheet.js" type="text/javascript"></script>
</head>
<body>
<h2 id="banner"></h2>
<h2 id="userAgent"></h2>
<ol id="tests"></ol>
<div id="main"></div>
</body>
</html>

View File

@@ -0,0 +1,86 @@
jQuery(document).ready(function() {
module("jQuery.twFile");
test("load", function() {
var actual, expected, filepath;
actual = jQuery.twFile.load();
expected = null;
same(actual, expected, "returns null if no argument is specified");
filepath = getDocumentPath() + "/sample.txt";
actual = jQuery.twFile.load(filepath);
expected = "lorem ipsum\n" +
"dolor sit amet\n" +
"\n" +
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~\n" +
"foo bar baz\n";
same(actual, expected, "returns contents of specified file");
filepath = "/null";
actual = jQuery.twFile.load(filepath);
expected = null;
same(actual, expected, "returns null if the specified file does not exist");
filepath = "sample.txt";
actual = jQuery.twFile.load(filepath);
expected = null;
same(actual, expected, "returns null if specified file path is not absolute");
});
test("save", function() {
var actual, expression, expected, str;
var filepath = getDocumentPath() + "/savetest.txt";
/* disabled as browser-level exceptions cannot be trapped
expression = function() { jQuery.twFile.save(); };
expected = "ReferenceError";
raises(expression, expected, "raises exception if no argument is specified");
*/
/* disabled as browser-level exceptions cannot be trapped
expression = function() { jQuery.twFile.save(filepath); };
expected = "TypeError";
raises(expression, expected, "raises exception if no content argument is specified");
*/
/* disabled as browser-level exceptions cannot be trapped
expression = function() { jQuery.twFile.save("foo.txt", "sample content"); };
expected = "ReferenceError";
raises(expression, expected, "raises exception if specified file path is not absolute");
*/
str = "lorem ipsum\n" +
"dolor sit amet\n" +
"\n" +
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~\n" +
//"\xa9\u010d\u010c\n" +
"foo bar baz\n" +
(new Date).toString();
saveAndLoadString(filepath, str, "writes given ANSI text content to specified file");
//str = "\xa9\u010d\u010c";
//saveAndLoadString(filepath, str, "writes given UTF-8 text content to specified file");
//jQuery.twFile.save(filepath, ""); // teardown: blank file contents (deletion impossible)
});
// helper function to save and load back a string to a file
var saveAndLoadString = function(filepath,str,desc) {
jQuery.twFile.save(filepath, str);
var actual = jQuery.twFile.load(filepath);
same(actual, str, desc);
}
// helper function to retrieve current document's file path
var getDocumentPath = function() {
var path = document.location.pathname;
var startpos = 0;
var endpos = path.lastIndexOf("/");
if(path.charAt(2) == ":") {
startpos = 1;
path = path.replace(new RegExp("/","g"),"\\")
}
return unescape(path.substring(startpos, endpos));
};
});

View File

@@ -0,0 +1,69 @@
jQuery(document).ready(function() {
module("jQuery.twStylesheet");
test("apply", function() {
var actual, expected, el;
el = jQuery('<div />').appendTo(document.body);
jQuery.twStylesheet("div { overflow: hidden; }");
actual = jQuery(el).css("overflow");
expected = "hidden";
same(actual, expected, "applies style definitions to document");
// teardown
jQuery(el).remove();
jQuery.twStylesheet.remove();
el = jQuery('<div />').appendTo(document.body);
jQuery.twStylesheet("div { font-style: italic; }");
actual = jQuery(el).css("font-style");
expected = "italic";
same(actual, expected, "applies style definitions to newly-created elements");
// teardown
jQuery(el).remove();
jQuery.twStylesheet.remove();
jQuery.twStylesheet("", { id: "dummyStyleSheet" });
actual = jQuery("#dummyStyleSheet").length;
expected = 1;
same(actual, expected, "generates style element using given ID");
// teardown
jQuery.twStylesheet.remove({ id: "dummyStyleSheet" });
// TODO: test for options.doc argument
});
test("remove", function() {
var actual, expected;
// setup
el = jQuery('<div />').appendTo(document.body);
jQuery.twStylesheet("div { overflow: hidden; }");
// test
jQuery.twStylesheet.remove();
actual = jQuery(el).css("overflow");
expected = "visible";
same(actual, expected, "neutralizes style definitions");
// teardown
jQuery(el).remove();
// setup
jQuery.twStylesheet("");
// test
jQuery.twStylesheet.remove();
actual = jQuery("#customStyleSheet").length;
expected = 0;
same(actual, expected, "removes default style sheet if no ID is given");
// setup
jQuery.twStylesheet("", { id: "dummyStyleSheet" });
// test
jQuery.twStylesheet.remove({ id: "dummyStyleSheet" });
actual = jQuery("#dummyStyleSheet").length;
expected = 0;
same(actual, expected, "removes style element using given ID");
// TODO: test for options.doc argument
});
});

View File

@@ -0,0 +1,5 @@
lorem ipsum
dolor sit amet
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~
foo bar baz