twittler Flashcards

1
Q

What are the main functions / event-handlers / operations you will need to implement and perform?

A
  1. Refresh/Display Tweets (whether all or individual user’s)
  2. Username Event-Handler: click on username –> view that user’s tweets
  3. ViewAllTweets Event-Handler: click on ViewAll button –> view all tweets
  4. SubmitTweet Event-Handler: click on Submit button –> adds message tweet to array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

For each tweet - What are we trying to accomplish?

A

Store the current tweet

var tweet = current_stream[index]

Each individual tweet will have component parts (msg, username, timestamp), each part is worthy of its own DOM node/HTML element…

  1. Create the DOM node/HTML element to house the content for each part (along with an identifying class). Store each one in a jQuery object
  2. Fill the DOM node/jQuery object with appropriate content using .text()-method
  3. Insert the jQuery object into appropriate DOM location using .prependTo() or .appendTo()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

DOM: What to do for each tweet?

A

Store in a jQuery variable

var $tweet =

Create appropriate DOM node (to house the entire tweet and its other component parts - tweet, timetsamp, username)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What to do w/ the TWEET jQuery object?

A

Fill it, using the text() method, with the tweet’s message

$tweet.text(tweet.message);

-basically filling the tweet-DIV with the message

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

So have a text-message in a div (have content in the jQuery object)–> What to do with that div?

A

Insert the tweet-jQuery-object into the main tweet display

$tweet.prependTo($(‘#tweets’));

// content.prependTo(targetContainer)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

DOM: What to do for the username?

A

Store in a jQuery variable

var $tweetuser =

Create the appropriate DOM element w/ class to house the username

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What to do w/ the USERNAME jQuery object?

A

Fill it with the tweet’s username

$tweetuser.text(tweet.user + “: “);

-basically filling the username-SPAN with the username

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

So have apropriate username text in the $tweetuser object () –> What to do with the object?

A

Insert into the div that houses the entire tweet

$tweetuser.prependTo($tweet);

// content.prependTo(targetContainer)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

DOM: What to do for the timestamp?

A

Store in a variable

$tweetTimestamp =

Create a DOM element w/ a class to house the timestamp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What to do w/ the TIMESTAMP jQuery object?

A

Fill it with the timestamp info

$tweetTimestamp.text(“Tweeted “ + $.timeago(tweet.created_at));

-basically filling the timeStamp-DIV with the timestamp info

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

So have timestamp text in the appropriate DOM node / jQuery object –> What to do with that object?

A

Insert into (or at the end of) the tweet-object

$tweet_timestamp.appendTo($tweet);

// content.appendTo(targetContainer)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to make each tweet’s username-DOM-element correspond with the actual user who created the tweet?

A

Take the [tweetuser (DOM element/jQuery object)] and set its #id to the username.

$tweetuser.attr(‘id’, tweet.user);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

*What do you need the user-EH to do, step by step? Upon clicking the user’s name…

A
  1. Prevent bubbling
  2. Return the id of the closest span element, which should be the username.
    1. Set to a variable currentUser
  3. Use that variable as the property name of the streams.users object. The property will contain an array of that user’s tweets.
    1. Set to the already-initiated variable currentStream (which is used by the *initiateTweet *display function)
  4. Display the viewAll button
  5. Hide the inputBox and submitButton
  6. Execute the initiateTweet function to display the tweets (in this case, the user’s tweets only)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to implement the user-EH?

A

When clicking on [tweetDisplay DIV - particular SPAN-named-class]…

$(“#tweetDisplay”).on(“click”, “.user”, function(event) {

Prevent the screen from bubbling up

event.preventDefault();

Find & store the id of that SPAN - should be the username

var currentUser = $(this).closest(“span”).attr(“id”);

Set the currentStream to be that user’s stream

currentStream = streams.users[currentUser];

Display the viewAll-Button

$(“#viewAll”).css(“display”, “block”);

Hide the inputBox & submitButton

$(“#userTweet, #submitTweet).hide();

Display the stream of tweets (for current user)

initiateTweets();

});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What do you need the viewAll-EH to do, step by step? Upon clicking the “View All” Button..

A
  1. Set the currentStream variable back to streams.home
  2. Hide the viewAll-button
  3. Refresh and display the tweets (now set to all tweets) using initiateTweets
  4. Show the inputBox and submitButton
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to implement the viewAll-EH?

A

When the viewAll-button is clicked…

$(“#viewAll”).on(“click”, function() {

set the currentStream (used by display) back to streams.home

currentStream = streams.home;

hide the viewAll-button

$(“#viewAll”).hide();

refresh and display the tweets (will display all tweets now)

initiateTweets();

show the inputBox and submitBox

$(“#userTweet, #submitTweet”).show();

});

17
Q

What do you need to do to implement submitTweet-EH, step by step? Upon clicking the “SubmitTweet” button…

A
  1. Retrieve the message inputted by the user
  2. if no msg is inputted –> error msg
  3. if yes msg is inputted –> execute the writeTweet function with the msg as an argument and then reset the inputbox to blank
18
Q

How to implement the submitTweet-EH?

A

Upon clicking the submitTweet button…

$(“submitTweet”).on(“click”, function(event) {

Take the input from the inputBox and store in variable msg

var msg = $(“#userTweet”).val();

if no inputted msg…

if (msg = null || msg = “”) {

provide a warning msg

alert(“Input something foo!”);

return false;

otherwise, if user did input a msg…

} else {

execute writeTweet, with inputted msg as argument

writeTweet(msg.slice(0, 160));

clear the input box

$(“#userTweet”).val(“”);

}

});