Wednesday, April 19, 2017

This Week's HTML5, CSS and Browser Tech News #286

Read this e-mail on the Web
FrontEnd Focus
Issue 286 — April 19, 2017
CSS Custom Properties (aka CSS variables) are now supported in all major browsers and they offer a lot of possibilities to Web developers, as seen in this thorough overview.
Serg Hospodarets

“Now that CSS Grid Layout is a reality, I wanted to see what it would take to replace an existing grid framework with CSS Grid.”
Dan Brown

Heather Migliorisi covers two accessibility issues to keep in mind when implementing smooth scrolling: focus management and animations.
CSS Tricks

Bitmovin
An easy to integrate and versatile HTML5 based MPEG-DASH and HLS player for desktop, mobile, VR Headsets, Chromecast, AirPlay, AppleTV and SmartTVs. Including a WebGL based VR and 360 video component and a completely customizable HTML5/CSS UI.
Bitmovin   Sponsor

How and why Geckoboard uses CSS Variables in combination with React to re-style their web app on the fly.
Dan Bahrami

Responsive Web design has changed the way we build sites. Here, Smashing Magazine looks at responsive navigation techniques, in particular.
Chris Poteet

position: sticky doesn’t work in Edge yet, but this provides similar ‘sticky header’-style functionality in under 2KB.
Dollar Shave Club

The Firefox team are getting rid of the Aurora channel and basing the Developer Edition on the beta build.
Mozilla Hacks

Jobs Supported by Hired.com

  • Frontend Developer at X-Team (Remote)We seek a developer with extensive Frontend knowledge. We're 100% remote and provide the funding needed to help you achieve your goals and grow. X-Team
  • Frontend Engineer at FR8StarWe are looking for a Frontend Engineer to help us revolutionize the trucking industry. FR8Star
  • Frontend Web DeveloperCreate an exceptional community experience for over 100 million Runtastic.com users. Join our team now! Runtastic GmbH

Can't find the right job? Want companies to apply to you? Try Hired.com.

In Brief

CSS3 Pseudo-Classes: The Basics tutorial
Some uncommon ones here such as :read-only and :in-range
Goldstein, Lazaris and Weyl

Focusing a background-image on a Precise Location with %ages tutorial
Jay Sitter

On Hiding Content tutorial
How the hidden attribute works, how it differs from aria-hidden and how it relates to just hiding with CSS.
Hidde de Vries

Creating Testable, Modularized Chrome Extensions tutorial
Nathaniel Woodthorpe

Encoding Data in CSS to Be Reused in JavaScript tutorial
Alex Gyoshev

Building a CSS Grid Overlay tutorial
Andreas Larsen

Full-day Workshop: Using ES6 and React with Netflix's Brian Holt course
React eschews the traditional MVC architecture, a counter-intuitive approach Brian explains along with JSX, React best practices, and the React component lifecycle.
Forward Courses  Sponsor

A Modern Front-End Workflow video
In 30 minutes, learn various DevTool secrets and how to adopt a modern development and debugging workflow.
Umar Hansa

The Benefits of Server-Side Rendering Over Client-Side Rendering opinion
Walmart Labs

Stop Using Device Breakpoints opinion
Content breakpoints give people better experiences no matter what size device they have.”
Adam Silver

3 CSS Grid Features That Make My Heart Flutter opinion
Una Kravets

Chrome Debugging Protocol Proxy: A Reverse WebSocket Proxy tools
If you want to debug the debugger..
Mateusz Gajewski

cssnano: A Modular Minifier, Built On Top of The PostCSS Ecosystem tools
Ben Briggs

CSSPeeper: A Smart CSS Viewer Tailored for Designers tools
A Chrome extension for inspecting items and styles.
Dawid Młynarz and Jędrzej Sadowski

SQL Source Control: track each change to your SQL Server database tools
Get a full history in your source control system. See who made changes, what they did & why. See how
Red Gate  Sponsor

RAGrid.css: A Grid Framework with Auto-Layout Features code
Adam Argyle

WebVR Experiments demo
Google recently launched WebVR Experiments, a site featuring a dozen or so interactive WebVR apps and their source code. Associated blog post here.
Google

A Pure CSS Crossword using CSS Grid demo
Adrian Roworth

Curated by Peter Cooper and Chris Brandrick and published by Cooperpress.
Like this? You may also enjoy: JavaScript Weekly, Node Weekly, and React Status.

Stop getting FrontEnd Focus : Change email address : Read this issue on the Web

© Cooper Press Ltd. Office 30, Lincoln Way, Louth, LN11 0LS, UK


by via FrontEnd Focus

Quick Tip: Working With Custom Fonts in Android O

Why You Need to Know About Sketch’s New File Format

Sketch 43

Sketch 43 recently introduced a rather interesting update to their “.sketch” file format, making it more human-readable when opened in a code editor (by that I mean we actually could read the coding of the .sketch file and see details of the layers and styles in code format).

“Huh? What? Why would you want to do that?”

Well, you wouldn’t — this new file format is designed to be read by web browsers so that we can build apps that interpret .sketch files (think: better design handoff, Git-like version control, maybe even Sketch → HTML/CSS automation).

File Format: Sketch 42 vs. Sketch 43

Prior to version 43, the .sketch file format was written in binary (you don’t need to know what that means, just that it’s unreadable). Now it’s written in JSON, which is not only human-readable but can be read and even parsed by web browsers.

You can witness first-hand how web browsers will read this new file format by reading it yourself. Quite literally, you could dive into the code of a .sketch file, edit the JSON code itself, then open the .sketch file in Sketch and see the changes made to our design (don’t worry, designers are still expected to design using the Sketch GUI, this update doesn’t change that).

Here’s how it’s done.

Decompressing and Editing a Sketch File

  • First, rename yourfile.sketch to yourfile.zip
  • Decompress the compressed zip
  • Edit the JSON code (change some styles, for example)
  • Recompress the files again
  • Rename yourfile.zip to back to yourfile.sketch
  • Open the file Sketch to see the changes!

Converting .sketch to JSON

Continue reading %Why You Need to Know About Sketch’s New File Format%


by Daniel Schwarz via SitePoint

Working With PHP Arrays in the Right Way

In this tutorial, I am going to make a list of common PHP array functions with examples of usage and best practices. Every PHP developer must know how to use them and how to combine array functions to make code readable and short.

Also, there is a presentation with given code examples, so you can download it from the related links and show it to your colleagues to build a stronger team.

The Basics

Let's start with the basic functions that work with array keys and values. One of them is array_combine(), which creates an array using one array for keys and another for its values:

You should know, that the function array_values() returns an indexed array of values, array_keys() returns an array of keys of a given array, and array_flip() exchanges keys with values:

Make Your Code Shorter

The function list(), which is not really a function, but a language construction, is designed to assign variables in a short way. For example, here is a basic example of using the list() function:

This construction works perfectly with functions like preg_slit() or  explode() . Also, you can skip some parameters, if you don't need them to be defined:

Also, list() can be used with foreach, which makes this construction even better:

With the extract() function, you can export an associative array to variables. For every element of an array, a variable will be created with the name of a key and value as a value of the element:

Be aware that extract() is not safe if you are working with user data (like results of requests), so it is better to use this function with the flags EXTR_IF_EXISTS and EXTR_PREFIX_ALL.

The opposite of the previous function is the compact() function, which makes an associative array from variables:

Filtering Functions

There is a great function for array filtering, and it is called array_filter(). Pass the array as the first param and an anonymous function as the second param. Return true in a callback function if you want to leave this element in the array, and false if you don't:

There is a way to filter not only by the values. You can use ARRAY_FILTER_USE_KEY or ARRAY_FILTER_USE_BOTH as a third parameter to pass the key or both value and key to the callback function.

Also, you can call array_filter() without a callback to remove all empty values:

You can get only unique values from an array using the array_unique() function. Notice that the function will preserve the keys of the first unique elements:

With array_column(), you can get a list of column values from a multi-dimensional array, like an answer from a SQL database or an import from a CSV file. Just pass an array and column name:

Starting from PHP 7, array_column() becomes even more powerful, because it is now allowed to work with an array of objects. So working with an array of models just became easier:

Walking Through the Arrays

Using array_map(), you can apply a callback to every element of an array. You can pass a function name or anonymous function to get a new array based on the given array:

There is a myth that there is no way to pass values and keys of an array to a callback, but we can bust it:

But this looks dirty. It is better to use array_walk() instead. This function looks the same as array_map(), but it works differently. First of all, an array is passed by a reference, so array_walk() doesn't create a new array, but changes a given array. So as a source array, you can pass the array value by a reference in a callback. Array keys can also be passed easily:

Joining the Arrays

The best way to merge two or more arrays in PHP is to use the array_merge() function. Items of arrays will be merged together, and values with the same string keys will be overwritten with the last value:

To remove array values from another array (or arrays), use array_diff(). To get values which are present in given arrays, use array_intersect(). The next examples will show how it works:

Do the Math With Array Values

Use array_sum() to get a sum of array values, array_product() to multiply them, or create your own formula with array_reduce():

To count all the values of an array, use array_count_values(). It will give all unique values of a given array as keys and a count of these values as a value:

Generating Arrays

To generate an array with a given size and the same value, use array_fill():

To generate an array with a range in of keys and values, like day hours or letters, use range():

To get a part of an array—for example, just the first three elements—use array_slice():

Sorting Arrays

It is good to remember that every sorting function in PHP works with arrays by a reference and returns true on success or false on failure. There's a basic sorting function called sort(), and it sorts values in ascending order without preserving keys. The sorting function can be prepended by the following letters:

  • a, sort preserving keys
  • k, sort by keys
  • r, sort in reverse/descending order
  • u, sort with a user function

You can see the combinations of these letters in the following table:

a k r u
a asort
arsort uasort
k ksort krsort
r arsort krsort rsort
u uasort
usort

Combining Array Functions Like a Boss

The real magic begins when you start to combine array functions. Here is how you can trim and remove empty values in just a single line of code with array_filter() and array_map():

To create an id to a title map from an array of models, we can use a combination of array_combine() and array_column():

To get the top three values of an array, we can use array_count_values(), arsort(), and array_slice():

It is easy to use array_sum() and array_map() to calculate the sum of order in a few rows:

Conclusion

As you can see, knowledge of the main array functions can make your code much shorter and more readable. Of course, PHP has many more array functions, and even the given functions have many variations to use with extra parameters and flags, but I think that in this tutorial we've covered the basics that every PHP developer should know.

Please note that I've created a presentation with the given examples, so you can download it from the related links and show it to your team.

If you have any questions, don't hesitate to ask them in the comments to the article. 

Further Reading and Related Links


by Anton Bagaiev via Envato Tuts+ Code

Getting Started With Chart.js: Line and Bar Charts

In the first introductory Chart.js tutorial of the series, you learned how to install and use Chart.js in a project. You also learned about some global configuration options that can be used to change the fonts and tooltips of different charts. In this tutorial, you will learn how to create line and bar charts in Chart.js.

Creating Line Charts

Line charts are useful when you want to show the changes in value of a given variable with respect to the changes in some other variable. The other variable is usually time. For example, line charts can be used to show the speed of a vehicle during specific time intervals.

Chart.js allows you to create line charts by setting the type key to line. Here is an example:

We will now be providing the data as well as the configuration options that we need to plot the line chart.

Since we have not provided any color for the line chart, the default color rgba(0,0,0,0.1) will be used. We have not made any changes to the tooltip or the legend. You can read more about changing the crate size, the tooltip or the legend in the first part of the series

In this part, we will be focusing on different options specifically available for modifying line charts. All the options and data that we provided above will create the following chart.

The color of the area under the curve is determined by the backgroundColor key. All the line charts drawn using this method will be filled with the given color. You can set the value of the fill key to false if you only want to draw a line and not fill it with any color.

One more thing that you might have noticed is that we are using discrete data points to plot the chart. The library automatically interpolates the values of all other points by using built-in algorithms. 

By default, the points are plotted using a custom weighted cubic interpolation. However, you can also set the value of the cubicInterpolationMode key to monotone to plot points more accurately when the chart you are plotting is defined by the equation y = f(x). The tension of the plotted Bezier curve is determined by the lineTension key. You can set its value to zero to draw straight lines. Please note that this key is ignored when the value of cubicInterpolationMode has already been specified.

You can also set the value of the border color and its width using the borderColor and borderWidth keys. If you want to plot the chart using a dashed line instead of a solid line, you can use the borderDash key. It accepts an array as its value whose elements determine the length and spacing of the dashes respectively.

The appearance of the plotted points can be controlled using the pointBorderColorpointBackgroundColorpointBorderWidthpointRadius, and pointHoverRadius properties. There is also a pointHitRadius key, which determines the distance at which the plotted points will start interacting with the mouse.

The above speedData object plots the same data points as the previous chart but with custom values set for all of the properties.

You can also plot multiple lines on a single chart and provide different options to draw each of them like this:

Creating Bar Charts

Bar charts are useful when you want to compare a single metric for different entities—for example, the number of cars sold by different companies or the number of people in certain age groups in a town. You can create bar charts in Chart.js by setting the type key to bar. By default, this will create charts with vertical bars. If you want to create charts with horizontal bars, you will have to set the type to horizontalBar

Let's create a bar chart which plots the density of all the planets in our solar system. The density data has been taken from the Planetary Fact Sheet provided by NASA. 

The parameters provided above will create the following chart:

Just like the line chart, the bars are filled with a light gray color this time as well. You can change the color of the bars using the backgroundColor key. Similarly, the color and width of the borders of different bars can be specified using the borderColor and borderWidth keys. 

If you want the library to skip drawing the border for a particular edge, you can specify that edge as a value of the borderSkipped key. You can set its value to top, left, bottom, or right.  You can also change the border and background color of different bars when they are hovered using the hoverBorderColor and hoverBackgroundColor key. 

The bars in the bar chart above were sized automatically. However, you can control the width of individual bars using the barThickness and barPercentage properties. The barThickness key is used to set the thickness of bars in pixels, and barPercentage is used to set the thickness as a percentage of the available category width. 

You can also show or hide a particular axis using its display key. Setting the value of display to false will hide that particular axis. You can read more about all these options on the documentation page.

Let's make the density chart more interesting by overriding the default values for bar charts using the following code.

The densityData object is used to set the border and background color of the bars. There are two things worth noticing in the above code. First, the values of the barPercentage and borderSkipped properties have been set inside the chartOptions object instead of the dataDensity object. 

Second, the chart type has been set to horizontalBar this time. This also means that you will have to change the value of barThickness and barPercentage for the y-axis instead of the x-axis for them to have any effect on the bars.

The parameters provided above will create the following bar chart.

You can also plot multiple datasets on the same chart by assigning an id of the corresponding axis to a particular dataset. The xAxisID key is used to assign the id of any x-axis to your dataset. Similarly, the yAxisID key is used to assign the id of any y-axis to your dataset. Both the axes also have an id key that you can use to assign unique ids to them.

If the last paragraph was a bit confusing, the following example will help clear things up.

Here, we have created two y-axes with unique ids, and they have been assigned to individual datasets using the yAxisID key. The barPercentage and categoryPercentage keys have been used here to group the bars for individual planets together. Setting categoryPercentage to a lower value increases the space between the bars of different planets. Similarly, setting barPercentage to a higher value reduces the space between bars of the same planet.

Final Thoughts

In this tutorial, we have covered all the aspects of line charts and bar charts in Chart.js. You should now be able to create basic charts, modify their appearance, and plot multiple datasets on the same chart without any issues. In the next part of the series, you will learn about the radar and polar area charts in Chart.js.

I hope you liked this tutorial. If you have any questions, please let me know in the comments.


by Monty Shokeen via Envato Tuts+ Code

This Week in Mobile Web Development (#154)

Mobile Web Weekly April 19, 2017   #154
Peter Cooper recommends
Mobile Web Video Playback Best Practices — Best practices from Google on creating the best mobile media experiences for the mobile Web.
Google Developers
Peter Cooper recommends
ReactXP: A Layer To Share React View Code Between Platforms — Built by the Skype team at Microsoft, ReactXP is a cross-platform layer for sharing view definitions, styles, and animations for multiple target platforms.
Microsoft
Brian Rinaldi recommends
6 Ways to Improve Long-Scroll Mobile Websites — Abbas Rajani shows us how to offer users a better mobile UX by optimizing the layout and content of long-scrolling mobile websites.
Sitepoint
Sponsored
Linux cloud hosting starting at 1GB of RAM for $5/mo. — Get a Linode server up and running in seconds. Simply choose your plan, distro and location and you’re ready to deploy your server. Use promo code MOBILEWEB20 for a $20 credit on a new account.
linode

Holly Schinsky recommends
Using HTML5 Canvas to Create a Rating Component in Ionic — How to build a rating component for Ionic apps using HTML5 Canvas.
Josh Morony
Chris Brandrick recommends
Develop An Angular Ionic Mobile App using Bluemix Push Services — Tim Minter runs through how to set up, configure, and test Push notifications the Angular way.
IBM
Holly Schinsky recommends
How to Use Service Workers in Progressive Web Apps — Why you should use service workers in your progressive web apps—and how to get started.
Mark Pedersen
Brian Rinaldi recommends
PWA Stats — Aggregates stats and news related to Progressive Web Apps.
CloudFour
Holly Schinsky recommends
Create Your First Cordova App — This guide shows you how to create your first Cordova app and deploy it to various native mobile platforms using the Cordova CLI.
Mahesh Kariya
Holly Schinsky recommends
Framework7 Tutorial — A guide to getting started with Framework7.
tutorialspoint
Holly Schinsky recommends
Continuous Integration for Mobile vs. Web Applications — A rundown of the key differences in using continuous integration for your mobile versus web apps.
Nevercode
Chris Brandrick recommends
TinyCrayon SDK for iOS — An SDK with tools for adding image cutout and layer mask capabilities to your mobile apps.
TinyCrayon
Brian Rinaldi recommends
RAGrid.css — A grid framework that works like auto-layout by aligning and distributing and uses recognizable attributes instead of classes.
Adam Argyle
Brian Rinaldi recommends
JavaScript Server-Side Rendering with Device Detection — The benefits of server-side rendering with device detection and an example of how to implement it using the Vue.js framework.
Ruadhán O'Donoghue
Holly Schinsky recommends
Network Detection for Apps Wrapped in a UIWebView — An approach for handling online/offline detection for Ruby/Rails/Framework7 powered apps inside a UIWebView.
Michael Edlund
Brian Rinaldi recommends
Replace Bootstrap Layouts with CSS Grid — Now that CSS Grid Layout is a reality, this article explores what it would take to replace an existing grid framework with CSS Grid.
Dan Brown
Brian Rinaldi recommends
Conversions: Psychology Behind Mobile Behaviors — A summary of Nathalie Nahai’s session discussing psychological principles to consider when designing mobile experiences.
Luke Wroblewski
Brian Rinaldi recommends
Understanding the Default Ionic Plugins — A look at the six plugins are automatically installed when you create a new Ionic application.
Chris Griffith
Chris Brandrick recommends
Deploying An Ionic App As A Mobile Website
Saurabh Odhyan
Holly Schinsky recommends
What Are The Basic Differences Between PhoneGap, Ionic, Titanium and Cordova? — An explanation and comparison of some popular mobile app solutions.
Mahesh Kariya


by via Mobile Web Weekly

Tech Radar 2017

Tech Radar 2017

Gorgeous design and transitions in this One Pager hosting an interactive Tech Radar infographic. The Single Page site by Kollegorna displays all the emerging tools and technologies they're an eye on. The mobile adaption, that includes Force Touch functionality, is simply stunning.

by Rob Hope via One Page Love