<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Tutorialzine</title>
	
	<link>http://tutorialzine.com</link>
	<description>Web Development Tutorials &amp; Resources</description>
	<lastBuildDate>Mon, 06 Feb 2012 08:49:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Tutorialzine" /><feedburner:info uri="tutorialzine" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>Tutorialzine</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Enhance Your Website with the FullScreen API</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/1tMd7-_hvF4/</link>
		<comments>http://tutorialzine.com/2012/02/enhance-your-website-fullscreen-api/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 08:49:42 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1821</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/02/enhance-your-website-fullscreen-api/"><img src="http://cdn.tutorialzine.com/img/featured/1821.jpg" /></a></div> There is a new API in town - Full Screen. With it you can make any element take the entire screen. Perfect for videos and canvas-based games, reports and print preview dialogs. Learn how to use it in this tutorial.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/02/enhance-your-website-fullscreen-api/"><img src="http://cdn.tutorialzine.com/img/featured/1821.jpg" /></a></div> <p>One of the benefits to having new browser versions out every six weeks, is the rapid pace with which new functionality is introduced. The transition from nightly builds to official releases is merely weeks away. This means that even those of you who keep a close eye on the feature lists might miss an api or two.</p>
<p>This is the case with the <a href="https://developer.mozilla.org/en/DOM/Using_full-screen_mode" target="_blank">Full Screen API</a>. As if overnight, it went from a neat experiment to a feature supported by more than half of the browsers in the wild. Right now you might be wondering how is this different from the regular full screen we&#8217;ve had for ages.</p>
<h3>What you need to know</h3>
<p>With this api, you can display not only entire pages full screen, but individual elements within them as well (something you can&#8217;t do with the regular full screen). The intent here is to allow for full screen HTML5 videos and games, so that we can finally declare HTML5 as a viable alternative to Flash.</p>
<p>In short, here is what you need to know about the FullScreen API:</p>
<ul>
<li>Works in <em>Firefox 10</em>, <em>Safari</em> and <em>Chrome</em>;</li>
<li>You trigger it using the new <code>requestFullScreen()</code> method;</li>
<li>It can display any element full screen, not only the entire page;</li>
<li>For security reasons, full screen can only be triggered from an event handler (as to be user initiated);</li>
<li>Also for security, Safari blocks all keyboard input except for the arrows and control keys, other browsers show warning messages when typing;</li>
<li>The API is still a work in progress, so you have to use the vendor specific methods (prefixed with <strong>moz</strong> and <strong>webkit</strong>);</li>
</ul>
<p>The idea of allowing developers to programatically take up the user screen doesn&#8217;t come without serious security implications, which is why keyboard usage is limited. Of course, there are many legitimate uses for keyboard input in full screen, which is going to be addressed in future revisions of the API via some kind of permission prompt.</p>
<p>However, even in its current, limited form, the API still gives us an opportunity to enhance the experience of the end user.</p>
<div id="attachment_1841" class="wp-caption alignnone" style="width: 630px"><a href="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/click-to-go-full-screen.jpg"><img class="size-full wp-image-1841" title="Click to go Full Screen" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/click-to-go-full-screen.jpg" alt="Click to go Full Screen" width="620" height="260" /></a><p class="wp-caption-text">Click to go Full Screen</p></div>
<h3>The basics</h3>
<p>According to the <a href="http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html" target="_blank">W3 draft</a>, we have access to a number of methods and properties that will aid us with the task of switching an element to full screen.</p>
<pre class="brush:js">var elem = document.getElementById('#content');

// Make this element full screen asynchronously
elem.requestFullscreen();

// When a full screen change is detected,
// an event will be dispatched on the document

document.addEventListener("fullscreenchange",function(){
    // Check if we are in full screen
    if(document.fullscreen)){
        // We are now in full screen!
    }
    else{
        // We have exited full screen mode
    }

}, false);

// We can also exit the full screen mode with code

document.exitFullscreen();</pre>
<p>At this time, however, dealing with the API is quite more cumbersome, as no browser has support for these methods yet &#8211; we will need to use <a href="http://hacks.mozilla.org/2012/01/using-the-fullscreen-api-in-web-browsers/" target="_blank">vendor specific ones</a> like <code>elem.mozRequestFullScreen()</code> and <code>elem.webkitRequestFullScreen()</code>.</p>
<p>The API also introduces a new CSS pseudo-selector that you can use to style the full screen element.</p>
<pre class="brush:css">#content:fullscreen {
    font-size: 18;
}</pre>
<p>Of course, it goes without saying that you will also need to supply moz and webkit prefixed versions of this as well. But there is an easier solution.</p>
<h3>The jQuery plugin</h3>
<p>There is a more elegant solution than ending up with a bunch of ugly code checking for every browser. You can use the <a href="https://github.com/martinaglv/jQuery-FullScreen" target="_blank">jQuery FullScreen plugin,</a> which works around various browser differences and gives you a simple method for triggering full screen mode.</p>
<pre class="brush:js">$('#fsButton').click(function(e){
    // Use the plugin
    $('#content').fullScreen();
    e.preventDefault();
});</pre>
<p>This will bring the #content element full screen. The plugin also adds a flag to the jQuery support object, so you can conditionally show your full screen button or trigger:</p>
<pre class="brush:js">if($.support.fullscreen){
    // Show the full screen button
    $('#fsButton').show();
}</pre>
<p>To exit the mode, call the fullScreen() method again.</p>
<p>The plugin adds the .fullScreen class to your element, so you can style it without needing to worry about browser-specific versions. Now let&#8217;s use it to do some good for the world!</p>
<h3>The fun part</h3>
<p>If you are a website owner you&#8217;ve probably made decisions that deteriorate the experience of your users. This should not come as a surprise to you &#8211; you need to show advertising, you need a search box, a navigation bar, a twitter widget, a comment section and all the things that make your site what it is. These are all necessary, but make your content, the very thing that people came to your site for, more difficult to read.</p>
<p>There is also a practical limit to how large your font can be before it gets out of place, not to mention the choice of a type face. If you have a sidebar, this also limits the horizontal space your content can take.</p>
<p>But we can fix this with the new API. We will use the functionality to bring the content section of your site full screen, thus improving the reading experience of your readers even on devices with small displays like laptops and netbooks.</p>
<div id="attachment_1840" class="wp-caption alignnone" style="width: 630px"><img class="size-full wp-image-1840" title="Reader Mode Using the Full Screen API" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/02/reader-mode-full-screen-api.jpg" alt="Reader Mode Using the Full Screen API" width="620" height="460" /><p class="wp-caption-text">Reader Mode Using the Full Screen API</p></div>
<h4>Making the reading mode</h4>
<p>It is pretty straightforward, we only need to some kind of button that will trigger the FullScreen plugin. We can use the <strong>$.support.fullscreen</strong> flag to test if the current browser supports the API. If it does, we will add the full screen button to the page.</p>
<pre class="brush:js">if($.support.fullscreen){

	var fullScreenButton = $('&lt;a class="goFullScreen"&gt;').appendTo('#buttonStrip');

	fullScreenButton.click(function(e){
		e.preventDefault();
		$('#main').fullScreen();
	});
}</pre>
<p>When the <span style="text-decoration: underline;">#main</span> div is brought full screen, it is assigned a width and height of 100%. We will have to work around this if we want it centered in the middle of the screen. This will call for some additional styling, applied only in full screen mode.</p>
<pre class="brush:css">a.goFullScreen{
	/* The styling of the full screen button goes here */
}

/* The following styles are applied only in Full Screen mode */

#main.fullScreen{
	/* Adding a width and margin:0 auto to center the container */
	width: 860px;
	margin: 0 auto;

	/* Increasing the font size for legibility*/
	font: 17px serif;
	padding: 45px 45px 10px;
}

#main.fullScreen h1{
	/* Styling the heading */
	font: 56px/1.1 Cambria,"Palatino Linotype",serif;
	text-align: center;
}

#main.fullScreen h3{
	/* Subheadings */
	font: 28px Cambria,"Palatino Linotype",serif;
}

#main.fullScreen #postAuthor{
	/* Centering the post author info */
	/* ... */
}

/* Hiding unneeded elements and ads */

#main.fullScreen #featuredImage,
#main.fullScreen #topMiniShare,
#main.fullScreen #wideZineBanner,
#main.fullScreen #downloadDemo{
	display:none;
}</pre>
<p>That is all there is to it! Only browsers that support full screen mode will display the button and users will enjoy a better, distraction-free reading experience.</p>
<h3><strong></strong>Done!</h3>
<p>There are plenty of places in a website where you can use a full screen view &#8211; from videos and canvas-based games, to reports and print preview dialogs. I would personally love to see this used for infographics and presentations. We can go a long way with a useful feature like this.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=1tMd7-_hvF4:wRh6UrfIYvQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=1tMd7-_hvF4:wRh6UrfIYvQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=1tMd7-_hvF4:wRh6UrfIYvQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=1tMd7-_hvF4:wRh6UrfIYvQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=1tMd7-_hvF4:wRh6UrfIYvQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=1tMd7-_hvF4:wRh6UrfIYvQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=1tMd7-_hvF4:wRh6UrfIYvQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=1tMd7-_hvF4:wRh6UrfIYvQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=1tMd7-_hvF4:wRh6UrfIYvQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=1tMd7-_hvF4:wRh6UrfIYvQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/1tMd7-_hvF4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/02/enhance-your-website-fullscreen-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2012/02/enhance-your-website-fullscreen-api/</feedburner:origLink></item>
		<item>
		<title>Question of the Day with CodeIgniter and MySQL</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/E6hjVQ_Eycg/</link>
		<comments>http://tutorialzine.com/2012/01/question-of-the-day-codeigniter-php-mysql/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 19:30:12 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1801</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/01/question-of-the-day-codeigniter-php-mysql/"><img src="http://cdn.tutorialzine.com/img/featured/1801.jpg" /></a></div> In this tutorial we will build a small application with CodeIgniter that will be backed by a MySQL database. It will present questions and give visitors the ability to post answers.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/01/question-of-the-day-codeigniter-php-mysql/"><img src="http://cdn.tutorialzine.com/img/featured/1801.jpg" /></a></div> <p>In this tutorial we will build a small application with CodeIgniter that will be backed by a MySQL database. It will present questions and give visitors the ability to post answers. There isn&#8217;t an admin interface for adding or changing questions, but if you follow and understand this tutorial, you will be able to create one yourself.</p>
<p>As this might be the first exposure to CodeIgniter for some of you, we will start with a brief intro. If you know what CI is, you can skip directly to the code.</p>
<h3>First, what is CodeIgniter?</h3>
<p><a href="http://codeigniter.com/" target="_blank">CodeIgniter</a> is a framework for developing web applications in PHP. It will help you properly organize your code using the model-view-controller (MVC) pattern, and give you useful functionality for getting your site up and running quickly. It hides away the tedious work like building and validating forms, communicating with a database, managing error pages and much more.</p>
<p>There are certainly a lot of frameworks to choose from, but CI has the winning combination of a big community, nice documentation and good performance. Unless you enjoy spending time building sites from scratch (which is not a bad thing), using a framework is the smarter way to go.</p>
<p>You should probably start by reading the <a href="http://codeigniter.com/user_guide/overview/getting_started.html" target="_blank">CodeIgniter introductory guide</a>, which will give you a better understanding of how CI works. Of course, if you are experienced with PHP you can grab the zip and jump directly to the code.</p>
<p><strong>Let&#8217;s begin!</strong></p>
<h3>The database</h3>
<p>Naturally, we will need a table for the questions, and a table for the answers.</p>
<div id="attachment_1809" class="wp-caption alignnone" style="width: 630px"><img class="size-full wp-image-1809" title="The Database Schema" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/01/database_schema.jpg" alt="The Database Schema" width="620" height="460" /><p class="wp-caption-text">The Database Schema</p></div>
<p>The questions table has only two fields &#8211; the <strong>ID</strong> of the question (automatically assigned with auto_increment) and the <strong>question</strong> body field. The answers also have an ID column, but they also have a <strong>qid</strong> field for the id of the question they relate to. The rest of the fields are the email and name of the author, along with the answer body and a timestamp (the dt field).</p>
<p>It is possible to create these tables with PHP code (CI gives us the ability to manipulate tables), but we will keep things simple and design them using a database management system like <em>phpMyAdmin</em>. It is even simpler for you, as I&#8217;ve included an export of the tables as an SQL file (<strong>tables.sql</strong> in the download archive). Import it into your database or copy/paste the code into the SQL tab of phpMyAdmin and you should be ready to go.</p>
<h3>Setting up CodeIgniter</h3>
<p>At this point you should <a href="http://codeigniter.com/downloads/" target="_blank">download CodeIgniter</a>. In this tutorial I am using version 2.1.0, the latest at the time of writing. Extract it in the directory where you are developing your website (move the files outside the CodeIgniter_2.1.0 folder and remove it). We will need to edit a few settings so the framework works the way we want it.</p>
<blockquote class="note"><p><strong>Important</strong><strong>:</strong> This section assumes that you are downloading a fresh copy of CodeIgniter. If you only want to make the downloaded demo work, you will only need to change your $config['base_url'] setting in config.php, and add your MySQL login details to database.php. The other changes are already made (you still need to create the MySQL tables).</p></blockquote>
<h4>Edit routes.php</h4>
<p>The application/config/routes.php file determines which controller is called by default. We need to set this to <strong>questions</strong>, which we will be creating in a moment.</p>
<pre class="brush:php">// Find this line:
$route['default_controller'] = "welcome";
// Replace it with this:
$route['default_controller'] = "questions";</pre>
<p>This will show the questions controller as the start page of the application.</p>
<h4>Edit config.php</h4>
<p>The application/config/config.php file holds much of the configuration settings of the framework.</p>
<pre class="brush:php">// Find this line:
$config['base_url'] = '';
// Replace it with the following:
$config['base_url']	= 'http://example.com/';</pre>
<p>The above setting, <strong>base_url</strong>, tells CI where your site is located. This information is used when forming links and including resources like stylesheets and images.</p>
<p>The following setting is optional. CodeIgniter adds index.php to every URL by default (like so: http://example.com/index.php/products/). If you want to hide it (so that the url becomes http://example.com/products/), you will need to edit the <strong>index_page</strong> setting:</p>
<pre class="brush:php">// Find this line:
$config['index_page'] = 'index.php';
// Replace it with the following:
$config['index_page'] = '';</pre>
<p>You will also need to create an <strong>.htaccess</strong> file, which rewrites the URLs so that they still get to index.php, although it is not included explicitly. The .htaccess I use in the demo follows:</p>
<h4>.htaccess</h4>
<pre class="brush:plain">Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]</pre>
<p>Now you only need to add your MySQL connection settings so that your application can connect to your database.</p>
<h4>Edit database.php</h4>
<p>Find these four lines in application/config/database.php and change them to reflect your connection settings:</p>
<pre class="brush:php">$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'user';
$db['default']['password'] = 'pass';
$db['default']['database'] = 'your_database_name';</pre>
<p>Great! We are done setting up CodeIgniter, so we can now move on with the code.</p>
<div id="attachment_1813" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/01/question-of-the-day-codeigniter-php-mysql/"><img class="size-full wp-image-1813" title="Question of the Day with CodeIgniter" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/01/comments.jpg" alt="Question of the Day with CodeIgniter" width="620" height="460" /></a><p class="wp-caption-text">Question of the Day with CodeIgniter</p></div>
<h3>Showing the questions</h3>
<p>To show the questions we will need to create two files &#8211; a controller, which will be called when we visit the <strong>/question/</strong> URL, and a view, which outputs the HTML code of the page. The controller will handle selecting records from the database and passing them to view. Note that we are not using any models in this app (the M in MVC). For simple applications like this one, they are purely optional and you can write CI apps without them.</p>
<h4>/application/controllers/questions.php</h4>
<pre class="brush:php">if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Questions extends CI_Controller {

	public function index(){

		// Loading only the libraries and helpers that we need.
		// This is one of the things that make CI fast.

		$this-&gt;load-&gt;database();
		$this-&gt;load-&gt;helper(array('date','url'));

		// Get the id of the last question

		$res = $this-&gt;db-&gt;
				select_max('id')-&gt;
				get('qod_questions')-&gt;
				result_array();

		$id = $res[0]['id'];

		$this-&gt;show($id);
	}

	public function show($id = -1){

		$this-&gt;load-&gt;database();
		$this-&gt;load-&gt;helper(array('date','url'));

		// Select the question

		$q = $this-&gt;db-&gt;
				where(array('id'=&gt;$id))-&gt;
				get('qod_questions')-&gt;
				result_array();

		if(empty($q)){
			// Show an error page
			show_404();
		}

		$a = $this-&gt;db-&gt;
				where(array('qid'=&gt;$id))-&gt;
				order_by('id','desc')-&gt;
				get('qod_answers')-&gt;
				result_array();

		// Get the ids of the previous
		// and next questions

		$prev = 0;
		$next = 0;

		$res = $this-&gt;db-&gt;
				select_min('id')-&gt;
				where("id &gt; $id")-&gt;
				get('qod_questions')-&gt;
				result_array();

		if(!empty($res)){
			$next = $res[0]['id'];
		}

		$res = $this-&gt;db-&gt;
				select_max('id')-&gt;
				where("id &lt; $id")-&gt;
				get('qod_questions')-&gt;
				result_array();

		if(!empty($res)){
			$prev = $res[0]['id'];
		}

		$this-&gt;load-&gt;view('question_of_the_day',array(
			'question'	=&gt; $q[0]['question'],
			'answers'	=&gt; $a,
			'previous'	=&gt; $prev,
			'next'		=&gt; $next,
			'id'		=&gt; $id
		));
	}
}</pre>
<p>The controller is basically a class that extends <strong>CI_Controller</strong> and resides in the <em>controllers</em> folder. The class methods are called by the framework depending on the URL. For example http://example.com/questions/ will execute the <em>index</em> method, and http://example.com/questions/show/213 &#8211; the <em>show</em> method. In the latter case, 213 will be passed as the id parameter.</p>
<p>In the <strong>show</strong> method we select the question with the passed ID and display it in the view. What the <strong>index</strong> method does, is to select the id of the newest question, and also call the show method. Because it is set as the default controller, this would mean that when you visit the start page of the application (the base url you set in the previous section), the latest question will be shown.</p>
<blockquote class="note"><p>Read more about the <a href="http://codeigniter.com/user_guide/general/urls.html" target="_blank">URLs</a>, <a href="http://codeigniter.com/user_guide/general/controllers.html" target="_blank">controllers</a>, <a href="http://codeigniter.com/user_guide/general/views.html" target="_blank">views</a>, <a href="http://codeigniter.com/user_guide/general/helpers.html" target="_blank">helpers</a> and the <a href="http://codeigniter.com/user_guide/database/examples.html" target="_blank">database class</a> of CodeIgniter in the docs.</p></blockquote>
<p>Now let&#8217;s see how the view works. When we load it, we pass an array. Each of the array keys (<em>question</em>, <em>answers</em>, <em>previous</em>, <em>next</em> and <em>id</em>) will be extracted and transformed into a variable. Instead of a class, the view is a simple PHP file.</p>
<h4>/application/views/question_of_the_day.php</h4>
<pre class="brush:html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;&lt;?php echo $question?&gt; - Question of the day | Tutorialzine Demo&lt;/title&gt;

        &lt;!-- Our CSS stylesheet file --&gt;
        &lt;link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Rancho" /&gt;
        &lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;assets/css/styles.css" /&gt;

        &lt;!--[if lt IE 9]&gt;
          &lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
        &lt;![endif]--&gt;
    &lt;/head&gt;

    &lt;body&gt;

		&lt;header id="blackboard"&gt;
			&lt;h1&gt;&lt;?php echo $question?&gt;&lt;/h1&gt;
			&lt;?php if($previous) echo anchor("questions/show/$previous",'&amp;laquo;','class="arrow left"')?&gt;
			&lt;?php if($next) echo anchor("questions/show/$next",'&amp;raquo;','class="arrow right"')?&gt;
		&lt;/header&gt;

		&lt;?php 

		// This method will create a link to the answer form. It is given relative
		// to your index page, but will be transformed depending on your base in config.php

		echo anchor("answers/add/$id",'Add your answer','class="addAnswer"');

		?&gt;

		&lt;ul id="answers"&gt;

		&lt;?php foreach ($answers as $ans): ?&gt;

			&lt;li&gt;
				&lt;?php
					// Forming the URL of the gravatar image.
					$gravatar = 'http://www.gravatar.com/avatar/'.md5( strtolower( trim($ans['email']) ) ).'?d=mm';
				?&gt;

				&lt;span class="avatar" style="background-image:url(&lt;?php echo $gravatar?&gt;)"&gt;&lt;/span&gt;
				&lt;span class="meta"&gt;
					&lt;a href="#" class="author"&gt;&lt;?php echo $ans['name']?&gt;&lt;/a&gt;
					&lt;?php
						// We are using the built-in timestamp method. We are using
						// array slice to limit the shown time divisions.
						$ts = explode(',', timespan(strtotime($ans['dt'])));
						$t = implode(',',array_slice($ts,0,2));
					?&gt;
					&lt;i&gt;&lt;?php echo $t?&gt; ago&lt;/i&gt;
				&lt;/span&gt;
				&lt;p class="answer"&gt;&lt;?php echo $ans['answer']?&gt;&lt;/p&gt;
			&lt;/li&gt;

		&lt;?php endforeach; ?&gt;

		&lt;/ul&gt;

    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>The script loops through the <strong>$answers</strong> array and outputs a li element for each answer. It <a href="http://en.gravatar.com/site/implement/hash/" target="_blank">assembles a gravatar URL</a> by generating an md5 hash of the email and includes it as the background-image of a rounded span element.</p>
<p>This gives us a functional answer browsing page. But how do we let people answer these questions?</p>
<div id="attachment_1814" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2012/01/question-of-the-day-codeigniter-php-mysql/"><img class="size-full wp-image-1814" title="The Blackboard" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/01/the-blackboard.jpg" alt="The Blackboard" width="620" height="260" /></a><p class="wp-caption-text">The Blackboard</p></div>
<h3>Posting answers</h3>
<p>We will again need to write a controller and a view for adding answers. Here we will use a few more of the neat CodeIgniter features &#8211; generating forms and validating them. The generation is handled by the <a href="http://codeigniter.com/user_guide/helpers/form_helper.html" target="_blank">form helper</a>, and the validation &#8211; by the <a href="http://codeigniter.com/user_guide/libraries/form_validation.html" target="_blank">form validation class</a>.</p>
<p>You can see the <strong>answers</strong> controller below.</p>
<h4>/application/controllers/answers.php</h4>
<pre class="brush:php">if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Answers extends CI_Controller {

	public function add($id = -1){

		$this-&gt;load-&gt;database();
		$this-&gt;load-&gt;helper(array('url','form'));
		$this-&gt;load-&gt;library('form_validation');

		// Check if there is such a question

		$q = $this-&gt;db-&gt;
				where(array('id'=&gt;$id))-&gt;
				get('qod_questions')-&gt;
				result_array();

		if(empty($q)){
			// Show an error page
			show_404();
		}

		// Adding validation rules.

		$this-&gt;form_validation-&gt;set_rules('name', 'Name', 'required|min_length[2]|max_length[32]');
		$this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required|valid_email');
		$this-&gt;form_validation-&gt;set_rules('answer', 'Answer', 'required|min_length[5]|max_length[255]');

		// If there are errors, show the form
		if ($this-&gt;form_validation-&gt;run() == FALSE){

			$this-&gt;load-&gt;view('add_answer',array(
				'question'	=&gt; $q[0]['question'],
				'qid'		=&gt; $q[0]['id']
			));

		}
		else{

			// Otherwise insert the answer to the database

			$this-&gt;db-&gt;insert('qod_answers', array(
				'qid'	=&gt; $q[0]['id'],
				'email'	=&gt; htmlspecialchars($this-&gt;input-&gt;post('email')),
				'name'	=&gt; htmlspecialchars($this-&gt;input-&gt;post('name')),

				// preserving new lines:
				'answer'=&gt; nl2br(htmlspecialchars($this-&gt;input-&gt;post('answer')))
			));

			redirect('questions/show/'.$q[0]['id']);
		}

	}
}</pre>
<p>With the help of the form validation class, we are able to add rules by which the data should be validated. We will insert the answer in the database only when presented with correct data. I am using the <code>htmlspecialchars()</code> PHP function to escape any HTML code that might have been typed in the form fields. When the answer is inserted, we redirect to the question page. If everything went as it should, the newly added answer should be at the top.</p>
<p>Equally interesting is how the answer form is generated. For this we will take a look at the view file.</p>
<h4>/application/views/add_answer.php</h4>
<pre class="brush:html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;&lt;?php echo $question?&gt; - Add Answer | Tutorialzine Demo&lt;/title&gt;

        &lt;!-- Our CSS stylesheet file --&gt;
        &lt;link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Rancho" /&gt;
        &lt;link rel="stylesheet" href="&lt;?php echo base_url()?&gt;assets/css/styles.css" /&gt;

        &lt;!--[if lt IE 9]&gt;
          &lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
        &lt;![endif]--&gt;
    &lt;/head&gt;

    &lt;body&gt;

		&lt;header id="blackboard"&gt;
			&lt;h1&gt;&lt;?php echo $question?&gt;&lt;/h1&gt;
		&lt;/header&gt;

		&lt;?php 

		// This will print a link to the question page
		echo anchor("questions/show/$qid",'Back to the question','class="addAnswer"');

		// Creating the form using the form helper

		echo form_open('');

		echo form_label('Name','name');
		echo form_input(array(
          'name'        =&gt; 'name',
          'id'          =&gt; 'name',
          'value'       =&gt; set_value('name'),
          'maxlength'   =&gt; '64'
        ));

		echo form_label('Email (gravatar enabled)','email');
		echo form_input(array(
          'name'        =&gt; 'email',
          'id'          =&gt; 'email',
          'value'       =&gt; set_value('email'),
          'maxlength'   =&gt; '128'
        ));

		echo form_label('Answer','answer');
		echo form_textarea(array(
          'name'        =&gt; 'answer',
          'id'          =&gt; 'answer',
          'value'       =&gt; set_value('answer'),
        ));

		echo form_submit('subm', 'Add Answer!'); 

		// Showing the validation errors
		$validation = validation_errors(); 

		if($validation):
		?&gt;
			&lt;div class="errorMessages"&gt;
				&lt;?php echo $validation?&gt;
			&lt;/div&gt;

		&lt;?php endif;?&gt;

		&lt;?php echo form_close()?&gt;

    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>As we included the form helper in the controller, we have access to all of its functions here, in the view. These functions make it easier to create forms and form fields. Of course, you can directly write the HTML of the forms, but you will have to update the code if you change the URL of your site.</p>
<p>At the bottom of the file we are accessing the <code>validate_errors()</code> function which will return a string with error messages, generated by the validation class. If there are any errors, we show them in a <em>.errorMessages</em> div.</p>
<p>That is it! All that is left is to add a pretty stylesheet and some images.</p>
<h3>The styling</h3>
<p>To finish this application, we need to add a stylesheet and images. Where we put them is more a matter of personal preference. I have chosen to go with an <strong>assets</strong> folder in the base directory of the application (you can see it in the zip file).</p>
<p>In the views I have specified the URL of the stylesheet like this: <code>&lt;?php echo base_url()?&gt;assets/css/styles.css</code> which gives us the correct location. <code>base_url()</code> is a function defined in the <a href="http://codeigniter.com/user_guide/helpers/url_helper.html" target="_blank">URL helper</a> of the framework, which we&#8217;ve included in the controller.</p>
<p>As the tutorial is already quite lengthy, I won&#8217;t be discussing the styling here. You can see it for yourself by opening /assets/css/styles.css in your code editor.</p>
<h3>We&#8217;re done!</h3>
<p>I am hoping that you learned a lot in this tutorial. If you decide to go with CodeIgniter for your next website, it will be a useful experience for you. Although there is a learning curve, once you understand the basics, you will appreciate just how much time you can save. And with <a href="http://getsparks.org/" target="_blank">Sparks</a>, you will become even more productive by adding easy to use open source modules to your projects.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=E6hjVQ_Eycg:W-TNd2JGo7s:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=E6hjVQ_Eycg:W-TNd2JGo7s:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=E6hjVQ_Eycg:W-TNd2JGo7s:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=E6hjVQ_Eycg:W-TNd2JGo7s:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=E6hjVQ_Eycg:W-TNd2JGo7s:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=E6hjVQ_Eycg:W-TNd2JGo7s:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=E6hjVQ_Eycg:W-TNd2JGo7s:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=E6hjVQ_Eycg:W-TNd2JGo7s:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=E6hjVQ_Eycg:W-TNd2JGo7s:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=E6hjVQ_Eycg:W-TNd2JGo7s:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/E6hjVQ_Eycg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/01/question-of-the-day-codeigniter-php-mysql/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2012/01/question-of-the-day-codeigniter-php-mysql/</feedburner:origLink></item>
		<item>
		<title>iPhorm Plugin Winners</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/MinkCURud1Y/</link>
		<comments>http://tutorialzine.com/2012/01/iphorm-plugin-winners/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 19:33:05 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tzine]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1796</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2012/01/iphorm-plugin-winners/"><img src="http://cdn.tutorialzine.com/img/featured/1796.jpg" /></a></div> Announcing the winners of the iPhorm WordPress plugin giveaway.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2012/01/iphorm-plugin-winners/"><img src="http://cdn.tutorialzine.com/img/featured/1796.jpg" /></a></div> <p>Just before the holidays, you took part in the <a title="Win a copy of the iPhorm WordPress plugin!" href="http://tutorialzine.com/2011/12/win-a-copy-of-iphorm-wordpress-plugin/">iPhorm WordPress Plugin Giveaway</a>, where two of you had a chance of winning a copy of the plugin. Now it is time to draw the winners!</p>
<p>And the two of you who got a late Christmas present are <strong>WPH</strong> and <strong>Mike Dedmon</strong>. They have been contacted and will receive their prizes shortly.</p>
<div id="attachment_1797" class="wp-caption alignnone" style="width: 630px"><a href="http://cdn.tutorialzine.com/wp-content/uploads/2012/01/winners.jpg"><img class="size-full wp-image-1797" title="iPhorm winners" src="http://cdn.tutorialzine.com/wp-content/uploads/2012/01/winners.jpg" alt="iPhorm winners" width="620" height="260" /></a><p class="wp-caption-text">iPhorm winners</p></div>
<p>For those of you who did not win, I wish the best of luck next time!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=MinkCURud1Y:Om-jXCzYttw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=MinkCURud1Y:Om-jXCzYttw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=MinkCURud1Y:Om-jXCzYttw:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=MinkCURud1Y:Om-jXCzYttw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=MinkCURud1Y:Om-jXCzYttw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=MinkCURud1Y:Om-jXCzYttw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=MinkCURud1Y:Om-jXCzYttw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=MinkCURud1Y:Om-jXCzYttw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=MinkCURud1Y:Om-jXCzYttw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=MinkCURud1Y:Om-jXCzYttw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/MinkCURud1Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2012/01/iphorm-plugin-winners/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2012/01/iphorm-plugin-winners/</feedburner:origLink></item>
		<item>
		<title>Making a jQuery Countdown Timer</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/GziO86IHIWA/</link>
		<comments>http://tutorialzine.com/2011/12/countdown-jquery/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 11:02:06 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1781</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2011/12/countdown-jquery/"><img src="http://cdn.tutorialzine.com/img/featured/1781.jpg" /></a></div> Today we are going to build a neat jQuery plugin for displaying a countdown timer. It will show the remaining days, hours, minutes and seconds to your event, as well as an animated updates on every second.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2011/12/countdown-jquery/"><img src="http://cdn.tutorialzine.com/img/featured/1781.jpg" /></a></div> <p>When building a <a title="Creating a Stylish Coming Soon Page with jQuery" href="http://tutorialzine.com/2010/10/ajaxed-coming-soon-page/">coming soon</a> or event page, you find yourself in search for a good way to display the remaining time. A countdown gives the feel of urgency, and combined with an email field will yield more signups for your newsletter.</p>
<p>Today we are going to build a neat jQuery plugin for displaying a countdown timer. It will show the remaining days, hours, minutes and seconds to your event, as well as an animated updates on every second. <strong>Note:</strong> the plugin is also available on <a href="https://github.com/martinaglv/jQuery-Countdown" target="_blank">Github</a>.</p>
<p>Let&#8217;s start with the markup!</p>
<h3>The HTML</h3>
<p>We will give the plugin the creative name of &#8220;countdown&#8221;. Called on an empty element, it will fill it with the HTML that is needed for the countdown timer. You don&#8217;t need to do anything but choose the element in which you want to show it.</p>
<h4>Generated markup</h4>
<pre class="brush:html">&lt;div id="countdown" class="countdownHolder"&gt;
	&lt;span class="countDays"&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
	&lt;/span&gt;

	&lt;span class="countDiv countDiv0"&gt;&lt;/span&gt;

	&lt;span class="countHours"&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
	&lt;/span&gt;

	&lt;span class="countDiv countDiv1"&gt;&lt;/span&gt;

	&lt;span class="countMinutes"&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
	&lt;/span&gt;

	&lt;span class="countDiv countDiv2"&gt;&lt;/span&gt;

	&lt;span class="countSeconds"&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
		&lt;span class="position"&gt;
			&lt;span class="digit static"&gt;&lt;/span&gt;
		&lt;/span&gt;
	&lt;/span&gt;

	&lt;span class="countDiv countDiv3"&gt;&lt;/span&gt;
&lt;/div&gt;</pre>
<p>In the above example, the plugin has been originally called on a div with an id of <strong>countdown</strong>. The plugin has then added a <strong>countdownHolder</strong> class to it (so a few styles are applied to the element via CSS).</p>
<p>Inside is the markup for the digits. There are two <strong>digit</strong> spans for every time unit (days, hours, minutes and seconds), which means that you can count down towards a date that is no more than 99 days in the future (for such time frames you should probably not use the timer anyway, it would be discouraging).</p>
<p>The static class of the digits gives them their gradient background and box-shadow. When animated, this class is removed so that these CSS3 touches don&#8217;t slow down the animation. The digits are brought together in groups so you can easily style them. Adding a font-size declaration to .<strong>countDays</strong>, will affect the size of both day digits.</p>
<div id="attachment_1782" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2011/12/countdown-jquery/"><img class="size-full wp-image-1782" title="A jQuery Countdown Timer" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/jquery-countdown-timer.jpg" alt="A jQuery Countdown Timer" width="620" height="260" /></a><p class="wp-caption-text">A jQuery Countdown Timer</p></div>
<p>The <strong>.countDiv</strong> spans are the dividers between the units. The colon is formed with :before/:after elements.</p>
<p>But how is this markup generated exactly?</p>
<h3>The jQuery</h3>
<p>First let&#8217;s write two helper functions used by the plugin:</p>
<ul>
<li><strong>init</strong> generates the markup you saw above;</li>
<li><strong>switchDigit</strong> takes a .position span and animates the digits inside it;</li>
</ul>
<p>Extracting this functionality as separate functions allows us to keep the plugin code clean.</p>
<h4>assets/countdown/jquery.countdown.js</h4>
<pre class="brush:js">	function init(elem, options){
		elem.addClass('countdownHolder');

		// Creating the markup inside the container
		$.each(['Days','Hours','Minutes','Seconds'],function(i){
			$('&lt;span class="count'+this+'"&gt;').html(
				'&lt;span class="position"&gt;\
					&lt;span class="digit static"&gt;0&lt;/span&gt;\
				&lt;/span&gt;\
				&lt;span class="position"&gt;\
					&lt;span class="digit static"&gt;0&lt;/span&gt;\
				&lt;/span&gt;'
			).appendTo(elem);

			if(this!="Seconds"){
				elem.append('&lt;span class="countDiv countDiv'+i+'"&gt;&lt;/span&gt;');
			}
		});

	}

	// Creates an animated transition between the two numbers
	function switchDigit(position,number){

		var digit = position.find('.digit')

		if(digit.is(':animated')){
			return false;
		}

		if(position.data('digit') == number){
			// We are already showing this number
			return false;
		}

		position.data('digit', number);

		var replacement = $('&lt;div&gt;',{
			'class':'digit',
			css:{
				top:'-2.1em',
				opacity:0
			},
			html:number
		});

		// The .static class is added when the animation
		// completes. This makes it run smoother.

		digit
			.before(replacement)
			.removeClass('static')
			.animate({top:'2.5em',opacity:0},'fast',function(){
				digit.remove();
			})

		replacement
			.delay(100)
			.animate({top:0,opacity:1},'fast',function(){
				replacement.addClass('static');
			});
	}</pre>
<p>Great! Now let&#8217;s move on with the plugin body. Our plugin must take an object with parameters for better configurability &#8211; a timestamp of the period we are counting towards, and a callback function, executed on every tick and passed the remaining time. For brevity, I&#8217;ve omitted the functions above from the code.</p>
<h4>assets/countdown/jquery.countdown.js</h4>
<pre class="brush:js">(function($){

	// Number of seconds in every time division
	var days	= 24*60*60,
		hours	= 60*60,
		minutes	= 60;

	// Creating the plugin
	$.fn.countdown = function(prop){

		var options = $.extend({
			callback	: function(){},
			timestamp	: 0
		},prop);

		var left, d, h, m, s, positions;

		// Initialize the plugin
		init(this, options);

		positions = this.find('.position');

		(function tick(){

			// Time left
			left = Math.floor((options.timestamp - (new Date())) / 1000);

			if(left &lt; 0){
				left = 0;
			}

			// Number of days left
			d = Math.floor(left / days);
			updateDuo(0, 1, d);
			left -= d*days;

			// Number of hours left
			h = Math.floor(left / hours);
			updateDuo(2, 3, h);
			left -= h*hours;

			// Number of minutes left
			m = Math.floor(left / minutes);
			updateDuo(4, 5, m);
			left -= m*minutes;

			// Number of seconds left
			s = left;
			updateDuo(6, 7, s);

			// Calling an optional user supplied callback
			options.callback(d, h, m, s);

			// Scheduling another call of this function in 1s
			setTimeout(tick, 1000);
		})();

		// This function updates two digit positions at once
		function updateDuo(minor,major,value){
			switchDigit(positions.eq(minor),Math.floor(value/10)%10);
			switchDigit(positions.eq(major),value%10);
		}

		return this;
	};

	/* The two helper functions go here */</pre>
<pre class="brush:js">})(jQuery);</pre>
<p>The tick function calls itself every second. Inside it, we calculate the time difference between the given timestamp and the current date. The <strong>updateDuo</strong> function then updates the digits comprising the time unit.</p>
<p><strong>The plugin is ready!</strong> Here is how to use it (as seen in the demo):</p>
<h4>assets/js/script.js</h4>
<pre class="&quot;brush:js">$(function(){

	var note = $('#note'),
		ts = new Date(2012, 0, 1),
		newYear = true;

	if((new Date()) &gt; ts){
		// The new year is here! Count towards something else.
		// Notice the *1000 at the end - time must be in milliseconds
		ts = (new Date()).getTime() + 10*24*60*60*1000;
		newYear = false;
	}

	$('#countdown').countdown({
		timestamp	: ts,
		callback	: function(days, hours, minutes, seconds){

			var message = "";

			message += days + " day" + ( days==1 ? '':'s' ) + ", ";
			message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
			message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " and ";
			message += seconds + " second" + ( seconds==1 ? '':'s' ) + " &lt;br /&gt;";

			if(newYear){
				message += "left until the new year!";
			}
			else {
				message += "left to 10 days from now!";
			}

			note.html(message);
		}
	});

});</pre>
<p>Of course, for this to work, you will have to include the css and js file from the countdown folder in your page.</p>
<h3>Done!</h3>
<p>You can use this script as the perfect addition to every launch page. The best thing about it is that it doesn&#8217;t use a single image, everything is done with CSS alone. Increasing or decreasing the font size will result in everything scaling nicely, and you only need a <strong>display:none</strong> declaration to hide the units you don&#8217;t need.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=GziO86IHIWA:sV968KIzydk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=GziO86IHIWA:sV968KIzydk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=GziO86IHIWA:sV968KIzydk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=GziO86IHIWA:sV968KIzydk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=GziO86IHIWA:sV968KIzydk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=GziO86IHIWA:sV968KIzydk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=GziO86IHIWA:sV968KIzydk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=GziO86IHIWA:sV968KIzydk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=GziO86IHIWA:sV968KIzydk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=GziO86IHIWA:sV968KIzydk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/GziO86IHIWA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2011/12/countdown-jquery/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2011/12/countdown-jquery/</feedburner:origLink></item>
		<item>
		<title>Win a copy of the iPhorm WordPress plugin!</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/SOfmID21WCA/</link>
		<comments>http://tutorialzine.com/2011/12/win-a-copy-of-iphorm-wordpress-plugin/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 19:00:06 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tzine]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1775</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2011/12/win-a-copy-of-iphorm-wordpress-plugin/"><img src="http://cdn.tutorialzine.com/img/featured/1775.jpg" /></a></div> Win a copy of the premium iPhorm WordPress plugin.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2011/12/win-a-copy-of-iphorm-wordpress-plugin/"><img src="http://cdn.tutorialzine.com/img/featured/1775.jpg" /></a></div> <p>WordPress is undoubtedly the most popular CMS in the world. It is used for so much more than the authors initially envisioned. With all of its wonderful features and incredible plugins, you can build anything – from a personal blog to a fully-fledged online shop.</p>
<p>With the holidays right around the corner, we decided to give away <strong>two copies</strong> of the iPhorm plugin which will help you create forms for your website with an easy to use drag-and-drop builder directly from WordPress.</p>
<div id="attachment_1776" class="wp-caption alignnone" style="width: 630px"><a href="http://www.themecatcher.net/iphorm-form-builder"><img class="size-full wp-image-1776" title="The iPhorm Plugin" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/620-300-for-tutorialzine.png" alt="The iPhorm Plugin" width="620" height="300" /></a><p class="wp-caption-text">The iPhorm Plugin</p></div>
<p><a href="http://www.themecatcher.net/iphorm-form-builder" target="_blank">iPhorm</a> is a WordPress plugin that makes building forms easy with elements that include email address, date and time, file uploads and many more. The form submissions are received as emails or directly in your dashboard. Designers have full control on how the forms looks, and for everybody else, two themes are provided. For a live demo, see <a href="http://demos.themecatcher.net/iphorm-form-builder/wp-admin" target="_blank">here</a>.</p>
<h3>How to Win</h3>
<p>For a chance to win a copy of the plugin, do the following:</p>
<ul>
<li>Leave a comment below this article;</li>
<li>Tweet it.</li>
</ul>
<p>The winners will be announced on <strong>January 5th 2012</strong>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=SOfmID21WCA:vcFwFb97YkA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=SOfmID21WCA:vcFwFb97YkA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=SOfmID21WCA:vcFwFb97YkA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=SOfmID21WCA:vcFwFb97YkA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=SOfmID21WCA:vcFwFb97YkA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=SOfmID21WCA:vcFwFb97YkA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=SOfmID21WCA:vcFwFb97YkA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=SOfmID21WCA:vcFwFb97YkA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=SOfmID21WCA:vcFwFb97YkA:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=SOfmID21WCA:vcFwFb97YkA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/SOfmID21WCA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2011/12/win-a-copy-of-iphorm-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>81</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2011/12/win-a-copy-of-iphorm-wordpress-plugin/</feedburner:origLink></item>
		<item>
		<title>HTML5 Charity Center Template</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/kMTsUAzOXV0/</link>
		<comments>http://tutorialzine.com/2011/12/html5-template-charity-center/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 20:34:54 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Templates]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1768</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2011/12/html5-template-charity-center/"><img src="http://cdn.tutorialzine.com/img/featured/1768.jpg" /></a></div> Charity Center is a free and beautiful HTML5 template for Tutorialzine readers.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2011/12/html5-template-charity-center/"><img src="http://cdn.tutorialzine.com/img/featured/1768.jpg" /></a></div> <p>With the help of our friends over at <a href="http://www.grafpedia.com/" target="_blank">Grafpedia</a>, I am happy to share with you a beautiful charity web site template to kick-start your development efforts. It is fully coded in HTML5 and uses the tiny <a href="http://projects.craftedpixelz.co.uk/craftyslide/" target="_blank">Craftyslider</a> jQuery plugin.</p>
<div id="attachment_1769" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2011/12/html5-template-charity-center/"><img class="size-full wp-image-1769" title="HTML5 Charity Template" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/html5-charity-template.jpg" alt="HTML5 Charity Template" width="620" height="460" /></a><p class="wp-caption-text">HTML5 Charity Template</p></div>
<p>Grafpedia have also published a <a href="http://www.grafpedia.com/tutorials/design-charity-web-layout">tutorial on how the design was created</a>. Refer to the included readme for the license.</p>
<p>Happy coding!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=kMTsUAzOXV0:qYtv6Sj01Ko:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=kMTsUAzOXV0:qYtv6Sj01Ko:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=kMTsUAzOXV0:qYtv6Sj01Ko:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=kMTsUAzOXV0:qYtv6Sj01Ko:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=kMTsUAzOXV0:qYtv6Sj01Ko:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=kMTsUAzOXV0:qYtv6Sj01Ko:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=kMTsUAzOXV0:qYtv6Sj01Ko:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=kMTsUAzOXV0:qYtv6Sj01Ko:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=kMTsUAzOXV0:qYtv6Sj01Ko:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=kMTsUAzOXV0:qYtv6Sj01Ko:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/kMTsUAzOXV0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2011/12/html5-template-charity-center/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2011/12/html5-template-charity-center/</feedburner:origLink></item>
		<item>
		<title>How to Block Adblock</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/K7juKsVNY5k/</link>
		<comments>http://tutorialzine.com/2011/12/how-to-block-adblock/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 17:43:10 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1751</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2011/12/how-to-block-adblock/"><img src="http://cdn.tutorialzine.com/img/featured/1751.jpg" /></a></div> Today we will give website owners a chance and write a plugin with which they can detect whether a visitor is using an ad blocker.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2011/12/how-to-block-adblock/"><img src="http://cdn.tutorialzine.com/img/featured/1751.jpg" /></a></div> <p>If you are a website owner, there is a pretty good chance that you rely on some form of advertising to pay for your hosting bills. And if you are lucky enough to have more than a few people visiting your site, you might even be able to pay yourself a supplement to your salary as a compensation for your hard work.</p>
<p>On the other side there are the people that browse the web. They are tired of being bombarded with intrusive advertising, flashy banners and announcements that ruin their browsing experience. They don&#8217;t need to be congratulated on being the millionth visitor of your website, they don&#8217;t want to shoot five iphones, their only wish is to read what you have to say.</p>
<p>As it is much easier for users to hide ads than for the entire industry to develop advertising ethics, a simple solution quickly emerged.</p>
<h3>Then Came Adblockers</h3>
<p>The idea of an adblocker is simple &#8211; it is a browser extension that blocks or removes advertising on the page. A &#8220;solution&#8221; is hardly the proper term, however, as it only serves one side &#8211; the users. There frankly couldn&#8217;t be a better deal for them. These extensions strip everything except the main content of the page, bringing a whole new dimension to the word free &#8211; it not only means that they don&#8217;t pay; it now means that you don&#8217;t get paid too!</p>
<div id="attachment_1754" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2011/12/how-to-block-adblock/"><img class="size-full wp-image-1754" title="Adblocker detected!" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/adblocker-detected.jpg" alt="Adblocker detected!" width="620" height="460" /></a><p class="wp-caption-text">Adblocker detected!</p></div>
<p>This didn&#8217;t use to be a big of a problem for website owners &#8211; people using ad blockers weren&#8217;t that many, and it did make users enjoy browsing your site more. But as the idea for browser extensions exploded in recent years, so did the proliferation of ad blockers. A quick look at the <a href="https://addons.mozilla.org/en-US/firefox/extensions/?sort=users" target="_blank">addon</a> <a href="https://chrome.google.com/webstore/category/popular" target="_blank">directories</a> reveals that ad blockers are the most popular category.</p>
<p>Small sites are most at risk, as they can&#8217;t attract the same interest from advertisers and experiment with different formats. With more than 20% of pageviews eaten away by adblockers (these are the number for Tutorialzine), it becomes evident that something has to change.</p>
<p>Miraculously, in the past few weeks there were news that the most popular ad blocker &#8211; AdBlock Plus <a href="https://adblockplus.org/en/acceptable-ads" target="_blank">will start allowing acceptable advertising by default</a>. Judging by the uproar this decision brought, a large percentage of people will still opt in for complete blocking of ads or move to a different extension. This means that we as publishers will still have to maneuver around this problem for some time to come. One solution would be to detect the presence of an ad blocker.</p>
<h3>How To Detect AdBlock</h3>
<p>It is simple &#8211; we will use ad blockers&#8217; overzealous interference against it. To block ads such an extension must look for files it believes contain code that shows adverts and prevent them from loading. So the idea is to have a JS file named <strong>advertisement.js</strong>, which will trigger adblock&#8217;s filters, and after this, check whether the file has been loaded.</p>
<p>Here is the file itself:</p>
<h4>assets/blockBlock/advertisement.js</h4>
<pre class="brush:js">jQuery.adblock = false;</pre>
<p>That&#8217;s all, one line. It creates a new property on the global jQuery object, which we will later look for. If it is undefined, it would mean that this file has been blocked from loading.</p>
<h4>assets/blockBlock/blockBlock.jquery.js</h4>
<pre class="brush:js">(function($){

	if ($.adblock === undefined){
		$.adblock = true;
	}

	$.fn.showOnAdBlock = function(){

		if($.adblock){
			this.show();
		}

		return this;
	};

})(jQuery);</pre>
<p>To find out if an ad blocker is present, simply do a conditional check for the $.adblock variable. In the same file, we also define a helper method that will conditionally show an element depending if such an extension is active.</p>
<p><strong>Update:</strong> This plugin is also <a href="https://github.com/martinaglv/BlockBlock" target="_blank">available on Github</a>.</p>
<p>When including the plugin in your site, remember to include the files above <strong>after</strong> the jQuery library. For the demo page I am also using the <a href="http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/">confirm dialog replacement</a> from last year to show a pretty dialog box informing the users they should disable adblock to view the page. Here is the code for that:</p>
<h4>assets/js/script.js</h4>
<pre class="brush:js">$(function(){

	if($.adblock){
		$.confirm({
			'title'		: 'Adblocker active!',
			'message'	: 'You are running an ..',
			'buttons'	: {
				'I will!'	: {
					'class'	: 'blue',
					'action': function(){
						// Do nothing
						return;
					}
				},
				'Never!'	: {
					'class'	: 'gray',
					'action': function(){
						// Redirect to some page
						window.location = 'http://tutorialzine.com/';
					}
				}
			}
		});
	}
});</pre>
<p>Bang! Now you can tell who is using an ad blocker. This simple method works with most of the popular ad cleaning plugins used at the moment.</p>
<h3>What to use it for?</h3>
<p>Okay, so you have a snippet of code that would tell you if a person is using an ad blocker or not. What to do now? Some ideas follow. I would not personally use any of the bad or evil ones, but I am obliged to share.</p>
<h4>Good ideas</h4>
<ul>
<li>Track how many people are blocking ads on your website. If the percentage is high, you can try different (non-banner) types of advertisement;</li>
<li>Replace the areas of your website where ads usually go with some useful content;</li>
<li>Inform visitors how adblock harms small websites with a heartbreaking personal appeal ala Jimmy Wales.</li>
</ul>
<h4>Bad ideas</h4>
<ul>
<li>Show a big message that adblocked users are not welcome (like in the demo);</li>
<li>Beg for donations;</li>
<li>Replace with ads for affiliate programs that are not blocked by the extension.</li>
</ul>
<h4>Outright evil ideas</h4>
<ul>
<li>Set up a paywall for adblocked users;</li>
<li>Require a sign-in with facebook or a registration;</li>
<li>Redirect to a daily deal website with your affiliate link.</li>
</ul>
<h3>A bright future?</h3>
<p>Hopefully the initiative behind AdBlock Plus&#8217; decision to show non-intrusive ads resonates in the community and we will enjoy advertising that is accepted and useful for both publishers and visitors.</p>
<p><strong>What are your thoughts about AdBlock?</strong></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=K7juKsVNY5k:IHZn1B_TftY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=K7juKsVNY5k:IHZn1B_TftY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=K7juKsVNY5k:IHZn1B_TftY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=K7juKsVNY5k:IHZn1B_TftY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=K7juKsVNY5k:IHZn1B_TftY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=K7juKsVNY5k:IHZn1B_TftY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=K7juKsVNY5k:IHZn1B_TftY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=K7juKsVNY5k:IHZn1B_TftY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=K7juKsVNY5k:IHZn1B_TftY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=K7juKsVNY5k:IHZn1B_TftY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/K7juKsVNY5k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2011/12/how-to-block-adblock/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2011/12/how-to-block-adblock/</feedburner:origLink></item>
		<item>
		<title>IM Creator Lifetime Subscription Winners</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/A2t4_PWJztc/</link>
		<comments>http://tutorialzine.com/2011/12/im-creator-lifetime-subscription-winners/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 11:04:14 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tzine]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1743</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2011/12/im-creator-lifetime-subscription-winners/"><img src="http://cdn.tutorialzine.com/img/featured/1743.jpg" /></a></div> Announcing the winners for the IM Creator Giveaway.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2011/12/im-creator-lifetime-subscription-winners/"><img src="http://cdn.tutorialzine.com/img/featured/1743.jpg" /></a></div> <p>Ten days ago you took part in the <a href="http://tutorialzine.com/2011/12/win-lifetime-subscription-imcreator/">IM Creator giveaway</a>, where three of you had a chance to win a lifetime subscription for their new web site building service. Now it is time to draw the winners!</p>
<p>And they are <strong>kit</strong>, <strong>Richard Bland</strong> and <strong>Chen YH</strong>. They have been contacted and will receive their prizes soon.</p>
<div id="attachment_1746" class="wp-caption alignnone" style="width: 630px"><img class="size-full wp-image-1746" title="The Winners" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/winners.jpg" alt="The Winners" width="620" height="260" /><p class="wp-caption-text">The Winners</p></div>
<p>I am wishing the best of luck in the coming competitions for those of you who did not win!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=A2t4_PWJztc:u7QgscvFy38:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=A2t4_PWJztc:u7QgscvFy38:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=A2t4_PWJztc:u7QgscvFy38:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=A2t4_PWJztc:u7QgscvFy38:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=A2t4_PWJztc:u7QgscvFy38:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=A2t4_PWJztc:u7QgscvFy38:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=A2t4_PWJztc:u7QgscvFy38:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=A2t4_PWJztc:u7QgscvFy38:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=A2t4_PWJztc:u7QgscvFy38:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=A2t4_PWJztc:u7QgscvFy38:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/A2t4_PWJztc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2011/12/im-creator-lifetime-subscription-winners/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2011/12/im-creator-lifetime-subscription-winners/</feedburner:origLink></item>
		<item>
		<title>What You Need To Know About The HTML5 Slider Element</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/uJm0cZmiP3w/</link>
		<comments>http://tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 16:26:38 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1722</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input/"><img src="http://cdn.tutorialzine.com/img/featured/1722.jpg" /></a></div> The new HTML5 slider control is useful for giving users the ability to conveniently modify a value without having to explicitly type it in a text box. In this short tutorial you will learn how to use it and how to emulate it in older browsers.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input/"><img src="http://cdn.tutorialzine.com/img/featured/1722.jpg" /></a></div> <p>HTML5 brought a lot of new tags and new rules on how the old ones should be used. One of them is the range input element, or the slider. This control has been available in operating systems for decades, but is only now that it has found its way into the browser.</p>
<p>The reason for this delay is probably that it is easy to emulate the functionality with JavaScript alone. The jQuery UI library includes a <a href="http://jqueryui.com/demos/slider/" target="_blank">pretty capable version</a> that is also easy to style. But having it built into the browser and ready to go is much more convenient, at least for the browsers that support it.</p>
<div id="attachment_1733" class="wp-caption alignnone" style="width: 630px"><a href="http://demo.tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input/"><img class="size-full wp-image-1733 " title="The Slider Element in Google Chrome" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/chrome-range-input-slider-element.jpg" alt="The Slider Element in Google Chrome" width="620" height="260" /></a><p class="wp-caption-text">20 years in the making, but we finally have it!</p></div>
<h3>Browser support</h3>
<p>All modern browsers support this element with the notable <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=344618" target="_blank">exception of Firefox</a>, but it can be easily recreated with <a href="http://frankyan.com/labs/html5slider/" target="_blank">html5slider.js</a>. Of course IE also does not support the range input (no surprise here), for which there are no easy fixes. This means that to use it cross-browser you will still need to include a separate enabling library like jQuery UI (more on that later on). The good thing is that even if the browser does not support the range element, it will fall back to a textbox.</p>
<div id="attachment_1734" class="wp-caption alignnone" style="width: 630px"><img class="size-full wp-image-1734" title="Browser support could be better." src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/browser-support.jpg" alt="Browser support for the range input" width="620" height="260" /><p class="wp-caption-text">Browser support for the range input</p></div>
<h3>How it works</h3>
<p>I referred to the slider as &#8220;range input&#8221; for a reason. It is a type of input element, rather than a separate tag &#8211; <code>&lt;input type="range" /&gt;</code> is all you need to display it in your page. It supports the regular <strong>value</strong> attribute shared by all input elements, along with <strong>min</strong> and <strong>max</strong>, which limit the range, and <strong>step</strong> which sets how much the value changes on every movement (default is 1).</p>
<table cellspacing="0" cellpadding="0">
<caption>Supported attributes by &lt;input type=&#8221;range&#8221; /&gt;</caption>
<tbody>
<tr>
<th>Attribute</th>
<th>Value</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>value</td>
<td>number</td>
<td>not set</td>
<td>The default position of the slider.</td>
</tr>
<tr>
<td>min</td>
<td>number</td>
<td>0</td>
<td>The bottom limit of the range. This is the value of the input when the slider is on the leftmost position.</td>
</tr>
<tr>
<td>max</td>
<td>number</td>
<td>100</td>
<td>The top limit of the range. This is the value of the input when the slider is on the rightmost position.</td>
</tr>
<tr>
<td>step</td>
<td>number</td>
<td>1</td>
<td>The amount with which the value changes on each movement of the slider.</td>
</tr>
</tbody>
</table>
<p>You can change these attributes with JavaScript/jQuery as you would with any regular input element. You can also use the onchange event to listen for changes. This is what the code looks like:</p>
<h4>Extracted from index.html</h4>
<pre class="brush:html">&lt;input id="defaultSlider" type="range" min="0" max="500" /&gt;
&lt;p class="note"&gt;Current value: &lt;span id="currentValue"&gt;0&lt;/span&gt;&lt;/p&gt;</pre>
<p>And this is the jQuery code that listens for the change event:</p>
<h4>assets/js/slider-default.js</h4>
<pre class="brush:js">$(function(){

	var currentValue = $('#currentValue');

	$('#defaultSlider').change(function(){
	    currentValue.html(this.value);
	});

	// Trigger the event on load, so
	// the value field is populated:

	$('#defaultSlider').change();

});</pre>
<p>Of course this code will only work if your browser supports the slider element. Otherwise you will be presented with a textbox.</p>
<h3>Lets level the field</h3>
<p>As more than two thirds of the internet population won&#8217;t be able to see our pretty slider, we need to take a different path. Lets build a quick and dirty version of the slider using <a href="http://jqueryui.com/demos/slider/" target="_blank">jQuery UI</a>, a library of interface components that sits on top of jQuery.</p>
<h4>Extracted from slider-jqueryui.html</h4>
<pre class="brush:html">&lt;div id="slider"&gt;&lt;/div&gt;
&lt;p class="note"&gt;Current value: &lt;span id="currentValue"&gt;0&lt;/span&gt;&lt;/p&gt;</pre>
<p>You can see the code for the jQuery UI Slider control below (you need to include jQuery UI alongside jQuery in your page).</p>
<h4>assets/js/slider-jqueryui.js</h4>
<pre class="brush:js">$(function(){

	var currentValue = $('#currentValue');

	$("#slider").slider({
		max: 500,
		min: 0,
		slide: function(event, ui) {
			currentValue.html(ui.value);
		}
	});

});</pre>
<p>The code is pretty straightforward. It simply uses the slider method and the library does the rest.</p>
<h3>The fun part</h3>
<p>Here comes a realization &#8211; as we are already presenting our own custom version of the slider, we can as well present an entirely different control. Lets use the <a title="Shiny Knob Control with jQuery and CSS3" href="http://tutorialzine.com/2011/11/pretty-switches-css3-jquery/" target="_blank">KnobKnob plugin</a> from last week.</p>
<p>We will have the range input control on the page, but it will be hidden. KnobKnob will then create a rotating control that will have the same limits as the original slider. On every change we will update the value of the hidden slider:</p>
<h4>slider-knob.html</h4>
<pre class="brush:html">&lt;div id="container"&gt;
	&lt;div id="control"&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;!-- The range input is hidden and updated on each rotation of the knob --&gt;
&lt;input type="range" id="slider" min="0" max="500" value="25" /&gt;

&lt;p class="note"&gt;Current value: &lt;span id="currentValue"&gt;0&lt;/span&gt;&lt;/p&gt;</pre>
<p>And for the jQuery part:</p>
<h4>assets/js/slider-knob.js</h4>
<pre class="brush:js">$(function(){

	var slider = $('#slider'),
		min = slider.attr('min'),
		max = slider.attr('max'),
		currentValue = $('#currentValue');

	// Hiding the slider:
	slider.hide();

	$('#control').knobKnob({
		snap : 10,
		value: 250,
		turn : function(ratio){
			// Changing the value of the hidden slider
			slider.val(Math.round(ratio*(max-min) + min));

			// Updating the current value text
			currentValue.html(slider.val());
		}
	});

});</pre>
<p>The code above takes the min and max attributes of the range input and uses it to calculate the corresponding value of the slider.</p>
<h3>Conclusion</h3>
<p>The slider control is useful for giving users the ability to conveniently modify a value without having to explicitly type it in a text box. Although there is much to be desired in terms of browser support, you can use progressive enhancement to display an alternative control using jQuery.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=uJm0cZmiP3w:uIVw0ESSaEc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=uJm0cZmiP3w:uIVw0ESSaEc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=uJm0cZmiP3w:uIVw0ESSaEc:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=uJm0cZmiP3w:uIVw0ESSaEc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=uJm0cZmiP3w:uIVw0ESSaEc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=uJm0cZmiP3w:uIVw0ESSaEc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=uJm0cZmiP3w:uIVw0ESSaEc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=uJm0cZmiP3w:uIVw0ESSaEc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=uJm0cZmiP3w:uIVw0ESSaEc:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=uJm0cZmiP3w:uIVw0ESSaEc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/uJm0cZmiP3w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input/</feedburner:origLink></item>
		<item>
		<title>Win a lifetime subscription to IM Creator!</title>
		<link>http://feedproxy.google.com/~r/Tutorialzine/~3/NfF9hat_VSg/</link>
		<comments>http://tutorialzine.com/2011/12/win-lifetime-subscription-imcreator/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 22:01:30 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[Tzine]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=1716</guid>
		<description><![CDATA[<div><a href="http://tutorialzine.com/2011/12/win-lifetime-subscription-imcreator/"><img src="http://cdn.tutorialzine.com/img/featured/1716.jpg" /></a></div> The folks behind IM Creator have generously offered three lifetime licenses for their premium plan to Tzine readers.]]></description>
			<content:encoded><![CDATA[<div><a href="http://tutorialzine.com/2011/12/win-lifetime-subscription-imcreator/"><img src="http://cdn.tutorialzine.com/img/featured/1716.jpg" /></a></div> <p>Every website is different. From complex online stores that test your development skills, to presentation oriented pages that depend heavily on design, and everything in between. But there is a right tool for any job. You can use an open source CMS to lift the development burden off complex sites, but it would be an overkill for simpler ones.</p>
<p>This is where a tool like IM Creator comes into play.</p>
<div id="attachment_1717" class="wp-caption alignnone" style="width: 630px"><a href="http://imcreator.com/?utm_source=tutorialzine&amp;utm_medium=article&amp;utm_content=article&amp;utm_campaign=tutorialzine"><img class="size-full wp-image-1717" title="IM Creator Lifetime License" src="http://cdn.tutorialzine.com/wp-content/uploads/2011/12/banner.jpg" alt="IM Creator Lifetime License" width="620" height="340" /></a><p class="wp-caption-text">IM Creator Lifetime License</p></div>
<p><a href="http://imcreator.com/?utm_source=tutorialzine&amp;utm_medium=article&amp;utm_content=article&amp;utm_campaign=tutorialzine">IM Creator</a> is a new simple and free HTML-based drag and drop website builder that allows you to create your website in a trouble-free, accessible and pleasant experience. With IM Creator, you can build a beautiful site, fast. <a href="http://app.imcreator.com/start?utm_source=tutorialzine&amp;utm_medium=article&amp;utm_content=article&amp;utm_campaign=tutorialzine">Start</a> from an existing design or make a new one - it’s up to you.</p>
<h3>The Prize</h3>
<p>The folks behind IM Creator have generously offered three lifetime licenses for their premium plan to Tutorialzine readers (valued at $95/year each). The offer applies to new clients of their service.</p>
<h3>How to Win</h3>
<p>For a chance to win a lifetime subscription, do the following:</p>
<ul>
<li>Leave a comment below this article;</li>
<li>Tweet it.</li>
</ul>
<p>The winners will be announced on <strong>December 15th 2011</strong>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=NfF9hat_VSg:xhUKIVt0CW0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=NfF9hat_VSg:xhUKIVt0CW0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=NfF9hat_VSg:xhUKIVt0CW0:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=NfF9hat_VSg:xhUKIVt0CW0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=NfF9hat_VSg:xhUKIVt0CW0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=NfF9hat_VSg:xhUKIVt0CW0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=NfF9hat_VSg:xhUKIVt0CW0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=NfF9hat_VSg:xhUKIVt0CW0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?i=NfF9hat_VSg:xhUKIVt0CW0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Tutorialzine?a=NfF9hat_VSg:xhUKIVt0CW0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Tutorialzine?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Tutorialzine/~4/NfF9hat_VSg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2011/12/win-lifetime-subscription-imcreator/feed/</wfw:commentRss>
		<slash:comments>90</slash:comments>
		<feedburner:origLink>http://tutorialzine.com/2011/12/win-lifetime-subscription-imcreator/</feedburner:origLink></item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using apc
Object Caching 701/738 objects using apc
Content Delivery Network via cdn.tutorialzine.com

Served from: tutorialzine.com @ 2012-02-06 01:49:53 -->

