Τετάρτη 29 Αυγούστου 2012

HTML5 new features

My first question, when started learning HTML5, was "What are the new features of this new version of HTML"? What new things can I do with HTML5, or how easier can I do some things I used to, while using HTML?

So, in this quick post, we will see the new interresting features in HTML5.

  • The canvas element for 2D drawing
  • New content-specific elements, like article, section, header, footer
  • The video and audio elements for media playback
  • Support for local storage
  • New form controls, like calendar, date, time, email, url, search

In the following posts, I will explain each feature seperately in more detail. 

Πέμπτη 23 Αυγούστου 2012

Print a div with javascript which opens in a new window using Javascript

Today I had to put a print button into a web application, which when clicked, should open a new window and print the contents of a certain div.

I found this very useful link http://sarwarhossain.com/2010/10/05/print-a-div-open-new-window-print-and-close-using-javascirpt/. I used the code and everything worked great in Firefox, but I noticed that it doesn’t work well with Chrome, launches straight to blank Print screen and doesn’t load content in new window first. Same in Safary (I didn't try IE, I was sure that it wouldn't work as well).

Here is the code I found from the above link and right after I will post 2 solutions for this problem.


Javascript Function

HTML


1st solution 

The first thing I thought was to remove following lines
in order to let Chrome and Safari open the new window with print button in the contents, but this relies on user to manually push print. I found this thought in the comments area too.

Everything worked great, but I wanted to open the new window and after that automatically invoke the print dialog window. So I did the following.


2nd solution

I just put onLoad=”self.print()” inside body element and everything worked like a charm:-) See the new code of the printContent function below. Hope it helps!

Σάββατο 26 Μαΐου 2012

To make your javascript code beautiful, just use jsbeautifier.

Paste your compressed, unreadable code into the text-editor, and simply push "Beautify Javascript or Html" on the top.

Παρασκευή 17 Φεβρουαρίου 2012

Jquery split & join example

Here I will show you how you can use jquery in order to wrap every 2nd word of a paragraph in a span.

So, if you have for example the following paragraph into your html:


and your stylesheet is:


by putting this:




your final result will be:

This is a test paragraph.

First you use split method, to split your sentence into single words. Then you store into a variable called numWords the size of the array. In a for loop, you check if your number is even and if that's the case, you wrap the specific element in a span. After this iteration, you use join, in order to show whole sentence.


Τετάρτη 8 Φεβρουαρίου 2012

Fireworks Favicon


If you are using Adobe Fireworks CS4 and want to create a favicon for your site, just follow the steps below.


  1. Go to http://johndunning.com/fireworks/about/ExportAsFavicon and download the favicon extension
  2. Open Fireworks -> click Help -> Manage Extensions
  3. Choose Fireworks from the left side and then the install button on top
  4. Locate the extension you downloaded before and you are ready.

How can we use it
  1. Go to Commands -> Favicon -> New Favicon - 16x16 to create your favicon
  2. Choose Commands->Favicon -> Export as Favicon to export it

Τρίτη 7 Φεβρουαρίου 2012

Responsive Web design

Take a look at the following link and watch a very good video (25 minutes) about Responsive Web Design!
http://css-tricks.com/video-screencasts/102-braindump-on-responsive-web-design/

                                            jsfiddle.net 

In the above picture you can see jsfiddle.net, an online editor for the web, which allows you to see how your code runs in action. Really very helpful!

Jquery fadeToggle

In this example, I will show you how we can use jquery fadeToggle function to achieve the behaviour described below!

What we have here, is some menu blocks, which show a lager block with more details, when we click on them. You can see a demo here. Only first block works, as it is under construction.



                         Before we click the first menu block


                           After we click the first menu block


Html markup

As you can see below, we have a div with class "box", and inside this div we have 2 main elements:
  1. an anchor tag, with a background-image as you can see in the css style later
  2. div with class "box_details" , which has an absolute position.



Css styles

Below you can see the css styles for our example. Just to say, that box_details has an absolute position. (accordingly, div with id "box1", has relative position) and display:none, which will change to block, when div with class box is clicked.



Javascript

Finally, we use javascript and fadeToggle function. I think it's pretty easy and self-explanatory. Wheneverer we click the box div, we find next box_details div, and make it fade in. When we click on the appeared div, it fades out. This is achieved with the use of fadeToggle.