First commit of the new doc system.

This commit is contained in:
John Resig 2006-08-13 03:05:31 +00:00
parent 41c94b4688
commit 8cef646d17
22 changed files with 5491 additions and 4608 deletions

2
docs/build.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
java -jar build/js.jar build/build.js

BIN
docs/build/js.jar vendored Normal file

Binary file not shown.

1
docs/data/jquery-docs-json.js vendored Normal file

File diff suppressed because one or more lines are too long

1
docs/data/jquery-docs-jsonp.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

80
docs/events/gen-events.pl Normal file
View file

@ -0,0 +1,80 @@
#!/usr/bin/perl
my @stuff = split(",", "blur,focus,load,resize,scroll,unload,click,dblclick," .
"mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," .
"submit,keydown,keypress,keyup,error");
foreach (@stuff) {
print qq~
/**
* Bind a function to the $_ event of each matched element.
*
* \@example \$("p").$_( function() { alert("Hello"); } );
* \@before <p>Hello</p>
* \@result <p on$_="alert('Hello');">Hello</p>
*
* \@name $_
* \@type jQuery
* \@param Function fn A function to bind to the $_ event on each of the matched elements.
* \@cat Events
*/
/**
* Trigger the $_ event of each matched element. This causes all of the functions
* that have been bound to thet $_ event to be executed.
*
* \@example \$("p").$_();
* \@before <p on$_="alert('Hello');">Hello</p>
* \@result alert('Hello');
*
* \@name $_
* \@type jQuery
* \@cat Events
*/
/**
* Bind a function to the $_ event of each matched element, which will only be executed once.
* Unlike a call to the normal .$_() method, calling .one$_() causes the bound function to be
* only executed the first time it is triggered, and never again (unless it is re-bound).
*
* \@example \$("p").one$_( function() { alert("Hello"); } );
* \@before <p on$_="alert('Hello');">Hello</p>
* \@result alert('Hello'); // Only executed for the first $_
*
* \@name one$_
* \@type jQuery
* \@param Function fn A function to bind to the $_ event on each of the matched elements.
* \@cat Events
*/
/**
* Removes a bound $_ event from each of the matched
* elements. You must pass the identical function that was used in the original
* bind method.
*
* \@example \$("p").un$_( myFunction );
* \@before <p on$_="myFunction">Hello</p>
* \@result <p>Hello</p>
*
* \@name un$_
* \@type jQuery
* \@param Function fn A function to unbind from the $_ event on each of the matched elements.
* \@cat Events
*/
/**
* Removes all bound $_ events from each of the matched elements.
*
* \@example \$("p").un$_();
* \@before <p on$_="alert('Hello');">Hello</p>
* \@result <p>Hello</p>
*
* \@name un$_
* \@type jQuery
* \@cat Events
*/
~;
}

View file

@ -1,92 +0,0 @@
#!/usr/bin/perl
use Data::Dumper;
$Data::Dumper::Pair = ": ";
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Terse = 1;
open( F, $ARGV[0] || "../jquery-svn.js" );
my $f = join('', <F>);
close( F );
my @c;
while ( $f =~ /\/\*\*\s*(.*?)\s*\*\//gs ) {
my $c = $1;
$c =~ s/^\s*\* ?//mg;
$c .= "!!!";
my %ret;
$ret{ 'params' } = [];
$ret{ 'examples' } = [];
#while ( $c =~ s/^\@(\S+)\s*<pre>(.*?)<\/pre>\n//ms ) {
#print "PARAM '$1' '$2'\n";
#}
while ( $c =~ s/^\@(\S+) *(.*?)(?=\n\@|!!!)//ms ) {
my $n = $1;
my $v = $2;
$v =~ s/\s*$//g;
$v =~ s/^\s*//g;
$v =~ s/&/&amp;/g;
$v =~ s/(\s\s+)/"&nbsp;" x length($1)/eg;
$v =~ s/</&lt;/g;
$v =~ s/>/&gt;/g;
$v =~ s/\n/<br>/g;
$v = 1 if ( $v eq '' );
if ( $n eq 'param' ) {
my ( $type, $name, @v ) = split( /\s+/, $v );
$v = { "type" => $type, "name" => $name, "desc" => join(' ', @v) };
$n = "params";
} elsif ( $n eq 'example' ) {
$v = { "code" => $v };
$n = "examples";
}
if ( $n eq 'desc' || $n eq 'before' || $n eq 'after' || $n eq 'result' ) {
my @e = @{$ret{'examples'}};
$e[ $#e ]{ $n } = $v;
} else {
if ( exists $ret{ $n } ) {
if ( ref $ret{ $n } eq 'ARRAY' ) {
push( @{$ret{ $n }}, $v );
} else {
$ret{ $n } = [ $ret{ $n }, $v ];
}
} else {
$ret{ $n } = $v;
}
}
}
$c =~ s/\s*!!!$//;
$c =~ s/\n\n/<br><br>/g;
$c =~ s/\n/ /g;
$ret{ 'desc' } = $c;
if ( $c =~ /^(.*?(\.|$))/s ) {
$ret{ 'short' } = $1;
#$ret{ 'short' } =~ s/<br>/ /g;
}
#print "###\n" . $c . "\n###\n";
if ( exists $ret{ 'name' } ) {
push( @c, \%ret );
}
}
open( F, ">" . ($ARGV[1] || "jquery-docs-json.js") );
print F Dumper( \@c );
close( F );
$Data::Dumper::Indent = 0;
open( F, ">" . ($ARGV[2] || "jquery-docs-jsonp.js") );
print F "docsLoaded(" . Dumper( \@c ) . ")";
close( F );

View file

@ -1,18 +0,0 @@
<html>
<head>
<title>jQuery Documentation</title>
<link rel="stylesheet" href="style/style.css"/>
<script src="../jquery-svn.js"></script>
<script src="js/tooltip.js"></script>
<script src="js/pager.js"></script>
<script src="js/jsont.js"></script>
<script src="js/doc.js"></script>
<script src="data/jquery-docs-jsonp.js"></script>
</head>
<body>
<h1>jQuery Docs &raquo; API</h1>
<ul id="docs">
<li>Loading...</li>
</ul>
</body>
</html>

2646
docs/index.xml Normal file

File diff suppressed because it is too large Load diff

4094
docs/jquery-docs-json.js vendored

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -4,7 +4,8 @@ var rules = {
"self[*]": "<li><span class='type'><span title='{@type($.type)}'>{$.type}</span></span> <span class='fn'>" +
"<a href='#{$.name}' class='name' title='{$.name}: {$.short}'>{$.name}</a>({$.params})</span>" +
"<div class='short'>{$.short}</div><div class='more'><div class='desc'>{$.desc}</div>{$.examples}</div></li>",
"self[*].params[*]": " <span class='arg-type' title='{@type($.type)}'>{$.type}</span> <span class='arg-name' title='{$.desc}'>{$.name}</span> ",
trim: function(a){ console.log( a ); return !a || a.replace(/, $/); },
"self[*].params[*]": " <span class='arg-type' title='{@type($.type)}'>{$.type}</span> <span class='arg-name' title='{$.desc}'>{$.name}</span>, ",
"self[*].examples[*]": "<div class='example'><h5>Example:</h5><p>{$.desc}</p><pre>{$.code}</pre><b>HTML:</b><pre>{$.before}</pre><b>Result:</b><pre>{$.result}</pre></div>"
};
@ -20,39 +21,14 @@ var types = {
Function: "A reference to a Javascript function."
};
function docsLoaded(docs) {
// Make sure that there are no private functions
docs = jQuery.grep( docs, "!a.private" )
// Sort by function name
.sort(function(a,b){
if ( a.name < b.name ) return -1;
else if ( a.name == b.name ) {
// Sort by number of parameters
if ( a.params.length < b.params.length ) return -1;
else if ( a.params.length == b.params.length ) return 0;
else return 1;
} else return 1;
$(document).ready(function(){
$("span[@title]").addClass("tooltip").ToolTipDemo('#fff');
$("a.name").click(function(){
$("div.more,div.short",this.parentNode.parentNode).toggle().find("div.desc",function(){
$(this).html( $(this).html().replace(/\n\n/g, "<br/><br/>") );
});
// Put in the DOM, when it's ready
$(document).ready(function(){
$("#docs").html( jsonT( docs, rules ) );
setTimeout(function(){
$("#docs").pager( function(){return this.firstChild.nextSibling.nextSibling.firstChild.innerHTML;}, function(s,e){
$(this).html( jsonT( docs.slice( s, e ), rules ) );
/*$(this).slideUp("slow",function(){
this.style.opacity = 1;
this.style.width = "";
this.style.height = "";
$(this).html( jsonT( docs.slice( s, e ), rules ) );
$(this).slideDown("slow");
});*/
$("span",this).filter("[@title]").addClass("tooltip").ToolTipDemo('#fff');
$("a.name",this).click(function(){
$("div.more,div.short",this.parentNode.parentNode).toggle();
return false;
});
});
}, 13);
return false;
});
}
$("#docs").alphaPager( 1 );
});

View file

@ -1,19 +1,39 @@
$.fn.clone = function(){
return this.pushStack( $.map(this,"a.cloneNode(true)"), arguments );
$.fn.alphaPager = function(fn,type) {
type = type || "char";
if ( fn == undefined ) {
fn = function(a){ return _clean( $.fn.text.apply( a.childNodes ) ); };
} else if ( fn.constructor == Number ) {
var n = fn;
fn = function(a){ return _clean( $.fn.text.apply( [a.childNodes[ n ]] ) ); };
}
function _clean(a){
switch (type) {
case "char":
return a.substr(0,1).toUpperCase();
case "word":
return /^([a-z0-9]+)/.exec(a)[1];
}
return a;
}
return this.pager( fn );
};
$.fn.pager = function(step,fn) {
$.fn.pager = function(step) {
var types = {
UL: "li",
OL: "li",
DL: "dt",
TABLE: "tbody > tr"
TABLE: "tr"
};
return this.each(function(){
var pagedUI = this;
var rows = $(types[this.nodeName], this);
var type = types[this.nodeName];
var pagedUI = type == "tr" ? $("tbody",this) : $(this);
var rows = $(type, pagedUI);
var curPage = 0;
var names = [], num = [];
@ -23,14 +43,14 @@ $.fn.pager = function(step,fn) {
if (rows.length > step)
for ( var i = 0; i <= rows.length; i += step ) {
names.push( names.length + 1 );
num.push( [ i * step, step ] );
num.push( [ i, step ] );
}
} else {
var last;
rows.each(function(){
var l = step.apply( this ).substr(0,1);
var l = step( this );
if ( l != last ) {
names.push( l.toUpperCase() );
names.push( l );
var pre = num.length ? num[ num.length - 1 ][0] + num[ num.length - 1 ][1] : 0;
num.push( [ pre, 0 ] );
@ -41,8 +61,11 @@ $.fn.pager = function(step,fn) {
});
}
if ( names.length ) {
var pager = $("<ul class='nav-page'></ul>");
if ( names.length > 1 ) {
var pager = $(this).prev("ul.nav-page").empty();
if ( !pager.length )
pager = $("<ul class='nav-page'></ul>");
for ( var i = 0; i < names.length; i++ )
$("<a href=''></a>").rel( i ).html( names[i] ).click(function() {
@ -65,7 +88,7 @@ $.fn.pager = function(step,fn) {
function handleCrop( page ) {
curPage = page - 0;
var s = num[ curPage ][0];
var e = s + num[ curPage ][1];
var e = num[ curPage ][1];
if ( !curPage ) prev.hide();
else prev.show();
@ -78,14 +101,9 @@ $.fn.pager = function(step,fn) {
.eq( curPage + 1 )
.addClass("cur");
rows
.hide()
.gt(s - 1).lt(e)
.show()
.end().end();
if ( fn )
fn.apply( pagedUI, [ s, e ] );
pagedUI.empty().append(
jQuery.merge( rows, [] ).slice( s, s + e )
);
return false;
}

View file

@ -1,58 +0,0 @@
function jsonT(self, rules) {
var T = {
output: false,
init: function() {
for (var rule in rules)
if (rule.substr(0,4) != "self")
rules["self."+rule] = rules[rule];
return this;
},
apply: function(expr) {
var trf = function(s){ return s.replace(/{([A-Za-z0-9_\$\.\[\]\'@\(\)]+)}/g,
function($0,$1){return T.processArg($1, expr);})},
x = expr.replace(/\[[0-9]+\]/g, "[*]"), res;
if (x in rules) {
if (typeof(rules[x]) == "string")
res = trf(rules[x]);
else if (typeof(rules[x]) == "function")
res = trf(rules[x](eval(expr)).toString());
}
else
res = T.eval(expr);
return res;
},
processArg: function(arg, parentExpr) {
var expand = function(a,e){return (e=a.replace(/^\$/,e)).substr(0,4)!="self" ? ("self."+e) : e; },
res = "";
T.output = true;
if (arg.charAt(0) == "@")
res = eval(arg.replace(/@([A-za-z0-9_]+)\(([A-Za-z0-9_\$\.\[\]\']+)\)/,
function($0,$1,$2){return "rules['self."+$1+"']("+expand($2,parentExpr)+")";}));
else if (arg != "$")
res = T.apply(expand(arg, parentExpr));
else
res = T.eval(parentExpr);
T.output = false;
return res;
},
eval: function(expr) {
var v = eval(expr), res = "";
if (typeof(v) != "undefined") {
if (v instanceof Array) {
for (var i=0; i<v.length; i++)
if (typeof(v[i]) != "undefined")
res += T.apply(expr+"["+i+"]");
}
else if (typeof(v) == "object") {
for (var m in v)
if (typeof(v[m]) != "undefined")
res += T.apply(expr+"."+m);
}
else if (T.output)
res += v;
}
return res;
}
};
return T.init().apply("self");
}

67
docs/style/docs.xsl Normal file
View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/*">
<html>
<head>
<title>jQuery Docs - API</title>
<link rel="stylesheet" href="style/style.css"/>
<script src="../jquery-svn.js"></script>
<script src="js/tooltip.js"></script>
<script src="js/pager.js"></script>
<script src="js/doc2.js"></script>
</head>
<body>
<h1>jQuery Docs - API</h1>
<ul id="docs">
<xsl:for-each select="method[not(@private)]">
<xsl:sort select="@name"/>
<xsl:sort select="count(params)"/>
<li>
<span class='type'><span title='TYPE' class='tooltip'><xsl:value-of select="@type"/></span></span>
<span class='fn'>
<a href='#{@name}' class='name' title=''><xsl:value-of select="@name"/></a>
<xsl:if test="not(@property)">(
<xsl:for-each select="params">
<span class='arg-type tooltip' title='TYPE'><xsl:value-of select="@type"/></span><xsl:text> </xsl:text>
<span class='arg-name tooltip' title='{@desc}'><xsl:value-of select="@name"/></span>
<xsl:if test="position() != last()">
<xsl:if test="@any"> or </xsl:if>
<xsl:if test="not(@any)">, </xsl:if>
</xsl:if>
</xsl:for-each>
)</xsl:if>
</span>
<div class='short'>
<xsl:value-of select="@short"/>
</div>
<div class='more'>
<div class='desc'>
<xsl:value-of select="desc"/>
</div>
<xsl:for-each select="examples">
<div class='example'>
<h5>Example:</h5>
<xsl:if test="desc">
<p><xsl:value-of select="desc"/></p>
</xsl:if>
<pre><xsl:value-of select="code"/></pre>
<xsl:if test="before">
<b>HTML:</b>
<pre><xsl:value-of select="before"/></pre>
</xsl:if>
<xsl:if test="result">
<b>Result:</b>
<pre><xsl:value-of select="result"/></pre>
</xsl:if>
</div>
</xsl:for-each>
</div>
</li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>