Thursday, June 11, 2015

AngularJS Testing Tips: Bootstrap blocks, Routes, Events, and Animations

In the process of building and delivering full featured software, we apply several techniques to check the correctness and quality of the software. Unit testing is one of these techniques. Many organizations pay a lot of attention towards unit testing as it reduces the cost of finding and fixing potential issues of an application. As we start developing applications with hundreds of thousands of JavaScript lines, we can't escape from testing the code. Several JavaScript developers say that testing JavaScript is even more important as behavior of the language is unknown until runtime. Thankfully, AngularJS makes testing the code written using the framework easier by supporting features like Dependency Injection (DI). In three of my past articles, I discussed a few tips on mocking, how to test controllers, services and providers and how to test directives. This article will cover testing Bootstrap blocks of an AngularJS application (includes config blocks, run blocks and route resolve blocks), scope events and animations.

Testing Config and Run blocks

Config and run blocks are executed at the beginning of the life cycle of a module. They contain important logic that controls the way a module, a widget, or an application works. It's a bit tricky to test them as they can't be called directly like other components. At the same time, they can't be ignored as their role is crucial. Consider the following config and run blocks: [code language="javascript"] angular.module('configAndRunBlocks', ['ngRoute']) .config(function ($routeProvider) { $routeProvider.when('/home', { templateUrl: 'home.html', controller: 'HomeController', resolve: { bootstrap: ['$q', function ($q) { return $q.when({ prop: 'value' }); }] } }) .when('/details/:id', { templateUrl: 'details.html', controller: 'DetailsController' }) .otherwise({ redirectTo: '/home' }); }) .run(function ($rootScope, messenger) { messenger.send('Bootstrapping application'); $rootScope.$on('$locationChangeStart', function (event, next, current) { messenger.send('Changing route to ' + next + ' from ' + current); }); }); [/code] Similarly to the case of testing providers, we need to make sure that the module is loaded before testing the functionality inside the config and run blocks. So, we will use an empty inject block to load the modules. The following snippet mocks the dependencies used in above block and loads the module: [code language="javascript"] describe('config and run blocks', function () { var routeProvider, messenger; beforeEach(function () { module('ngRoute'); module(function ($provide, $routeProvider) { routeProvider = $routeProvider; spyOn(routeProvider, 'when').andCallThrough(); spyOn(routeProvider, 'otherwise').andCallThrough(); messenger = { send: jasmine.createSpy('send') }; $provide.value('messenger', messenger); }); module('configAndRunBlocks'); }); beforeEach(inject()); }); [/code] I intentionally didn't mock the $routeProvider object as we'll test the registered routes later in this article.

Continue reading %AngularJS Testing Tips: Bootstrap blocks, Routes, Events, and Animations%


by Ravi via SitePoint

Introducing Pure.css – A Lightweight Responsive Framework

Frameworks make it easy to design websites. You may already have been using popular frameworks like Bootstrap in your projects. Today I will introduce you to Pure.css (simply referred to as “Pure”), a small framework made up of CSS modules. All its modules put together weigh less than 4.0KB if served minified and gzip'd. You can save even more bytes if you decide to use only one or two of the modules.

Pure’s minimal styling ensures that you can customize the look of elements to suit your needs without much effort. You can include Pure in your projects using the following line:

[code language="html"] [/code]

Introducing the Grid System

The grid system in Pure differs considerably from that of Bootstrap and it is powerful and easy to work with once you get past the basics. There are a few things that you need to keep in mind before proceeding:

  • Pure has a wrapper grid class called pure-g and unit classes named pure-u-* . Make sure all your content is inside the grid units for proper rendering.
  • Widths are calculated based on fractions. The fractions themselves are decided by class names. For example, pure-u-2-5 has a width of 40%.
  • All child elements within a pure-g element must have the class name pure-u or pure-u-* .

By using additional class names like pure-u-md-2-3 you can control the width of different elements at specific breakpoints. Take a look at the following HTML:

[code language="html"]
One
Two
Three
[/code]

The above code does the following: When the screen size is smaller than 568px, all divs will be 100% wide. When the screen size is above the medium screen category (768px) the first div is set to a width of 20% while others are 40% wide each.

The grids are based on a 5th and 24th fraction system. For example, in the class name pure-u-x-24, x can be anything between 1 and 24 inclusive. Furthermore, pure-u-1-12 and pure-u-2-24 are the same. For a more detailed discussion of the grid system, refer to the official documentation.

Pure provides vertical menus by default. Minimal styling and use of low-specificity selectors make it a lot easier to customize the menus. Here is the code to create a vertical menu:

[code language="html"] [/code]

To change the above menu to horizontal, add the class name pure-menu-horizontal. Additionally, you can mark a menu item as selected or disabled using the class names pure-menu-selected and pure-menu-disabled, respectively.

Creating Dropdown Navigation

Creating dropdown navigation requires small changes in the markup. You need to add the class name pure-menu-has-children to the appropriate menu item. To display the submenu on hover, include the class name pure-menu-allow-hover. The code snippet below should clear things up:

[code language="html"] [/code]

You can also include this example script written in vanilla JavaScript to make the menu more accessible. It provides ARIA support, submenu arrow key navigation, and menu dismissal based on outside events.

Below is a demo of Pure's navigation menu with a dropdown.

Continue reading %Introducing Pure.css – A Lightweight Responsive Framework%


by Monty Shokeen via SitePoint

5 Stunning WordPress Portfolio Themes for Designers

Portfolios are difficult endeavours. If you meet any designer, chances are they will mention their portfolio at some point. Just look at Behance or Dribbble; these communities organize Portfolio Reviews or Meetups regularly to mingle with their own kind, so their portfolio is always up to date.

Obsessions aside, having a portfolio is a need in today’s digital age. Where a physical portfolio is seen very rarely these days, you will find it hard to land a job or gig without a portfolio or an established online presence, especially as a creative.

While it’s very helpful to be present on social networks for designers as Behance or Dribbble, you might want to settle with an independently hosted portfolio which you have control over. As an open source CMS, WordPress is perfect for this task.

I won’t be getting into the details how to install a WordPress installation, instead I'm going to suggest some of the best WordPress portfolio themes I witnessed this year. Some of them are accompanied with a real use case so you will be able to see how this might look outside of the idealistic preview of the theme providers.

Continue reading %5 Stunning WordPress Portfolio Themes for Designers%


by Elio Qoshi via SitePoint

It’s competition time! Post in June, and win big!

“OMG I love competitions!” I hear you say. Of course you do, who doesn’t like a good win? During the month of June, you can win one of eight incredible prizes just for posting on the SitePoint forums. You read correctly: just for posting on the SitePoint forums in June, you can win. Big. Every […]

Continue reading %It’s competition time! Post in June, and win big!%


by Jasmine Elias via SitePoint

Infographic: Are You a Victim of “The Struggle?”

This piece was originally found on growth everywhere, a site where the worlds top entrepreneurs are interviewed. According to Ben Horowitz, The Struggle is when your dreams turn into nightmares. “…Then, after working night and day to make your vision reality, you wake up to find that things did not go as planned. Your company […]

Continue reading %Infographic: Are You a Victim of “The Struggle?”%


by Eric Siu via SitePoint

BiStudyo

Responsive and clean web site.


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

Atomic: A Faster Way To Design Beautiful Interactions?

Interaction design is the art of creating logical responses to a user's action on the web. Whether you're an interaction specialist, a user experience consultant, or a broadly-skilled web designer, it's your responsibility to decide how a web element reacts to interaction and communicate that to the development team, even if you don't quite understand the technologies that they'll use.

But what is the fastest way to do that, without walking over to your developers desk and gesturing insane hand movements?

Also, what if you work remotely?

Atomic finally released their beta last week and it's the fastest way of sampling an interaction idea and sending it out.

atomic logo

Before Atomic

FramerJS, Origami and Pixate are some of the tools at our disposal already, but we don't always want to code our interactions or test them on native devices, do we?

Atomic is blazingly fast, and if you're coming from a Sketch App background, it's even better. It mimics the same keyboard shortcuts, has the same intuitive snap-to features, and quite honestly it felt like I was using Sketch, only with the ability to prototype interactions.

Getting Started

Ready to start? It'll only take a few minutes of your time. Head over to the atomic website, sign up for the beta, and select "New Design" at the Projects screen. In this small tutorial we'll be transitioning a dropdown arrow into a close icon upon a click interaction.

Sample project seletion

Creating The First State

Press "L" to initiate a simple Line.

The other shortcuts are "S" for Select, "R" for Rectangle, "O" for Oval, "T" for Text, "I" for Image and "H" for Hotspot.

You can hold "Shift" while dragging to create a completely accurate 45 degree angle; to skip ahead a few steps, the X, Y, X2 and Y2 should be 350, 250, 450, 350 respectively, and also make sure the "Stroke" is 10px.

Draw a line diagonally right and down

Press "D" for Duplicate and enter a new set of coordinates: 453, 250, 443 and 350. We now have our dropdown icon, but we need it center-aligned. See the layers on the left-hand side? Click both of them while holding Shift and drag both lines together into the center of the artboard. You'll know you've hit the spot when the red auto-alignment lines appear.

We've created our first state.

First state: The complete down arrow shape

Creating The Second State

Click "Pages" in the layers sidebar; click "Page 1" on the card and rename it to something more relevant, like State 1 (Dropdown). Click the hamburger menu icon, also on the card, and duplicate our first state - then rename the duplication to State 2 (Close).

Atomic: Duplicate state 1 as your starting point.

Switch back to "Layers" and select that right-most line; drag it to the left until the dropdown icon resembles a close icon. Repeat the multiple layer select step (by selecting both layers while holding Shift, in case you forgot) and drag into the center of the artboard again.

Creating Interactive Hotspots

Now this is where the magic happens. Press "H" to create a Hotspot. Since we're only sampling a single interaction, the hotspot can be any size you wish, as long as it fully covers the dimensions of our icon.

After you've created the hotspot, a new set of options will appear. Under the "Interaction" heading, select the first state as the "Go To" option. Select "Cubic: Ease Out" as the animation type. Atomic is able to handle interactions of much higher complexity, but for the sake of this tutorial we'll keep it simple and use the default values for the other options.

Continue reading %Atomic: A Faster Way To Design Beautiful Interactions?%


by Daniel Schwarz via SitePoint