{"size": 1189, "ext": "js", "max_stars_repo_path": "src/functionality/canvas_resizer.js", "max_stars_repo_name": "theozaurus/drawing-fabric.js", "max_stars_repo_stars_event_min_datetime": "2015-02-11T13:21:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-19T15:20:33.000Z", "max_issues_repo_path": "src/functionality/canvas_resizer.js", "max_issues_repo_name": "theozaurus/drawing-fabric.js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/functionality/canvas_resizer.js", "max_forks_repo_name": "theozaurus/drawing-fabric.js", "max_forks_repo_forks_event_min_datetime": "2017-01-03T23:24:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-23T15:12:13.000Z"}
{"max_stars_count": 9, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 21.6181818182, "max_line_length": 70, "alphanum_fraction": 0.5382674516}
//= require jquery
//= require ../drawing_fabric
//= require ../canvas

DrawingFabric.Functionality.canvasResizer = (function(){

  return function(container){

    this.initialize = function(){

      var that = this;

      var getDimensions = function(){
        return {width: container.width(), height: container.height()};
      };

      var isVisible = function(){
        return container.is(":visible");
      };

      var last;
      var correctSize = function(){
        if(isVisible()){
          var dimensions = getDimensions();
          if(last != dimensions){
            that.fabricCanvas.setDimensions(dimensions);
            last = dimensions;
          }
        } else {
          queueCheck();
        }
      };

      var timer = null;
      var queueCheck = function(){
        clearTimeout(timer);
        timer = setTimeout(correctSize, 1000);
      };

      var validContainer = function(){
        return container &&
               typeof container.width == 'function' &&
               typeof container.height == 'function';
      };

      if(validContainer()){
        $(window).resize(correctSize);
        correctSize();
      }
    };

  };

}());
