├── Ajax PHP shoutbox
├── README.md
├── css
│ └── lecture22.css
├── database.php
├── index.php
├── scripts
│ └── lecture22.js
└── shoutbox.php
├── Apple Style Thumbslider
├── css
│ └── lecture27.css
├── images
│ ├── active_bg.png
│ └── slides
│ │ ├── device-imac-thumb.png
│ │ ├── device-imac.png
│ │ ├── device-ipad-thumb.png
│ │ ├── device-ipad.png
│ │ ├── device-iphone-thumb.png
│ │ ├── device-iphone.png
│ │ ├── device-macbook-thumb.png
│ │ └── device-macbook.png
├── lecture27.html
└── scripts
│ └── lecture27.js
├── JavaScript quiz
├── css
│ └── lecture4.css
├── lecture3.html
├── lecture4.html
└── scripts
│ ├── lecture4.js
│ └── modernizr.js
├── README.md
├── jQuery YouTube API search
├── Notes about YouTube API
│ ├── Google-Developers-Console.png
│ ├── data items returned by GET request.png
│ ├── get YouTube API key Notes.txt
│ └── using the YouTube API.png
├── css
│ ├── fancybox_loading.gif
│ ├── fancybox_overlay.png
│ ├── fancybox_sprite.png
│ ├── jquery.fancybox.css
│ └── lecture12.css
├── lecture12.html
└── scripts
│ ├── jquery.fancybox.pack.js
│ ├── lecture12.js
│ ├── lecture12_backup.js
│ └── lecture12_backup_before_lightbox.js
├── jQuery accordion
├── css
│ └── lecture18.css
├── images
│ └── arrow.png
├── lecture18.html
└── scripts
│ └── lecture18.js
└── jQuery content slider
├── css
└── lecture9.css
├── images
├── arrow-left.png
├── arrow-right.png
├── slide1.jpg
├── slide2.jpg
├── slide3.jpg
├── slide4.jpg
├── slide5.jpg
├── slide6.jpg
└── slide7.jpg
├── lecture9.html
└── scripts
├── lecture9.js
└── lecture9_b.js
/Ajax PHP shoutbox/README.md:
--------------------------------------------------------------------------------
1 | #Notes on Project 5: Ajax PHP shoutbox
2 |
3 | In this project, I created a new MySQL database on a server, wrote a connection script, submitted a new row to the database via an HTML form, and also wrote to the live page (via jQuery) at the same time. When the page is reloaded, the full contents of the database are written to the page. Whenever the form is submitted, a new row is written to the db.
4 |
5 | Downloaded [XAMPP](https://www.apachefriends.org/index.html)
6 |
7 | Installed XAMPP - MySQL and PHP and server in one handy DMG. Nice.
8 |
9 | Go to Applications, open XAMPP folder.
10 | HTDOCS - "This is basically your Web server," says the instructor.
11 |
12 | His HTDOCS has a million things in it; mine has very few.
13 |
14 | 1. In HTDOCS, I made a new folder named **js_shoutbox** for this project.
15 |
16 | 2. Create these new files in that folder:
17 |
18 | - index.php
19 | - database.php (to connect to MySQL database)
20 | - shoutbox.php (to take the POST request and write to the db)
21 |
22 | 3. Create the usual folders for CSS and JS
23 |
24 | 4. In browser, open
25 |
26 | 5. Databases tab > Create database
27 | - name it **jsshoutbox**
28 | - > Create
29 |
30 | 6. Click database name (jsshoutbox)
31 | - Create table
32 | - name it **shouts**
33 | - Number of columns: 4
34 | - > Go
35 |
36 | 7. Create id field - INT - 11 (he says he likes 11, doesn't say why) - and
37 | Index: make it the PRIMARY field (scroll to the right, find **Index**)
38 |
39 | 8. Check box immediately following Index (**A_I**): this is auto-increment, will add new row after each insertion.
40 |
41 | 9. Fill other fieldnames: name (VARCHAR), shout (VARCHAR), date (TEXT)
42 |
43 | - Note: For date, he's not using the date options provided, so he selects TEXT as the type.
44 |
45 | None of these have an Index selected. Add char limits for each one.
46 |
47 | 10. SAVE the table.
48 |
49 | Leave phpmyadmin, and open index.php at
50 |
51 | ***
52 | Write HTML and CSS for index.php (includes a form).
53 |
54 | * index.php
55 | * lecture22.css
56 |
57 | ***
58 |
59 | ##CONNECT TO DATABASE
60 |
61 | database.php
62 |
63 | First, return to XAMPP and set a password.
64 |
65 | * localhost/xampp
66 | * Security (link on left side)
67 | * /Applications/XAMPP/xamppfiles/xampp security
68 |
69 | Well, that didn't work (Mac OS), so I searched and found:
70 |
71 |
72 |
73 | Open Terminal
74 |
75 | Paste:
76 |
77 | ```
78 | sudo /Applications/XAMPP/xamppfiles/xampp security
79 | ```
80 |
81 | It walks you through everything with no difficulty.
82 |
83 | 4 passwords set:
84 |
85 | * XAMPP pages
86 | * MySQL/phpMyAdmin user pma
87 | * MySQL root password
88 | * FTP password for user 'daemon'
89 |
90 | All good now.
91 |
92 |
93 | EDIT database.php
94 |
95 | $conn is just a normal PHP variable name
96 |
97 |
98 |
99 | Now add include to index.php (AT TOP, ABOVE DOCTYPE)
100 |
101 | ```
102 |
103 | ```
104 |
105 | You can test page now. Should not throw any errors.
106 |
107 | NOTE: If you force an error (by changing text in database.php), the error message will write at the top of the Web page.
108 |
109 | ***
110 |
111 | ##WRITE the jQuery
112 |
113 | lecture22.js
114 |
115 | 1. On submit, get all the values for all the vars.
116 | 2. Build the date from JavaScript new Date
117 | 3. Build the string to write to the MySQL database.
118 | 4. Use `$.ajax()` to send HTTP POST request
119 |
120 | Write many options.
121 |
122 | He adds a function to format the JavaScript date like a MySQL date.
123 | This seems unnecessary, since we told the database to treat the date field like plaintext, not like a date.
124 | (But the function might prove useful.)
125 |
126 | (At this point, our file shoutbox.php is still empty.)
127 |
128 | We fill in some dummy PHP to test it:
129 | ``
130 |
131 | Test. Good.
132 |
133 | In Chrome, use the console (Network tab) to see results (file list).
134 |
135 | ***
136 |
137 | ##WRITING the data
138 |
139 | shoutbox.php
140 |
141 | Add the same include AT TOP of file:
142 |
143 | ```
144 |
145 | ```
146 |
147 | Then all is wrapped in one PHP if-statement, with validation and
148 | error-checking, put the values passed by AJAX into the SQL database.
149 | And also write them to the UL in index.php. Which seems kind of
150 | stupid, since we could have just done that directly.
151 |
152 | Ah. He wants the full contents of the db to write into the shoutbox.
153 | Without the next step, each line writes. But when you reload, all
154 | lines disappear.
155 |
156 | To view contents of the db:
157 |
158 | *
159 | * Databases
160 | * jsshoutbox
161 | * Browse (near top)
162 |
163 | So, final steps:
164 |
165 | * Add more PHP to top of index.php to grab the stuff from the db.
166 | * It's a SQL call to the db, in the PHP.
167 | * Note it will get them in descending order by ID.
168 |
169 | Also in index.php, we write some PHP inside the UL to make the database contents write there.
170 |
171 | ##TRANSFER the project to Web hosting
172 |
173 | I had a new hosting company I haven't used for any databases yet, so I wanted to see if I could make this work there. I did, and it wasn't too hard.
174 |
175 | 1. Create a new MySQL database. My hosting company has a link just for this, separate from the CPanel. Name the db and create a new user to use it. Add that user to the database. This username and password should be different from the username/pw you use to log in at the hosting company's site.
176 |
177 | 2. Find out how to get into **phpMyAdmin** on your hosting service. If they have CPanel, it should be like this:
178 |
179 | - Database Tools >
180 | - phpMyAdmin (click to open it)
181 | - Log in again with your usual hosting service login and pw
182 |
183 | 3. Set up the new database -- this is the same as the steps at the beginning of this document. You have to create a table and make your four fieldnames. Make sure all the names are the same as in your original project so your code from the project will work without any changes.
184 |
185 | 4. **Edit the file database.php.** Remember, this is your connection script, so the PHP has to be changed to match your new db.
186 |
187 | ```
188 | $conn = mysqli_connect("localhost", "db_username", "db_password", "name_of_MySQL_database");
189 | ```
190 |
191 | You don't change "localhost," but you do change the rest to match the new database you just made.
192 |
193 | 5. Transfer your files. You can use any FTP program to do this (I like [FIleZilla](https://filezilla-project.org/)). You should use the exact same folder name as in your project, so you can just grab the whole folder and drag it over. Note that most hosting services will be set up to have your Web pages inside a folder named `public_html` that's already set up by them.
194 |
195 | 
196 |
197 | 
198 |
199 | (end)
200 |
--------------------------------------------------------------------------------
/Ajax PHP shoutbox/css/lecture22.css:
--------------------------------------------------------------------------------
1 | * {
2 | -moz-box-sizing: border-box;
3 | -webkit-box-sizing: border-box;
4 | box-sizing: border-box;
5 | margin: 0;
6 | padding: 0;
7 | }
8 |
9 | body {
10 | margin: 20px auto;
11 | background: #000;
12 | color: #fff;
13 | font-family: Verdana, sans-serif;
14 | font-size: 100%;
15 | line-height: 1.5em;
16 | }
17 |
18 | #container {
19 | width: 750px;
20 | margin: 0 auto;
21 | border: 1px solid #666;
22 | margin-top: 50px;
23 | }
24 |
25 | header {
26 | text-align: center;
27 | padding: 20px 0;
28 | background: #333;
29 | }
30 |
31 | h1 {
32 | font-weight: normal;
33 | font-size: 250%;
34 | }
35 |
36 | /* Shouts box */
37 |
38 | #shouts {
39 | padding: 30px;
40 | }
41 |
42 | ul {
43 | height: 300px;
44 | overflow: auto;
45 | padding: 20px;
46 | border: 1px solid #333;
47 | }
48 |
49 | ul li {
50 | list-style: none;
51 | line-height: 1.7em;
52 | }
53 |
54 | #inputs {
55 | background: #333;
56 | padding: 10px;
57 | text-align: center;
58 | }
59 |
60 | label {
61 | font-size: 110%;
62 | padding-right: 5px;
63 | }
64 |
65 | input[type='text'] {
66 | font-family: monospace;
67 | font-size: 120%;
68 | margin-right: 15px;
69 | width: 100px;
70 | height: 100%;
71 | }
72 |
73 | /* this is cool: style the input by id (weird syntax) */
74 | input#shout {
75 | width: 250px;
76 | }
77 |
78 | /* Submit button */
79 |
80 | input[type='submit'] {
81 | background: #c00;
82 | color: #fff;
83 | font-weight: bold;
84 | font-size: 140%;
85 | border: 0;
86 | padding: 7px 15px;
87 | cursor: pointer;
88 | height: 100%;
89 | }
90 |
91 | input[type='submit']:hover {
92 | background: #f00;
93 | }
94 |
95 | input[type='submit']:focus {
96 | outline: none;
97 | }
98 |
--------------------------------------------------------------------------------
/Ajax PHP shoutbox/database.php:
--------------------------------------------------------------------------------
1 |
15 |
--------------------------------------------------------------------------------
/Ajax PHP shoutbox/index.php:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 | Project 5 JS Shoutbox
11 |
12 |
13 |
14 |
15 |
16 |
17 |
A thumbnail menu below displays large images in the main window.
16 | Horizontal sliding action.
17 |
18 |
19 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
45 |
46 |
47 |
48 |
49 |
50 |
The autoplay function on this took me a while to figure out. It was not well explained in the tutorial. But it's pretty cool. Once you click any thumbnail, the autoplay quits, and I have not included a means to restart it. I changed a lot of the CSS in the tutorial and really simplified the HTML a lot (took out a lot of DIVs), so I don't know if this will break in browsers other than mine.
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/Apple Style Thumbslider/scripts/lecture27.js:
--------------------------------------------------------------------------------
1 | $(document).ready(function(){
2 | // ----------------------------------------------------------------------------
3 |
4 | var totalWidth = 0;
5 | var positions = new Array();
6 |
7 | // put gray bg in first LI (behind thumbnail image)
8 | $('#thumbs ul li').first().addClass('active');
9 |
10 | // build an array containing the left edge position of each big image
11 | // loop through all slides
12 | $('#slides .slide').each(function(i) {
13 | positions[i] = totalWidth;
14 | totalWidth += $(this).width();
15 |
16 | if (!$(this).width()) {
17 | alert("Please add a width to your images.");
18 | return false;
19 | }
20 | // console.log(positions);
21 | // [0, 900, 1800, 2700] now we know where each slide starts
22 | });
23 |
24 | // set width of slides container to the total of all slides' widths
25 | $('#slides').width(totalWidth);
26 |
27 | // click event handler for the thumbnails:
28 | // the 2 args, 'e' and 'keepScrolling,' are only nec. b/c of the autoscroll
29 | // function at bottom. If we remove autoscroll() we do not need the args.
30 | // NOTE: 'e' will be 'click' event in either case.
31 | $('#thumbs ul li img').click(function(e, keepScrolling) {
32 |
33 | // the .active class adds a gray background on the thumbnail
34 | // remove .active class from all LIs
35 | $('#thumbs ul li').removeClass('active');
36 | // add .active class to current LI
37 | $(this).parent().addClass('active');
38 |
39 | // find out how many LIs are before this one --
40 | // returns 0 for first item, 1 for second, etc. (nice!)
41 | // use pos to associate thumb clicked with position number in array
42 | var pos = $(this).parent().prevAll().length;
43 | // console.log(pos); // works
44 |
45 | // the .prevAll() method searches through the predecessors of
46 | // these elements in the DOM tree and constructs a new jQuery object
47 | // from the matching elements; the elements are returned in order
48 | // beginning with the closest sibling.
49 |
50 | $('#slides').stop().animate(
51 | {
52 | marginLeft:-positions[pos]+'px'
53 | }, 450);
54 | // 450 is the speed.
55 | // at this point, the slider already works.
56 | // I don't get why stop() comes first here, before animate --
57 | // stop() should work on a currently running animation --
58 | // but this works! Nicely!
59 |
60 | // if click was NOT triggered by autoscroll() function, stop autoplay
61 | // ('keepScrolling' will = '' if you manually clicked a thumbnail --
62 | // then it would be false)
63 | if (!keepScrolling) clearInterval(doAutoscroll);
64 | // this was done wrong in the original tutorial, so autoplay never stopped
65 |
66 | });
67 |
68 |
69 | // autoplay function
70 | // $('#thumbs ul li img') is the set of all img objects in that UL.
71 | // .eq() "reduces the set of matched elements to the one at the
72 | // specified index," i.e. img[0], or img[1], etc.
73 | // this is brilliant: dividing by the length of the array always
74 | // yields remainders that match the set elements, in order, no matter
75 | // how long the function runs.
76 | // Example: 98 % 4 = 2, 99 % 4 = 3, 100 % 4 = 0 ...
77 | var current = 1;
78 | function autoscroll() {
79 | if (current == -1) return false; // if NaN
80 | $('#thumbs ul li img').eq(current % $('#thumbs ul li img').length)
81 | .trigger('click', [true]);
82 | // this [true] will be passed in as arg/param 'keepScrolling'
83 | current++;
84 | // console.log(current % $('#thumbs ul li img').length);
85 | // this cycles 2, 3, 0, 1, 2, 3, 0 ...
86 | // 3 % 4 = 3 (remainder 3; modulus is integers only)
87 | // 4 & 4 = 0
88 | // 5 % 4 = 1 ... etc.
89 | }
90 |
91 |
92 | var doAutoscroll = setInterval(autoscroll, 2000);
93 | // remember how setInterval and clearInterval work: we cannot clear
94 | // unless we have a var. Also, no () in function name here.
95 | // 2000 is milliseconds, the length of the interval (the pause
96 | // before re-running the function)
97 |
98 | // ----------------------------------------------------------------------------
99 | });
100 |
--------------------------------------------------------------------------------
/JavaScript quiz/css/lecture4.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 20px auto;
3 | padding: 0;
4 | background: #2A7510;
5 | color: #000;
6 | font-family: Verdana, sans-serif;
7 | font-size: 100%;
8 | line-height: 1.5em;
9 | }
10 |
11 | #wrapper {
12 | background: #B2E3A1;
13 | width: 900px;
14 | margin: 0 auto;
15 | }
16 |
17 | header {
18 | text-align: center;
19 | border-bottom: dashed 1px #fff;
20 | padding-top: 20px;
21 | }
22 |
23 | #results p {
24 | background: #fff;
25 | padding: 10px;
26 | margin: 10px 0;
27 | }
28 |
29 | section {
30 | padding: 10%;
31 | padding-top: 0;
32 | }
33 |
34 | h1 {
35 | font: normal 4em/1em Georgia, serif;
36 | margin: 10px 0;
37 | }
38 |
39 | header p {
40 | font-size: 130%;
41 | }
42 |
43 | .question {
44 | font-size: 120%;
45 | font-weight: bold;
46 | }
47 |
48 | /* Submit Answers button */
49 |
50 | input[type='submit'] {
51 | background: #2A7510;
52 | color: #fff;
53 | font-weight: bold;
54 | font-size: 150%;
55 | border: 0;
56 | padding: 10px 15px;
57 | cursor: pointer;
58 | }
59 |
60 | input[type='submit']:hover {
61 | background: #3AA116;
62 | }
63 |
64 | input[type='submit']:focus {
65 | outline: none;
66 | }
67 |
68 | /* add some space to right of each radio button */
69 |
70 | input[type='radio'] {
71 | margin-right: 10px;
72 | }
73 |
--------------------------------------------------------------------------------
/JavaScript quiz/lecture3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JavaScript Section 2 Lecture 3
6 |
7 |
60 |
61 |
62 |
63 |
64 |
JavaScript Section 2 Lecture 3
65 |
66 |
67 |
alert()
68 |
variables (var keyword)
69 |
if-else if-else
70 |
arrays
71 |
for loop
72 |
functions
73 |
74 |
75 |
Make sure you've opened View > Developer > JavaScript Console in Chrome.
').appendTo("body"),b=a.children(),b=b.innerWidth()-b.height(99).innerWidth();a.remove();return b});f.support.fixedPosition===w&&(f.support.fixedPosition=function(){var a=f('').appendTo("body"),
46 | b=20===a[0].offsetTop||15===a[0].offsetTop;a.remove();return b}());f.extend(b.defaults,{scrollbarWidth:f.scrollbarWidth(),fixed:f.support.fixedPosition,parent:f("body")});a=f(s).width();K.addClass("fancybox-lock-test");d=f(s).width();K.removeClass("fancybox-lock-test");f("").appendTo("head")})})(window,document,jQuery);
--------------------------------------------------------------------------------
/jQuery YouTube API search/scripts/lecture12.js:
--------------------------------------------------------------------------------
1 | $(function(){
2 | $('#search-form').submit(function(e) {
3 | e.preventDefault();
4 | });
5 | })
6 | // I don't get why this is needed -- isn't GET actually submitting
7 | // the form? It seems like by using preventDefault() we would be
8 | // preventing the GET request! But script doesn't work w/o it.
9 |
10 |
11 | // I added two args (they are blank if you use the search form)
12 | // so that same function can be used for paging instead of copying
13 | // all the code TWICE into the Prev and Next Page functions.
14 | // Seems to work fine.
15 | function search(token, q) {
16 | // clear the containers we already have in HTML
17 | $('#results').html('');
18 | $('#buttons').html('');
19 |
20 | // grab the form field input
21 | // I added the if-test to streamline Prev and Next Page functions
22 | if (!q) {
23 | q = $('#query').val(); // id of the search input field in HTML
24 | }
25 |
26 | // send GET request to the API (jQuery method)
27 | // the URL for GET came from:
28 | // https://developers.google.com/youtube/v3/docs/search/list
29 | // also the options, such as part and q, come from there (long list)
30 | $.get(
31 | "https://www.googleapis.com/youtube/v3/search",{ // URL for GET
32 | part: 'snippet, id',
33 | q: q,
34 | pageToken: token,
35 | type: 'video',
36 | key: 'AIzaSyCH0i8znvwIBCWC_nZgFr8rmaUOW6AH1Hs' // my own key
37 | },
38 | function(data){ // see below re: "data"
39 | var nextPageToken = data.nextPageToken;
40 | var prevPageToken = data.prevPageToken;
41 | // nextPageToken and prevPageToken are supplied by YouTube
42 | // and will allow us to retrieve the next set of results
43 |
44 | // log data
45 | console.log(data);
46 | // "data" contains all the data sent from YouTube API.
47 | // By logging it, we can see that, and we can open the
48 | // "snippet" in the Console and see title, descrip, etc.
49 | // for each video (see http://api.jquery.com/jquery.get/
50 | // for origin of "data")
51 |
52 | $.each(data.items, function(i, item) {
53 | // get HTML output; see below for the function
54 | var output = getOutput(item);
55 |
56 | // display results on HTML page
57 | // output comes from getOutput() below
58 | $('#results').append(output);
59 | });
60 |
61 | var buttons = getButtons(prevPageToken, nextPageToken, q);
62 | // create two buttons in HTML; see below for the function
63 | // buttons comes from getButtons() below
64 | $('#buttons').append(buttons);
65 |
66 | }
67 | ); // end .get() method
68 | } // end search function
69 |
70 |
71 | // Prev and Next Page functions
72 | // in the tute, the guy COPIED all the search() code and repeated it
73 | // in EACH page function -- NUTS. So instead I pass the new vars into
74 | // the search() function
75 | function prevPage() {
76 | var token = $('#prev-button').data('token');
77 | var q = $('#prev-button').data('query');
78 | // above does not exist in HTML; is written by getButtons() below
79 | search(token, q);
80 | }
81 |
82 | function nextPage() {
83 | var token = $('#next-button').data('token');
84 | var q = $('#next-button').data('query');
85 | // above does not exist in HTML; is written by getButtons() below
86 | search(token, q);
87 | }
88 |
89 |
90 | // build the output to be displayed in our HTML
91 | function getOutput(item) {
92 |
93 | // the guy in the tutorial is not clear about this at all. See:
94 | // PNG "data items returned by GET request.png" (my file).
95 | // You can dig into the data via the console and find these
96 | // parameter names that way: Object > Items > 0-5 > id, snippet
97 | var videoId = item.id.videoId;
98 | var title = item.snippet.title;
99 | var description = item.snippet.description;
100 | var thumb = item.snippet.thumbnails.medium.url;
101 | var channelTitle = item.snippet.channelTitle;
102 | // sometimes this is empty
103 | var videoDate = item.snippet.publishedAt;
104 |
105 | // build output string with HTML for one video
106 | // we're building two divs to float left & right inside a single
107 | // all styled in the CSS
108 | var output = '
' +
120 | '' +
121 | '';
122 |
123 | return output;
124 | }
125 |
126 |
127 | // build the buttons to be displayed in our HTML
128 | // I also rewrote this function to get rid of redundancy
129 | function getButtons(prevPageToken, nextPageToken, q) {
130 | var prevButton = '';
133 |
134 | var nextButton = '';
137 |
138 | if(!prevPageToken){
139 | var buttonOutput = '
' +
140 | nextButton + '
';
141 | // probably should add if-not-nextPageToken but not going to
142 | // they might go on forever anyway
143 | } else {
144 | var buttonOutput = '
' +
145 | prevButton + ' ' +nextButton+ '
';
146 | }
147 |
148 | return buttonOutput;
149 | }
150 |
--------------------------------------------------------------------------------
/jQuery YouTube API search/scripts/lecture12_backup.js:
--------------------------------------------------------------------------------
1 | $(function(){
2 | $('#search-form').submit(function(e) {
3 | e.preventDefault();
4 | });
5 | })
6 | // I don't get why this is needed -- isn't GET actually submitting
7 | // the form? It seems like by using preventDefault() we would be
8 | // preventing the GET request! But this doesn't work w/o it.
9 |
10 |
11 | function search() {
12 | // clear the containers we already have in HTML
13 | $('#results').html('');
14 | $('#buttons').html('');
15 |
16 | // grab the form field input
17 | q = $('#query').val(); // id of the search input field in HTML
18 |
19 | // send GET request to the API (jQuery method)
20 | // the URL for GET came from:
21 | // https://developers.google.com/youtube/v3/docs/search/list
22 | // also the options, such as part and q, come from there (long list)
23 | $.get(
24 | "https://www.googleapis.com/youtube/v3/search",{ // URL for GET
25 | part: 'snippet, id',
26 | q: q,
27 | type: 'video',
28 | key: 'AIzaSyCH0i8znvwIBCWC_nZgFr8rmaUOW6AH1Hs' // my own key
29 | },
30 | function(data){ // see below re: "data"
31 | var nextPageToken = data.nextPageToken;
32 | var prevPageToken = data.prevPageToken;
33 | // nextPageToken and prevPageToken are supplied by YouTube
34 | // and will allow us to retrieve the next set of results
35 |
36 | // log data
37 | console.log(data);
38 | // "data" contains all the data sent from YouTube API
39 | // by logging it, we can see that, and we can open the
40 | // "snippet" in the Console and see title, descrip, etc.
41 | // for each video (see http://api.jquery.com/jquery.get/
42 | // for origin of "data")
43 |
44 | $.each(data.items, function(i, item) {
45 | // get output
46 | var output = getOutput(item);
47 |
48 | // display results on HTML page
49 | $('#results').append(output);
50 | });
51 |
52 | }
53 | ); // end .get() method
54 | } // end search function
55 |
56 |
--------------------------------------------------------------------------------
/jQuery YouTube API search/scripts/lecture12_backup_before_lightbox.js:
--------------------------------------------------------------------------------
1 | $(function(){
2 | $('#search-form').submit(function(e) {
3 | e.preventDefault();
4 | });
5 | })
6 | // I don't get why this is needed -- isn't GET actually submitting
7 | // the form? It seems like by using preventDefault() we would be
8 | // preventing the GET request! But script doesn't work w/o it.
9 |
10 |
11 | // I added two args (they are blank if you use the search form
12 | // so that same function can be used for paging instead of copying
13 | // all the code TWICE into the Prev and Next Page functions.
14 | // Seems to work fine.
15 | function search(token, q) {
16 | // clear the containers we already have in HTML
17 | $('#results').html('');
18 | $('#buttons').html('');
19 |
20 | // grab the form field input
21 | // I added the if-test to streamline Prev and Next Page functions
22 | if (!q) {
23 | q = $('#query').val(); // id of the search input field in HTML
24 | }
25 |
26 | // send GET request to the API (jQuery method)
27 | // the URL for GET came from:
28 | // https://developers.google.com/youtube/v3/docs/search/list
29 | // also the options, such as part and q, come from there (long list)
30 | $.get(
31 | "https://www.googleapis.com/youtube/v3/search",{ // URL for GET
32 | part: 'snippet, id',
33 | q: q,
34 | pageToken: token,
35 | type: 'video',
36 | key: 'AIzaSyCH0i8znvwIBCWC_nZgFr8rmaUOW6AH1Hs' // my own key
37 | },
38 | function(data){ // see below re: "data"
39 | var nextPageToken = data.nextPageToken;
40 | var prevPageToken = data.prevPageToken;
41 | // nextPageToken and prevPageToken are supplied by YouTube
42 | // and will allow us to retrieve the next set of results
43 |
44 | // log data
45 | console.log(data);
46 | // "data" contains all the data sent from YouTube API.
47 | // By logging it, we can see that, and we can open the
48 | // "snippet" in the Console and see title, descrip, etc.
49 | // for each video (see http://api.jquery.com/jquery.get/
50 | // for origin of "data")
51 |
52 | $.each(data.items, function(i, item) {
53 | // get HTML output; see below for the function
54 | var output = getOutput(item);
55 |
56 | // display results on HTML page
57 | // output comes from getOutput() below
58 | $('#results').append(output);
59 | });
60 |
61 | var buttons = getButtons(prevPageToken, nextPageToken, q);
62 | // create two buttons in HTML; see below for the function
63 | // buttons comes from getButtons() below
64 | $('#buttons').append(buttons);
65 |
66 | }
67 | ); // end .get() method
68 | } // end search function
69 |
70 |
71 | // Prev and Next Page functions
72 | // in the tute, the guy COPIED all the search() code and repeated it
73 | // in EACH page function -- NUTS. So instead I pass the new vars into
74 | // the search() function
75 | function prevPage() {
76 | var token = $('#prev-button').data('token');
77 | var q = $('#prev-button').data('query');
78 | // above does not exist in HTML; is written by getButtons() below
79 | search(token, q);
80 | }
81 |
82 | function nextPage() {
83 | var token = $('#next-button').data('token');
84 | var q = $('#next-button').data('query');
85 | // above does not exist in HTML; is written by getButtons() below
86 | search(token, q);
87 | }
88 |
89 |
90 | // build the output to be displayed in our HTML
91 | function getOutput(item) {
92 |
93 | // the guy in the tutorial is not clear about this at all. See:
94 | // PNG "data items returned by GET request.png" (my file).
95 | // You can dig into the data via the console and find these
96 | // parameter names that way: Object > Items > 0-5 > id, snippet
97 | var videoId = item.id.videoId;
98 | var title = item.snippet.title;
99 | var description = item.snippet.description;
100 | var thumb = item.snippet.thumbnails.medium.url;
101 | var channelTitle = item.snippet.channelTitle;
102 | // sometimes this is empty
103 | var videoDate = item.snippet.publishedAt;
104 |
105 | // build output string with HTML for one video
106 | // we're building two divs to float left & right inside a single
107 | // all styled in the CSS
108 | var output = '
' +
109 | '
' +
110 | '' +
111 | '
' +
112 | '
' +
113 | '
' +title+ '
' +
114 | '
By ' +channelTitle+ ' on ' +videoDate+ '
' +
115 | '
' +description+ '
' +
116 | '
' +
117 | '
' +
118 | '' +
119 | '';
120 |
121 | return output;
122 | }
123 |
124 |
125 | // build the buttons to be displayed in our HTML
126 | function getButtons(prevPageToken, nextPageToken, q) {
127 | var prevButton = '';
130 |
131 | var nextButton = '';
134 |
135 | if(!prevPageToken){
136 | var buttonOutput = '
' +
137 | nextButton + '
';
138 | // probably should add if-not-nextPageToken but not going to
139 | } else {
140 | var buttonOutput = '
There are 10 nations in the Association of Southeast Asian Nations (ASEAN): Brunei, Cambodia, Indonesia, Laos, Malaysia, Myanmar (Burma), the Philippines, Singapore, Thailand, and Vietnam.
24 |
25 |
Which languages are spoken in Southeast Asia?
26 |
There are many more languages than nations. In Brunei, Malaysia, and Indonesia, the primary language is similar (Bahasa Indonesia and Bahasa Malaysia), but there are literally hundreds of languages spoken throughout the archipelago of Indonesia. Mandarin Chinese and other Chinese languages are spoken throughout Malaysia and Singapore, as well as several Indian languages. Filipino (Tagalog) and English are spoken in the Philippines. Cambodia, Laos, Myanmar (Burma), Thailand, and Vietnam each have their own national languages, and of those, only Vietnam uses the Latin alphabet.
27 |
28 |
What is the religion of Southeast Asia?
29 |
Various religions are practiced throughout the region. Brunei, Indonesia, and Malaysia are majority Muslim, with Indonesia being the largest Muslim nation in the world. Cambodia, Laos, Myanmar (Burma), and Thailand are majority Buddhist. In Vietnam, under a communist government, many people might not admit to practicing a religion, but there are plenty of Buddhist temples and Roman Catholic churches. The Philippines is mostly Roman Catholic. In Singapore, you'll find a mix of Buddhists, Muslims, Taoists, Roman Catholics, and Hindus.
30 |
31 |
What foreign influences have shaped Southeast Asia?
32 |
Before the 12th century CE, Indian culture and religion played a large role in many countries of the region. Chinese traders traveled by land and sea far to to west, carrying with them cuisine, building techniques, business practices. Arab traders also came in large numbers and even settled in the coastal areas. Much later, the Portuguese, Dutch, Spanish, and British came in search of spices and other trade goods. The French came later still, making colonies of Vietnam, Cambodia, and Laos.
33 |
34 |
What are the forms of government in Southeast Asia?
35 |
Thailand (which never was colonized by a European power) still has a king and an elected legislature, although there was a military coup in 2014. Cambodia is also a constitutional monarchy. Malaysia is nominally a democracy and also maintains a system of regional hereditary rulers (sultans), one of whom serves as king. Brunei is ruled by the sultan. Laos and Vietnam are communist states. Myanmar (Burma) has had a parliamentary government since 2011, after years of rule by a military junta. The Philippines and Indonesia are republics, headed by a president. Singapore is a parliamentary republic.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae commodo sem. Integer eros nibh, molestie congue elementum quis, mattis nec tortor. Vivamus sed hendrerit sed vitae orci convallis.
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
Slider Two
34 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae commodo sem. Integer eros nibh, molestie congue elementum quis, mattis nec tortor. Vivamus sed hendrerit sed vitae orci convallis.
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
Slider Three
43 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae commodo sem. Integer eros nibh, molestie congue elementum quis, mattis nec tortor. Vivamus sed hendrerit sed vitae orci convallis.
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
Slider Four
52 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae commodo sem. Integer eros nibh, molestie congue elementum quis, mattis nec tortor. Vivamus sed hendrerit sed vitae orci convallis.
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
Slider Five
61 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae commodo sem. Integer eros nibh, molestie congue elementum quis, mattis nec tortor. Vivamus sed hendrerit sed vitae orci convallis.
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/jQuery content slider/scripts/lecture9.js:
--------------------------------------------------------------------------------
1 | $(document).ready(function() { // do not delete
2 | // ----------------------------------------------------------------------------
3 |
4 | // simple content slider with no auto-play options
5 |
6 | // slider options
7 | var speed = 500; // fade speed, in milliseconds
8 |
9 | // add active class to first slide
10 | $('.slide').first().addClass('active');
11 |
12 | // hide all slides
13 | $('.slide').hide();
14 |
15 | // show first slide
16 | $('.active').show();
17 |
18 | // click action event handlers (next and prev)
19 | $('#next').on('click', function() {
20 | $('.active').removeClass('active').addClass('oldActive');
21 | // check to see if we have reached the final slide
22 | if ($('.oldActive').is(':last-child')) {
23 | $('.slide').first().addClass('active');
24 | } else {
25 | $('.oldActive').next().addClass('active');
26 | }
27 | $('.oldActive').removeClass('oldActive');
28 | $('.slide').fadeOut(speed);
29 | $('.active').fadeIn(speed);
30 | });
31 |
32 | $('#prev').on('click', function() {
33 | $('.active').removeClass('active').addClass('oldActive');
34 | // check to see if we are on the first slide
35 | if ($('.oldActive').is(':first-child')) {
36 | $('.slide').last().addClass('active');
37 | } else {
38 | $('.oldActive').prev().addClass('active');
39 | }
40 | $('.oldActive').removeClass('oldActive');
41 | $('.slide').fadeOut(speed);
42 | $('.active').fadeIn(speed);
43 | });
44 |
45 |
46 | // ----------------------------------------------------------------------------
47 | });
48 |
--------------------------------------------------------------------------------
/jQuery content slider/scripts/lecture9_b.js:
--------------------------------------------------------------------------------
1 | $(document).ready(function() { // do not delete
2 | // ----------------------------------------------------------------------------
3 |
4 | // content slider with auto-play options - setInterval() and clearInterval()
5 | // note: does not include ability to restart auto-play
6 | // auto-play simply ceases if you click Prev or Next arrows
7 |
8 | // slider options
9 | var speed = 500; // fade speed, in milliseconds
10 | var autoswitch = true; // auto-play on
11 | var autoswitchSpeed = 3000; // sliding speed
12 |
13 | // add active class to first slide
14 | $('.slide').first().addClass('active');
15 |
16 | // hide all slides
17 | $('.slide').hide();
18 |
19 | // show first slide
20 | $('.active').show();
21 |
22 | // click action event handlers - now they call named functions
23 | $('#next').on('click', function() {
24 | clearInterval(autoplay); // stops slider auto-playing
25 | nextSlide();
26 | });
27 | $('#prev').on('click', prevSlide);
28 |
29 | // start auto-playing
30 | if (autoswitch) {
31 | var autoplay = setInterval(nextSlide, autoswitchSpeed);
32 | }
33 |
34 | function nextSlide() {
35 | $('.active').removeClass('active').addClass('oldActive');
36 | // check to see if we have reached the final slide
37 | if ($('.oldActive').is(':last-child')) {
38 | $('.slide').first().addClass('active');
39 | } else {
40 | $('.oldActive').next().addClass('active');
41 | }
42 | $('.oldActive').removeClass('oldActive');
43 | $('.slide').fadeOut(speed);
44 | $('.active').fadeIn(speed);
45 | }
46 |
47 | function prevSlide() {
48 | clearInterval(autoplay);
49 | $('.active').removeClass('active').addClass('oldActive');
50 | // check to see if we are on the first slide
51 | if ($('.oldActive').is(':first-child')) {
52 | $('.slide').last().addClass('active');
53 | } else {
54 | $('.oldActive').prev().addClass('active');
55 | }
56 | $('.oldActive').removeClass('oldActive');
57 | $('.slide').fadeOut(speed);
58 | $('.active').fadeIn(speed);
59 | }
60 |
61 | // ----------------------------------------------------------------------------
62 | });
63 |
--------------------------------------------------------------------------------