Friday, January 6, 2017

JS30 Challenge Day6 - Type ahead (Difficult)


Disclaimer: For this project, I did a ton of copy-paste. Maybe I should revisit this project later for study.

transform: perspective(100px);
Sets the z=0 plane further behind, by the given value

background: linear-gradient(to bottom, white 0%, black 100%);
The % in linear gradient means that that color should reach its full hue by that location in the gradient.

fetch(url);
We used this command in combination with the 'then' property to retrieve the json data from the given city-state website.

'…' is spread. It is used to spread all arguments passed to the array as their own elements

How to put a variable into regular expression
const regex = new RegExp(wordToMatch, ‘gi’);
where g is for global
and i is for case insensitive
wordToMatch is our variable
Then do element.match(regex) or element.replace(regex)

We use filter because we want to apply a function to every single element in the array

'change' can also be an event in addEventListener
Especially handy for inputs
The change event only fires when you step outside that input
So it's a good idea to tie the element up with the 'keyup' event as well

Don't make me think - highlights - Ch.6

Ch. 6. Street signs and bread-crumbs
Designing navigation.


Like a store, there is no clerk to explain the map of the website to you. The “search” functionality fulfills this purpose.

Difference between real world and web world:
No sense of scale: In real life, we can have a rough estimate of how large a store is. But a website could have huge corners we have no idea about seeing the home-page. We can’t tell how large a website is, usually.

No sense of direction or location in websites as opposed to the real world.

Don’t use breadcrumbs instead of page name!

Tabs are a great way to show a user where he/she is. The chapter talks about some reasons why tabs are great. Also, tabs were probably invented by Leonardo Da Vinci.

Thursday, January 5, 2017

JS30 Challenge Day 5 - Flexbox Gallery

Day 5


This was more of a CSS heavy project

It reminded me that we can use cubic-bezier in transition
transition:
    font-size 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
    flex 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),

It reminded me that we can set flex-direction to column
flex-direction:column;

And finally, I learned the includes function:

e.propertyName.includes('flex')

JS30 Challenge Day4 - Array functions

Day 4


Some basic concepts revisited:

Filter:
You pass a function to a filter which will loop over every item in the array

We can use console.table instead of console.log to display it pretty 

I learned a fancy and compact way to return a value instead of an if-statement returning ‘true’.

const fifteen=inventors.filter(inventor => inventor.year <1600 && inventor.year>= 1500);

Map:
Takes in an array, modifies it and returns a new array

We use + for concatenation in JS and . in PHP

Reduce:
Builds something on each entry

const tot = inventors.reduce((total,inventor) => {return total+ inventor.passed-inventor.year},0);

The 0 at the end is to set the total to an initial value of 0
So following this idea, you could as well initialize it to a 5, for example, for some different kind of functionality.

Reminder: querySelectorAll does not return an Array but returns a NodeList
Array.from(some_nodeList); converts a NodeList into Array

textContent:
const de= links.map(link=> link.textContent);
link.textContent returns the names enclosed within ‘a’ tags where links is a list of ‘a’ tags on the page

Reduce explained:

const transport = data.reduce(function(obj,item){

      if(!obj[item]) obj[item]=0;
      obj[item]++;
      return obj;

    },{});

In the code above, obj is an element passed to the reduce function which will gather data over each iteration. For each unique element in an array, an obj will be created. The name of the element goes into the index of the obj. So every time an element is found, the value of that item ( the element from the data array) will increase by 1 in the obj object. To initialize the object as a blank object, we have added {} at the end.

In short, the parameters of a reduce function should match the structure of an element in the calling array. This could be a name value pair or simply a variable like total which accrues count over time and is not part of the array element originally. It may act as just another variable as we saw in the first usage of reduce function or it may act as an object containing its own processed values.


Wednesday, January 4, 2017

JS30 Challenge Day 3 - Image Editor (CSS Variables)

Day 3 

Github link

In the previous project, I had created a new branch to make changes to the code.
Today I merged that branch with the master.
To merge a branch, checkout into the main branch you want to keep
and then type
git merge secondary-branch-name
in the terminal

HTML & CSS

The for property of a label binds the label to the element it is meant to address.
<label for=“specifies the element this label is bound to”>

Writing CSS for the page, it reminded me to use
*{
margin:0;
padding:0;
}

If we don’t do this, sometimes we get a scrollbar on the browser window because something somewhere started with a non-zero margin or padding.

It also reminded me to put a ./ at the beginning of every path (as in the 'img src' path in this case).
I have encountered situations where I specified the entire path without the prefix given above and the library or plugin just wouldn’t work.

I learned about a new input type, 'range', which is basically a slider that has a default “value” a min value and max value.
<input type=“range” min="10" max="100" name="blur" value="20">
Notice that the min and max values have to be in quotes

data-sizing is a custom attribute we used in this project.

I learned about another input type, called color.
<input type=“color” value=“ffc600>

Can we change the color of the slider in range?
Probably. The slide itself is called ‘track’ and the bob is called ‘thumb’. These can be controlled only by using browser prefixes.
input[type=range]::-browser-prefix-thumb
{
background: coral;}
I tried doing it without prefixes but it didn’t work, so I left it at that.

To scale the inputs down, I just put a width to 'input' elements
input{ width: 100px; }

JS

CSS variables! Doesn’t that sound great? It’s a new feature.
And though SASS can have variables, they after processing get cast into something fixed and not dynamic. That’s how CSS variables differ from SASS variables.

I learned about :root, the selector for the base element in HTML.
You need to declare the variable on some element. And we will do that on :root

So basically, we declare all the variables in :root
For example,
:root{
—blur: #ffc600;
}
and wherever we want to use the CSS variable, we use
var(—variableName)
For example, for blur, we could use
filter:blur(var(—blur));

querySelectorAll(); does not return an array. It returns a NodeList which is like an array but without most of the functions in the prototype.

Once again, it reminded me that you can’t use forEach on its own. It has to be with some element. Like input.forEach();

I learned about mousemove event. The second M is not capital
Just like we learned about transitionend event in the previous project.

this.dataset returns all the “data” prefixed properties and their values

And finally, a bunch of new terms in
document.documentElement.style.setProperty();
What is documentElement?
From MDN, we find out:
document.documentElement returns the root element of the document for example, the HTML element for HTMLdocuments.

style.setProperty() takes in the name of the property, for example, the “name” attribute assigned to an input, in our case spacing|blur|base, and takes in the value for that element, as in, the value assigned to the “value” attribute in that element. The value also must have a unit-suffix if it applies (like px, s, pt, etc.).

And that's a wrap up :)

Monday, January 2, 2017

JS30 Challenge Day2 - Clock

Day 2


This exercise refreshed my memory about the cover parameter for background-size.
background-size: cover;
This fits the image in a way that covers the entire window with that image, while some parts of the image might go out of the window.

rem unit
This is a relative unit which multiplies the font-size of body element with the value specified.
So if the body font size is 10px, 2rem would equal 20px.

transform-origin:100%; //moves the origin of rotation along x-axis
So a 100% transform-origin would shift the origin to the rightmost end of the element (in our case, hand).

In the original exercise, all the hands are the same length and color
I decided to make the hands different colors and lengths
From longest to shortest, I have placed the hands on top of one another in respective order.

Because the dimensions of the hands had to be different, and given that the initial hand we draw is in horizontal position,
I gave 50% width to the second hand which makes the hand touch the center of the dial.
In minute hand however, I made the width 40% and what we get is a hand that does not touch the center of the dial. Hence we need to give it a 10% margin.
Similarly for hour hand, 30% width requires 20% margin.
The logic is that the addition of width of the hand and its left margin should be 50%.

Then, I learned about transition-timing-function
The normal values are ease-in, ease-out, ease-in-out
But we can customize the transition using a cubic bezier curve, like so:
transition-timing-function: cubic-bezier(0.1,2,7,0.58,1);

JS

The setInterval function runs a function passed to it on every interval specified
setInterval(functionName, milliseconds)
We have used it to call setDate function after every second. 
setDate is the function in which all the hours, minutes and seconds are retrieved and degrees for the hands are calculated and applied

For the final extra bit, I was able to remove the glitch that occurs at every 0th second.
When any hand transitions from final state to initial state, because the number of degrees reduce, the hand makes a (reverse) anti-clockwise motion to reach the 0 degree mark.
Because the transition is set at 0.05s, a slight hint of this animation is visible.

To bypass this, just change the transition to ‘all 0s’ using javascript.
I created a class called .fast
It contains the following line of code
transition: all 0s;

At every 0, I add the class and at every 1, I remove the class thus returning the hand to the cubic bezier curve at 0.05s

if(seconds===0)
secondHand.classList.add(‘fast’);
if(seconds===1)
secondHand.classList.remove(‘fast’);

And voila! All done.

Sunday, January 1, 2017

Don't make me think summary - Ch.3, 4 & 5

Ch. 3.Billboard design 101
Design pages for scanning not reading

1.Create a visual hierarchy
Relationships, especially hierarchical ones, should be clearly shown on the page. This includes element-size, grouping and nesting. Newspapers are good examples of this.

2.Take advantage of conventions
Designers are often afraid to follow conventions because they think re-inventing the wheel is often the ways to go. But conventions bolster the usability and make scanning easy and fast.

3.Break pages into clearly defined areas

4.Make it obvious what's clickable
Users are often looking for the next thing to click.

5.Minimize noise

Ch. 4.Animal, vegetable or mineral?
Why users like mindless choices

*Krug's second law of usability:
It doesn't matter how many times I have to click as long as each click is mindless and unambiguous.

"Three mindless, unambiguous clicks is equal to one that requires thought"

Ch. 5.Omit words

*Krug's third law of usability
Get rid of half the words on the page. Then get rid of half of what's left.

A sentence should contain no unnecessary words, a paragraph, no unnecessary sentences.
Happy talk or small talk must be eliminated.
Instructions must die.