Theme Inspinia
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery.flot.resize.js 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Flot plugin for automatically redrawing plots as the placeholder resizes.
  2. Copyright (c) 2007-2014 IOLA and Ole Laursen.
  3. Licensed under the MIT license.
  4. It works by listening for changes on the placeholder div (through the jQuery
  5. resize event plugin) - if the size changes, it will redraw the plot.
  6. There are no options. If you need to disable the plugin for some plots, you
  7. can just fix the size of their placeholders.
  8. */
  9. /* Inline dependency:
  10. * jQuery resize event - v1.1 - 3/14/2010
  11. * http://benalman.com/projects/jquery-resize-plugin/
  12. *
  13. * Copyright (c) 2010 "Cowboy" Ben Alman
  14. * Dual licensed under the MIT and GPL licenses.
  15. * http://benalman.com/about/license/
  16. */
  17. (function($,e,t){"$:nomunge";var i=[],n=$.resize=$.extend($.resize,{}),a,r=false,s="setTimeout",u="resize",m=u+"-special-event",o="pendingDelay",l="activeDelay",f="throttleWindow";n[o]=200;n[l]=20;n[f]=true;$.event.special[u]={setup:function(){if(!n[f]&&this[s]){return false}var e=$(this);i.push(this);e.data(m,{w:e.width(),h:e.height()});if(i.length===1){a=t;h()}},teardown:function(){if(!n[f]&&this[s]){return false}var e=$(this);for(var t=i.length-1;t>=0;t--){if(i[t]==this){i.splice(t,1);break}}e.removeData(m);if(!i.length){if(r){cancelAnimationFrame(a)}else{clearTimeout(a)}a=null}},add:function(e){if(!n[f]&&this[s]){return false}var i;function a(e,n,a){var r=$(this),s=r.data(m)||{};s.w=n!==t?n:r.width();s.h=a!==t?a:r.height();i.apply(this,arguments)}if($.isFunction(e)){i=e;return a}else{i=e.handler;e.handler=a}}};function h(t){if(r===true){r=t||1}for(var s=i.length-1;s>=0;s--){var l=$(i[s]);if(l[0]==e||l.is(":visible")){var f=l.width(),c=l.height(),d=l.data(m);if(d&&(f!==d.w||c!==d.h)){l.trigger(u,[d.w=f,d.h=c]);r=t||true}}else{d=l.data(m);d.w=0;d.h=0}}if(a!==null){if(r&&(t==null||t-r<1e3)){a=e.requestAnimationFrame(h)}else{a=setTimeout(h,n[o]);r=false}}}if(!e.requestAnimationFrame){e.requestAnimationFrame=function(){return e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(t,i){return e.setTimeout(function(){t((new Date).getTime())},n[l])}}()}if(!e.cancelAnimationFrame){e.cancelAnimationFrame=function(){return e.webkitCancelRequestAnimationFrame||e.mozCancelRequestAnimationFrame||e.oCancelRequestAnimationFrame||e.msCancelRequestAnimationFrame||clearTimeout}()}})(jQuery,this);
  18. (function ($) {
  19. var options = { }; // no options
  20. function init(plot) {
  21. function onResize() {
  22. var placeholder = plot.getPlaceholder();
  23. // somebody might have hidden us and we can't plot
  24. // when we don't have the dimensions
  25. if (placeholder.width() == 0 || placeholder.height() == 0)
  26. return;
  27. plot.resize();
  28. plot.setupGrid();
  29. plot.draw();
  30. }
  31. function bindEvents(plot, eventHolder) {
  32. plot.getPlaceholder().resize(onResize);
  33. }
  34. function shutdown(plot, eventHolder) {
  35. plot.getPlaceholder().unbind("resize", onResize);
  36. }
  37. plot.hooks.bindEvents.push(bindEvents);
  38. plot.hooks.shutdown.push(shutdown);
  39. }
  40. $.plot.plugins.push({
  41. init: init,
  42. options: options,
  43. name: 'resize',
  44. version: '1.0'
  45. });
  46. })(jQuery);