Be Slightly Careful with Sub Elements of Clickable Things

Say you want to attach a click handler to a

Getting Tired of Endless Client Revisions? 270+ Pre-Built Websites Are the Solution (Sponsored)

Website revisions are to be expected. They also tend to be few and are usually minor in nature. However, some clients never seem to be satisfied. Sometimes, they also have a problem explaining what they expect from you. On the other hand, your design tools could be a factor. They may not have the capability […]
The post Getting Tired of Endless Client Revisions? 270+ Pre-Built Websites Are the Solution (Sponsored) appeared first on David Walsh Blog.

Link: https://davidwalsh.name/tired-endless-client-revisions-270-prebuilt-websites-solution

Accessing parent Route params in Angular

With the router/URL being an application’s “source of truth”, we need to be able to access parts of the URL for data purposes, such as grabbing a dynamic :id property from the URL, passing it into a service and bringing back the relevant data. Let’s look at how we can use Angular’s Observable-driven Router so get automatic updates when a parent route changes.

Table of contents

Scenario
Parent Route Param subscriptions

Scenario
I’m currently working on building out Ultimate Angular’s platform, and as such have these routes (in the URL, not my routing definitions) – with us assuming 1234 is our dynamic :id:
/admin/courses/1234/metadata
/admin/courses/1234/curriculum
/admin/courses/1234/prices
/admin/courses/1234/coupons

What this structure allows me to do is click a particular “course” from /admin/courses, and be navigated to the /1234/metadata view where I can edit the course’s name, author and so forth.
Parent Route Param subscriptions
What I needed to do is (based on the parent’s param), is go off to my Store and fetch the appropriate course I’m viewing.
First let’s walk through the routes:
// routes
export const ROUTES: Routes = [
{
path: ”,
canActivate: [CoursesGuard],
component: CoursesComponent,
},
{
path: ‘:id’,
canActivate: [CoursesGuard],
component: CourseComponent,
children: [
{ path: ”, redirectTo: ‘metadata’, pathMatch: ‘full’ },
{ path: ‘metadata’, component: CourseMetadataComponent },
{ path: ‘curriculum’, component: CourseCurriculumComponent },
{ path: ‘prices’, component: CoursePricesComponent },
{ path: ‘coupons’, component: CourseCouponsComponent },
],
},
];

When my path is ”, I use the CoursesComponent, and when we navigate to (for example /courses/1234/) – the CourseComponent is loaded (non-plural version). At this point, this CourseComponent is simply a container which renders a . Once we hit that :id, we’re directed to the first child route, metadata.
Let’s look what’s inside the CourseMetadataComponent, paying attention to ActivatedRoute and the course$ Observable:
// … other imports etc.
import { ActivatedRoute } from ‘@angular/router’;

@Component({
selector: ‘course-metadata’,
styleUrls: [‘course-metadata.component.scss’],
template: `
<div class=”course-metadata">
{{ course$ | async | json }}
</div>
`,
})
export class CourseMetadataComponent {
course$ = this.router.parent.params.switchMap(params => {
return this.store
.select(getCoursesState)
.map((courses: any) => courses.courses.find(course => course._id === params.id));
});

constructor(
private router: ActivatedRoute,
private store: Store<CoursesState>
) {}

}

At this point, the switchMap is given the params Object, which as you can see is driven from this.router.parent.params – which you may have used this before (without the .parent):
// not the parent, it’s the current param
course$ = this.router.params.switchMap(params => {
// do something with local "params"
});

So what is params when we do this?
course$ = this.router.parent.params.switchMap(params => {
// params = { id: 1234 }
});

In my case, with /admin/courses/1234/metadata, the params on the parent are in fact an Object containing { id: 1234 }.
This means from */1234/metadata, */1234/curriculum, */1234/prices and */1234/coupons – I have access to 1234 for passing off into ngrx/store to fetch the correct course. The courses are always available when hitting these routes because I’m using:
{ canActivate: [CoursesGuard] }

This way, it’ll make an API request if ngrx/store doesn’t contain any courses, otherwise it’ll pass the API request and head straight across to the correct course, pulling the data from the pre-populated store.

Link: https://toddmotto.com/angular-parent-routing-params

Make All Images on Your Website Responsive in 3 Easy Steps (Sponsored)

Images are crucial to website performance, but most still don’t implement responsive images. It’s not just about fitting an image on the screen, but also making the the image size relatively rational to the device. The srcset and sizes options, which are your best hit are hard to implement. Cloudinary provides an easier way, which we will discuss in this article.In this blog, I’ll share a valuable shortcut that can help you turn all images responsive. But first, let’s talk a bit about what responsive images are: an image is considered responsive if it retains its quality on varying device sizes without having an unpleasant impact on performance. To better understand this concept, let’s take a look at some device dimensions: Possible Full-Width Image Dimensions by Screen Sizes Large/X-Large commercial screens: 2000+ pixels Websites: 760 – 1200 pixels Mobile Phones: < 760 pixels Let’s assume you have a mobile-first strategy for building responsive apps. You may decide to use 760px images throughout, without considering larger screens. If these images are meant to take the full width of the devices on which they are rendered, then your content will look distorted and unprofessional on websites or commercial screens. Your next attempt would be to use the largest possible image (2000px) and scale it down based on the screen sizes on which it is displayed.Down-Scaling Images Using CSS or JavaScript to down-scale images only makes them dimensionally responsive. The following image illustrates this better: Down-scaling illustration on mobile Down-scaling illustration on desktop Both on web and mobile devices, the size is still 8.9MB. Bearing in mind that your mobile phones have less resources than your PC, we still have more work to do. Using only a down-scaling approach is not ideal because it does not account for the size of the image; just its dimensions. We have already seen that up-scaling wouldn’t work either, hence we need something that handles both dimensions and size. Size-Fitting Our best option is to generate images based on the screen size and render them. This process can be extremely complex, but there’s a shortcut that can help you automate much of the process. You can make all images responsive in three easy steps with Cloudinary: 1. Include Cloudinary in Your Project Add the Cloudinary SDK to your project simply by including it in your index.html using script tags: <script src="https://cdnjs.cloudflare.com/ajax/libs/cloudinary-core/2.3.0/cloudinary-core-shrinkwrap.min.js"></script>
2. Add Images with data-src You don’t want the images rendered immediately, until JavaScript runs. Hence, include the image using the data-src attribute instead of src: <img data-src="http://res.cloudinary.com/christekh/image/upload/w_auto,c_scale/v1501761946/pexels-photo-457044_etqwsd.jpg" alt="" class="cld-responsive">
Using this approach, Cloudinary analyzes your browser screen first, resizes the image saved in Cloudinary storage as provided in data-src, and then renders the image in the appropriate size and dimension using JavaScript. Two things to note from the tag: w_auto,c_scale transformation parameters tell Cloudinary to dynamically generate an image URL scaled to the correct width value, based on the detected width actually available for the image in the containing element. The class cld-responsive tells Cloudinary which images to apply this feature too. 3. JavaScript Call Finally, initialize a Cloudinary instance in your JavaScript files and call the responsive method on this instance: const cl = cloudinary.Cloudinary.new({ cloud_name: ‘YOUR_CLOUD_NAME’ })
cl.responsive()
Remember to create a free Cloudinary account so you can receive a cloud name for configuring this instance. This piece of code will walk through the DOM, find all image tags with the class cld-responsive to apply size and dimension fitting images on them. Final Words Always keep in mind that when you use CSS like the following code below to make images responsive, it does not guarantee a good user experience: img {
width: 100%;
height: auto;
}
The sizes of these images remain the same. Large images on mobile devices eat up resources (like allocated memory and running processes) causing slow downloads or unexpected behavior on the user’s device. Responsive images ensure that users save lots of data bandwidth & have great experiences when using your image-rich website or app. Lastly, it’s good to keep in mind that the suggested approach relies on JavaScript. Therefore, the preloading capabilities provided by srcset and sizes are sacrificed and your browser must have JavaScript enabled for this feature to work.

Link: https://ponyfoo.com/articles/make-all-images-on-your-website-responsive-in-3-easy-steps

Getting Started With Cucumber.js on Node.js

Cucumber.js
Cucumber.js is a Node.js library used for automation. Cucumber.js helps to test our site’s features using pure JavaScript and the Selenium WebDriver. So there is no longer the burden of installing jars and formatting the response and all sorts of time-consuming tasks like we used to do when writing automation scripts in Java using the Eclipse IDE. I am not comparing the power of Java with Node.js, but every language has its advantages and different learning curves. So, for getting a quick automation script working and impressing your colleagues, or for adding onto your resume for impressing your employer, let’s start coding and explore it.
Pre-Requisites: 
Before getting started, you should be well aware of Node.js async antipatterns and promises. We will be using Node.js 6.9.4 and a module named selenium-cucumber-js which is a clean package that comes with the selenium driver for Node.js, as well as a reporting mechanism by default. Wow! That’s awesome, right?

Link: https://dzone.com/articles/getting-started-with-cucumberjs-on-nodejs?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev