github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/server/camlistored/ui/style.js (about)

     1  /*
     2  Copyright 2013 The Camlistore Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  goog.provide('cam.style');
    18  
    19  goog.require('goog.math.Coordinate');
    20  goog.require('goog.string');
    21  goog.require('goog.style');
    22  
    23  // Returns |url| wrapped in url() so that it can be used as a CSS property value.
    24  // @param {string} url
    25  // @returns {string}
    26  cam.style.getURLValue = function(url) {
    27  	return goog.string.subs('url(%s)', url);
    28  };
    29  
    30  // Sets a style property to a URL value.
    31  // @param {Element} elm
    32  // @param {string} dashedCSSProperty The CSS property to set, formatted with dashes, in the CSS style, not camelCase.
    33  // @param {string} url
    34  cam.style.setURLStyle = function(elm, dashedCSSProperty, url) {
    35  	goog.style.setStyle(elm, dashedCSSProperty, cam.style.getURLValue(url));
    36  };
    37  
    38  // @param {Element} elm
    39  // @param {goog.math.Coordinate} origin
    40  // @param {string=} opt_unit The CSS units the origin is in. If unspecified, defaults to pixels.
    41  cam.style.setTransformOrigin = function(elm, origin, opt_unit) {
    42  	var unit = opt_unit || 'px';
    43  	goog.style.setStyle(elm, 'transform-origin', goog.string.subs('%s%s %s%s', origin.x, unit, origin.y, unit));
    44  };
    45  
    46  // Note that this currently clears any previous CSS transform. Currently we only
    47  // needs to support rotate().
    48  // @param {Element} elm
    49  // @param {number} degrees
    50  cam.style.setRotation = function(elm, degrees) {
    51  	goog.style.setStyle(elm, 'transform', goog.string.subs('rotate(%sdeg)', degrees));
    52  };