123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- goog.provide('goog.style.transform');
- goog.require('goog.functions');
- goog.require('goog.math.Coordinate');
- goog.require('goog.math.Coordinate3');
- goog.require('goog.style');
- goog.require('goog.userAgent');
- goog.require('goog.userAgent.product.isVersion');
- goog.style.transform.isSupported = goog.functions.cacheReturnValue(function() {
- return !goog.userAgent.IE || goog.userAgent.product.isVersion(9);
- });
- goog.style.transform.is3dSupported =
- goog.functions.cacheReturnValue(function() {
- return goog.userAgent.WEBKIT || goog.userAgent.EDGE ||
- (goog.userAgent.GECKO && goog.userAgent.product.isVersion(10)) ||
- (goog.userAgent.IE && goog.userAgent.product.isVersion(10));
- });
- goog.style.transform.getTranslation = function(element) {
- var transform = goog.style.getComputedTransform(element);
- var matrixConstructor = goog.style.transform.matrixConstructor_();
- if (transform && matrixConstructor) {
- var matrix = new matrixConstructor(transform);
- if (matrix) {
- return new goog.math.Coordinate(matrix.m41, matrix.m42);
- }
- }
- return new goog.math.Coordinate(0, 0);
- };
- goog.style.transform.setTranslation = function(element, x, y) {
- if (!goog.style.transform.isSupported()) {
- return false;
- }
-
-
- var translation = goog.style.transform.is3dSupported() ?
- 'translate3d(' + x + 'px,' + y + 'px,' +
- '0px)' :
- 'translate(' + x + 'px,' + y + 'px)';
- goog.style.setStyle(
- element, goog.style.transform.getTransformProperty_(), translation);
- return true;
- };
- goog.style.transform.getScale = function(element) {
- var transform = goog.style.getComputedTransform(element);
- var matrixConstructor = goog.style.transform.matrixConstructor_();
- if (transform && matrixConstructor) {
- var matrix = new matrixConstructor(transform);
- if (matrix) {
- return new goog.math.Coordinate3(matrix.m11, matrix.m22, matrix.m33);
- }
- }
- return new goog.math.Coordinate3(0, 0, 0);
- };
- goog.style.transform.setScale = function(element, x, y, z) {
- if (!goog.style.transform.isSupported()) {
- return false;
- }
- var scale = goog.style.transform.is3dSupported() ?
- 'scale3d(' + x + ',' + y + ',' + z + ')' :
- 'scale(' + x + ',' + y + ')';
- goog.style.setStyle(
- element, goog.style.transform.getTransformProperty_(), scale);
- return true;
- };
- goog.style.transform.getRotation = function(element) {
- var transform = goog.style.getComputedTransform(element);
- var matrixConstructor = goog.style.transform.matrixConstructor_();
- if (transform && matrixConstructor) {
- var matrix = new matrixConstructor(transform);
- if (matrix) {
- var x = matrix.m11 + matrix.m22;
- var y = matrix.m12 - matrix.m21;
- return Math.atan2(y, x) * (180 / Math.PI);
- }
- }
- return 0;
- };
- goog.style.transform.setRotation = function(element, degrees) {
- if (!goog.style.transform.isSupported()) {
- return false;
- }
- var rotation = goog.style.transform.is3dSupported() ?
- 'rotate3d(0,0,1,' + degrees + 'deg)' :
- 'rotate(' + degrees + 'deg)';
- goog.style.setStyle(
- element, goog.style.transform.getTransformProperty_(), rotation);
- return true;
- };
- goog.style.transform.getTransformProperty_ =
- goog.functions.cacheReturnValue(function() {
- return goog.userAgent.IE && goog.userAgent.DOCUMENT_MODE == 9 ?
- '-ms-transform' :
- 'transform';
- });
- goog.style.transform.matrixConstructor_ =
- goog.functions.cacheReturnValue(function() {
- if (goog.isDef(goog.global['WebKitCSSMatrix'])) {
- return goog.global['WebKitCSSMatrix'];
- }
- if (goog.isDef(goog.global['MSCSSMatrix'])) {
- return goog.global['MSCSSMatrix'];
- }
- if (goog.isDef(goog.global['CSSMatrix'])) {
- return goog.global['CSSMatrix'];
- }
- return null;
- });
|