• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Create Animated Progress Showing Favicon Like Pie Charts

By Abhishek Ghosh August 29, 2012 7:56 am Updated on August 29, 2012

Create Animated Progress Showing Favicon Like Pie Charts

Advertisement

Create Animated Progress Showing Favicon Like Pie Charts, sounds odd but there is no way to describe this cute function that adds a virtual progress bar in Pie. Chrome, Firefox and Opera currently supports these feature and trick.

 

How Create Animated Progress Showing Favicon Like Pie Charts

 

Its quite easy to create animated progress showing favicon like Pie Charts. Basically we will just show the usage of small Open Source javascript, its alteration and how to use it. The official name is Piecon – Pie charts in your favicon. It look like this while the webpage loading :

 

Create Animated Progress Showing Favicon Like Pie Charts

Create Animated Progress Showing Favicon Like Pie Charts : Guide, Tips and Resources

 

Go to this webpage :

Advertisement

---

 

Vim
1
https://github.com/lipka/piecon

 

Download the file named piecon.js. Open it any text editor with syntax highlighting feature like Gedit, it will look like this :

 

(function(){
var Piecon = {};

var currentFavicon = null;
var originalFavicon = null;
var originalTitle = null;
var canvas = null;
var options = {};
var defaults = {
color: ‘#ff0084‘,
background: ‘#bbb‘,
shadow: ‘#fff‘,
fallback: false
};

var ua = (function () {
var agent = navigator.userAgent.toLowerCase();
return function (browser) {
return agent.indexOf(browser) !== -1;
};
}());

var browser = {
ie: ua(‘msie’),
chrome: ua(‘chrome’),
webkit: ua(‘chrome’) || ua(‘safari’),
safari: ua(‘safari’) && !ua(‘chrome’),
mozilla: ua(‘mozilla’) && !ua(‘chrome’) && !ua(‘safari’)
};

var getFaviconTag = function() {
var links = document.getElementsByTagName(‘link’);

for (var i = 0, l = links.length; i < l; i++) {
if ((links[i].getAttribute(‘rel’) || ”).match(/biconb/)) {
return links[i];
}
}

return false;
};

var removeFaviconTag = function() {
var links = document.getElementsByTagName(‘link’);
var head = document.getElementsByTagName(‘head’)[0];

for (var i = 0, l = links.length; i < l; i++) {
if (typeof(links[i]) !== ‘undefined’ && links[i].getAttribute(‘rel’) === ‘icon’) {
head.removeChild(links[i]);
}
}
};

var setFaviconTag = function(url) {
removeFaviconTag();

var link = document.createElement(‘link’);
link.type = ‘image/x-icon’;
link.rel = ‘icon’;
link.href = url;

document.getElementsByTagName(‘head’)[0].appendChild(link);
};

var getCanvas = function () {
if (!canvas) {
canvas = document.createElement(“canvas”);
canvas.width = 16;
canvas.height = 16;
}

return canvas;
};

var drawFavicon = function(percentage) {
var canvas = getCanvas();
var context = canvas.getContext(“2d”);
var percentage = percentage || 0;
var src = currentFavicon;

var faviconImage = new Image();
faviconImage.onload = function() {
context.clearRect(0, 0, 16, 16);

// Draw shadow
context.beginPath();
context.moveTo(canvas.width / 2, canvas.height / 2);
context.arc(canvas.width / 2, canvas.height / 2, Math.min(canvas.width / 2, canvas.height / 2), 0, Math.PI * 2, false);
context.fillStyle = options.shadow;
context.fill();

// Draw background
context.beginPath();
context.moveTo(canvas.width / 2, canvas.height / 2);
context.arc(canvas.width / 2, canvas.height / 2, Math.min(canvas.width / 2, canvas.height / 2) – 2, 0, Math.PI * 2, false);
context.fillStyle = options.background;
context.fill();

// Draw pie
if (percentage > 0) {
context.beginPath();
context.moveTo(canvas.width / 2, canvas.height / 2);
context.arc(canvas.width / 2, canvas.height / 2, Math.min(canvas.width / 2, canvas.height / 2) – 2, (-0.5) * Math.PI, (-0.5 + 2 * percentage / 100) * Math.PI, false);
context.lineTo(canvas.width / 2, canvas.height / 2);
context.fillStyle = options.color;
context.fill();
}

if (context) {
setFaviconTag(canvas.toDataURL());
}
};

// allow cross origin resource requests if the image is not a data:uri
// as detailed here: https://github.com/mrdoob/three.js/issues/1305
if (!src.match(/^data/)) {
faviconImage.crossOrigin = ‘anonymous’;
}

faviconImage.src = src;
};

var updateTitle = function(percentage) {
if (options.fallback) {
if (percentage > 0) {
document.title = ‘(‘ + percentage + ‘%) ‘ + originalTitle;
} else {
document.title = originalTitle;
}
}
};

Piecon.setOptions = function(custom) {
options = {};

for (var key in defaults){
options[key] = custom.hasOwnProperty(key) ? custom[key] : defaults[key];
}

return this;
};

Piecon.setProgress = function(percentage) {
if (!originalTitle) {
originalTitle = document.title;
}

if (!originalFavicon || !currentFavicon) {
var tag = getFaviconTag();
originalFavicon = currentFavicon = tag ? tag.getAttribute(‘href’) : ‘/favicon.ico’;
}

if (!isNaN(parseFloat(percentage)) && isFinite(percentage)) {
if (!getCanvas().getContext || browser.ie || browser.safari || options.fallback == true) {
// Fallback to updating the browser title if unsupported
return updateTitle(percentage);
} else if (options.fallback === ‘force’) {
updateTitle(percentage);
}

return drawFavicon(percentage);
}

return false;
};

Piecon.reset = function() {
if (originalTitle) {
document.title = originalTitle;
}

if (originalFavicon) {
currentFavicon = originalFavicon;
setFaviconTag(currentFavicon);
}
};

Piecon.setOptions(defaults);
window.Piecon = Piecon;
})();

 

The reason to write the whole code is to show the variables. The red colored text can be altered according to your choice for showing the color of the pie chart. If you read the code’s comments, you will understand it is not very difficult to change for customizing the look.

 

Save it. Now the implementation part. If you place javascript at root of your server, add this code within header tag :

 

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<span style="color: #0000ff;">&lt;!doctype html&gt; </span>
<span style="color: #0000ff;">&lt;!More Stuffs Here&gt;</span>
<span style="color: #0000ff;">&lt;head&gt;</span>
 
<span style="color: #ff00ff;">&lt;script src="piecon.js"&gt;&lt;/script&gt;</span>
<span style="color: #ff00ff;">&lt;script&gt;</span>
<span style="color: #ff00ff;">(function(){</span>
<span style="color: #ff00ff;">var count = 0;</span>
<span style="color: #ff00ff;">Piecon.setOptions({fallback: 'force'});</span>
<span style="color: #ff00ff;">var i = setInterval(function(){</span>
<span style="color: #ff00ff;">if (++count &gt; 100) { Piecon.reset(); clearInterval(i); return false; }</span>
<span style="color: #ff00ff;">Piecon.setProgress(count);</span>
<span style="color: #ff00ff;">}, 250);</span>
<span style="color: #ff00ff;">})();</span>
<span style="color: #ff00ff;">&lt;/script&gt;</span>
 
<span style="color: #0000ff;">&lt;!More Stuffs Here&gt;</span>
<span style="color: #0000ff;">&lt;/head&gt;</span>

 

So, to create animated Progress Showing Favicon Like Pie Charts, you have to add it within the header tag. Change the script src to full url in case you have you have placed it in subfolder or a CDN. You can optimize the script by minifying it after modification and saving using any online tools to minify js. We said ” virtual progress bar” in the description as its actually not related to page loading progress. It will work for any webpage including free Blogger, Hosted WordPress or any HTML webpage where javascript can be added.

 

 

Signature

 

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Create Animated Progress Showing Favicon Like Pie Charts

  • Embed Matrix Code Rain Animation Effect in WordPress Post

    One Can Create The Matrix Code Rain Animation Effect With Javascript on HTML5 Webpage and Customize According to Need. Here is resources.

  • Favicon : Why is it important that your website have a favicon?

    Favicon might look good or bad, other than its look, Favicon has other importances for your website or blog.

  • Windows 7 Right Click Menu Tips,Tricks and Tutorials : Index

    Windows 7 Right Click Menu Tips,Tricks and Tutorials those has been published within The Customize Windows till date is listed here along with description.

  • How to Correctly Include jQuery-UI Effects on WordPress

    How to correctly include JQuery-UI effects on WordPress on your existing Theme without much compromise on Page Loading Speed? It is made easy with our Guide.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Comments

  1. Avatarwww says

    September 17, 2012 at 3:16 pm

    Spot on with this write-up, I actually feel this website needs far more attention.
    I’ll probably be back again to read through more, thanks for the information!

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Market Segmentation in BriefSeptember 20, 2023
  • What is Booting?September 18, 2023
  • What is ncurses?September 16, 2023
  • What is JTAG in Electronics?September 15, 2023
  • iPhone 15 Pro Max Vs Samsung Galaxy S22/S23 UltraSeptember 14, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy