Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
updating README, ajax support files, more closure info in js101
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Murphey committed Sep 24, 2009
1 parent 241e0d8 commit 9aa8e0d
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 15 deletions.
17 changes: 15 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 67,7 @@ Rebecca Murphey is a front-end architecture consultant based in Durham, NC. She
* before, after
* insertBefore, insertAfter
* attr
* val
* NOTE: add blocks of html all at once, not one element at a time
* EXERCISE: make all links open in a new window
* EXERCISE: create a table of contents for the page
Expand All @@ -79,7 80,8 @@ Rebecca Murphey is a front-end architecture consultant based in Durham, NC. She
* combination methods (hover, one, toggle)
* bind and trigger
* EXERCISE: make clicking on a headilne hide the next element
* EXERCISE: change the color of an element on hover
* EXERCISE: add/remove a class on an element on hover
* EXERCISE: use the label for an input as hint text; clear hint on focus
* Effects
* built-in effects
* show/hide
Expand All @@ -95,9 97,20 @@ Rebecca Murphey is a front-end architecture consultant based in Durham, NC. She
* choosing a data type
* POST vs. GET
* convenience methods vs $.ajax method
* load, get, post
* $.ajax
* EXERCISE: use load to bring in part of a document
* EXERCISE: use $.ajax to load json for specials
* EXERCISE: serialize form data and send it to the server as a POST
* Utility methods
* trim, inArray, extend, etc.
* trim
* inArray
* extend
* ... and more
* Plugins
* Finding
* Using
* Writing

= Reference Material =

Expand Down
4 changes: 2 additions & 2 deletions dummy.php
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
<?
$foo = $_REQUEST;
$foo['extra_thing'] = 'hello there!';
$foo = $_POST;
$foo['message'] = 'Your information has been saved!';
echo (json_encode($foo));
?>
2 changes: 2 additions & 0 deletions html/curry.html
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
<h2>Curry</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
2 changes: 2 additions & 0 deletions html/onions.html
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
<h2>Onions</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
2 changes: 2 additions & 0 deletions html/stirfry.html
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
<h2>Stir fry</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
2 changes: 2 additions & 0 deletions html/tomatoes.html
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
<h2>Tomatoes</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
14 changes: 13 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 67,19 @@ <h3><a href="blog/post-2.php">Blog post 2</a></h3>
</li>
</ul>
</div>


<form id="search" method="GET" action="dummy.php">
<label for="search">Search for Something</label>
<input type="text" class="input_text" name="search" />
<input type="submit" class="input_submit" value="Go" />
</form>

<form id="update_server" method="POST" action="dummy.php">
<label for="data">Enter some data</label>
<input type="text" class="input_text" name="data" />
<input type="submit" class="input_submit" value="Go" />
</form>

<div class="module" id="specials">
<h2>Specials</h2>
<p>Choose the day of the week to see the specials:</p>
Expand Down
47 changes: 37 additions & 10 deletions js/solutions/js101.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 50,13 @@ myObject.property; // 'value'
myObject.method(); // alerts 'hello'


var MyThing = function() {

return this;
};


/* functions */

// defining a function
function myFunction() {
// do stuff
};

var myFunction = function() {
// do stuff
};
Expand Down Expand Up @@ -104,9 102,9 @@ var myFunction = function() {
alert(myClosedVariable); // error; myClosedVariable isn't defined outside the function

var myFunction = function() {
var myFn = function() {
function myFn() {
alert(myClosedVariable);
};
}

var myClosedVariable = 'hello';

Expand All @@ -116,5 114,34 @@ var myFunction = function() {
alert(myClosedVariable); // error; myClosedVariable isn't defined outside the function

var f = myFunction(); // returns the function created inside myFunction
f(); // this function still has access to myClosedVariable, because the function and the variable
// were created in the same scope. this is an example of a closure.
f(); // this function still has access to myClosedVariable,
// because the function and the variable
// were created in the same scope. this is an example of a closure.


/* another closure example */

// this won't work as expected! all will alert '4'
for (i=0; i<5; i ) {
$('p').appendTo('body').click(function() {
alert(i);
});
}

// this will work -- put the variable i inside a closure
for (i=0; i<5; i ) {
(function(i){
$('p').appendTo('body').click(function() {
alert(i);
});
})(i);
}

// this will also work, and is a little more clear about what's going on
var createFunction = function(i) {
return function() { alert(i); };
};

for (i=0; i<5; i ) {
$('p').appendTo('body').click(createFunction(i));
}

0 comments on commit 9aa8e0d

Please sign in to comment.