Tuesday, January 23, 2018

How to create an offscreen navigation?

Website navigation is a very important website element from the user experience perspective. It allows the user to search for relevant information. In this article I will try to to explain what you have to take into consideration while building your own website navigation. I will start with description of mobile version and move to desktop.

Requirements and what we want to achieve:

Our navigation is meant to work both on desktop and mobile devices on multiple modern browsers (FF, IE11, Edge, Chrome 60+, Safari 9+). Our navigation should stick to the top of the screen during the scroll movement of the page. It should be placed in position fixed both on desktop and mobile versions. To achieve the best possible performance with transition animation on mobile devices we aim at utilising hardware acceleration feature of the transition animation for smooth rendering of different elements.

Mobile navigation

By "mobile version" we mean the navigation visible for devices using <768px screen width with pixel ratio 1 (<768px CSS width). The navigation, just like mentioned above, should maintain position fixed. That means it should stay on top of the screen always on top of the content area. It also characterise itself with simplicity. We should maintain only 2 states of the navigation.

1. The navigation visible only in the top of the screen. The only visible elements are header, which is an anchor linking to the homepage, and main navigation button. The click or tap on the button moves us to second state of the navigation.
Thanks to this state the user can easily access and view different content sections of the website without scrolling and searching for links in the static navigation on top of the page. That is certainly useful when working with websites with a lot of content as the user maintains access to main sections of the website within 2-3 clicks on the screen. With this navigation we implement the three-click rule.


2. The second state displays the navigation open. The offscreen section of the navigation should cover the rest of the page displaying a navigation overlay on top of the website content. It should display the horizontal list of elements with possible sub-lists. One of the top corners should also display a close button (possible cross icon) that will close the navigation and move the navigation state to state one.



Please take a minute to see the result's codebase in the JSFiddle below:


Desktop navigation

By "desktop navigation" we mean the navigation visible for devices using >=768px screen width with pixel ratio 1 (>=768px CSS width). This version of the navigation, just like mobile one, should be a "sticky" navigation always visible to the users while scrolling the content down the page. This is a much simpler navigation version as it does not contain any hidden elements. Hence, there is no additional behavior that we have to add to our elements.

Please see below for the JSFiddle preview of such navigation. The elements in the navigation are positioned using display: flex rule that allows easy alignment of child elements in a wrapper both vertically and horizontally.







What's more, please note that the height of the whole navigation element is "5rem". That means that it is 5 * the height of root element font-size (14px in our example). This allows us to position the content below the navigation with just the same rule i.e. "top: 5rem" and "padding-top: 2rem" for extra space. This way if we changed the root "font-size" from 14px to 20px the navigation height will change and the content will still be nicely visible below it.

Just a few lines of code

In the example above you can see how easy it is to create a mobile and desktop navigation with just a few lines of code. You do not have to use, sometimes, expensive plugins on the website you create. Basic understanding of HTML, CSS, and JavaScript is good enough for you to start the development.

References:
- https://mydevice.io/devices/
- Three click rule - https://articles.uie.com/three_click_rule/
- Fixed navigation Bars: Cons and Pros - Zach Ruthenford - https://www.awwwards.com/fixed-navigation-bars-pros-and-cons.html

Sunday, September 17, 2017

How to start your first website project?


How to start your first website project? That was the question I have asked myself a few years ago. I have searched for the answer on various forums and web portals. I remember that the outcome of that first project inspired me to learn more about web development.
Now, a few years later, I wanted to answer the same question. Maybe it will help somebody who seeks creative fulfillment at work or as a hobby with the assistance of web technologies.
To commence my first project I was using XAMP project (version 7.8.1 is the latest version at the time of writing this article). It uses APACHE as a web server. What’s more XAMPP provides you with MYSQL server, FTP server, PHP (version 7.8.1 is the latest at the time of writing this article), and PHP admin panel pre installed. All of the above can be started from the GUI (Graphical User Interface). The above is all you need to get started with a simple website project. In this article I’m going to focus on building just a simple front-end website with neither back-end code nor data stored in database. However, you need to bear in mind that the above technologies allow to you to create complex applications. What’s more you may use XAMPP Add-ons to install very useful applications e.g. Wordpress or Joomla! CMS (Content Management System).

Firstly, you need to download XAMPP and install it on you machine. In my case the machine had Windows 10 operating system installed but you may also find versions for most popular operating systems as well. You may find the download page to XAMPP here. To install it you need to follow simple installation steps from the installation wizard. After the successful installation you should notice XAMPP icon in the icons tray in the right bottom corner of the screen. When you press it you should be be able to start the web server by clicking "start" in "APACHE" line. By default you are using port 80. Before you do that please check if the port isn’t used by another programme though as that may throw an error in the XAMPP console. You may find if your port is already in use in two ways.
First way is to check logs in the XAMPP console at the bottom of the window. XAMPP should throw an error "Problem detected! Port 80 is in use by "process name" with PID...!" if the port is already in use.
Another way is using “netstat” command in command prompt. Please read this page for details. If you want to change the port due to conflict with other programmes running on your machine click on "config" next to APACHE in XAMPP GUI and next "httpd.conf". That should allow you to edit the configuration file of the web server. To change the port that will be listened to edit "Listen 80" to e.g. "Listen 8080" and save the file.

When you start the server you should be able to open the browser of your choice and navigate to your default page. In the address bar type in “localhost:80” or IP address “127.0.0.1:80” (change the port number if you edited it before). Both addresses should redirect you to the default page "localhost:80/dashboard".

Now a short explanation on what actions the server is performing. In the "httpd.conf" file of the server it is defined which file the server will serve when you navigate to the default directory mentioned above. By default the file is located in “C://xampp/htdocs/dashboard/index.html”. This is the file that you may use to unleash your creative thinking and build your first web project. You may remove its content and start a new page from scratch or edit the content already present. Using this file you may create a simple HTML page, add some style and look to your first project using CSS, and use JavaScript to add extra dynamics and behaviour to your page elements. Now, you may open the “index.html” file with any text editor of your choice and try to apply simple changes. After saving the file you should see that the text changed after refreshing the page.

With those simple steps you may create your first website project. With HTML, CSS, JavaScript technologies now you can build both simple websites as well as very complex applications e.g. SPA (Single Page Applications). I hope that the post will be helpful for some of your who want to start creating with web technologies.
Please do not hesitate to ask questions in the comments I will be more then happy to talk about the technologies mentioned in this article.
References:

1. XAMPP project page - https://www.apachefriends.org/download.html
2. Command Windows - The Windows Command Line, Batch Files, and Scripting - https://commandwindows.com/

Saturday, August 15, 2015

No event is dispatched when a physical contact with digitizer is made - Firefox (v40) Windows 8 touch screen


No event is dispatched when a physical contact with digitizer is made - Firefox (v40-42) Windows 8 touch screen


The title speaks for itself. 

I have come across this issue last week. After a short research I've noticed that Hammer.js developers started to investigate solutions and workarounds for the issue.

This issue relates to the following two Firefox cases documented in the following bugzilla cases:

Content touch-events on Firefox-desktop should be disabled until we can support them properly
Some sites won't touch-scroll using a touch-screen

I created this issue to get some more details about it and thankfully I found out that it will be solved in Firefox version 42.

Sunday, May 10, 2015

Scotland js 2015 - conference private notes




Scotland js 2015 - private notes

ScotlandJS is a great event organized annually in Edinburgh, Scotland. It's gathering lots of interesting people from around the web focused on JavaScript. That was the third time I joined the conference personally and wanted to share some of the notes. I hope they're going to be useful to some.


Thursday


10:00am - Dave Kennedy - @bangline_ - TDD in the real world

10:25am - Katie Fenn - @katie_fenn - Chrome DevTools, Front to Back




10:50am - Colin Gemmell - @colin_gemmell - Look Ma No Framework


11:30am - Ben Longden - @blongden - Adaptive and evolvable applications




11:55am - Gleb Bahmutov - @bahmutow - Journey from procedural to reactive JavaScript with stops




12:20pm - Greg Tarnoff - @gregtarnoff - UX of Stairs: When Simple Tasks Aren’t So Simple




1:40pm - Varya Stepanova - @varya_en - Driving the Style Guide Driven Development




2.05pm - Daniel Perez Alvarez - @unindented - The one trick to scaling your frontend codebase




2.30pm - Chris Price - @100pxls - Creating D3 components: a journey of pain, joy, frustration, and enlightenment




3.10pm - Orde Saunders - decadecity - Cascade, Specificity and a Single name space or: How I learned to stop worrying and tolerate CSS





3:35pm - Chris Lowis - @chrislowis - A Brief History of Synthesis with the Web Audio API






Friday



9:00am - Francisco M.S. Ferreira - @fmsf303 - JavaScript Craftsmanship



9:25am - Andrew Duncan - @andrewmduncan - Memory Leak Health Check - Our Quest to Diagnose & Cure


9:50am - Joe Nash - @jna_sh - A Monad is a Burrito and other Functional Myths


10:15am - Kim Joar Bekkelund - @kimjoar - Writing Beautiful JavaScript Tests





11:00am - Mark Connell - @mconnell - Accessibility & JavaScript-based websites





11:25am - Sam Beckham - @sambeckham - Improving pattern libraries, with Polymer




11:50am - Hubert Sablonniere - @hsablonniere - Exploring multi-screen web techniques



  • chromecast - for multi devices if you don’t need server
  • localStorage - two windows open share local storage (hacky)
  • shared worker - if you start a port you can send messages to other devices on the same origin
  • service workers
  • to come - w3c presentation api

1:10pm - Amy Wibowo & Matt Baker - @sailorhg - Programming Building Block





1:35pm - Philipp Reither - @philreither - Fire your Sysadmin: use Docker to Build, Ship and Run Any App, Anywhere




2:00pm - Jaume Sanchez Elias - @thespite - What are Shaders (Webgl) and what can they do for me?




2:40pm - Phil Holden & Ellen Huang - Intelligent Responsive Typography



  • song lyrics in browser
  • measure font size (measure) problem (DOM, Canvas, SVG, Webgl)
  • Youtube video

3:05pm - Lewis Cowper - @lewiscowper - How I went from forklift driver to developer in 9 months




3:40pm - Lena Reinhard - @lrnrd - Keynote Speaker





Companies:
Some photos from the event

Saturday, May 2, 2015

Prevent default event for Ctrl + O shortcut in IE11




Prevent default behavior for Ctrl + O shortcut in IE11


If you are working on a web application that wants to use some complex shortcuts you have to take into account some browsers' limitations. 

For me a minor limitation I've come across was the shortcut Ctrl + O. It's kindda strange that you cannot prevent default browser behavior for such shortcut. 

I've checked some popular libraries like e.g. KeyboardJS, or KeypressJS but to no avail.

You can check the two experiments made:
http://dstefaniak-staging.com/tests/keyboard/KeyboardJS-master/experiment.html
http://dstefaniak-staging.com/tests/keyboard/Keypress/experiment.html

There is an official issue added to Internet Explorer Feedback site:
https://connect.microsoft.com/IE/feedback/details/1046712/javascript-interception-and-termination-of-some-key-events-is-broken

However, from 13 Jan 2015 there was no feedback whether or when this is going to be fixed. Workarounds that were suggested on IE feedback page and any other forums e.g. this one doesn't seem to work (not for me at least).

If you are one of the devs that have the same problem don't forget to click "Repros" button after signing in confirming that you were able to reproduce the behavior.

Even though I think that IE11 is in many aspects better than Firefox, (definitely) Safari this is one of the examples where you to bang your head against a wall.

Thursday, February 19, 2015

Check your mobile Safari application performance - FPS rate





Check your mobile Safari application performance - FPS rate

I was asked to check the performance of a web application in Android and MobileSafari. The application was focused on drawing and elements' manipulation on a canvas. I figured that I will have to find app's rendering bottlenecks. The question was what software to use and where to find it.

Android

The answer to debugging a web application on Android could not be easier - Dev Tools. I installed Android Studio, Android API, SDK tools, Chrome ADB extension and after a few minutes I was ready to go.

iOS

The answer to this was a little bit more difficult. Xcode and Safari enable you to use webkit debugging tools. However, the timeline tab doesn't provide you with the same tools as Chrome(version 40 at the moment of writing this post). I was looking for Frames Per Second measurement in particular. 

It appears that Xcode and Mac has got some cool tools behind it's sleeve  that can be used with your device. Open Xcode > Open Developer Tools > Instruments and choose 'Core Animation'. As soon as you open it in the left top corner you should see record button and, right next to it, you should be able to choose the device and the application you want to test. Select MobileSafari and open the web application you want to test.

Start recording and you should see the following:




That should be it! Happy perf testing!

Sunday, February 15, 2015

Build and publish Android application with Phonegap






Build and publish android application with phonegap

In this post I'm going to describe how to build an android application with Phonegap, WebStorm IDE, and publish it in Google Play Store.  

I'm using Cordova version 3.5.0, WebStorm 9.0.3, Yosemite 10.10.1.

I would assume that you already have Node.js and Android Studio installed on your machine and that using 'SDK Manager' in Android Studio you already installed 'platform-tools' and you have at least 'api rev 19'+.
It is important that you should have phonegap and/or cordova installed globally - I'll be using cordova.
You should have the Google Play store developer's account.

Why WebStorm

WebStorm IDE is used only to speed the process up. Why is it helpful:
- it builds the PhoneGap/Cordova project from scratch
- it provides you with build in terminal
- it provides you with the ability to configure Node, Git, Mocha, Phonegap commands which you use most often in your project
- very useful version control functionalities
- and a lot more...

(I'm not selling the product I'm just a happy user)

Let's get started

1. Setup the project with WS using 'new project' option and choose 'PhoneGap/Cordova project'


2. Add android platform to the project (you can use a build in terminal for that)

cd /path/to/project/ && cordova platform add android
You should see that additional folder appeared in 'platforms' directory of your project.


3. Debugging your app (2 ways)

- Android Device - connect your device using usb (make sure you have all debugging options set on your phone/tablet and it's is unlocked)


cordova run android --debug
- Browser - use python in terminal to create a simple server and debug your app (e.g. Chrome)


cd /path/to/project/ && python -m SimpleHTTPServer

Now you should be able to open your project in the browser (most probably http://localhost:8000/www/).


4. As soon as you are ready to build the final product try using

cordova build --release android

After this step you should see your application (apk file) in 'platform/android/ant-build' directory. You may try to install your app by transferring the apk file to your device. If you come across errors try uninstalling previous installations of the app on the device. 

I'm sure that just like me at this point you would like to upload your application to Play Store. The only issue is that your application still isn't signed. You didn't generate the 'keystore' for you application yet. I think that a good idea is to create the keystore somewhere in the root of your project. To do that use the following commands:

keytool -genkey -v -keystore <keystoreName>.keystore -alias <Keystore AliasName> -keyalg <Key algorithm> -keysize <Key size> -validity <Key Validity in Days>

e.g.:


keytool -genkey -v -keystore NAME-mobileapps.keystore -alias NAMEmobileapps -keyalg RSA -keysize 2048 -validity 10000

Remember what password and alias you've used as you'll be asked for that later on.


5. now you have to make sure that your application is going to be signed when you build it

Create the 'ant.properties' file if it's not already available in 'platform/android/' directory. 


key.store=projectroot/filepath/key_name.keystore

key.alias=myApp_alias

Next, build your application and it should be properly signed.

6. Create the release version of your application
cordova build --release android
and upload it to your play store!


Zipalign

Before you prepare yourself for your application deployment make sure you have 'zipalign' in 'your_path_to/adt-bundle.../sdk/platform-tools/'. It's going to be needed to optimise the apk before the upload to production. You should follow the commands here.

"com.example" package issue

You might have some difficulties while uploading your final apk file even after signing the application. If you get 'com.example' it means that you have to go to config.xml and AndroidManifest.xml and change the package name. After you do that rebuild the project and upload the apk file again.

Updating your application

Before you upload your updated apk to the Google Play Store remember that you have to update the version of your code. This one can be found in AndroidManifest.xml inside Android platform folder - android:versionCode="10000"
To generate the updated version of this file go to config.xml of your project and simply change 'version="1.0.0"' to anything appropriate.

Conclusion

It may be easy to develop some applications with phonegap. However, we still have to find the optimal way to debug, build, and publish them. I hope I managed to shed some light on the topic.

Please let me know if I missed something or something is unclear in the description above.

References:

3. stackoverflow - link 1
4. stackoverflow - link 2
5. developer.android.com
6. ionic