Wednesday, November 11, 2015

Face Proximity Detection with JavaScript

Let’s suppose you'd like to let the visitors of your website make a video recording or take a picture of their face. How can you explain to them how close they're supposed to sit to the camera? You could write lengthy instructions, but you know that today almost nobody reads the instructions. Probably, a better approach to solve this problem would be to use a face detection algorithm that can evaluate where a face is in proportion to the frame, figuring out if the face is too far away or too close.

My development team at Mozilla needed a “video booth” feature where people were able to record themselves talking into the web camera and have those videos uploaded and shared, all in a web application. In cases like this one, the quality problems are usually related to the audio. Ideally people should use a decent quality microphone and sit in a room with minimal echo, but often it isn't possible. The best way to solve this issue is to ensure the user sits close to the built-in microphone of their laptop. To do that, we have implemented a face detection on the viewfinder, in order to tell them whether they are sitting near enough or not.

In this article, I'll show you how to build this functionality and learn something about the components involved.

Continue reading %Face Proximity Detection with JavaScript%


by Peter Bengtsson via SitePoint

This Week's HTML5 and Browser Technology News (Issue 214)


Read this e-mail on the Web
HTML 5 Weekly
Issue 214 — November 11, 2015
eBay Tech Blog
A thorough look at eBay’s approach to accessibility using HTML5, ARIA, and a variation of the BEM approach to CSS.


Jeremy Keith
The potential of Service Workers has gotten Jeremy Keith excited and in an experimental mood. Here, he takes a code-heavy look at what he’s been doing.


Mailgun  Sponsored
Easy SMTP integration and a simple, RESTful API abstracts away the messy details of sending transactional or bulk email. Scale quickly, whether you need to send 10 or 10 million emails. Start sending email now with Mailgun.

Mailgun

Wufoo
The formaction attribute forces a form to direct to the specified URL instead of the URL specified as the value of the action attribute in the parent form element.


Mozilla Hacks
Firefox’s special ‘developer edition’ is now a year old. Version 44 includes new visual editing and memory management tools, plus a WebSocket debugging API, which are shown off here.


Michael Fouquet
Some straight forward style and tooling suggestions for writing front-end code that’s ‘durable, reliable and would make NASA proud.’


Dean Hume
A demonstration of using a Service Worker to intercept requests for JPEGs and PNGs and rewriting them to request more efficient WebP images instead.


Jobs

In brief

Curated by Peter Cooper and published by Cooper Press.
Want to post a job? E-mail us or use our self-serve system.

Unsubscribe : Change email address : Read this issue on the Web

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


by via HTML5 Weekly

Using HTML5’s Native Drag and Drop API

Everyone loves an easy-to-use and interactive user interface and ever since the introduction of smartphones there has been a jump in expectations from users; The expectation is that your website will be intuitive, will use universally understood actions, and overall proving an easy way to engage with your site.

Giving your users the ability to drag, drop, and sort makes your site more intuitive as people understand how to move element X to position Y and that moving object A in front of object B makes object A come first.

Handling dragging, dropping, and sorting has always been a task for JavaScript and developers have previously had the option of building their own interactions or to use a prebuilt solution. With the advent of the HTM5 Drag and Drop API, developers will be able to hook into native events and attributes to handle these interactions.

A Brief Introduction

Lets go through the API so we can get an overview of how it all works.

The native API lets us define elements that are draggable by using the draggable="true" attribute on your desired elements. Some elements are by default draggable even without any modifications (such as images or text).

Native drag and drop text and image

By default when draggable elements are dragged, only form elements such as input will be able to accept them as a drop. You would have seen this before; if you select some text and drag it into a textarea the text is copied into the textarea element.

Dragging text directly into a textarea element

The native API also handles drags from external areas on your OS onto your drop zones. Almost all good Content Management Systems provide drag and drop uploading of content. Since these elements are external, all you need to configure is the drop zone (and also have a compatible browser).

Using the native drag and drop on Gmail

Drag and Drop API Events

The native API provides the following events that you can listen for. These events will apply to either the draggable item or the drop zone and will be triggered at set times.

When these events are fired, we have access to a local object (which we will call event). This object holds more information about the event itself and will give you access to the dataTransfer object where you will set most of your methods and properties.

We will need to hook a callback function onto each of the events so we can interact with the API:

[code language="javascript"]
// add a handler to trigger on dragstart
document.addEventListener('dragstart', function(event) {
// add your dragstart code here
}, false);
[/code]

These events are triggered only on draggable items.

dragstart
Triggered as soon as we start dragging. It’s here we will need to tell the API about what we will be dragging and set up other values. Use the setData() method to set the data you want to save, set the effectAllowed property for the draggable element, and define the draggable helper with setDragImage().

drag
This event is triggered continually during dragging. The number of times it occurs depends on the browser. This is useful for determining exactly where the draggable item is.

dragend
This is event fires as soon as the draggable is dropped (regardless of where it is dropped) and generally triggered directly after the drop zone’s drop event. You can use this event to reset styles applied when dragging or to perform other cleanup actions. The dragend event has access to the draggable so you can do calculations after dragging has ended (for example seeing if the drop event was successful by looking for newly added elements and then removing the original draggable).

These events are triggered only on elements that you specify as drop targets (or are already naturally drop targets, like form elements):

dragenter
Triggered just once as soon as a draggable enters a droppable area. This will trigger when more than 50% of the draggable is inside the drop zone.

This event sets the dropEffectof the drop zone. By default drops on non-form elements won’t do anything. You will need to manually call event.preventDefault() and event.stopPropagation() to tell the API that this drop should take place.

You can check the dataTransfer object for the effectAllowed value that has been set by the draggable and then compare it to the value your drop zone has for its dropEffect. If these values won’t work together (i.e one is copy and the other is link) then the browser won’t drop the item successfully (even if you prevented defaults and stopped propagation).

You can use the types property to get a list of all data types that have been set in the dragstart event. You can’t see the data but you can see its type. It’s here you can use another method called contains to see if a certain type of data has been set up. This is done via the event.dataTransfer.types.contains(type) method. You could use this to ensure that something has been set to the text/html type for example.

You can set classes or trigger actions now that you know your draggable has entered into the drop zone (a common theme is to style the drop zone differently to show it is being activated).

dragover
This event is essentially the same as dragenter but it is called continually while the draggable item is inside the drop zone. This event is perfect if you want to determine the exact position of the draggable (because it is updated continually).

This event sets the dropEffect of the drop zone and, like dragenter, you will need to prevent default and propagation.

dragleave
This is triggered once a draggable has moved away from a drop zone. It’s generally used to remove styles added in either the dragenter or dragover events and fires once the draggable is not overlapping with the drop zone.

drop
This event is triggered once the draggable has been released and the drop area agrees to accept the drop. This will only fire if the draggable element and the drop area have correct dropEffect andeffectAllowed values. On drop you will need to collect the information using the getData() method.

Continue reading %Using HTML5’s Native Drag and Drop API%


by Simon Codrington via SitePoint

Ideal Image Slider

Ideal Image Slider is a simple slider that has just the right amount of features, with no bloat and be easy to extend so that more features can be added as "extensions".


by via jQuery-Plugins.net RSS Feed

New Course: Upgrade an App to watchOS 2

With the recent announcement of watchOS 2, many developers have been eager to learn all its new features and functionality. 

We'll be covering those features in other courses, but first, here's a quick, free course showing you how to upgrade an app to watchOS 2 from the older watch platform.

What You’ll Learn

In just eight short videos, Envato Tuts+ instructor Derek Jensen will walk you through the process of taking an existing application and upgrading it to use the new Swift 2.1 syntax as well as making it compatible with watchOS 2. 

By the end of this course, you'll be ready to convert your watchOS apps to the latest platform and start exploring all those new features. And if you need help with your UI design, you can also check out this selection of different Apple Watch templates and interface kits on GraphicRiver!

Watch the Introduction

Take the Course

To take this free course, simply go to the course page and follow the steps to create a free account. If you already have an account, just log in and you’ll be able to get started right away.


by Andrew Blackman via Tuts+ Code

Core Data and Swift: Relationships and More Fetching

UiDSGN

UiDSGN – Daily Ui Design Inspiration and Freebies.


by csreladm via CSSREEL | CSS Website Awards | World best websites | website design awards | CSS Gallery