function URI(str) {
if (!str) str = "";
var parser = /^(?:([^:\/?\#]+):)?(?:\/\/([^\/?\#]*))?([^?\#]*)(?:\?([^\#]*))?(?:\#(.*))?/;
var result = str.match(parser);
this.scheme    = result[1] || null;
this.authority = result[2] || null;
this.path      = result[3] || null;
this.query     = result[4] || null;
this.fragment  = result[5] || null;
}
URI.prototype.toString = function () {
var str = "";
if (this.scheme) {
str += this.scheme + ":";
}
if (this.authority) {
str += "//" + this.authority;
}
if (this.path) {
str += this.path;
}
if (this.query) {
str += "?" + this.query;
}
if (this.fragment) {
str += "#" + this.fragment;
}
return str;
};
(function () {
function merge(base, rel_path) {
var dirname = /^(.*)\//;
if (base.authority && !base.path) {
return "/" + rel_path;
}
else {
return base.path.match(dirname)[0] + rel_path;
}
}
var DoubleDot = /\/((?!\.\.\/)[^\/]*)\/\.\.\//;
function remove_dot_segments(path) {
if (!path) return "";
var newpath = path.replace(/\/\.\//g, '/');
newpath = newpath.replace(/\/\.$/, '/');
while (newpath.match(DoubleDot)) {
newpath = newpath.replace(DoubleDot, '/');
}
newpath = newpath.replace(/\/([^\/]*)\/\.\.$/, '/');
while (newpath.match(/\/\.\.\//)) {
newpath = newpath.replace(/\/\.\.\//, '/');
}
return newpath;
}
URI.prototype.resolve = function (base) {
var target = new URI();
if (this.scheme) {
target.scheme    = this.scheme;
target.authority = this.authority;
target.path      = remove_dot_segments(this.path);
target.query     = this.query;
}
else {
if (this.authority) {
target.authority = this.authority;
target.path      = remove_dot_segments(this.path);
target.query     = this.query;
}
else {
if (!this.path) {
target.path = base.path;
if (this.query) {
target.query = this.query;
}
else {
target.query = base.query;
}
}
else {
if (this.path.charAt(0) === '/') {
target.path = remove_dot_segments(this.path);
} else {
target.path = merge(base, this.path);
target.path = remove_dot_segments(target.path);
}
target.query = this.query;
}
target.authority = base.authority;
}
target.scheme = base.scheme;
}
target.fragment = this.fragment;
return target;
};
})();
(function($){
$.fn.colorTip = function(settings){
var defaultSettings = {
color	: 'black',
timeout	: 500,
size	: 100,
}
var supportedColors = ['red','green','blue','white','yellow','black'];
settings = $.extend(defaultSettings,settings);
return this.each(function(){
var elem = $(this);
var scheduleEvent = new eventScheduler();
url = elem.attr("href");
this_uri = new URI(window.location.href);
uri = new URI(url);
url = uri.resolve(this_uri);
content = "<img src='http://chart.apis.google.com/chart?cht=qr&chs=" + settings.size + "x" + settings.size + "&choe=UTF-8&chld=L%7C0&chl=" + url + "' />";
var tip = new Tip(content);
elem.append(tip.generate()).addClass('colorTipContainer');
var hasClass = false;
for(var i=0;i<supportedColors.length;i++)
{
if(elem.hasClass(supportedColors[i])){
hasClass = true;
break;
}
}
if(!hasClass){
elem.addClass(settings.color);
}
elem.hover(function(){
tip.show(settings.size);
scheduleEvent.clear();
},function(){
scheduleEvent.set(function(){
tip.hide();
},settings.timeout);
});
elem.removeAttr('title');
});
}
function eventScheduler(){}
eventScheduler.prototype = {
set	: function (func,timeout){
this.timer = setTimeout(func,timeout);
},
clear: function(){
clearTimeout(this.timer);
}
}
function Tip(txt){
this.content = txt;
this.shown = false;
}
Tip.prototype = {
generate: function(){
return this.tip || (this.tip = $('<span class="colorTip">'+this.content+
'<span class="pointyTipShadow"></span><span class="pointyTip"></span></span>'));
},
show: function(size){
if(this.shown) return;
this.tip.css('margin-top', -size);
this.tip.css('margin-left',-this.tip.outerWidth()/2).fadeIn('fast');
this.shown = true;
},
hide: function(){
this.tip.fadeOut();
this.shown = false;
}
}
$.fn.qr = function(settings) {
var defaultSettings = {
size	: 100
}
settings = $.extend(defaultSettings,settings);
jQuery(this).colorTip(settings);
};
})(jQuery);
