src/pyams_skin/resources/js/ext/jquery-plot-resize-1.1.js
changeset 0 bb4aabe07487
equal deleted inserted replaced
-1:000000000000 0:bb4aabe07487
       
     1 /*
       
     2  Flot plugin for automatically redrawing plots when the placeholder
       
     3  size changes, e.g. on window resizes.
       
     4 
       
     5  It works by listening for changes on the placeholder div (through the
       
     6  jQuery resize event plugin) - if the size changes, it will redraw the
       
     7  plot.
       
     8 
       
     9  There are no options. If you need to disable the plugin for some
       
    10  plots, you can just fix the size of their placeholders.
       
    11  */
       
    12 
       
    13 
       
    14 /* Inline dependency: 
       
    15  * jQuery resize event - v1.1 - 3/14/2010
       
    16  * http://benalman.com/projects/jquery-resize-plugin/
       
    17  * 
       
    18  * Copyright (c) 2010 "Cowboy" Ben Alman
       
    19  * Dual licensed under the MIT and GPL licenses.
       
    20  * http://benalman.com/about/license/
       
    21  */
       
    22 (function ($, h, c) {
       
    23 	var a = $([]), e = $.resize = $.extend($.resize, {}), i, k = "setTimeout", j = "resize", d = j + "-special-event", b = "delay", f = "throttleWindow";
       
    24 	e[b] = 250;
       
    25 	e[f] = true;
       
    26 	$.event.special[j] = {setup: function () {
       
    27 		if (!e[f] && this[k]) {
       
    28 			return false
       
    29 		}
       
    30 		var l = $(this);
       
    31 		a = a.add(l);
       
    32 		$.data(this, d, {w: l.width(), h: l.height()});
       
    33 		if (a.length === 1) {
       
    34 			g()
       
    35 		}
       
    36 	}, teardown: function () {
       
    37 		if (!e[f] && this[k]) {
       
    38 			return false
       
    39 		}
       
    40 		var l = $(this);
       
    41 		a = a.not(l);
       
    42 		l.removeData(d);
       
    43 		if (!a.length) {
       
    44 			clearTimeout(i)
       
    45 		}
       
    46 	}, add: function (l) {
       
    47 		if (!e[f] && this[k]) {
       
    48 			return false
       
    49 		}
       
    50 		var n;
       
    51 
       
    52 		function m(s, o, p) {
       
    53 			var q = $(this), r = $.data(this, d);
       
    54 			r.w = o !== c ? o : q.width();
       
    55 			r.h = p !== c ? p : q.height();
       
    56 			n.apply(this, arguments)
       
    57 		}
       
    58 
       
    59 		if ($.isFunction(l)) {
       
    60 			n = l;
       
    61 			return m
       
    62 		} else {
       
    63 			n = l.handler;
       
    64 			l.handler = m
       
    65 		}
       
    66 	}};
       
    67 	function g() {
       
    68 		i = h[k](function () {
       
    69 			a.each(function () {
       
    70 				var n = $(this), m = n.width(), l = n.height(), o = $.data(this, d);
       
    71 				if (m !== o.w || l !== o.h) {
       
    72 					n.trigger(j, [o.w = m, o.h = l])
       
    73 				}
       
    74 			});
       
    75 			g()
       
    76 		}, e[b])
       
    77 	}
       
    78 })(jQuery, this);
       
    79 
       
    80 
       
    81 (function ($) {
       
    82 	var options = { }; // no options
       
    83 
       
    84 	function init(plot) {
       
    85 		function onResize() {
       
    86 			var placeholder = plot.getPlaceholder();
       
    87 
       
    88 			// somebody might have hidden us and we can't plot
       
    89 			// when we don't have the dimensions
       
    90 			if (placeholder.width() == 0 || placeholder.height() == 0)
       
    91 				return;
       
    92 
       
    93 			plot.resize();
       
    94 			plot.setupGrid();
       
    95 			plot.draw();
       
    96 		}
       
    97 
       
    98 		function bindEvents(plot, eventHolder) {
       
    99 			plot.getPlaceholder().resize(onResize);
       
   100 		}
       
   101 
       
   102 		function shutdown(plot, eventHolder) {
       
   103 			plot.getPlaceholder().unbind("resize", onResize);
       
   104 		}
       
   105 
       
   106 		plot.hooks.bindEvents.push(bindEvents);
       
   107 		plot.hooks.shutdown.push(shutdown);
       
   108 	}
       
   109 
       
   110 	$.plot.plugins.push({
       
   111 							init: init,
       
   112 							options: options,
       
   113 							name: 'resize',
       
   114 							version: '1.0'
       
   115 						});
       
   116 })(jQuery);