mirror of
https://github.com/balkian/balkian.github.com.git
synced 2025-08-24 04:32:20 +00:00
Move to Hugo
This commit is contained in:
92
static/js/jquery.tagcloud.js
Executable file
92
static/js/jquery.tagcloud.js
Executable file
@@ -0,0 +1,92 @@
|
||||
/*!
|
||||
* jquery.tagcloud.js
|
||||
* A Simple Tag Cloud Plugin for JQuery
|
||||
*
|
||||
* https://github.com/addywaddy/jquery.tagcloud.js
|
||||
* created by Adam Groves
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/*global jQuery*/
|
||||
"use strict";
|
||||
|
||||
var compareWeights = function(a, b)
|
||||
{
|
||||
return a - b;
|
||||
};
|
||||
|
||||
// Converts hex to an RGB array
|
||||
var toRGB = function(code) {
|
||||
if (code.length === 4) {
|
||||
code = code.replace(/(\w)(\w)(\w)/gi, "\$1\$1\$2\$2\$3\$3");
|
||||
}
|
||||
var hex = /(\w{2})(\w{2})(\w{2})/.exec(code);
|
||||
return [parseInt(hex[1], 16), parseInt(hex[2], 16), parseInt(hex[3], 16)];
|
||||
};
|
||||
|
||||
// Converts an RGB array to hex
|
||||
var toHex = function(ary) {
|
||||
return "#" + jQuery.map(ary, function(i) {
|
||||
var hex = i.toString(16);
|
||||
hex = (hex.length === 1) ? "0" + hex : hex;
|
||||
return hex;
|
||||
}).join("");
|
||||
};
|
||||
|
||||
var colorIncrement = function(color, range) {
|
||||
return jQuery.map(toRGB(color.end), function(n, i) {
|
||||
return (n - toRGB(color.start)[i])/range;
|
||||
});
|
||||
};
|
||||
|
||||
var tagColor = function(color, increment, weighting) {
|
||||
var rgb = jQuery.map(toRGB(color.start), function(n, i) {
|
||||
var ref = Math.round(n + (increment[i] * weighting));
|
||||
if (ref > 255) {
|
||||
ref = 255;
|
||||
} else {
|
||||
if (ref < 0) {
|
||||
ref = 0;
|
||||
}
|
||||
}
|
||||
return ref;
|
||||
});
|
||||
return toHex(rgb);
|
||||
};
|
||||
|
||||
$.fn.tagcloud = function(options) {
|
||||
|
||||
var opts = $.extend({}, $.fn.tagcloud.defaults, options);
|
||||
var tagWeights = this.map(function(){
|
||||
return $(this).attr("rel");
|
||||
});
|
||||
tagWeights = jQuery.makeArray(tagWeights).sort(compareWeights);
|
||||
var lowest = tagWeights[0];
|
||||
var highest = tagWeights.pop();
|
||||
var range = highest - lowest;
|
||||
if(range === 0) {range = 1;}
|
||||
// Sizes
|
||||
var fontIncr, colorIncr;
|
||||
if (opts.size) {
|
||||
fontIncr = (opts.size.end - opts.size.start)/range;
|
||||
}
|
||||
// Colors
|
||||
if (opts.color) {
|
||||
colorIncr = colorIncrement (opts.color, range);
|
||||
}
|
||||
return this.each(function() {
|
||||
var weighting = $(this).attr("rel") - lowest;
|
||||
if (opts.size) {
|
||||
$(this).css({"font-size": opts.size.start + (weighting * fontIncr) + opts.size.unit});
|
||||
}
|
||||
if (opts.color) {
|
||||
$(this).css({"color": tagColor(opts.color, colorIncr, weighting)});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.tagcloud.defaults = {
|
||||
size: {start: 14, end: 18, unit: "pt"}
|
||||
};
|
||||
|
||||
})(jQuery);
|
36
static/js/main.js
Normal file
36
static/js/main.js
Normal file
@@ -0,0 +1,36 @@
|
||||
// To make images retina, add a class "2x" to the img element
|
||||
// and add a <image-name>@2x.png image. Assumes jquery is loaded.
|
||||
|
||||
function isRetina() {
|
||||
var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
|
||||
(min--moz-device-pixel-ratio: 1.5),\
|
||||
(-o-min-device-pixel-ratio: 3/2),\
|
||||
(min-resolution: 1.5dppx)";
|
||||
|
||||
if (window.devicePixelRatio > 1)
|
||||
return true;
|
||||
|
||||
if (window.matchMedia && window.matchMedia(mediaQuery).matches)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
function retina() {
|
||||
|
||||
if (!isRetina())
|
||||
return;
|
||||
|
||||
$("img.2x").map(function(i, image) {
|
||||
|
||||
var path = $(image).attr("src");
|
||||
|
||||
path = path.replace(".png", "@2x.png");
|
||||
path = path.replace(".jpg", "@2x.jpg");
|
||||
|
||||
$(image).attr("src", path);
|
||||
});
|
||||
};
|
||||
|
||||
$(document).ready(retina);
|
6
static/js/main.min.js.bak
Normal file
6
static/js/main.min.js.bak
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user