Skip to content

Instantly share code, notes, and snippets.

@clouddueling
Last active August 29, 2015 14:02
Show Gist options
  • Save clouddueling/f50fa9af43c8dad1b81a to your computer and use it in GitHub Desktop.
Save clouddueling/f50fa9af43c8dad1b81a to your computer and use it in GitHub Desktop.

Revisions

  1. clouddueling revised this gist Jun 12, 2014. 1 changed file with 61 additions and 59 deletions.
    120 changes: 61 additions & 59 deletions fabric-align-text.js
    Original file line number Diff line number Diff line change
    @@ -1,74 +1,76 @@
    self.center = function() {
    var activeObject = self.canvas.getActiveObject();
    if (activeObject) {
    activeObject.center();
    activeObject.setCoords();
    setUnsaved();
    }
    };
    var SCALE_FACTOR = 1.2;

    self.centerH = function() {
    var activeObject = canvas.getActiveObject();
    if (activeObject) {
    activeObject.centerH();
    activeObject.setCoords();
    setUnsaved();
    }
    };
    self.center = function() {
    var activeObject = self.canvas.getActiveObject();
    if (activeObject) {
    activeObject.center();
    activeObject.setCoords();
    setUnsaved();
    }
    };

    self.centerV = function() {
    var activeObject = canvas.getActiveObject();
    if (activeObject) {
    activeObject.centerV();
    activeObject.setCoords();
    setUnsaved();
    }
    };
    self.centerH = function() {
    var activeObject = canvas.getActiveObject();
    if (activeObject) {
    activeObject.centerH();
    activeObject.setCoords();
    setUnsaved();
    }
    };

    self.centerV = function() {
    var activeObject = canvas.getActiveObject();
    if (activeObject) {
    activeObject.centerV();
    activeObject.setCoords();
    setUnsaved();
    }
    };
    // Reset Zoom
    self.resetZoom = function(cb) {
    var width = canvas.getWidth();
    var height = canvas.getHeight();
    self.resetZoom = function(cb) {
    var width = canvas.getWidth();
    var height = canvas.getHeight();

    var tempWidth = width * (1 / canvas.scale);
    var tempHeight = height * (1 / canvas.scale);
    var tempWidth = width * (1 / canvas.scale);
    var tempHeight = height * (1 / canvas.scale);

    canvas.setWidth(tempWidth);
    canvas.setHeight(tempHeight);
    canvas.setWidth(tempWidth);
    canvas.setHeight(tempHeight);

    canvas.scale = 1;
    canvas.setZoom(1);
    canvas.scale = 1;
    canvas.setZoom(1);

    if (cb) {
    cb();
    }
    };
    if (cb) {
    cb();
    }
    };

    // Zoom In
    self.zoomIn = function() {
    canvas.scale = canvas.scale * SCALE_FACTOR;
    canvas.setZoom(canvas.scale);
    // Zoom In
    self.zoomIn = function() {
    canvas.scale = canvas.scale * SCALE_FACTOR;
    canvas.setZoom(canvas.scale);

    var width = canvas.getWidth();
    var height = canvas.getHeight();
    var width = canvas.getWidth();
    var height = canvas.getHeight();

    var tempWidth = width * SCALE_FACTOR;
    var tempHeight = height * SCALE_FACTOR;
    var tempWidth = width * SCALE_FACTOR;
    var tempHeight = height * SCALE_FACTOR;

    canvas.setWidth(tempWidth);
    canvas.setHeight(tempHeight);
    };
    canvas.setWidth(tempWidth);
    canvas.setHeight(tempHeight);
    };

    // Zoom Out
    self.zoomOut = function() {
    canvas.scale = self.canvas.scale / SCALE_FACTOR;
    canvas.setZoom(canvas.scale);
    // Zoom Out
    self.zoomOut = function() {
    canvas.scale = self.canvas.scale / SCALE_FACTOR;
    canvas.setZoom(canvas.scale);

    var width = canvas.getWidth();
    var height = canvas.getHeight();
    var width = canvas.getWidth();
    var height = canvas.getHeight();

    var tempWidth = width * (1 / SCALE_FACTOR);
    var tempHeight = height * (1 / SCALE_FACTOR);
    var tempWidth = width * (1 / SCALE_FACTOR);
    var tempHeight = height * (1 / SCALE_FACTOR);

    canvas.setWidth(tempWidth);
    canvas.setHeight(tempHeight);
    };
    canvas.setWidth(tempWidth);
    canvas.setHeight(tempHeight);
    };
  2. clouddueling revised this gist Jun 12, 2014. 1 changed file with 24 additions and 2 deletions.
    26 changes: 24 additions & 2 deletions fabric-align-text.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,29 @@
    self.setTextAlign = function(value) {
    setActiveProp('textAlign', value.toLowerCase());
    self.center = function() {
    var activeObject = self.canvas.getActiveObject();
    if (activeObject) {
    activeObject.center();
    activeObject.setCoords();
    setUnsaved();
    }
    };

    self.centerH = function() {
    var activeObject = canvas.getActiveObject();
    if (activeObject) {
    activeObject.centerH();
    activeObject.setCoords();
    setUnsaved();
    }
    };

    self.centerV = function() {
    var activeObject = canvas.getActiveObject();
    if (activeObject) {
    activeObject.centerV();
    activeObject.setCoords();
    setUnsaved();
    }
    };
    // Reset Zoom
    self.resetZoom = function(cb) {
    var width = canvas.getWidth();
  3. clouddueling created this gist Jun 12, 2014.
    52 changes: 52 additions & 0 deletions fabric-align-text.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    self.setTextAlign = function(value) {
    setActiveProp('textAlign', value.toLowerCase());
    };

    // Reset Zoom
    self.resetZoom = function(cb) {
    var width = canvas.getWidth();
    var height = canvas.getHeight();

    var tempWidth = width * (1 / canvas.scale);
    var tempHeight = height * (1 / canvas.scale);

    canvas.setWidth(tempWidth);
    canvas.setHeight(tempHeight);

    canvas.scale = 1;
    canvas.setZoom(1);

    if (cb) {
    cb();
    }
    };

    // Zoom In
    self.zoomIn = function() {
    canvas.scale = canvas.scale * SCALE_FACTOR;
    canvas.setZoom(canvas.scale);

    var width = canvas.getWidth();
    var height = canvas.getHeight();

    var tempWidth = width * SCALE_FACTOR;
    var tempHeight = height * SCALE_FACTOR;

    canvas.setWidth(tempWidth);
    canvas.setHeight(tempHeight);
    };

    // Zoom Out
    self.zoomOut = function() {
    canvas.scale = self.canvas.scale / SCALE_FACTOR;
    canvas.setZoom(canvas.scale);

    var width = canvas.getWidth();
    var height = canvas.getHeight();

    var tempWidth = width * (1 / SCALE_FACTOR);
    var tempHeight = height * (1 / SCALE_FACTOR);

    canvas.setWidth(tempWidth);
    canvas.setHeight(tempHeight);
    };