[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/jquery/ -> jquery.tagcloud.js (source)

   1  /*!
   2   * jquery.tagcloud.js
   3   * A Simple Tag Cloud Plugin for JQuery
   4   *
   5   * https://github.com/addywaddy/jquery.tagcloud.js
   6   * created by Adam Groves
   7   */
   8  (function($) {
   9  
  10    /*global jQuery*/
  11    "use strict";
  12  
  13    var compareWeights = function(a, b)
  14    {
  15      return a - b;
  16    };
  17  
  18    // Converts hex to an RGB array
  19    var toRGB = function(code) {
  20      if (code.length === 4) {
  21        code = jQuery.map(/\w+/.exec(code), function(el) {return el + el; }).join("");
  22      }
  23      var hex = /(\w{2})(\w{2})(\w{2})/.exec(code);
  24      return [parseInt(hex[1], 16), parseInt(hex[2], 16), parseInt(hex[3], 16)];
  25    };
  26  
  27    // Converts an RGB array to hex
  28    var toHex = function(ary) {
  29      return "#" + jQuery.map(ary, function(i) {
  30        var hex =  i.toString(16);
  31        hex = (hex.length === 1) ? "0" + hex : hex;
  32        return hex;
  33      }).join("");
  34    };
  35  
  36    var colorIncrement = function(color, range) {
  37      return jQuery.map(toRGB(color.end), function(n, i) {
  38        return (n - toRGB(color.start)[i])/range;
  39      });
  40    };
  41  
  42    var tagColor = function(color, increment, weighting) {
  43      var rgb = jQuery.map(toRGB(color.start), function(n, i) {
  44        var ref = Math.round(n + (increment[i] * weighting));
  45        if (ref > 255) {
  46          ref = 255;
  47        } else {
  48          if (ref < 0) {
  49            ref = 0;
  50          }
  51        }
  52        return ref;
  53      });
  54      return toHex(rgb);
  55    };
  56  
  57    $.fn.tagcloud = function(options) {
  58  
  59      var opts = $.extend({}, $.fn.tagcloud.defaults, options);
  60      var tagWeights = this.map(function(){
  61        return $(this).attr("rel");
  62      });
  63      tagWeights = jQuery.makeArray(tagWeights).sort(compareWeights);
  64      var lowest = tagWeights[0];
  65      var highest = tagWeights.pop();
  66      var range = highest - lowest;
  67      if(range === 0) {range = 1;}
  68      // Sizes
  69      var fontIncr, colorIncr;
  70      if (opts.size) {
  71        fontIncr = (opts.size.end - opts.size.start)/range;
  72      }
  73      // Colors
  74      if (opts.color) {
  75        colorIncr = colorIncrement (opts.color, range);
  76      }
  77      return this.each(function() {
  78        var weighting = $(this).attr("rel") - lowest;
  79        if (opts.size) {
  80          $(this).css({"font-size": opts.size.start + (weighting * fontIncr) + opts.size.unit});
  81        }
  82        if (opts.color) {
  83          $(this).css({"color": tagColor(opts.color, colorIncr, weighting)});
  84        }
  85      });
  86    };
  87  
  88    $.fn.tagcloud.defaults = {
  89      size: {start: 14, end: 18, unit: "pt"}
  90    };
  91  
  92  })(jQuery);


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1