You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Squashed commit of the following:
commit: 32cec8f
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:52:08 2013 +0100
Fix space before new sentence in two places.
commit 42bce3b
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:42:53 2013 +0100
andif -> and if
commit ee2dee2
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:42:12 2013 +0100
Fix a few typos.
commit 1c350ed
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:37:01 2013 +0100
milleseconds -> milliseconds
commit 6a9d4e3
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:35:29 2013 +0100
availble -> available
commit 0ac8be2
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:33:11 2013 +0100
recieve -> receive
commit 005c7f6
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:30:35 2013 +0100
Fix a couple of typos.
commit c866fd9
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:26:46 2013 +0100
simpiler -> simpler
commit 3a446fd
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:12:00 2013 +0100
doesn"t -> doesn't
commit 66ac8e8
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:10:03 2013 +0100
inconsist -> inconsistent
commit ffb9496
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 01:00:38 2013 +0100
Fix Selecing -> Selecting and space after //
commit f216fa6
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 00:56:55 2013 +0100
wfirst -> first
commit c3c79dd
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 00:43:36 2013 +0100
falsey -> falsy
commit 734b35e
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 00:39:24 2013 +0100
Fix a couple of typos.
commit e7247e7
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 00:21:17 2013 +0100
Fix a few typos.
commit 217e621
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 00:18:32 2013 +0100
Fix a couple of typos.
commit 05db7f0
Author: Markus Amalthea Magnuson <markus.magnuson@gmail.com>
Date: Sat Feb 23 00:16:09 2013 +0100
Fix a couple of typos.
This simply passes the `.is()` method a selector to see if the element"s `href` attributes starts with "http". Also we have removed the `event.preventDefault();` statement, this is because we want the default action to happen (which is to following the `href`)
91
91
92
-
We can actually take this a step further and make our code simpiler and more concise by allowing the selector argument to `.on()` do our logic for us.
92
+
We can actually take this a step further and make our code simpler and more concise by allowing the selector argument to `.on()` do our logic for us.
93
93
```
94
94
// attach a delegated event with a more refined selector
Copy file name to clipboardExpand all lines: page/events/event-extensions.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ props: Array
44
44
: Strings representing properties that should be copied from the browser's event object to the jQuery event object. If omitted, no additional properties are copied beyond the standard ones that jQuery copies and normalizes (e.g., `event.target` and `event.relatedTarget`).
45
45
46
46
filter: Function( event, originalEvent )
47
-
: jQuery calls this function after it constructs the `jQuery.Event` object, copies standard properties from `jQuery.event.props`, and copies the `fixHooks`-specific props (if any) specified above. The function can create new properties on the event object or modify existing ones. The second argument is the browser's native event object, which is also availble in `event.originalEvent`.
47
+
: jQuery calls this function after it constructs the `jQuery.Event` object, copies standard properties from `jQuery.event.props`, and copies the `fixHooks`-specific props (if any) specified above. The function can create new properties on the event object or modify existing ones. The second argument is the browser's native event object, which is also available in `event.originalEvent`.
48
48
49
49
Note that for all events, the browser's native event object is available in `event.originalEvent`; if the jQuery event handler examines the properties there instead of jQuery's normalized `event` object, there is no need to create a `fixHooks` entry to copy or modify the properties.
Copy file name to clipboardExpand all lines: page/events/history-of-events.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,7 @@ When we use `.live()` our event is bound to `$( document )`. When the `<li>` is
70
70
*`<html>`
71
71
**document* root
72
72
73
-
The last element to recieve the *click* event is *document*, this is where our `.live()` event is bound. `.live()` will then check to see if our selector `#list li` is the element that triggered the event, if so our event handler is executed.
73
+
The last element to receive the *click* event is *document*, this is where our `.live()` event is bound. `.live()` will then check to see if our selector `#list li` is the element that triggered the event, if so our event handler is executed.
Copy file name to clipboardExpand all lines: page/events/introduction-to-events.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ The event we want to listen to is specified by the button's `onclick` attribute,
33
33
1. First, we're coupling our view code (HTML) with our interaction code (JS). That means that whenever we need to update functionality, we'd have to edit our HTML which is just a bad practice and a maintenance nightmare.
34
34
2. Second, it's not scalable. If you had to attach this functionality onto numerous buttons, you'd not only bloat the page with a bunch of repetitious code, but you would again destroy maintainability.
35
35
36
-
Utilizing inline event handlers like this can be considered *obtrusive JavaScript,* but its opposite, *unobtrustive JavaScript* is a much more common way of discussing the topic. The notion of *unobtrusive JavaScript* is that your HTML and JS are kept separate and are therefore more maintainable. Separation of concerns is important because it keeps like pieces of code together (ie HTML, JS, CSS) and unlike pieces of code apart, facilitating changes, enhancements, etc. Furthermore, unobtrustive JavaScript stresses the importance of adding the least amount of cruft to a page as possible. If a user's browser doesn't support JavaScript, then it shouldn't be intertwined into the markup of the page. Also, to prevent naming collisions, JS code should utilize a single namespace for different pieces of functionality or libraries. jQuery is a good example of this, in that the `jQuery` object/constructor (and also the `$` alias to `jQuery`) only utilizes a single global variable, and all of jQuery's functionality is packaged into that one object.
36
+
Utilizing inline event handlers like this can be considered *obtrusive JavaScript,* but its opposite, *unobtrusive JavaScript* is a much more common way of discussing the topic. The notion of *unobtrusive JavaScript* is that your HTML and JS are kept separate and are therefore more maintainable. Separation of concerns is important because it keeps like pieces of code together (i.e. HTML, JS, CSS) and unlike pieces of code apart, facilitating changes, enhancements, etc. Furthermore, unobtrusive JavaScript stresses the importance of adding the least amount of cruft to a page as possible. If a user's browser doesn't support JavaScript, then it shouldn't be intertwined into the markup of the page. Also, to prevent naming collisions, JS code should utilize a single namespace for different pieces of functionality or libraries. jQuery is a good example of this, in that the `jQuery` object/constructor (and also the `$` alias to `jQuery`) only utilizes a single global variable, and all of jQuery's functionality is packaged into that one object.
37
37
38
38
To accomplish the desired task unobtrusively, let's change our HTML a little bit by removing the `onclick` attribute and replacing it with an `id`, which we'll utilize to "hook onto" the button from within a script file.
39
39
@@ -118,7 +118,7 @@ As of jQuery 1.7, all events are bound via the `on` method, whether you call it
118
118
119
119
Let's look at the `on` examples from above and discuss their differences. In the first example, a string of `click` is passed as the first argument to the `on` method, and an anonymous function is passed as the second. This looks a lot like the `bind` method before it. Here, we're attaching an event handler directly to `#helloBtn`. If there were any other buttons on the page, they wouldn't alert "Hello" when clicked because the event is only attached to `#helloBtn`.
120
120
121
-
In the second `on` example, we're passing an object (denoted by the curly braces `{}`), which has a property of `click` whose value is an anonymous function. The second argument to the `on` method is a jQuery selector string of `button`. While examples 1–3 are functionally equivalent, example 4 is different in that the `body` element is listening for click events that occur on *any* button element, not just `#helloBtn`. The final example above is exactly the same as the one preceding it, but instead of passing an object, we pass an event string, a selector string, and the callback. Both of these are examples of event delegation, a process by which an element higher in the DOM tree listens for events occuring on its children.
121
+
In the second `on` example, we're passing an object (denoted by the curly braces `{}`), which has a property of `click` whose value is an anonymous function. The second argument to the `on` method is a jQuery selector string of `button`. While examples 1–3 are functionally equivalent, example 4 is different in that the `body` element is listening for click events that occur on *any* button element, not just `#helloBtn`. The final example above is exactly the same as the one preceding it, but instead of passing an object, we pass an event string, a selector string, and the callback. Both of these are examples of event delegation, a process by which an element higher in the DOM tree listens for events occurring on its children.
122
122
123
123
Event delegation works because of the notion of *event bubbling*. For most events, whenever something occurs on a page (like an element is clicked), the event travels from the element it occurred on, up to its parent, then up to the parent's parent, and so on, until it reaches the root element, aka the `window`. So in our table example, whenever a `td` is clicked, its parent `tr` would also be notified of the click, the parent `table` would be notified, the `body` would be notified, and ultimately the `window` would be notified as well. While event bubbling and delegation work well, the delegating element (in our example, the `table`) should always be as close to the delegatees as possible so the event doesn't have to travel way up the DOM tree before its handler function is called.
In this slightly different example, we're defining a function called `sayHello` and then passing that function into the `on` method instead of an anonymous function. So many online examples show anonymous functions used as event handlers, but it's important to realize that you can also pass defined functions as event handlers as well. This is important if different elements or different events should perform the same functionality. This helps to keep your code DRY.
146
146
147
-
But what about that `event` argument in the `sayHello` function—what is it and why does it matter? In all DOM event callbacks, jQuery passes an *event object* argument which contains information about the event, such as precisely when and where it occurred, what type of event it was, which element the event occured on, and a plethora of other information. Of course you don't have to call it `event`; you could call it `e` or whatever you want to, but `event` is a pretty common convention.
147
+
But what about that `event` argument in the `sayHello` function—what is it and why does it matter? In all DOM event callbacks, jQuery passes an *event object* argument which contains information about the event, such as precisely when and where it occurred, what type of event it was, which element the event occurred on, and a plethora of other information. Of course you don't have to call it `event`; you could call it `e` or whatever you want to, but `event` is a pretty common convention.
148
148
149
149
If the element has default functionality for a specific event (like a link opens a new page, a button in a form submits the form, etc), that default functionality can be cancelled. This is often useful for AJAX requests. When a user clicks on a button to submit a form via AJAX, we'd want to cancel the button/form's default action (to submit it to the form's `action` attribute), and we would instead do an AJAX request to accomplish the same task for a more seamless experience. To do this, we would utilize the event object and call its `preventDefault` method. We can also prevent the event from bubbling up the DOM tree using `stopPropagation` so that parent elements aren't notified of its occurrence (in the case that event delegation is being used).
Copy file name to clipboardExpand all lines: page/events/triggering-event-handlers.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ $("a").trigger("click");
30
30
## How can I mimic a native browser event, if not `.trigger()`?
31
31
32
32
In order to trigger a native browser event, you have to use [document.createEventObject](http://msdn.microsoft.com/en-us/library/ie/ms536390%28v=vs.85%29.aspx) for < IE9 and [document.createEvent](https://developer.mozilla.org/en/DOM/document.createEvent) for all other browsers.
33
-
Using these two APIs, you can programatically create an event that behaves exactly as if someone has actually clicked on a file input box. The default action will happen, and the browse file dialog will display.
33
+
Using these two APIs, you can programmatically create an event that behaves exactly as if someone has actually clicked on a file input box. The default action will happen, and the browse file dialog will display.
34
34
35
35
The jQuery UI Team created [jquery.simulate.js](https://github.com/eduardolundgren/jquery-simulate/blob/master/jquery.simulate.js) in order to simplify triggering a native browser event for use in their automated testing. Its usage is modeled after jQuery's trigger.
36
36
@@ -49,7 +49,7 @@ There are four differences between `.trigger()` and `.triggerHandler()`
49
49
1.`.triggerHandler()` only triggers the event on the first element of a jQuery object.
50
50
2.`.triggerHandler()` cannot be chained. It returns the value that is returned by the last handler, not a jQuery object.
51
51
3.`.triggerHandler()` will not cause the default behavior of the event (such as a form submission).
52
-
4. Events triggered by `.triggerHandler()`, will not bubble up the DOM heirarchy. Only the handlers on the single element will fire.
52
+
4. Events triggered by `.triggerHandler()`, will not bubble up the DOM hierarchy. Only the handlers on the single element will fire.
53
53
54
54
For more information see the [triggerHandler documentation](http://api.jquery.com/triggerHandler)
The _initialisation_ statement is executed only once, before the loop starts. It gives you an opportunity to prepare or declare any variables.
35
35
36
-
The _conditional_ statement is executed before each iteration, and its return value decides whether the loop is to continue. If the conditional statement evaluates to a falsey value, then the loop stops.
36
+
The _conditional_ statement is executed before each iteration, and its return value decides whether the loop is to continue. If the conditional statement evaluates to a falsy value, then the loop stops.
37
37
38
38
The _iteration_ statement is executed at the end of each iteration and gives you an opportunity to change the state of important variables. Typically, this will involve incrementing or decrementing a counter and thus bringing the loop closer to its end.
Copy file name to clipboardExpand all lines: page/javascript-101/syntax-basics.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ JavaScript has support for single and multi-line comments. Comments are ignored
24
24
25
25
### Whitespace
26
26
27
-
Whitespace is also ignored in JavaScript. There are many tools that will strip out all the whitespace in a program, reducing the overall file size and improving network latency. Given the availability of tools like these, whitespace should be leveraged to make the code as readible as possible.
27
+
Whitespace is also ignored in JavaScript. There are many tools that will strip out all the whitespace in a program, reducing the overall file size and improving network latency. Given the availability of tools like these, whitespace should be leveraged to make the code as readable as possible.
28
28
29
29
```
30
30
// Whitespace is insignificant.
@@ -64,7 +64,7 @@ Identifiers are used to give variables and functions a unique name so they can s
64
64
* Can only be composed of letters, numbers, dollar signs, and underscores.
65
65
* The first character cannot be a number.
66
66
67
-
It's a best practice to name identifers in a way that will make sense to you and other developers later on.
67
+
It's a best practice to name identifiers in a way that will make sense to you and other developers later on.
Copy file name to clipboardExpand all lines: page/plugins/basic-plugin-creation.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ Notice that to use `css()`, another method, we use `this`, not `$( this )`. This
37
37
38
38
##Chaining
39
39
40
-
This works, but there's a couple of things we need to do for our plugin to survive in the real world. One of jQuery's features is chaining, when you link five or six actions onto one selector. This is accomplished by having all jQuery object methods return the original jQuery object again (there are a few exeptions: `width()` called without parameters returns the width of the selected element, and is not chainable). Making our plugin method chainable takes one line of code:
40
+
This works, but there's a couple of things we need to do for our plugin to survive in the real world. One of jQuery's features is chaining, when you link five or six actions onto one selector. This is accomplished by having all jQuery object methods return the original jQuery object again (there are a few exceptions: `width()` called without parameters returns the width of the selected element, and is not chainable). Making our plugin method chainable takes one line of code:
41
41
42
42
```
43
43
$.fn.greenify = function() {
@@ -127,7 +127,7 @@ It would be much better to have one slot, and use parameters to control what act
127
127
128
128
## Using the `each()` Method
129
129
Your typical jQuery object will contain references to any number of DOM elements, and that's why jQuery objects are often referred to as collections.
130
-
If you want to do any manipulating with specific elements (eg: getting data an attribute, calculating specific positions) then you need to use `each()` to
130
+
If you want to do any manipulating with specific elements (e.g. getting data an attribute, calculating specific positions) then you need to use `each()` to
131
131
loop through the elements.
132
132
133
133
```
@@ -182,7 +182,7 @@ $("div").greenify({
182
182
});
183
183
```
184
184
185
-
The default value for `color` of `#556B2F` gets overriden by `$.extend()` to be orange.
185
+
The default value for `color` of `#556B2F` gets overridden by `$.extend()` to be orange.
0 commit comments