NFL Week 12 betting guide: Odds, key matchups, stats & trends, injury report for every game
by Sportsbook ReviewNow that week 11 is in the books, we look straight ahead towards the upcoming week’s NFL odds board, a veritable 14-game buffet of pivotal matchups for NFL bettors to sink their teeth into.
MORE: Get the latest NFL odds & betting advice at Sportsbook Review
Houston Texans kick off the week with a Thursday Night showdown against the Indianapolis Colts, all the while looking to bounce back from a let-down performance against the Ravens. Sunday serves up several intriguing matchups, none more so than the blockbuster showdown between the Packers and Niners at Levi’s Stadium; and rounding out the NFL betting action is a Monday Night showdown between the Baltimore Ravens and Los Angeles Rams.
In this column, we analyze each and every game in the context of the NFL odds, all the while sifting through various NFL betting stats and trends, and much, much more.
Indianapolis Colts vs. Houston Texans
- Thursday, Nov. 21, 2019, 8:20 p.m. ET
- NRG Stadium, Houston
- TV Broadcast: FOX/ NFL
- Opening NFL Line: Texans -3.5 / 46.5
- Season Record: Colts (6-4-0) vs Texans (6-4-0)
The Texans will look to bounce back in week 12 against the Colts at the NRG Stadium after getting a right spanking in Baltimore by Lamar Jackson and the Ravens. Deshaun Watson and the Texans et al simply failed to show up and went on to lose 41-7.
The Colts, meanwhile, put in a solid 33-13 win over the Jacksonville Jaguars. When the main talking point ahead of the game was the return of Nick Foles to the Jaguars’ lineup, Jacoby Brissett made absolutely sure he was the main talking point in the postscript. Subtly reminding all and sundry – especially those in the AFC South field – who the new boss in the hood really is.
Both the Colts and Texans are on a level at 6-4 in the AFC South standings, but the Colts have the head-to-head edge having won the first meeting 30-23 at Lucas Oil Stadium. (The Colts with Andy Luck as their signal-caller also beat the Texans in the playoffs last season).
Deshaun Watson and the Texans are better than their week 11 result in Baltimore would suggest. Bookmakers opened with the Texans giving up 3.5 points to the Colts on the NFL odds board, and early public betting appears to be pushing the needle in Houston’s favor (several sportsbooks are already hanging Texans on a 4-point spread).
If you’re giving the Colts a nod on your NFL picks, grab the points now while you can. By all accounts, this should be a close affair, and with increasing betting volume this NFL line is likely to swing back down again by kick-off. By that same token, for those that are down with the Texans then wait it out. Closer to kick-off you may be able to get a lower number, potentially even the key field goal number.
NFL Betting Trends:
- Colts are 5-4-1 ATS in their last 10 games
- Colts are 6-1 SU in their last 7 games against Texans
- Texans are 9-3 SU in their last 12 games at home
- The total has gone UNDER in 7 of Houston’s last 8 games at home
Key Injuries:
IND – WR T.Y. Hilton (Calf), T Anthony Castonzo (Toe), TE Eric Ebron (Ankle), S George Odum (Shoulder), CB Shakial Taylor (Ankle), TE Mo Alie-Cox (Thumb), CB Kenny Moore II (Shin), CB Rock Ya-Sin (Ankle) are all listed as questionable for TNF; RB Marlon Mack (Hand) is out indefinitely; S Khari Willis (Concussion) is out for TNF.
HOU – QB Deshaun Watson (Ankle) is listed as probable for TNF; LB Dylan Cole (Knee), Tashaun Gipson Sr. (Back), G Tytus Howard (Knee), CB Lonnie Johnson Jr. (Foot), S Justin Reid (Concussion) and S Mike Adams (Concussion) are all listed as questionable for TNF.
MORE: Follow the latest betting trends for Colts vs. Texans
Tampa Bay Buccaneers vs. Atlanta Falcons
- Sunday, Nov. 24, 2019, 1 p.m. ET
- Mercedes Benz Stadium, Atlanta
- TV Broadcast FOX
- Opening NFL Line: Falcons -4 / 54
- Season Record: Buccaneers (3-7-0) vs Falcons (3-7-0)
The Atlanta Falcons must have undergone some sort of revolutionary identity transplant because they’re unrecognizable since coming out of their week 9 bye. Indeed, the last two weeks are exactly what many thought they’d see from the Falcons and why Atlanta was tipped in preseason NFL betting markets by many experts as a sleeper NFL pick to spot.
At 3-7 SU it might be a little bit too late for the Dirty Birds as far as the postseason goes, but if the Falcons keep this up they just might salvage some respect by season end. What about that defense? In the last two games, they’ve held opponents to 12 points combined. Divisional opponents, mind you.
If this trend continues, the 3-7 SU Bucs are in for an excruciating trip to Atlanta. Well, the Bucs can be counted on making things excruciatingly difficult for themselves. They don’t need much help on that score, particularly Jameis Winston who continues to turnover the ball at a frantic rate. There was plenty of evidence of why he’s just not the solution for Tampa in last week’s loss 34-17 loss to the Saints.
Before the bye week, betting on the Falcons as the favorites was a wasteful exercise. Heck, betting on the Falcons as faves or underdogs was akin to throwing money at a problem (Falcons were 2-6 ATS in their first 8 games). Since week 9, they’re 2-0 SU and ATS with a +30.25 differential versus the spread on average. Talk about turning the tables.
If you’re buying what the Falcons are selling, grabbing the Falcons at -4 now is an exploitable bet. Early signs show the needle is moving up (60% or early ticket count is on the Falcons according to SBR Consensus betting reports) and several sportsbooks are already hanging the Falcons on -4.5 as a result.
NFL Betting Trends:
- Bucs are 2-3 ATS in their last 5 games on the road
- Bucs are 1-5 SU in their last 6 games
- Falcons are 1-4 SU in their last 5 games at home
- Falcons are 5-0 SU in their last 5 games against Bucs
Key Injuries:
TB – DB M.J. Stewart (Knee) is out until mid-December, QB Jameis Winston (Ankle) and G Ali Marpet (Ankle) are both listed as probable for Sunday; DL William Gholston (Ankle) is questionable for Sunday.
ATL – DE Takkarist McKinley (Shoulder) and DE Adrian Clayborn (Groin) are both questionable against Bucs.
MORE: Follow the latest betting trends for Buccaneers vs. Falcons
Denver Broncos vs. Buffalo Bills
- Sunday, Nov. 24, 2019, 1 p.m. ET
- New Era Field, Buffalo
- TV Broadcast: CBS
- Opening NFL Line: Bills -5 / 36.5
- Season Record: Broncos (3-7-0) vs Bills (7-3-0)
The Denver Broncos very nearly pulled off what would have been a seismic upset in week 11 to send shockwaves up the Richter scale through NFL betting markets. Broncos led the Vikings 20-0 going into the second half at U.S. Bank Stadium, before fritting the lead away and succumbing to the 27-23 loss.
All was not lost. Spread bettors that backed the Broncos as the whopping +10.5 closing underdogs were rewarded, and by that token the public appears to be high on the Broncos at the expense of Buffalo Bills in week 12 hoping to cash in again on a suddenly attractive NFL underdog.
As it is, the Broncos are taking in almost 60% of early tickets. A consequence that has the NFL line moving in Denver’s direction, taking the point spread down from Broncos +5 to +4 at most sports betting outlets. The total is also on the move on the NFL odds board, going up from an initial serving of 36.5 to 37.5.
Brandon Allen is still an unknown but he seems to have sparked life in the Broncos’ camp, namely the offense as the Broncos are getting points on the board with more frequency than before. However, a two-game sample is still a small cross-section to build on. With the NFL line in motion, bettors might want to play it cool to see how the market progresses before pulling the trigger either way. That said, the low total is exploitable for OVER bettors now.
NFL Betting Trends:
- Broncos are 5-1 ATS in their last 6 games
- Broncos are 3-2 ATS in their last 5 games on the road
- Bills are 5-0 ATS in their last 5 games against Broncos
- Bills are 4-4 ATS in their last 8 games
Key Injuries:
DEN – FB Andy Janovich (Elbow) is out for the season; DL Mike Purcell (Ribs) is listed as day-to-day.
BUF –S Siran Neal (Concussion) and T Ty Nsekhe (Ankle) are both listed as questionable against Broncos.
MORE: Follow the latest betting trends for Broncos vs. Bills
New York Giants vs. Chicago Bears
- Sunday, Nov. 24, 2019, 1 p.m. ET
- Soldier Field, Chicago
- TV Broadcast: FOX
- Opening NFL Line: Bears -7.5 / 41.5
- Season Record: Giants (2-8-0) vs Bears (4-6-0)
Danny Dimes mania must seem a lifetime ago now. Since winning his first two starts, Daniel Jones and the Giants have been on a downward trajectory – six straight losses that include just a 1-5 ATS mark when they covered as the +6.5 road underdogs in a 31-26 loss to the Lions.
Chicago’s divisional-winning campaign of 2018 must seem like a dream now, a fantastical sojourn down the NFC North rabbit hole. Last week’s loss to the Rams in Sunday Night Football only highlighted everything that is (and maybe always was) wrong with the Bears on national television:. Mitch Trubisky.
Indeed, the quarterback was yanked out of the game in the final minutes (with an alleged hip injury) to give way to Chase Daniels. For all the good it did Chicago.
It’s hard to feel confident about either of these teams for week 12 NFL picks. Given the Giants’ woes and significant injury list, it’s hard to trust them against the spread even when they’re getting a bucketload of points.
On the flip side, the Bears laying a touchdown or thereabouts seems unreasonable when they’re 1-5 ATS in their last six games. The only cover they pulled off was in a win over the Lions, who were without Matthew Stafford.
As it is, Trubisky remains a question mark ahead of week 12. As does the status of Saquon Barkley and Even Engram for the Giants. Perhaps it’s best to wait to see where this spread is later in the week before pulling the trigger either way.
NFL Betting Trends:
- NY Giants are 0-6 SU in their last 6 games
- NY Giants are 3-5 ATS in their last 8 games
- The total has gone OVER in 5 of NY Giants’ last 5 games on the road
- The total has gone UNDER in 4 of Chicago’s last 5 games
Key Injuries:
NYG – TE Rhett Ellison (Concussion), RB Saquon Barkley (Shoulder), CB Janoris Jenkins (Concussion), T Nate Solder (Concussion), C Jon Halapio (Hamstring), T Mike Remmers (Back) and TE Evan Engram (Foot) are all listed as questionable against Bears.
CHI – QB Mitch Trubisky (Hip), OL Bobby Massie (Back) and TE Adam Shaheen (Foot) are all listed as questionable against the NY Giants.
MORE: Follow the latest betting trends for Giants vs. Bears
Pittsburgh Steelers vs. Cincinnati Bengals
- Sunday, Nov. 24, 2019, 1 p.m. ET
- Paul Brown Stadium, Cincinnati
- TV Broadcast: CBS
- Opening NFL Line: Steelers -7.5 / 39.5
- Season Record: Steelers (5-5-0) vs Bengals (0-10-0)
The Steelers are faced with a must-win game after succumbing to a loss to Cleveland last Thursday, a game that will be remembered for all the wrong reasons. In any event, Pittsburgh is faced with a second straight divisional foe in as many weeks and by all accounts this is a straight-up win in the bag.
The Bengals remain winless on 2019 despite the quarterback change from Andy Dalton to rookie Ryan Finley. Although the Bengals succumbed to their second-straight loss with the rookie signal caller, the 17-10 defeat in Oakland had a better ring to it than the previous beatdown against the Ravens at Paul Brown.
Lookahead lines had the Steelers laying -7.5 at early doors, but early betting has seen this line trimmed down to -6.5 and, even, -6 in some cases. It’s not often the Steelers are favored this season, given all the adversity they’ve faced, but the -6 point spread currently on offer does seem reasonable for week 12 NFL picks. Keep in mind, the Steelers hammered the Bengals earlier this season 27-3 at Heinz Field.
NFL Betting Trends:
- Steelers are 5-0 SU in their last 5 games against Bengals
- Steelers are 6-4 ATS in their last 10 games
- Bengals are 4-6 ATS in their last 10 games
- The total has gone OVER in 4 of Cincinnati’s last 5 games at home
Key Injuries:
PIT – C Maurice Pouncey (Suspension) is eligible week 15; LB Olasunkanmi Adeniyi (Concussion), CB Artie Burns (Knee), RB James Conner (Shoulder) WR Dionte Johnson (Concussion) and WR JuJu Smith-Schuster (Concussion) are all listed as questionable against Bengals.
CIN – CB William Jackson III (Arm) and WR Auden Tate (Concussion) are both listed as questionable.
MORE: Follow the latest betting trends for Steelers vs. Bengals
Miami Dolphins vs. Cleveland Browns
- Sunday, Nov. 24, 2019, 1 p.m. ET
- FirstEnergy Stadium, Cleveland
- TV Broadcast: FOX
- Opening NFL Line: Browns -12.5 / 45
- Season Record: Dolphins (2-8-0) vs Browns (4-6-0)
The Cleveland Browns appear to be enjoying a little bit of late season momentum winning two in a row, including masterminding their first win over Pittsburgh in five years –albeit without Big Ben under center. It’s no surprise, oddsmakers tip the Browns as the massive home chalk to the visiting Miami Dolphins on Sunday, but the double-digit spread does seem a bit overly generous.
Early public betting appears to be clamoring on Miami’s bandwagon, betting down the Dolphins from an opening +12.5 to +10.5 at various sports betting outlets. The Dolphins are coming off a 37-20 loss to Buffalo, but they’ve covered in five of their last six games – three of which included double-digit spreads and one of which they won outright.
Is this a trap game for Cleveland? Consider the Dolphins beat the Colts 16-12 on the road to cover as the +11 underdogs a few weeks ago. In their last six games, they’ve also shown a lack of quit that has earned them some fans. On the flip side, the Browns have underestimated several opponents, including the Broncos and Titans this season.
NFL Betting Trends:
- Dolphins are 5-5 ATS in their last 10 games
- Dolphins are 1-6 ATS in their last 7 games against Browns
- Browns are 3-6-1 ATS in their last 10 games
- Browns are 1-3-1 ATS in their last 5 games at home
Key Injuries:
MIA – S Bobby McCain (Shoulder) and WR Gary Jennings Jr. (Shoulder) are questionable against Browns.
CLE – DE Myles Garrett (Suspension) is out for the season and DT Larry Ogunjobi (Suspension) is eligible week 13; S Morgan Burnett (Achilles) is out for the season.
MORE: Follow the latest betting trends for Dolphins vs. Browns
Carolina Panthers vs. New Orleans Saints
- Sunday, November 24, 2019, 1 p.m. ET
- Mercedes-Benz Superdome, New Orleans
- TV Broadcast: CBS
- Opening NFL Line: Saints -11.5 /48
- Season Record Panthers (5-5-0) vs Saints (8-2-0)
The Saints bounced back with a comprehensive win over the Tampa Bay Buccaneers in week 11, a win that saw the NFC hopefuls improve to an 8-2 SU record and maintain the pressure on the Packers and Niners in the race for top seed.
For a second straight week the Saints take on an NFC South opponent, the Carolina Panthers who are coming off a loss to the Atlanta Falcons. The Panthers have now lost two in a row and slip to .500 on the season. It’s no coincidence this run of form coincides with two suspect games for Kyle Allen. One wonders whether opposing coaches have figured out Kyle Allen or whether the announcement he was the starter for the foreseeable put untold pressure on the undrafted quarterback’s shoulders.
It’s one thing when a quarterback is playing freely (with house money so to speak) all the while looking to capitalize on an opportune chance. Another when the burden of expectation is firmly at your feet. When it’s suddenly your job to lose and not gain.
Whatever it is it’s tough to tell. What is looking likely however is Allen’s woes aren’t going to end. IF Brees is anywhere nearly as hot as he was last week and the Saints defense goes after Allen as they did Winston, it could be another tough day in the office.
Having said that the Saints opened as the whopping -11.5 home chalk, which does seem a touch generous. That NFL line didn’t hold water for long as the public has bet down the Saints to as low as -8.5. Some sportsbooks have come down to Saints laying -10.
Depending on which side of the coin NFL bettors are looking to bet, shopping around for the best line that meets the wager is recommended. There’s a big difference between backing the Saints at -8.4 and -10, obvs.
NFL Betting Trends:
- Panthers are 2-2 ATS in their last 4 games on the road
- The total has gone OVER in 4 of Carolina’s last 5 games against New Orleans
- Saints are 3-2 ATS in their last 5 games at home
- Saints are 7-1 ATS in their last 8 games
Key Injuries:
CAR – CB Ross Cockrell (Quadricep) and T Dennis Daley (Groin) are both questionable against Saints.
NO – TE Josh Hill (Concussion) is questionable against Panthers.
MORE: Follow the latest betting trends for Panthers vs. Saints
Oakland Raiders vs. New York Jets
- Sunday, Nov. 24, 2019, 1 p.m. ET
- MetLife Stadium, East Rutherford
- TV Broadcast: CBS
- Opening NFL Line: Raiders -4.5 / 47.5
- Season Record: Raiders (6-4-0) vs Jets (3-7-0)
The Jets overcome some adversity – from mono to seeing ghosts to a slew of injuries – to finally put together their first winning streak of the season. A whopping two-game winning streak that includes wins over the Giants and Redskins. Are they ready to take it up a notch though and beat an above .500 side at home?
Well, the Jets did upset the Cowboys at MetLife earlier this season so it’s not without the realm of possibility. The Oakland Raiders are enjoying their own surge of three-straight wins ahead of week 12, but it’s worth noting the Raiders haven’t blown the competition out of the water this season. In fact, they’ve been winning by the skin of their teeth for the most part.
Raiders are 6-4 ATS with a -2.5 losing margin on average and just a +0.1 differential versus the spread. On the road, the Raiders are 2-2 ATS with a -8.5 losing margin on average and a -2.4 differential versus the spread.
Lookahead lines had the Raiders as the -4.5 road faves, but since open doors the public has bet up the hosts prompting the line to move down to Raiders -3. While the key field goal number feels reasonable, bettors might want to play the wait and see game to see how this line unfolds closer to kick-off before pulling the trigger.
NFL Betting Trends:
- Raiders are 6-4 ATS in their last 10 games
- Raiders are 4-1 ATS in their last 5 games against NY Jets
- NY Jets are 4-6 ATS in their last 10 games
- The total has gone OVER in 5 of NY Jets’ last 6 games
Key Injuries:
OAK – no new injuries listed
NY Jets – T Kelvin Beachum (Ankle), T Chuma Edoga (Ankle) and LB Paul Worrilow (Quadricep) are listed as questionable against Raiders.
MORE: Follow the latest betting trends for Raiders vs. Jets
Seattle Seahawks vs. Philadelphia Eagles
- Sunday, Nov. 24, 2019, 1 p.m. ET
- Lincoln Financial Field, Philadelphia
- TV Broadcast: FOX
- Opening NFL Line: Eagles -3 / 49.5
- Season Record: Seahawks (8-2-0) vs Eagles (5-5-0)
How the Philadelphia Eagles could even be considered home favorites in this matchup in Vegas lookahead lines is unimaginable. Yet, that is the case as early servings tipped the Eagles with the customary field goal edge at home.
Evidently, that hasn’t gone down with the public at all. Early money is pouring in on the Seahawks (almost 70% of early wagering tickets according to SBR Consensus Betting reports), forcing the NFL line to move dramatically. As it is, the Eagles are merely -2 favorites. It won’t be surprising if the script completely flips on this game and the Seahawks close as the road chalk. The Eagles fell flat against the Patriots in week 11 and lost 17-10 with Carson Wentz not playing up to snuff.
For those that are buying what the Seahawks are selling, grabbing the points now is worthwhile. The Seahawks are coming off a bye week after upsetting the Niners on the road in week 10. Few would be shocked if the Seahawks kept the ball rolling with yet another road upset.
NFL Betting Trends:
- Seahawks are 5-5 ATS in their last 10 games
- Seahawks are 5-0 SU in their last 5 games on the road
- Eagles are 4-6 ATS in their last 10 games
- The total has gone UNDER in 4 of Philadelphia’s last 5 games against Seattle
Key Injuries:
SEA – WR Tyler Lockett (Leg) is listed as probable against Eagles; TE Luke Willson (Hamstring) is listed as doubtful against Eagles.
PHI – T Lane Johnson (Concussion) and RB Jordan Howard (Stinger) are listed as questionable against Seahawks; RB Darren Sproles (Hip Flexor) is on I-R.
MORE: Follow the latest betting trends for Seahawks vs. Eagles
Detroit Lions vs. Washington Redskins
- Sunday, Nov. 24, 2019, 1 p.m. ET
- FedEx Field, Landover
- TV Broadcast: FOX
- Opening NFL Line: Lions -1 / 41.5
- Season Record: Lions (3-6-1) vs Redskins (1-9-0)
The Lions played the Cowboys rather well despite succumbing to the 35-27 loss. Indeed, they gave America’s favorite team a right run for its money all the while backup Jeff Driskel led the charge.
Going into week 12, Matthew Stafford’s status is still up in the air. It’s more likely than not, Driskel will start against the Redskins on Sunday. Why risk Stafford in a game that isn’t going to salvage their season.
The Redskins, meanwhile, are 1-9-0 SU on the season and winless with Haskins in his last two starts. The rookie had a subpar showing against the Jets in the nation’s capital and it looks like he’ll be enduring growing pains for some time to come.
Overall, there’s not much to like about the Redskins right now. So, it’s no surprise, Washington opened as the nominal home puppies on the NFL odds board.
Early betting has pushed the line however to above a field goal in favor of the Lions. These two teams are certainly going nowhere fast this season but on balance the Lions are the better team in this matchup. This should be a long overdue win for the maligned Lions. Betting the Lions to win and cover isn’t a bad idea for week 12 picks.
NFL Betting Trends:
- Lions are 4-6 ATS in their last 10 games
- Lions are 4-1 ATS in their last 5 games against Redskins
- Redskins are 0-5 SU in their last 5 games at home
- The total has gone UNDER in 6 of Washington’s last 7 games
Key Injuries:
DET – QB Matthew Stafford (Back) is out indefinitely; CB Jamal Agnew (Ankle), FB Nick Bawden (Knee), DE Trey Flowers (Concussion), OL Frank Ragnow (Concussion) and DB Tracy Walker (Knee) are all listed as questionable against Redskins.
WAS – P Tress Way (Leg) and DL Daron Payne (Ankle) are both listed as questionable against Lions.
MORE: Follow the latest betting trends for Lions vs. Redskins
Jacksonville Jaguars vs. Tennessee Titans
- Sunday, Nov. 24, 2019, 4:05 p.m. ET
- Nissan Stadium, Nashville
- TV Broadcast: CBS
- Opening NFL Line: Titans -3 / 41.5
- Season Record: Jaguars (4-6-0) vs Titans (5-5-0)
The Tennessee Titans recorded an eyebrow raising upset over the Kansas City Chiefs a couple of weeks ago before going into a bye week. It was a statement-making win for both Mike Vrabel and Ryan Tannehill and saw the Titans improve to 5-5 SU in the AFC South.
Next up for the Titans is a divisional foe in Jacksonville Jaguars. Nick Foles’ belated return didn’t go to plan as the Jaguars lost to the Colts 33-13 last Sunday and slipped to 4-6 SU on the season.
For both sides, this is a must-win game if they hope to keep their playoff bid alive. More so for the Jags, who are quickly losing faith in public betting circles. Earlier in the season, the Jags beat the Titans 20-7; however, both teams had different quarterbacks.
Vegas opened this game on a field goal advantage for the Titans, a customary edge awarded to home teams in a tossup game. This is a total tossup for week 12 NFL picks. Could Foles get his groove back with a second game under his belt?
NFL Betting Trends:
- Jaguars are 4-7-1 ATS in their last 12 games on the road
- Jaguars are 2-4 SU in their last 6 games
- Titans are 5-0 SU in their last 5 games when playing at home against Jaguars
- Titans are 4-1 ATS in their last 5 games against Jaguars
Key Injuries:
JAX – DE Lerentree McCray (Hamstring) and TE Josh Oliver (Back) are both listed on I-R.
TEN – CB Malcolm Butler (Wrist) is listed on I-R.
MORE: Follow the latest betting trends for Jaguars vs. Titans
Dallas Cowboys vs. New England Patriots
- Sunday, Nov. 24, 2019, 4:25 p.m. ET
- Gillette Stadium, Foxboro
- TV Broadcast: FOX
- Opening NFL Line: Patriots 7 /46
- Season Record: Cowboys (6-4-0) vs Patriots (9-1-0)
Dallas Cowboys are faced with their toughest ask this season when they take on the New England Patriots at the Foxboro. Appropriately, oddsmakers opened the Cowboys as the massive road underdogs.
Thus far, the Cowboys have enjoyed immense success against questionable opposition wins against the Giants, Redskins, Eagles, Dolphins and Lions are hardly anything to write home about. They’ve yet to beat a legitimate contender home or away. Cowboys are 0-3 SU against winning teams.
Should the Cowboys pull off the unthinkable against the Patriots, it would put paid on all the criticism they’ve endured thus far. How realistic are their chances though? Not very, by all accounts.
Terrific Tom may not be so terrific this season but the Patriots defense is nothing to scoff at. Moreover, beating the Patriots at the Foxboro is a tough ask for any team, never mind the Cowboys.
Opening markets tipped the Patriots as the -7 home chalk but the NFL line has come down to -6 already with several sports betting outlets. Given the Patriots are typically currency at the NFL betting exchange, attacking the point spread now for week 12 NFL picks is worthwhile.
That said, playing the waiting game to see if the NFL line drops further in order to grab a better number for the Patriots is also an option. There might be late money coming down the wire on the Boys that could push the line down further.
NFL Betting Trends:
- Cowboys are 6-4 ATS in their last 10 games
- Cowboys are 3-2 SU in their last 5 games on the road
- Patriots are 9-1 SU in their last 10 games
- Patriots are 7-3 ATS in their last 10 games
Key Injuries:
DAL – CB Anthony Brown (Tricep) and C Adam Redmond (Back) are both listed on I-R; WR Amari Cooper (Knee) is listed as probable against Patriots; S Xavier Woods (Finger) and T La’el Collins (Knee) are both listed as questionable against Patriots.
NE – WR Phillip Dorsett II (Head) and RB Damien Harris (Hamstring) are both listed as questionable against Cowboys.
MORE: Follow the latest betting trends for Cowboys vs. Patriots
Green Bay Packers vs. San Francisco 49ers
- Sunday, Nov. 24, 2019, 8:20 p.m. ET
- Levi’s Stadium, Santa Clara
- TV Broadcast: NBC
- Opening NFL Line: Niners -3 / 46
- Season Record: Packers (8-2-0) vs Niners (9-1-0)
Two of the stalwarts in the NFC collide in this blockbuster Sunday Night Football showdown; arguably, one of the most intriguing matchups of the 2019 NFL season with the pair in the running for the No.1 seed in the playoffs. Indeed, it’s a big deal and the reason why it was rescheduled to feature in this primetime slot.
As it is, the Niners have homefield advantage and enter this game as the nominal field goal faves. However, early money appears to be leaning towards the Packers ever so slightly.
The 8-2 SU Packers come into week 12 following a bye week. They’ll be well rested and raring to go at Levi’s Stadium. On the road, the Packers are 3-1 SU with their only blemish a surprising loss to the Los Angeles Chargers a few weeks back.
The Niners bounced back with a win over the Arizona Cardinals last week, beating Kyler Murray and company 36-26 to improve to a 9-1 SU record. However, taking the shine off of the Niners somewhat is the growing injury list on the offensive side of the ball. George Kittle is a day-to-day decision and Emanuel Sanders is still not 100%.
To be fair, both sides have a legitimate stake in the win making a bet either way a reasonable one. The Packers to keep it close or go for the upset wouldn’t surprise anybody, Similarly, the Niners underscoring their homefield advantage with a hard fought win over the Niners would be par for the course. They’ve been putting paid on their critics from game-to-game and finding ways to win even when the chips are down.
NFL Betting Trends:
- Packers are 7-3 ATS in their last 10 games
- Packers are 5-1 SU in their last 6 games
- Niners are 9-1 SU in their last 10 games
- Niners are 5-4-1 ATS in their last 10 games
Key Injuries:
GB – LB Ty Summers (Concussion) and CB Tremon Smith (Concussion) are both listed as questionable against 49ers.
SF – TE George Kittle (Knee) is listed as day-to-day; DL Dee Ford (Hamstring), WR Deebo Samuel (Shoulder) and CB K’Waun Williams (Stinger) are listed as questionable against Packers.
MORE: Follow the latest betting trends for Packers vs. 49ers
Baltimore Ravens vs. Los Angeles Rams
- Monday, Nov. 25, 2019, 8:15 p.m. ET
- Los Angeles Memorial Coliseum, Los Angeles
- TV Broadcast: ESPN
- Opening NFL Line: Ravens -2.5 / 49
- Season Record: Ravens (8-2-0) vs Rams (6-4-0)
How can the Ravens be favored by a field goal or less in this matchup? Haven’t the oddsmakers been watching what the Baltimore is doing to opponents. Last week, they practically rendered Deshaun Watson and the Texans a non-factor in a most lopsided outcome. Indeed, in the last few games, Lamar Jackson has done enough to earn a little bit of a respite in the fourth quarter. A chance to put his feet up while the backup gets a few twirls up and down the field.
Jared Goff and the Rams, by contrast, have looked anything but like the Super Bowl runners-up. They’ve enjoyed a mixed season and have struggled against some of the better teams. In Sunday Night Football, the Rams got back in the win column but how much stock can NFL bettors put in a win over the Bears? Let alone a narrow 17-7 win that saw the Rams pull ahead late in the game with a brief inspired series from Jared Goff.
The Ravens are 4-1 SU on the road and 3-2 ATS with a 19.4 winning margin on average and a +16.7 differential versus the spread. The Rams are 2-2 ATS at home with no winning margin edge and a -4.8 differential versus the spread. The last time the Rams faced a legitimate contender at home they were blown away 20-7 by the Niners.
NFL Betting Trends:
- Ravens are 5-5 ATS in their last 10 games
- Ravens are 6-0 SU in their last 6 games
- LA Rams are 3-5 SU in their last 8 games
- The total has gone UNDER in 5 of LA Rams’ last 5 games
Key Injuries:
BAL – no new injuries currently listed
LAR – WR Robert Woods (Personal) is questionable against Ravens.
MORE: Follow the latest betting trends for Ravens vs. Rams
Bye Week: Kansas City Chiefs, Los Angeles Chargers, Minnesota Vikings and Arizona Cardinals


--- date: "2019-08-22T13:46:14+02:00" title: Resources weight: 5 ---
Below are links to some of the many online tutorials for learning R.
R for Novices (written for journalists)
Resources page of R for Epidemics Consortium (RECON) website
Tutorial for learning ggplot (the most common R package for visualizations, graphs, and maps)
Googling
Typically when you are “stuck”, it is a good strategy to use Google to find notes from other people who have worked through your same problem. If you phrase your search terms carefully, relevant results from Question/Answer sites such as StackExchange will appear and you can often get insights on approach, code examples, and be pointed toward other resources. If you decide to post a question yourself, use these guidelines.
Within RStudio you can read the documentation of any package or function that you have installed.
In the lower-right pane of RStudio (with tabs: Files, Plots, Packages, Help, and Viewer), click the Help tab and use the search bar to look for names of packages or functions. You can also search Packages and click on the name of a package to see its Help documentation.
For packages, the Help page will contain:
For functions, the Help page will contain:


About Olivier Martin
Personal details
- Firstname:
- Olivier
- Lastname:
- Martin
- Birthdate:
- Country:
-
France
- Mail:
-
<EMAIL_ADDRESS>- Address:
-
50 rue chantecrit
33300, Bordeaux
France
Short Biography
I'm Olivier Martin, 31 years old living in Bordeaux, France.
Work and Job
I work for Orange, a multinational telecom provider. I'm a Phone Operator in a technical center call.
More about my job
Basically i've to fix customer troubles by phone.
I'm working at an expertise degree so, most of the time, i'm not dealing with customers directly but rather with colleague that get difficulties to solve problems.
I'm working on all IP based services we offer (like Voip, Tvip and Internet access) as well as mobiles phones. Some examples of my daily work could be :
- Assign a schedule so that a technician have to go fix an analog phone line.
- Troubleshoot network difficulties on computers, private networks, routeurs and alikes.
- Help customers to remove virus, backdoor, trojans, malware and the likes.
- Troubleshoot system problem on mobile phone or sending bug reports to moblie phone constructors.
- Inform and assist in depth customers to discover new mobile OS features
- Troubleshoot communication problems regarding mobiles phones.
- Diagnose TV's jiter and reset boxes or change them according to the default
It might sound interesting and sometimes is but most of the time it's boring so i'm doing programing at the same time :]
I've studied computer programing at IUT de Bayonne et Du pays Basque. It did not end in a job in pure programing but i've keep playing with tools along the year, especially regarding digital arts.
I've been mainly active in the Pure Data, VVVV, and Processing communities. In , i did a workshop at an event call node08 : this workshop was about realtime communication and behavorial algorithms between generative media. In short and less barbaric term how to generate sound and visual using behaviors algorithms like velvet integration, physics, boids links them together and create some kind of autonomous piece of generative content.
 You can listen some tunes here.
I do play bass and keyboards (oldies analog ones, so if some classroom mates wants to share about moog, arp, siel, korg, etc...).
We released our first untitled EP which is just 4 tracks and out on a friend label Radar Swarm.
More about my band
Bagarre Générale is like running naked in the forest shooting into the air with an assault rifle and two or three acids dissolving under the tongue. As if Keelhaul and High On Fire, under a Zeuhl crisis took out the brass as brandishing a machete. Or as if lustful ghosts of Mahler and Mussorgsky began to sodomize young math-metal ephebes. Bagarre Générale plays epic, massive and unreal music where brass mix with guitars to deliver a terrific sonic magma backed by a relentless rhythm section.


|
LibDS
Qt-based library for controlling FRC robots
|
Implements the FRC 2015-2019 communication protocol. More...
#include <FRC_2015.h>
Public Member Functions | |
| FRC_2015 () | |
| virtual QString | name () |
| virtual int | fmsFrequency () |
| virtual int | robotFrequency () |
| virtual int | fmsInputPort () |
| virtual int | fmsOutputPort () |
| virtual int | robotInputPort () |
| virtual int | robotOutputPort () |
| virtual int | netconsoleInputPort () |
| virtual int | maxPOVCount () |
| virtual int | maxAxisCount () |
| virtual int | maxButtonCount () |
| virtual int | maxJoystickCount () |
| virtual void | rebootRobot () |
| virtual void | restartRobotCode () |
| virtual void | onRobotWatchdogExpired () |
| virtual qreal | nominalBatteryVoltage () |
| virtual qreal | nominalBatteryAmperage () |
| virtual DS::SocketType | fmsSocketType () |
| virtual DS::SocketType | robotSocketType () |
| virtual QString | radioAddress () |
| virtual QString | robotAddress () |
| virtual QByteArray | getFMSPacket () |
| virtual QByteArray | getRobotPacket () |
| virtual bool | interpretFMSPacket (const QByteArray &data) |
| virtual bool | interpretRobotPacket (const QByteArray &data) |
| Public Member Functions inherited from Protocol | |
| virtual int | radioFrequency () |
| virtual int | radioInputPort () |
| virtual int | radioOutputPort () |
| virtual int | netconsoleOutputPort () |
| virtual qreal | nominalBatteryVOltage () |
| virtual void | onFMSWatchdogExpired () |
| virtual void | onRadioWatchdogExpired () |
| virtual DS::SocketType | radioSocketType () |
| virtual QString | fmsAddress () |
| QByteArray | generateFMSPacket () |
| QByteArray | generateRadioPacket () |
| QByteArray | generateRobotPacket () |
| void | readFMSPacket (const QByteArray &data) |
| void | readRadioPacket (const QByteArray &data) |
| void | readRobotPacket (const QByteArray &data) |
| void | resetLossCounter () |
| int | sentFMSPackets () |
| int | sentRadioPackets () |
| int | sentRobotPackets () |
| int | receivedFMSPackets () |
| int | receivedRadioPackets () |
| int | receivedRobotPackets () |
| int | recvRobotPacketsSinceConnect () |
| int | sentRobotPacketsSinceConnect () |
Protected Member Functions | |
| virtual QByteArray | getTimezoneData () |
| virtual QByteArray | getJoystickData () |
| virtual DS::Alliance | getAlliance (DS_Byte station) |
| virtual DS::Position | getPosition (DS_Byte station) |
| virtual void | readExtended (const QByteArray &data) |
| virtual DS_Byte | getControlCode () |
| virtual DS_Byte | getRequestCode () |
| virtual DS_Byte | getFMSControlCode () |
| virtual DS_Byte | getTeamStationCode () |
| virtual DS_Byte | getJoystickSize (const DS::Joystick &joystick) |
| Protected Member Functions inherited from Protocol | |
| DS_Config * | config () |
| DS_Joysticks * | joysticks () |
| virtual QByteArray | getRadioPacket () |
| virtual bool | interpretRadioPacket (const QByteArray &data) |
Private Attributes | |
| bool | m_restartCode |
| bool | m_rebootRobot |
| bool | m_sendDateTime |
Implements the FRC 2015-2019 communication protocol.
|
explicit |
Implements the 2015 FRC Communication protocol
|
virtual |
Send 2 FMS packets every second
Reimplemented from Protocol.
|
virtual |
We receive data from FMS at local port 1120
Reimplemented from Protocol.
|
virtual |
We send data to the FMS to remote port 1160
Reimplemented from Protocol.
|
virtual |
FMS communications work with UDP datagrams
Reimplemented from Protocol.
References DS::kSocketTypeUDP.
|
protectedvirtual |
This function returns the alliance color referenced by the given station code. This function is used to follow the instructions outlined by the FMS packets.
References DS::kAllianceBlue, and DS::kAllianceRed.
|
protectedvirtual |
Returns the control code sent to the robot. This code contains the following information:
References DS::kControlAutonomous, DS::kControlTeleoperated, and DS::kControlTest.
|
protectedvirtual |
Returns the control code sent to the FMS. This code is very similar to the control code sent to the robot, however, it contains addional information regarding the robot radio.
This code contains the following information:
References DS::kControlAutonomous, DS::kControlTeleoperated, and DS::kControlTest.
|
virtual |
|
protectedvirtual |
Constructs a joystick information structure for every attached joystick. Unlike the 2014 protocol, the 2015 protocol only generates joystick data for the attached joysticks.
This information is separated with a joystick header code (specified at the top of this file).
|
protectedvirtual |
Returns the size of the given joystick. This function is used to generate joystick data (which is sent to the robot).
This information will help the robot decide where a information starts and ends for each attached joystick.
References DS::Joystick::numAxes, DS::Joystick::numButtons, and DS::Joystick::numPOVs.
|
protectedvirtual |
This function returns the position referenced by the given station code. This function is used to follow the instructions outlined by the FMS packets.
References DS::kPosition1, DS::kPosition2, and DS::kPosition3.
|
protectedvirtual |
Generates the request code sent to the robot, which may instruct it to:
|
virtual |
|
protectedvirtual |
Returns the team station code sent to the robot. This value may be used by the robot program to use specialized autonomous modes or adjust sensor input.
References DS::kAllianceRed, DS::kPosition1, DS::kPosition2, and DS::kPosition3.
|
protectedvirtual |
Returns information regarding the current date and time and the timezone of the client computer.
The robot may ask for this information in some cases (e.g. when initializing the robot code).
References DS::timezone().
|
virtual |
Interprets the packet and follows the instructions sent by the FMS. Possible instructions are:
Reimplemented from Protocol.
References DS::kControlAutonomous, DS::kControlTeleoperated, and DS::kControlTest.
|
virtual |
|
virtual |
FRC 2015 protocol supports a maximum of 6 axes. Remaining axes will be ignored.
Reimplemented from Protocol.
|
virtual |
FRC 2015 protocol supports a maximum of 12 buttons. Remaining buttons will be ignored.
Reimplemented from Protocol.
|
virtual |
|
virtual |
FRC 2015 protocol supports only 1 POV. Remaining POVs will be ignored.
Reimplemented from Protocol.
|
virtual |
|
virtual |
We received broadcasted messages from the robot in port 6666
Reimplemented from Protocol.
|
virtual |
Returns the nominal amperage given by the robot battery
Reimplemented from Protocol.
|
virtual |
Returns the nominal/maximum voltage given by the robot battery.
|
virtual |
Do not reboot robot or restart code when we re-establish communications with the robot.
Reimplemented from Protocol.
|
virtual |
|
protectedvirtual |
Sometimes, the roboRIO will send us additional information, such as CPU usage and CAN metrics. This function is in charge of extracting this information from the packet and updating DS values accordingly.
|
virtual |
Reboots the robot in the next packet cycle
Reimplemented from Protocol.
|
virtual |
Restarts the robot code in the next packet cycle
Reimplemented from Protocol.
|
virtual |
|
virtual |
Send 50 robot packets every second
Reimplemented from Protocol.
|
virtual |
We receive data from the robot at local port 1150
Reimplemented from Protocol.
|
virtual |
We send data to the robot at remote port 1110
Reimplemented from Protocol.
|
virtual |
Robot communications work with UDP datagrams
Reimplemented from Protocol.
References DS::kSocketTypeUDP.


The Output Viewer displays the available outputs for the selected object. The values in the Output Viewer are updated continuously as the simulation progresses.
Numerical outputs are normally shown in the appropriate SI unit, except for time which is shown in hours. When it is more convenient to view an output in another unit, the user can specify a set of preferred units using the Units entry in the Menu bar (see Section 4.3.1).
Hovering the cursor over an output name will display a tooltip containing a brief description of the output.
Text can be copied from the Value column to the clipboard by selecting the desired row and pressing Ctrl-C. If the Value column contains an object name, it can be selected in the Entity Finder by pressing Ctrl-F. If it contains a list of object names, Ctrl-F will select the first one.


We often need to repeat actions.
For example, outputting goods from a list one after another or just running the same code for each number from 1 to 10.
Loops are a way to repeat the same code multiple times.
The while
loop has the following syntax:
While the condition
is truthy, the code
from the loop body is executed.
For instance, the loop below outputs i
while i < 3
:
js run let i = 0; while (i < 3) { // shows 0, then 1, then 2 alert( i ); i++; }
A single execution of the loop body is called an iteration. The loop in the example above makes three iterations.
If i++
was missing from the example above, the loop would repeat (in theory) forever. In practice, the browser provides ways to stop such loops, and in server-side JavaScript, we can kill the process.
Any expression or variable can be a loop condition, not just comparisons: the condition is evaluated and converted to a boolean by while
.
For instance, a shorter way to write while (i != 0)
is while (i)
:
js run let i = 3; *!* while (i) { // when i becomes 0, the condition becomes falsy, and the loop stops */!* alert( i ); i--; }
```smart header="Curly braces are not required for a single-line body" If the loop body has a single statement, we can omit the curly braces
{…}`:
js run let i = 3; *!* while (i) alert(i--); */!*
````
The condition check can be moved below the loop body using the do..while
syntax:
The loop will first execute the body, then check the condition, and, while it’s truthy, execute it again and again.
For example:
js run let i = 0; do { alert( i ); i++; } while (i < 3);
This form of syntax should only be used when you want the body of the loop to execute at least once regardless of the condition being truthy. Usually, the other form is preferred: while(…) {…}
.
The for
loop is more complex, but it’s also the most commonly used loop.
It looks like this:
Let’s learn the meaning of these parts by example. The loop below runs alert(i)
for i
from 0
up to (but not including) 3
:
js run for (let i = 0; i < 3; i++) { // shows 0, then 1, then 2 alert(i); }
Let’s examine the for
statement part-by-part:
| part | ||
|---|---|---|
| begin | i = 0 |
Executes once upon entering the loop. |
| condition | i < 3 |
Checked before every loop iteration. If false, the loop stops. |
| body | alert(i) |
Runs again and again while the condition is truthy. |
| step | i++ |
Executes after the body on each iteration. |
The general loop algorithm works like this:
Run begin
→ (if condition → run body and run step)
→ (if condition → run body and run step)
→ (if condition → run body and run step)
→ ...
That is, begin
executes once, and then it iterates: after each condition
test, body
and step
are executed.
If you are new to loops, it could help to go back to the example and reproduce how it runs step-by-step on a piece of paper.
Here’s exactly what happens in our case:
// for (let i = 0; i < 3; i++) alert(i)
// run begin
let i = 0
// if condition → run body and run step
if (i < 3) { alert(i); i++ }
// if condition → run body and run step
if (i < 3) { alert(i); i++ }
// if condition → run body and run step
if (i < 3) { alert(i); i++ }
// ...finish, because now i == 3
```smart header="Inline variable declaration" Here, the "counter" variable
i` is declared right in the loop. This is called an “inline” variable declaration. Such variables are visible only inside the loop.
js run for (*!*let*/!* i = 0; i < 3; i++) { alert(i); // 0, 1, 2 } alert(i); // error, no such variable
Instead of defining a variable, we could use an existing one:
```js run let i = 0;
for (i = 0; i < 3; i++) { // use an existing variable alert(i); // 0, 1, 2 }
alert(i); // 3, visible, because declared outside of the loop
Any part of for
can be skipped.
For example, we can omit begin
if we don’t need to do anything at the loop start.
Like here:
```js run let i = 0; // we have i already declared and assigned
for (; i < 3; i++) { // no need for “begin” alert( i ); // 0, 1, 2 } ```
We can also remove the step
part:
```js run let i = 0;
for (; i < 3;) { alert( i++ ); } ```
This makes the loop identical to while (i < 3)
.
We can actually remove everything, creating an infinite loop:
Please note that the two for
semicolons ;
must be present. Otherwise, there would be a syntax error.
Normally, a loop exits when its condition becomes falsy.
But we can force the exit at any time using the special break
directive.
For example, the loop below asks the user for a series of numbers, “breaking” when no number is entered:
```js run let sum = 0;
while (true) {
let value = +prompt(“Enter a number”, ’’);
! if (!value) break; // () /!*
sum += value;
} alert( ‘Sum:’ + sum ); ```
The break
directive is activated at the line (*)
if the user enters an empty line or cancels the input. It stops the loop immediately, passing control to the first line after the loop. Namely, alert
.
The combination “infinite loop + break
as needed” is great for situations when a loop’s condition must be checked not in the beginning or end of the loop, but in the middle or even in several places of its body.
The continue
directive is a “lighter version” of break
. It doesn’t stop the whole loop. Instead, it stops the current iteration and forces the loop to start a new one (if the condition allows).
We can use it if we’re done with the current iteration and would like to move on to the next one.
The loop below uses continue
to output only odd values:
```js run no-beautify for (let i = 0; i < 10; i++) {
// if true, skip the remaining part of the body !if (i % 2 == 0) continue;/!
alert(i); // 1, then 3, 5, 7, 9 } ```
For even values of i
, the continue
directive stops executing the body and passes control to the next iteration of for
(with the next number). So the alert
is only called for odd values.
```smart header="The
continue` directive helps decrease nesting" A loop that shows odd values could look like this:
```js run for (let i = 0; i < 10; i++) {
if (i % 2) { alert( i ); }
}
From a technical point of view, this is identical to the example above. Surely, we can just wrap the code in an `if` block instead of using `continue`.
But as a side-effect, this created one more level of nesting (the `alert` call inside the curly braces). If the code inside of `if` is longer than a few lines, that may decrease the overall readability.
```warn header="No
break/continueto the right side of '?'" Please note that syntax constructs that are not expressions cannot be used with the ternary operator
?. In particular, directives such as
break/continue` aren’t allowed there.
For example, if we take this code:
…and rewrite it using a question mark:
js no-beautify (i > 5) ? alert(i) : *!*continue*/!*; // continue isn't allowed here
…it stops working: there’s a syntax error.
This is just another reason not to use the question mark operator ?
instead of if
. ````
Sometimes we need to break out from multiple nested loops at once.
For example, in the code below we loop over i
and j
, prompting for the coordinates (i, j)
from (0,0)
to (2,2)
:
```js run no-beautify for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
let input = prompt(`Value at coords (${i},${j})`, '');
// what if we want to exit from here to Done (below)?
} }
alert(‘Done!’); ```
We need a way to stop the process if the user cancels the input.
The ordinary break
after input
would only break the inner loop. That’s not sufficient–labels, come to the rescue!
A label is an identifier with a colon before a loop:
The break <labelName>
statement in the loop below breaks out to the label:
```js run no-beautify !outer:/! for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
let input = prompt(`Value at coords (${i},${j})`, '');
// if an empty string or canceled, then break out of both loops
if (!input) *!*break outer*/!*; // (*)
// do something with the value...
} } alert(‘Done!’); ```
In the code above, break outer
looks upwards for the label named outer
and breaks out of that loop.
So the control goes straight from (*)
to alert('Done!')
.
We can also move the label onto a separate line:
js no-beautify outer: for (let i = 0; i < 3; i++) { ... }
The continue
directive can also be used with a label. In this case, code execution jumps to the next iteration of the labeled loop.
````warn header=“Labels do not allow to "jump" anywhere” Labels do not allow us to jump into an arbitrary place in the code.
For example, it is impossible to do this:
A call to break/continue
is only possible from inside a loop and the label must be somewhere above the directive. ````
We covered 3 types of loops:
while
– The condition is checked before each iteration.do..while
– The condition is checked after each iteration.for (;;)
– The condition is checked before each iteration, additional settings available.To make an “infinite” loop, usually the while(true)
construct is used. Such a loop, just like any other, can be stopped with the break
directive.
If we don’t want to do anything in the current iteration and would like to forward to the next one, we can use the continue
directive.
break/continue
support labels before the loop. A label is the only way for break/continue
to escape a nested loop to go to an outer one.


Which Course is Best for You?
Answer the following questions to help you pick which course Epicodus offers that you would like the most by selecting either "yes" or "no".
It looks like you would be most intrested in learning...
You don't have any intrest in any of these things? They may be hiring janitors


Test Block Wrapper for all
Test Block Wrapper for each item
Second Around for item 1
First Around for item 1
Second Before for item 1
First Before for item 1
Test Block Wrapper for item 1
Second Surround for item 1
First Surround for item 1
Second Prepended block 1
First Prepended block 1
Actual block 1
First Appended block 1
Second Appended block 1
First After for item 1
Second After for item 1
Test Block Wrapper for each item
Second Around for item 2
First Around for item 2
Second Before for item 2
First Before for item 2
Test Block Wrapper for item 2
Second Surround for item 2
First Surround for item 2
Second Prepended block 2
First Prepended block 2
Actual block 2
First Appended block 2
Second Appended block 2
First After for item 2
Second After for item 2


In experience, it is possible to write code that can run on 2.4-2.6(7) at the same time. But it almost never works that way from the start.


--- layout: page title: "jQuery: Novice to Ninja" prev: OEBPS/ch04.html next: OEBPS/ch06.html book_path: books/earle-castledine-craig-sharkie-jquery-novice-to-ninja-_oeb/ --- {% include JB/setup %} {% raw %}
nav
element, it’s still only going to be a
wrapper for our tried-and-tested list elements. From a semantic
standpoint, this is perfectly reasonable; after all, a navigation menu
is just a list of links. For our expandable menu, we’ll start off with a
set of nested lists:

What's new?

Weekly specials

Last night's pics!

Users' comments

Member extras

Premium Celebrities

24-hour Surveillance
 …
#menu, #menu ul { list-style-type: none; padding: 0; margin: 0; } #menu li { cursor: pointer; background: #94C5EB; border-bottom: 1px solid #444; } #menu li a { text-decoration: none; } #menu > li > a { padding: 2px 10px; font-weight: bold; } #menu li li { cursor: auto; border: 0; padding: 0 14px; background-color: #fff; }
$('#menu > li > ul') .hide() .click(function(event) { event.stopPropagation(); });
event
.stopPropagation()
line in this
block. We’ll cover that shortly, but first let’s finalize our effect
with a toggle
function to slide the menu up and
down:
$('#menu > li').toggle(function() { $(this).find('ul').slideDown(); }, function() { $(this).find('ul').slideUp(); });
stopPropagation
method is doing.
div
s, one inside the other. The
outer and inner div
s will have
id
s of outer
and inner
, respectively:

 Click Outer!
 Click Inner!

click
handler to each
of the div
elements, so that when
we click on an element an alert will pop up and tell us the element’s name:
$('div').click(function() { alert('Hello from ' + $(this).attr('id')); });
div
: unsurprisingly, you’ll see an alert
saying “Hello from outer.” Now, click on the inner div
. You’ll see the expected “Hello from
inner.” But then you’ll also see “Hello from outer” … what gives? We
only clicked once, so why are we seeing two click events?
As you probably guessed, rather than two click events, it’s actually one
click event happening in two different places.
The event starts at our inner div
and checks to see if there are any event handlers attached to it. It
then bubbles (or propagates) up to the div
’s parent element (in this case the outer
div
), and checks to see if there
are any event handlers attached to that element. The event continues
to bubble up the DOM hierarchy until there are no more parents
available.
This event bubbling is desirable in many cases; we’ll often want
to handle the same event at multiple levels of the DOM. For example,
if we wanted to set a parent node’s class when any children were
clicked, it would be far more efficient to add an event handler to the
parent node itself than to add a handler to each child. You might have
heard of this approach as
event delegation: one event
handler set to catch events from many descendants. But we still want
to be able to attach individual click handlers to any of the
children.
On the other hand, it can be undesirable to have an event to
bubble up. Sometimes we want the child node to stop the event from
going any further. As an example, imagine we were making a
Whac-A-Mole-type game. The game is made up of two parts: a game board
and some moles. The moles randomly appear on the screen for a few
seconds and then disappear. We might want to attach a handler to each
mole to detect a direct hit, and another handler to the game board to
detect a miss. With event propagation, we’d end up recording both a
hit and a miss as the event bubbled up to our game board. Sure, we
could check the event’s target
property to see
what was hit, but let’s focus on propagation.
There are a few techniques available for controlling event
propagation. A common JavaScript technique is simply to return
false
from the event handler. This works fine, and
is supported across all major browsers. However, jQuery’s event system
normalizes all events to the W3C standard, which means there’s no need
to worry about how different browsers treat different edge
cases.
To stop event propagation using jQuery, we use the
stopPropagation
method as we’ve
already done. Our anonymous callback function is passed a parameter
we’ll name event
. Then we simply call
stopPropagation
on that event, and it will
cease propagating further up the DOM.
preventDefault
. The
preventDefault
method stops the browser from
executing the default action that an event would normally perform. Its
most common use is stopping a link from loading its target when
clicked:
$('a').click(function(event) { event.preventDefault(); });This code effectively disables every link on the page. It’s highly unusual to want to do this to every link, of course, but it’s common to override a link’s action this way when we’re implementing progressive enhancements—such as the lightbox effect we saw in Chapter 4. If JavaScript is unavailable to a particular user, the link will work as normal. But if JavaScript is available, the normal link is replaced with our jQuery functionality. Now you’re in control and can either prevent the element’s default response, or stop the event from propagating. Why are we pointing this out? Because the technique we mentioned where you simply return
false
from the event handler has the same
effect as calling both preventDefault
and
stopPropagation
. And maybe that’s not what
you were expecting.
You can also use the commands
isDefaultPrevented
and
isPropagationStopped
to test
whether an event’s flow has been modified. As might be implied from
their names, these functions will return true
if
the default action has been prevented or the event propagation
stopped, respectively, and false
otherwise.
li
elements inside the menu, and then remove
it from deeper nested items:
#menu li { cursor: pointer; border-bottom: 1px solid #444; background: #94C5EB url(arrows.png) no-repeat right top; } … #menu li li { cursor: auto; border: 0; padding: 0 14px; background-color:#fff; background-image: none; }
css
action before we drill down to find the
ul
to show or hide:
$('#menu > li').toggle(function() { $(this) .css('background-position', 'right -20px') .find('ul').slideDown(); }, function() { $(this) .css('background-position', 'right top') .find('ul').slideUp(); });
hover
event fires the instant you
move your mouse over the target item. But for this effect we’ll delay the execution so that it
only fires if the user hovers for a short while. Otherwise, the control
would be virtually unusable, as it would snap open and closed if you so
much as grazed it with the mouse.
It’s a subtle but important change—and if you try the menu both
with and without a delay as follows, you’ll notice that the feel of the
control is altered dramatically:
When the user first mouses over the menu element, we add a class
called waiting
to the menu item,
then set a timer for 600 milliseconds. If the user moves the mouse away
from the menu item before the delay concludes, we remove the
class.
Once the delay expires it looks for a menu item containing the
waiting
class
(which will only exist if the user
hasn’t moved the mouse away). If the user is still waiting, we “click”
the menu item, causing the effect to fire. This is the first time we’ve
seen the
click
action used in this way;
when called without parameters, it actually fires the click event on the
targeted element(s), rather than setting up an event handler. Finally,
once we fire the effect we remove the class—so we’re back to square one.
We also need to modify the click action we defined earlier. As it is, if
a user mouses over a menu and then clicks it, the waiting
class will cause it to close when the
timer goes off. We simply need to add the same
removeClass
call to the click handler.
What we’re doing—and we’ve done this before with earlier
effects—is use classes to provide
state management. State management is just a fancy way of
saying we provide the control with a way of remembering what “state” it
is in. We want to remember if the user has moved away from the menu
before the delay expires, so we add and remove the waiting
class
appropriately. Using class names for
state management is a nifty trick—but it’s certainly not the only (or
best) way. We’ve already seen the data functionality provided by jQuery,
which is a great way to store simple state information. For larger and
more complex controls, we can also integrate state management into the
widget’s code—as we saw at the end of Chapter 4.
As always, the method you use is dependent on the circumstance, and on
what feels simplest to you.
:hover
pseudo-selector to trigger the
showing and hiding of the child items. We should always aim to use
simpler technologies such as CSS when they’re suitable. That said, there
are some issues with using pure CSS drop-down menus. Really old browsers
are unable to style the :hover
pseudo selector on
non-link elements, and even for those that can, the showing/hiding
effect can be a little abrupt.
The Suckerfish drop-downs make an excellent base for enhancement:
they provide an adequate solution, which can then be improved and
streamlined with jQuery. In this example, we’ll be adapting the
Suckerfish technique to work with browsers that have incomplete support
for :hover
. We’ll also make the drop-down effect a
little sleeker with some jQuery animation; for instance, delaying the
drop-down from hiding when the user mouses out.
class
we’ve attached to the
:hover
CSS declaration. We’ll need this to keep our
menu drop-down visible when it otherwise wouldn’t be:
#container { position: relative; } #menu { position: absolute; top: 0; right: 0; } #menu, #menu ul { padding: 0; margin: 0; list-style: none; } #menu li { float: left; background: #FFF; } #menu a { display: block; padding: 4px; width: 10em; } #menu li ul { position: absolute; width: 10em; left: -999em; } #menu li:hover ul, #menu li ul:hover { left:auto; }
:hover
and jQuery
hover
? It’s messy—they’re very
evenly matched!
One obvious workaround would be to override the CSS class in our
hover event handler. But this will fail, as you’re unable (currently)
to target
pseudo selectors in jQuery to set CSS properties:
$('#nav li:hover ul').css('left', '-999em'); // doesn’t work!That puts us in a quandary: how can we keep the goodness of Suckerfish CSS menus, but still apply our jQuery enhancements? One solution would be to carefully undo the CSS properties as we hover—but an easier way is to take over the child menu item’s CSS properties, regardless of whether we’re hovering or not: The first part of this script overrides the CSS we set earlier and hides the submenus using
display: "none"
. When
the user hovers over a list item, we find the related child list
container and display it. Here we’ve used
slideDown
and
fadeOut
, but you’ll be able to come up with
some wacky easing options and CSS background sprites to liven it up.
The stop(true, true)
command, as we saw in the section called “Animated Navigation
” in Chapter 3, ensures that the menu will refrain
from queuing up animations if we move the mouse around quickly. If you
like, you could even add in a delay
, from the
same chapter.
The best aspect of this menu control is that when a user
visits the site with JavaScript disabled, the Suckerfish drop-downs
still work nicely, albeit without the animation effects.
mouseover
event—and you may have
noticed that they can sometimes feel a bit too eager to activate. The
very instant you pass your mouse over a target element the effect
springs to life, even if you’re just passing through. This is
excellent for making fluid animated effects, but sometimes we’re after
a different result. With our drop-down menus, the false start can
appear unnecessary and distracting. We need a method of delaying the
effect until we’re sure that the user really wants to activate the
target element.
Earlier, we saw a method for achieving this by setting a timer
when the user moves over the element. But this has a few side effects.
For example, if you have a small timer and a large target area, the
user might fail to make it all the way across the element before the
timer expires.
Brian Cherne implemented a nice workaround for this
issue, in the form of the Hover
Intent plugin. Hover Intent has some smarts built into it to
calculate the speed of the mouse as it moves across the elements. The
effect will only kick in if the mouse slows down enough for the plugin
to think the user intends to stop there.
Once you’ve included the plugin, you can use it wherever you’d
normally use the
hover
action. As an example, if
we wanted to add a delay to our drop-down menus from the previous
section, we’d just need to replace the command
hover
with the command
hoverIntent
:
$('#menu li').hoverIntent(function() {
…
}, function() {
…
});
hoverIntent
, the menus will only slide open
when the mouse comes to rest.
As with most plugins, the documentation outlines the handful of
options you can specify to fine-tune the effect, so be sure to read
through it if you plan on using this functionality.

 "A" List Celebrities

Computadors New!

Johnny Stardust

Beau Dandy

 "B" List Celebrities

Sinusoidal Tendancies

Steve Extreme

 …

div
s, with header elements
providing the title of each section. Just about any structure is
suitable, as long as it’s consistent and allows you to select all the
header triggers and related content. We’ve styled the list with some
CSS, which you can consult in the sample code archive.
When our page loads, all our content areas are visible. By now you
should know what’s coming next: we need to hide all the content, except
for our default item:
$('#celebs ul > li ul') .click(function(event) { event.stopPropagation(); }) .filter(':not(:first)') .hide();
filter
command is a really handy
way of narrowing down a selection mid-statement. Any elements that don’t
match the criteria passed to it are discarded from the selection and are
no longer affected by subsequent jQuery commands. You can specify the
criteria as a selector or as a function (see the note below). We’ve used
filter selectors in the previous example (:not
and
:first
), but you can use any jQuery selector to help
you find the elements you’re after.
:not
is a neat utility selector, as it
selects the opposite of whatever follows it in parentheses. So
$(':not(p)')
will select every element that’s not a
paragraph, and $('p:not(.active)')
will select
paragraphs without the active
class.
And where the filter
method does a
smashing job of removing elements from a selection, we can do the
reverse with
add
, which appends new elements
to the selection. By combining filter
and
add
you can do an awful lot of processing in a
single jQuery chain, adding and removing elements as necessary along the
way.
filter
true
, the
element stays in the selection; otherwise, it’s scrapped. As an
example, let’s keep every paragraph element that’s either the third in
the selection or has the class
active
:
$('p').filter(function(index) { return index == 2 || $(this).hasClass('active'); });Notice that we have access to the zero-based index of each element in the selection, and that the scope is of the current element? That’s why we can refer to it with
$(this)
. You can include any amount of processing
in your criteria function—just be sure to return
true
if you want to hold on to the
element.
selfClick
evaluates to true
,
we simply exit the function using the JavaScript
return
keyword:

"A" List Celebrities

Computadors New!

Rising Stars

Johnny Stardust

Beau Dandy

Falling Stars

Kellie Kelly

Darth Fader
 …
$('#accordion > li').click(…)
. As the structure of
our nested list is exactly the same as before, we need to apply the same
code to the nested elements, which we can accomplish simply by adding
them to the selector:
$('#accordion > li, #accordion > li > ul > li').click(…);
#accordion
’s direct children li
s; then find any descendant lists and items,
and use addSelf
to bring those first child
li
s back into the
equation:$('#accordion > li).find('> ul > li').addSelf().click(…);
It can be easy to miss that leading >
in the
find
, though, so see which style you prefer. In
either event, the resulting menu is shown in Figure 5.5.
If you want to add more levels to the accordion, just repeat this
process. If the long selectors get out of hand, you could add an extra
class to the root of each level; any more than a few levels, though, and
perhaps there are more appropriate controls to better present your
information, rather than accordions (see Chapter 8).
mouseover
, and reacting in specific ways to the
accordion’s containing element (for example, you can choose to let the
content areas have a fixed
height or an
auto
height). And as if that weren’t enough, it’s
also fully themed.
An example of the jQuery UI accordion, using the Sunny theme, can
be seen in Figure 5.6.
Like our custom accordion, the markup for the jQuery UI accordion
requires pairs of headers and content elements. By default, it assumes
that the headers are link tags and that the content immediately follows
them; however, it will be confused if the content includes links, so
it’s usually best to specify a selector to help it determine which part
of your content is the title:
This is all the code you’ll need to turn your content into a fully
functional accordion, as long as the h3
’s next sibling is the content pane you want
to hide or show.
The accordion also provides functionality to programmatically
interact with the control. For example, you can open a particular
content pane using the activate
option, along
with the index of the pane you want to open. To open the third pane
(remember, indexes start from zero), you’d write the following:
There are many other options available for configuring and
interacting with the accordion, and these are well documented on the
jQuery UI
site.
Using the jQuery UI control comes at a significant cost in terms
of file size and bandwidth use compared with our custom control, but if
you require advanced functionality and prefer to avoid spending the time
to implement it yourself, it can be a viable option.
div
elements:

 Welcome to StarTrackr! the planet's premier …

 StarTrackr! was founded in early 2009 when a young …

 Disclaimer! This service is not intended for those …

Intro

About Us

Disclaimer

$('#info p').hide().eq(0).show();But this makes jQuery do more work than is necessary; we want to avoid hiding a tab only to show it again straight away. Instead, we can be more specific with our selector; we can combine filters to select everything except the first element: The important point is that once the page loads, only one tab content pane is displayed to the user. The code to switch tabs is straightforward, and quite similar to the other hide/show controls we’ve built so far:
$('#info-nav li').click(function(event) { event.preventDefault(); $('#info p').hide(); $('#info-nav .current').removeClass("current"); $(this).addClass('current'); var clicked = $(this).find('a:first').attr('href'); $('#info ' + clicked).fadeIn('fast'); }).eq(0).addClass('current');
href
attribute of the link
directly to our selector using the JavaScript
+
operator. This only works because
anchor links use the
hash symbol (#
) to identify their
targets, and jQuery also uses the hash symbol to select elements by
id
. This is pure coincidence, but
it’s very fortunate for us as there’s no need to parse the text or use
regular expressions to create our selector. Secondly, you’ll notice that
we call preventDefault
as early in the method
as possible. Here we’re ensuring that if there’s a problem with the
code, at least the default link will be prevented. Small comfort, but
comfort nonetheless!
After we’ve attached the click handler, we filter our navigation
list to just the first element using the
.eq
selector and add the current
class to it. In our example the first
tab is the default tab; if you want a different tab to be first, you
need to change the 0 (as it’s a zero-based index) to the one you’d
prefer.

Intro

About StarTrackr!

Disclaimer

 Welcome to StarTrackr! the planet's premier …

id
of the element containing the
related content (#intro
in our
example). The next two tabs are our Ajax tabs; they simply point to HTML
files on the server (or in our case, on the hard disk). In a real web
application, they’d point to server-side scripts that generate dynamic
content; for the sake of illustrating how jQuery UI’s Ajaxy tabs work,
we’ll stick with a few static HTML files. These can contain whatever
content you’d like to load into your tabs.
The functionality we’ll implement will degrade gracefully in the
absence of JavaScript; those tabs will simply act
as links to the referenced files. When JavaScript is enabled, however,
jQuery will load the content of the target page into the tab content
pane without refreshing the page. There’s no need to worry about it
pulling in the whole HTML page; it’s smart enough to only include the
content between the opening and closing
tags.
To turn the above markup into an Ajax-enabled tab interface, all
you need to write is:
Try it out in your browser to confirm that it works (it should say
“Write less, do more”).
$('#info').tabs({ event: 'mouseover', fx: { opacity: 'toggle', duration: 'fast' }, spinner: 'Loading...', cache: true });
event
, fx
,
spinner
, and cache
. The event
option lets you choose the
event that changes tabs; here we’ve replaced the default
click
with mouseover
. To change
tabs now, the user need only hover over the desired tab.
Next, we’ve added some animation options to specify a
fast fade transition when we switch between tabs. The
fx
option works exactly like the
animate
command, letting you
tweak the transition in whichever way you need.
The last two options are for our Ajax tabs.
spinner
specifies the HTML to display while the
content is being loaded. With all your pages sitting on your local
machine, you’re likely to never see this text, but you’ll certainly
notice the delay (and therefore the spinner
text)
when you put your pages up on a real web server. It’s called
spinner
as it’s often used to display an animated
GIF image of a spinning icon, which is meant to indicate loading and
almost always named spinner.gif.
The cache
option instructs the
browser to hold on to a copy of the tab content after it’s loaded.
This way, if a user is clicky on your tabs—switching repeatedly back
and forth—the browser won’t need to download a fresh copy of the data
each time.
tabs
call sets up our tab
pane, and the second one instructs jQuery to cycle through the tabs
every 3,500 milliseconds (or 3.5 seconds). There’s a lot more you can
do with your tabs, so have a look at the documentation to see what’s
possible.
The last item we’ll have a look at is selecting a tab
programmatically. You can find the currently selected tab by using the
selected option:
$('#tabs').tabs('option', 'selected');Of course, you can also set the current tab. This is handy if you want links in your content to simply change the open tab rather than linking to a new page. For this example, we’ve inserted a link to the About Us page in the content of the first tab. We can hijack that link and have it open the About Us tab instead:
$('#login form').hide(); $('#login a').toggle(function() { $(this) .addClass('active') .next('form') .animate({'height':'show'}, { duration: 'slow', easing: 'easeOutBounce' }); }, function() { $(this) .removeClass('active') .next('form') .slideUp(); });
css
action. Because
these classes are only really used when JavaScript is available (as
otherwise we’ll be presenting a control that’s always open), neither
solution is necessarily better, and the one you choose will depend more
on your preference.
This was a bit too easy, so we’ll finesse it a touch. If our login
form were to submit via Ajax (without triggering a page refresh), we’d
want the panel to disappear after the form was submitted. Actually, even
if we’re loading a new page, having the menu slide up after clicking is
a nice flourish:
We start by capturing the click
event on the
form’s submit button, and then move back up the DOM tree looking for the
containing element. We could just perform our hide here, but given that
we’ve already written code to handle the hiding in our original handler,
we can just step back through the DOM using the
prev
method, and click on our hide/show
link.
.cart a { position: absolute; width: 32px; height: 32px; right: 15px; top: -10px; background: transparent url(shoppingcart.png) no-repeat 0 0; text-indent: -9999px; } .cart a:hover, .cart-hover { background-position: 0 -32px; } #overlay { position: absolute; width: 100%; height: 100px; top: 0; left: 0; color: #fff; background-color: #000; display: none; text-align: center; } #overlay a { font-size: 130%; font-weight: bold; }
class
of active
as long as it’s open, and use that
class
to determine when it needs to
be closed. This is another great candidate for
data
that we covered in the section called “Smarter Scrolling with the
data
Method” in Chapter 4, although that might change if we were also
using the class to add styling. When the user mouses away from it, we
remove the class
, and set a timer,
which will look for an overlay without the active
class
and close it after a little less than
a second. This way, if the user re-opens the overlay while the timer is
running, the timer method will do nothing:
$('

') .attr('id', 'overlay') .css('opacity', 0.65) .hover(function() { $(this).addClass('active'); }, function() { $(this).removeClass('active'); setTimeout(function() { $('#overlay:not(.active)').slideUp(function() { $('a.cart-hover').removeClass('cart-hover'); }); }, 800); }).appendTo('body');
opacity
CSS property to make our
overlay semitransparent. opacity
values range from
0 to 1, with 1 being completely opaque and 0 being invisible.
$('.cart a').mouseover(function() { $(this).addClass('cart-hover'); $('#overlay:not(:animated)') .addClass('active') .html('
You have 5 items in your cart.
 ↵View Cart Checkout') .slideDown(); });
:animated
, which allows us to select
elements that are currently being animated (or, as in this case,
combined with the
:not
filter to select elements which
are not mid-animation). We add some static markup to our overlay, but in
a real application you’d want to obtain the number of cart items in
order to display it here.
We are also adding a class to the trigger link to style it, as its
hover style would otherwise switch off when the overlay came between it
and the cursor.
Of course, this is only one example of this sort of functionality;
it’s likely you can think of many others. Transparency is remarkably
easy to manipulate in jQuery, and really makes interface components feel
a lot slicker.
title
attribute for a link or an
alt
attribute for an
image, the browser will usually display it as a tooltip when the user
hovers over that element. Tooltips typically appear when the user hovers
over a
hyperlink to provide additional information about where the
link will take them.
JavaScript tooltips have a bit of a bad rap. They tend to be
implemented in an obnoxious manner, acting more like an ad popup than a
useful information tool. However, there are situations in which a tooltip
can provide just the right touch to your application, helping to inform
your users in a contextual fashion without cluttering the rest of your
interface.
First, we’ll have a go at replacing the browser’s default tooltips
with ones we can style and animate. Then we’ll look at extending this to
create a much more versatile tooltip, which can contain HTML and be
attached to any element on the page.
title
attribute of the links. This is great
for our ever-vigilant efforts to maintain acceptable functionality for
users without JavaScript support; depending on their browser, they’ll
most likely see the text as a basic browser tooltip:
 New York
title
attribute can
be a bit limiting: you’re unable (technically or reliably) to have HTML
nested inside your tooltip, and you’ll need to be careful with special
characters that might break the tag. There are a few alternate
techniques for storing the tooltip’s text. We’ll have a look at another
method when we make our advanced tooltip, but it’s important to note
that any method will have upsides and downsides, so you’ll need to
decide what’s best in each particular circumstance.
Being able to style the tooltip is the main reason for
implementing a custom control in the first place—so go nuts with your
styles! However, for our example, we’ll define some very basic styles
for our tooltips:
.tooltip { display: none; position: absolute; border: 1px solid #333; background-color: #ffed8a; padding: 2px 6px; }
hover
function, followed by a chained
mousemove
function. We want the tooltip to turn
on and off with the hover
event, and update its
position whenever the mouse is moved:
$('.location').hover(function(event) { // Hover over code }, function() { // Hover out code }).mousemove(function(event) { // Mouse move code });
event
into the hover code. This
is important, as we’ll need to access the X and Y coordinates of the
event in order to position the tooltip:
First we need to grab the title
from the link, which will be the text
we want our tooltip to display.
The next part of the code is a touch peculiar: it saves the
tooltip text using the
data
method that we saw in the section called “Smarter Scrolling with the
data
Method” in Chapter 4. We need to do this because we’ll be removing
the title
from the link, in order
to prevent the browser from displaying its default tooltip that will
conflict with our custom one. By storing the text using the
data
method, we can recover and replace the
link title later.
We now have everything we need to create our tooltip control.
We’ll create a new paragraph element with a class
of tooltip
, in order to hook into the styles we
created earlier. Then we use the
text
method to set the tooltip’s
contents. We could use
html
instead of
text
here, but according to W3C standards, the
title
attribute should not contain
HTML. The advanced tooltip we’ll be looking at shortly will allow us to
include HTML, but for the moment we’ll stick with plain text.
id
with
jQuery like this: $('

').attr('id',
'tooltip')
. Likewise, we could have used JavaScript string
concatenation to populate the element’s content:
$('
' + titleText + '
')
. The
methods result in the same DOM objects, and they’re all fairly clear
and readable, so it’s up to your personal coding style whether you
prefer doing more with jQuery chaining or with plain
JavaScript.
appendTo
) we set a few inline
styles, using the event object (event
) to obtain the
position where we need to place the tooltip.
pageX
and
pageY
are properties of the event
object that allow you to find out where the event took place on the
page. This can be tremendously useful in a lot of situations; you’ll
often find yourself needing to position an element on the screen based
on an event that just fired:
// Hover out code $(this).attr('title', $(this).data('tipText')); $('.tooltip').remove();
title
attribute and removing the
tooltip:
// Mouse move code $('.tooltip') .css('top', (event.pageY - 10) + 'px') .css('left', (event.pageX + 20) + 'px');
title
attribute into our
actual markup. We’ll hide them with CSS, then reveal and position them
using jQuery as required. The final effect is illustrated in Figure 5.11.
Our dialog markup will consist of two nested span
elements, which will sit inside the
element we want to use to trigger the dialog. This may occasionally
require some creativity with your markup, but it helps us to position
the dialog, as we can give it an absolute position offset from the
parent element. It also aids with triggering events, since, if the user
moves the mouse over the dialog, it will still be over the triggering
element, so no additional hover
event handling is
required.
Here’s an example of the dialog box markup:

 Welcome to StarTrackr!  Legal Disclaimer   the planet's premier celebrity tracking …

DIALOG
object that will contain all our code. We set a delay
property at the top of the object (this will make it easier to modify
the configuration of the widget without hunting through the code to find
where this variable was set):
Then we add a function called
setDialogs
, which we’ll run when the page loads
or is resized. This function will find all the dialogs on the page and
determine their position by looking at their parent elements. It will
also set up a hover
event on each of them so that
they’re displayed on mouse over. Here’s the hover
event:
$('.dialog').parent().hover(function() { // store the dialog being hovered DIALOG.current = $(this); DIALOG.timer = setTimeout(function() { (1) // find the dialog, $(this).find(".dialog").fadeIn('fast'); }, DIALOG.delay); }, function() { // on mouseout, clear timer and hide dialog clearTimeout(DIALOG.timer); (2) $(this).find(".dialog").fadeOut('fast'); }).attr("title", ""); // clear the title to stop browser tooltips
for
versus each
each
loop:
$(".dialog").each(function(){// grab the containing element
each
to
replace a for
loop, we have to call jQuery,
and that takes time. Tiny fractions of a millisecond, sure, but
still time. And those fractions add up.
So we should always use a for
loop,
right? Not at all! If you know that there will be a time hit and are
aware what its impact will be on your code, go for your life. And
more importantly, if you’re storing a value inside the loop for reference later,
an each
loop provides that for free, whereas a
for
loop often needs extra legwork. So it’s not
always cut and dried, but as in this instance we store a value,
we’re going to stick with our each
loop.
each
to loop
over them, but first we’ll grab the height and width of the screen. If
we were to do this inside the loop, jQuery would need to calculate those values once for
each dialog box, even though they’re always the same. By storing the
values outside the loop, we avoid this wasteful calculation and improve
the performance of our script:
setDialogs: function () { var screenWidth = $(window).width(), screenBottom = $(window).scrollTop() + $(window).height(); … $(".dialog").each(function(){// grab the containing element ↵var container = $(this).parent(), top = container.height(), // default placement(1) totalHeight = top + $(this).outerHeight(),(2) width = $(this).outerWidth(), offset = container.offset(), left = 0; // give it relative position if required (3) if (container.css('position') != 'absolute' && ↵container.css('position') != 'fixed') { container.css({position: 'relative'}); } … } }
$(this).parent()
over and over. Here’s a breakdown of
the contents of the loop:
if
statement, you can use the
&&
operator to mean
and. So in the above example, the contents of the
if
block will only execute if
both conditions (on either side of
&&
) are met.
You can also write
||
(two pipe symbols) to mean
or. If we’d used that instead of
&&
above, the contents of the
if
block would execute if
either condition was met.
// re-position if it's off the right of the screen if (offset.left + width > screenWidth) { left = 0 - width + 42; $(this).addClass('left'); } else { $(this).removeClass('left'); } // re-position if it's off the bottom of the screen if (offset.top + totalHeight > screenBottom) { top = 0 - $(this).outerHeight(); $(this).addClass('above'); } else { $(this).removeClass('above'); }
top
or left
property
respectively, and assign a class that we’ll use to display the
appropriate part of our background image sprite.
The final (and easiest) step is to use the
css
action to assign the calculated
top
and left
properties to the
tips:
We’ll call our setDialogs
method on
document-ready, and also each time the window is resized, to ensure that
our tips are always adequately positioned:
$(document).ready(function() { DIALOG.setDialogs(); }); $(window).resize(function() { DIALOG.setDialogs(); });
span.dialog.left { background-position: 100% 0; } span.dialog.left span { padding: 15px 0 0 17px; } span.dialog.above { background-position: 0 100%; } span.dialog.above span { padding: 13px 0 0 12px; } span.dialog.above.left { background-position: 100% 100%; } span.dialog.above.left span { padding: 13px 0 0 17px; }
class
selectors together. This will
confuse Internet Explorer 6, which will only see the last class
in any style rule. Moreover, our PNG
image relies on alpha-channel transparency for the dialog’s drop
shadow, and this is also unsupported by IE6.
Over the last few years, several major sites (including YouTube
and Facebook) began phasing out support for IE6. This doesn’t mean
that they totally ignore this browser; rather, they accept that IE6
users will receive a degraded experience (perhaps similar to what
visitors without JavaScript will see).
For our dialog example, we could use conditional
comments to target some styles specifically to IE6 and provide
it with the same dialog functionality—except using a flat background
image without a thought-bubble style or a drop shadow. This way, the
background position would be inconsequential, and the PNG issue
solved.
Another option for folks doggedly hanging on to IE6 is Google’s Chrome
Frame. Chrome Frame brings Chrome’s Open Web technologies and
JavaScript engine to IE. If your environment lets you install plugins,
and you need to hang onto IE6, you might need to take a look at Chrome
Frame.
span
s with a dialog
class
, and you’re off to the races. This is
an important lesson: you should always try to structure your code in
such a way that you can reuse it later. This will save you work in the
long run, and give you more time to experiment with cool new
functionality instead of rebuilding the same old widgets every time you
need them.


Karma, taken Sept 05, 2011
Ch Staghorn's Adios Amigos (Karma)
(Madabout's Adieu to Staghorn's X BISS Am/Can CH Sunset Lubberline Spinnaker)
D.O.B.: Sept 16, 2010
OFA Prelim Hips Good, Elbows Normal, Cerf Clear
Call the Police!!! Our hearts have been stolen!!!
 She's quite similar in type to her older sister, Maddie (Staghorn's Adieu to the Madness). We're very happy with what Patsy produced for us here at Staghorn.
View
Karma's Pedigree
Left: Karma (Sept.04, 2011) ; Right : Karma (June 20, 2012)


datakali's products
Texas Fullz | SSN + DOB + DL | 100% Vali...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 154
In stock: 388
Digital delivery
Ships worldwide
Pennsylvania Fullz | SSN + DOB + DL | 10...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 0
In stock: 226
Digital delivery
Ships worldwide
Georgia Fullz | SSN + DOB + DL | 100% Va...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 332
In stock: 237
Digital delivery
Ships worldwide
Maryland Fullz | SSN + DOB + DL | 100% V...
1.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 130
In stock: 0
Digital delivery
Ships worldwide
Ohio Fullz | SSN + DOB + DL | 100% Valid...
2.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 300
In stock: 0
Digital delivery
Ships worldwide
Alabama Fullz | SSN + DOB + DL | 100% Va...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 20
In stock: 189
Digital delivery
Ships worldwide
South Carolina Fullz | SSN + DOB + DL | ...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 46
In stock: 531
Digital delivery
Ships worldwide
California Fullz | SSN + DOB + DL | 100%...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 533
In stock: 73
Digital delivery
Ships worldwide
Arizona Fullz | SSN + DOB + DL | 100% Va...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 0
In stock: 206
Digital delivery
Ships worldwide
Florida Fullz | SSN + DOB + DL | 100% Va...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 62
In stock: 336
Digital delivery
Ships worldwide
Oregon Fullz | SSN + DOB + DL | 100% Val...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 46
In stock: 154
Digital delivery
Ships worldwide
Nevada Fullz | SSN + DOB + DL | 100% Val...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 8
In stock: 233
Digital delivery
Ships worldwide
Kansas Fullz | SSN + DOB + DL | 100% Val...
3.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 73
In stock: 127
Digital delivery
Ships worldwide
USA Fullz | SSN + DOB | 100% Valid
1.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 50
In stock: 1150
Digital delivery
Ships worldwide
South Carolina Fullz | SSN + DOB | 100% ...
1.00
USD
datakali (347)
Vendor Level 3
Category: Personal Info
Sold: 8
In stock: 392
Digital delivery
Ships worldwide


Our Scotland Highlights
About us
Scenic Skye for the Soul
Hogwarts Experience for Harry Potter Fans
Galloway Forest Park Trial of Miles


Trojan Source Code (Can we trust open-source anymore?)
Last year, I overheard my boyfriend listening to a podcast that talks about the Trojan Source Code. I got interested and read the paper. Here is a beginner friendly explanation if you don’t want to read it (but I cannot see why).
First, let’s have some fun!
Open the online Python console here and try running the following code:
hello = "Hello world"
world = hello
print(world)
It is a standard “Hello world” right? How about this:
hello = "Hello world"
world = hello
print(world)
Wait! They LOOK the same!
Yes my friend, you are right. They look the same but are NOT the same.
Unicode! Uηicσժe!! Ⓤⓝⓘⓒⓞⓓⓔ!!!
We all know unicode is a bit wacky. But can you imagine a world that does not support unicode?
Unicode started as an attempt to make computer characters display all writing systems in the world. I benefit from it when I was a kid, learning how to use a computer at school. Like all “good kids” I will secretly open Netscape to browse websites. At that time, no one really care about the encoding when designing website. Sometimes, I would browse a website in Chinese but was displayed in random symbols. Then I know it’s time to change the encoding.
The most common unicode encoding is UTF-8, but there are many. For example, we use Big-5 for Chinese characters.
Our favourite emojis 💖😃🧸 are mostly added in 2014, and there will be more coming.
Bidirectional characters
Since unicode are designed to handle all writing system, and some writing systems (like Arabic and Hebrew) are reading and writing form right to left, oppose to left to right, what we English speakers are used to, there needs to be a way to tell the computer to “read” and display the characters from right to left. That way, is a set of “invisible” characters that indicate the directions of the text - Bidirectional characters.
Using bidirectional characters where it is not suppose to be, like codes, then it is not just weird, but it can cause more harm than that.
Trojan Source Code
We all know the story about the Trojan Horse, hiding solders in a huge horse that was suppose to be the gift. This is what Trojan Source Code is like, hiding in the source code. In the paper the researchers listed 3 types of Trojan Source Code:
1) Early returns
By hiding the bidirectional characters and return
statement in the comment, what appear to be harmless comment can force a function end early and leave out codes that needed to be executed.
2) Commenting-out
It is common to have comments alongside the code to help readability. By strategically adding bidirectional characters, what appear to be code that are executable will actually be a part of the comment when executed. Using this can make the code behave not as expected.
3) Stretched strings
Similar to commenting-out, what appear to be not included in a string can be “put” inside the string with bidirectional characters and “change” the behaviour of the code.
Besides there Trojan Source Code there are also similar exploitation with unicode:
1) Invisible character
Hiding invisible characters can be easily used to change behaviour of the code. Like replacing variable names or strings etc.
2) Homoglyphs
Similarly, homoglyphs (which means characters that looks the same but aren’t the same) can be used to replace function names so the unexpected one will be executed instead.
Should we be worried?
For the list of what works in Python you can see here at the GitHub repo. You are welcome to try those Trojan Source Code and see if they works on newer versions of Python.
For my personal opinion, the piece of advice I would give to other Pythonistas is that, use a editor with good syntax highlight or that will warn you if there’s hidden characters (GitHub will give you a warning if the code file contains bidirectional characters). Keep a good habit of linting your code (Pylint is a good choice, it will also give you warning if it “sees” hidden characters) and double check before running any code, especially those that copy and paste form the internet.
That’s only the beginning
As someone who works in open-source, I am always aware of the security of our work. We don’t want to accidentally spread malicious code and that harm the trust on the open-source software as a whole. There are more security issue that people keep finding and warning others, and we should all be aware.
I would like to thank the researchers who publish their findings. If you would like to know more, make sure you check out their website: https://trojansource.codes/
Here is my presentation slides:


Home
Products
BIO zone
Tea
Eco bakery
About me
Contact
Address
123 Main Street, Madrid, Spain 10030
Lets Talk
+1 8000 123456789
General Support
<EMAIL_ADDRESS>Send Us A Message
Tell us your name*
Enter your email*
Enter phone number*
Message*