Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1afacaa
style conformance for about-jquery/how-jquery-works
Nov 7, 2012
a98b0bf
style conformance for javascript-101/getting-started
Nov 7, 2012
776c4aa
style conformance for javascript-101/syntax-basics
Nov 7, 2012
f7641f4
style conformance for javascript-101/running-code
Nov 7, 2012
87ce1f2
style conformance for javascript-101/types
Nov 8, 2012
74be2db
style conformance for javascript-101/operators
Nov 8, 2012
cc01ee8
style conformance for javascript-101/conditional-code
Nov 8, 2012
2b4cf16
found the section on truthy/falsy
Nov 8, 2012
70b2003
style conformance for javascript-101/loops
Nov 8, 2012
6b04bb6
style conformance for javascript-101/arrays
Nov 8, 2012
0d7b57e
adding links to objects/arrays sections
Nov 8, 2012
f97c941
style conformance for javascript-101/objects
Nov 8, 2012
47fda0e
style conformance for javascript-101/functions
Nov 8, 2012
e498797
style conformance for javascript-101/testing-type
Nov 8, 2012
f1c8aff
link to testing-type section
Nov 8, 2012
2254121
style conformance for javascript-101/this-keyword
Nov 8, 2012
2dfb23a
style conformance for javascript-101/scope
Nov 8, 2012
1cb18ad
style conformance for javascript-101/closures
Nov 8, 2012
4259929
horizontal scrolling issues
Nov 8, 2012
a709de1
consistency with —
Nov 8, 2012
adcbaeb
style conformance for using-jquery-core/dollar-object-vs-function
Nov 8, 2012
bbe819e
style conformance for using-jquery-core/document-ready
Nov 8, 2012
bc6b21c
style conformance for using-jquery-core/avoid-conflicts-other-libraries
Nov 8, 2012
24b91ce
style conformance for using-jquery-core/attributes
Nov 8, 2012
8989211
style conformance for using-jquery-core/selecting-elements
Nov 8, 2012
d8c1ff5
style conformance for using-jquery-core/working-with-selections
Nov 9, 2012
3f9e54a
style conformance for using-jquery-core/manipulating-elements
Nov 9, 2012
947dff6
style conformance for using-jquery-core/data-methods
Nov 9, 2012
b17307b
style conformance for using-jquery-core/utility-methods
Nov 9, 2012
40c11cf
style conformance for using-jquery-core/jquery-object
Nov 9, 2012
96f06d4
style conformance for using-jquery-core/traversing
Nov 9, 2012
a52fe58
style conformance for using-jquery-core/css-styling-dimensions
Nov 9, 2012
6256c9e
style conformance for using-jquery-core/iterating
Nov 9, 2012
8f96503
style conformance for using-jquery-core/understanding-index
Nov 9, 2012
e512536
deleting obsolete exercises.md page
Nov 9, 2012
d6d5dcb
Update config-sample to reflect local.* instead of dev.*
ajpiano Nov 9, 2012
4ae27eb
Upgrade to grunt-jquery-content 0.5.10, add grunt-check-modules to gr…
ajpiano Nov 9, 2012
495a7b0
README.md updates
ajpiano Nov 9, 2012
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ The goal of this site is twofold:
1. To serve as a central, trustworthy, narrative compendium of information about how to use jQuery and JavaScript.
2. To remain a timely, vibrant, and community-driven reference with a low barrier to contribution.

Much of the initial content - and spirit - comes from [jQuery Fundamentals](https://github.com/rmurphey/jqfundamentals), an open-source book about jQuery, originally written by [Rebecca Murphey](http://www.rmurphey.com/) and released in 2010. In 2011, Rebecca [bequeathed the book](http://rmurphey.com/blog/2011/03/17/the-future-of-jquery-fundamentals-and-a-confession/) unto the jQuery Project to serve as the foundation for this site.
Much of the initial content - and spirit - comes from [jQuery Fundamentals](https://github.com/rmurphey/jqfundamentals), an open-source book about jQuery, originally written by [Rebecca Murphey](http://www.rmurphey.com/) and released in 2010. In 2011, Rebecca [bequeathed the book](http://rmurphey.com/blog/2011/03/17/the-future-of-jquery-fundamentals-and-a-confession/) unto the jQuery Foundation to serve as the basis for this site.


## How This Site Works

This site's core content consists of [Markdown](http://daringfireball.net/projects/markdown/) files. We use [nanoc](http://nanoc.stoneship.org/), a Ruby-based [static site generator](http://www.mickgardner.com/2011/04/27/An-Introduction-To-Static-Site-Generators.html), to process these files for previewing. For production on [learn.jquery.com](http://learn.jquery.com), a node.js script post-processes the nanoc results and puts them into the learning section of the jQuery Wordpress network.

The template that controls the site's appearance is a [child theme](https://github.com/jquery/web-base-template/tree/master/themes/learn-jquery-com) of the jQuery [web base template](https://github.com/jquery/web-base-template), and any issues with the presentation should be directed to [that repository](https://github.com/jquery/web-base-template).
This site's core content consists of [Markdown](http://daringfireball.net/projects/markdown/) files. The template that controls the site's appearance is a [child theme](https://github.com/jquery/web-base-template/tree/master/themes/learn-jquery-com) of the jQuery [web base template](https://github.com/jquery/web-base-template), and any issues with the presentation should be directed to [that repository](https://github.com/jquery/web-base-template).

### Site Organization

All of the content lives inside of the subdirectories of the `content` directory. Each of these subdirectories is considered a **category**, and contains one or more **articles**. Each category also contains a `dex.md` file that contains the category's human-readable title and an overview, which will appear on the category's landing page.
All of the content lives inside of the subdirectories of the `page` directory. Each of these subdirectories is considered a **category**, and contains one or more **articles**, and there is also a top level file that corresponds to each category, which contains the category's human-readable title and an overview, which will appear on the category's landing page.

An [`order.yml`](https://github.com/jquery/learn.jquery.com/blob/master/order.yml) file controls the order that categories and articles appear in the site. Categories or articles that do not appear in this file will not be published in the production site.


### YAML Conventions

Each of the articles on the site has some [YAML "Front Matter"](https://github.com/mojombo/jekyll/wiki/YAML-Front-Matter) that contains metadata. All articles should include the following:
Expand Down
2 changes: 1 addition & 1 deletion config-sample.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"url": "dev.learn.jquery.com",
"url": "local.learn.jquery.com",
"username": "admin",
"password": "sample"
}
3 changes: 2 additions & 1 deletion grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ grunt.loadNpmTasks( "grunt-clean" );
grunt.loadNpmTasks( "grunt-html" );
grunt.loadNpmTasks( "grunt-wordpress" );
grunt.loadNpmTasks( "grunt-jquery-content" );
grunt.loadNpmTasks( "grunt-check-modules" );

grunt.initConfig({
clean: {
Expand Down Expand Up @@ -44,7 +45,7 @@ grunt.initConfig({
});

grunt.registerTask( "default", "wordpress-deploy" );
grunt.registerTask( "build-wordpress", "clean lint build-pages build-resources");
grunt.registerTask( "build-wordpress", "check-modules clean lint build-pages build-resources");
grunt.registerTask( "deploy", "wordpress-deploy" );

};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"grunt-clean": "0.3.0",
"grunt-html": "0.1.1",
"grunt-wordpress": "1.0.3",
"grunt-jquery-content": "0.5.9"
"grunt-jquery-content": "0.5.10",
"grunt-check-modules": "0.1.0"
}
}
47 changes: 22 additions & 25 deletions page/about-jquery/how-jquery-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ can use:
<script src="jquery.js"></script>
```

You can download your own copy of jQuery from the [Downloading jQuery](http://jquery.com/download/) page
Download a copy of jQuery from the [Downloading jQuery](http://jquery.com/download/) page.

### Launching Code on Document Ready
The first thing that most Javascript programmers end up doing is adding some code to their program, similar to this:
Expand All @@ -42,7 +42,7 @@ window.onload = function() {

}
```
Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using window.onload in the first place is that the HTML 'document' isn't finished loading yet, when you first try to run your code.
Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using `window.onload` in the first place is that the HTML 'document' isn't finished loading yet, when you first try to run your code.

To circumvent both problems, jQuery has a simple statement that checks the `document` and waits until it's ready to be manipulated, known as the [ ready event ](http://api.jquery.com/ready):

Expand Down Expand Up @@ -91,11 +91,11 @@ The following is an example of what the complete HTML file might look like if
you were to use the script in your own file. Note that it links to Google's
[CDN](http://code.google.com/apis/libraries/) to load the jQuery core file.
Also, while the custom script is included in the `<head>`, it is generally
preferable to place it in a separate file and refer that file with the script
element's src attribute
preferable to place it in a separate file and refer to that file with the script
element's `src` attribute.

```
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -129,7 +129,7 @@ element's src attribute

Another common task is adding (or removing) a `class`.

First, add some style information into the `head` of your document, like this:
First, add some style information into the `head` of the document, like this:

```
<style>
Expand All @@ -139,15 +139,15 @@ First, add some style information into the `head` of your document, like this:
</style>
```

Next, add the [addClass](http://api.jquery.com/addClass) call to your script:
Next, add the [addClass](http://api.jquery.com/addClass) call to the script:

```
$("a").addClass("test");
```

All your `a` elements will now be bold.
All `a` elements will now be bold.

To remove the `class`, use [removeClass](http://api.jquery.com/removeClass)
To remove the `class`, use [removeClass](http://api.jquery.com/removeClass):

```
$("a").removeClass("test");
Expand All @@ -156,8 +156,8 @@ $("a").removeClass("test");
### Special Effects

In jQuery, a couple of handy [effects](http://api.jquery.com/category/effects/)
are provided, to really make your web site stand out. To put this to the test,
change the click that you added earlier to this:
are provided, to really make web sites stand out. For example,
change the click you added earlier to the following:

```
$("a").click(function( event ){
Expand All @@ -169,29 +169,29 @@ $("a").click(function( event ){
});
```

Now, if you click any link, it should make itself slowly disappear.
Now, the link should slowly disappear when clicked.

## Callback and Functions
## Callbacks and Functions

A callback is a function that is passed as an argument to another function and
is executed after its parent function has completed. The special thing about a
callback is that functions that appear after the "parent" can execute before
the callback executes. Another important thing to know is how to properly pass
the callback.

### Callback *without* arguments
### Callback *without* Arguments

For a callback with no arguments you pass it like this:
Pass callbacks with no arguments like this:

```
$.get( "myhtmlpage.html", myCallBack );
```

**Note** that the second parameter here is simply the function name (but *not* as a string and without parentheses). Functions in Javascript are 'First class citizens' and so can be passed around like variable references and executed at a later time.
**Note** that the second parameter here is simply the function name (but *not* as a string and without parentheses). Functions in Javascript are 'First class citizens' and can be passed around like variable references and executed at a later time.

### Callback *with* arguments
### Callback *with* Arguments

"What do you do if you have arguments that you want to pass?", you might ask yourself.
Executing callbacks with arguments can be tricky. The below example illustrates how to think about callbacks with arguments:

#### Wrong
The Wrong Way (will ***not*** work!)
Expand All @@ -201,18 +201,15 @@ $.get( "myhtmlpage.html", myCallBack(param1, param2) );
```


This will not work because it calls `myCallBack( param1, param2 )`


and then passes the return value as the second parameter to [$.get()](http://api.jquery.com/jQuery.get/)
This will not work because it calls `myCallBack( param1, param2 )` and then passes the return value as the second parameter to [$.get()](http://api.jquery.com/jQuery.get/).

#### Right

The problem with the above example is that `myCallBack( param1, param2 )` is
evaluated before being passed as a function. Javascript and by extension jQuery
expects a function pointer in cases like these, e.g., `setTimeout( function() {}, 100)`
evaluated before being passed as a function. Javascript (and by extension, jQuery)
expects a function pointer in cases like these, e.g., `setTimeout( function() {}, 100)`.

In the below usage, an anonymous function is created (just a block of
In the example below, an anonymous function is created (just a block of
statements) and is registered as the callback function. Note the use of
`function() {`. The anonymous function does exactly one thing: calls
`myCallBack`, with the values of `param1` and `param2` from the outer scope.
Expand Down
Loading