Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: polymer_0.5.0/bower_components/web-animations-js/src/apply-preserving-inline-style.js

Issue 786953007: npm_modules: Fork bower_components into Polymer 0.4.0 and 0.5.0 versions (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: polymer_0.5.0/bower_components/web-animations-js/src/apply-preserving-inline-style.js
diff --git a/polymer_0.5.0/bower_components/web-animations-js/src/apply-preserving-inline-style.js b/polymer_0.5.0/bower_components/web-animations-js/src/apply-preserving-inline-style.js
new file mode 100644
index 0000000000000000000000000000000000000000..c96a3359d150593d6d2193ca7bfb330a72506f68
--- /dev/null
+++ b/polymer_0.5.0/bower_components/web-animations-js/src/apply-preserving-inline-style.js
@@ -0,0 +1,183 @@
+// Copyright 2014 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+(function(scope, testing) {
+
+ var styleAttributes = {
+ cssText: 1,
+ length: 1,
+ parentRule: 1,
+ };
+
+ var styleMethods = {
+ getPropertyCSSValue: 1,
+ getPropertyPriority: 1,
+ getPropertyValue: 1,
+ item: 1,
+ removeProperty: 1,
+ setProperty: 1,
+ };
+
+ var styleMutatingMethods = {
+ removeProperty: 1,
+ setProperty: 1,
+ };
+
+ function configureProperty(object, property, descriptor) {
+ descriptor.enumerable = true;
+ descriptor.configurable = true;
+ Object.defineProperty(object, property, descriptor);
+ }
+
+ function AnimatedCSSStyleDeclaration(element) {
+ WEB_ANIMATIONS_TESTING && console.assert(!(element.style instanceof AnimatedCSSStyleDeclaration),
+ 'Element must not already have an animated style attached.');
+
+ // Stores the inline style of the element on its behalf while the
+ // polyfill uses the element's inline style to simulate web animations.
+ // This is needed to fake regular inline style CSSOM access on the element.
+ this._surrogateElement = document.createElement('div');
+ this._surrogateStyle = this._surrogateElement.style;
+ this._style = element.style;
+ this._length = 0;
+ this._isAnimatedProperty = {};
+
+ // Copy the inline style contents over to the surrogate.
+ for (var i = 0; i < this._style.length; i++) {
+ var property = this._style[i];
+ this._surrogateStyle[property] = this._style[property];
+ }
+ this._updateIndices();
+ }
+
+ AnimatedCSSStyleDeclaration.prototype = {
+ get cssText() {
+ return this._surrogateStyle.cssText;
+ },
+ set cssText(text) {
+ var isAffectedProperty = {};
+ for (var i = 0; i < this._surrogateStyle.length; i++) {
+ isAffectedProperty[this._surrogateStyle[i]] = true;
+ }
+ this._surrogateStyle.cssText = text;
+ this._updateIndices();
+ for (var i = 0; i < this._surrogateStyle.length; i++) {
+ isAffectedProperty[this._surrogateStyle[i]] = true;
+ }
+ for (var property in isAffectedProperty) {
+ if (!this._isAnimatedProperty[property]) {
+ this._style.setProperty(property, this._surrogateStyle.getPropertyValue(property));
+ }
+ }
+ },
+ get length() {
+ return this._surrogateStyle.length;
+ },
+ get parentRule() {
+ return this._style.parentRule;
+ },
+ // Mirror the indexed getters and setters of the surrogate style.
+ _updateIndices: function() {
+ while (this._length < this._surrogateStyle.length) {
+ Object.defineProperty(this, this._length, {
+ configurable: true,
+ enumerable: false,
+ get: (function(index) {
+ return function() { return this._surrogateStyle[index]; };
+ })(this._length)
+ });
+ this._length++;
+ }
+ while (this._length > this._surrogateStyle.length) {
+ this._length--;
+ Object.defineProperty(this, this._length, {
+ configurable: true,
+ enumerable: false,
+ value: undefined
+ });
+ }
+ },
+ _set: function(property, value) {
+ this._style[property] = value;
+ this._isAnimatedProperty[property] = true;
+ },
+ _clear: function(property) {
+ this._style[property] = this._surrogateStyle[property];
+ delete this._isAnimatedProperty[property];
+ },
+ };
+
+ // Wrap the style methods.
+ for (var method in styleMethods) {
+ AnimatedCSSStyleDeclaration.prototype[method] = (function(method, modifiesStyle) {
+ return function() {
+ var result = this._surrogateStyle[method].apply(this._surrogateStyle, arguments);
+ if (modifiesStyle) {
+ if (!this._isAnimatedProperty[arguments[0]])
+ this._style[method].apply(this._style, arguments);
+ this._updateIndices();
+ }
+ return result;
+ }
+ })(method, method in styleMutatingMethods);
+ }
+
+ // Wrap the style.cssProperty getters and setters.
+ for (var property in document.documentElement.style) {
+ if (property in styleAttributes || property in styleMethods) {
+ continue;
+ }
+ (function(property) {
+ configureProperty(AnimatedCSSStyleDeclaration.prototype, property, {
+ get: function() {
+ return this._surrogateStyle[property];
+ },
+ set: function(value) {
+ this._surrogateStyle[property] = value;
+ this._updateIndices();
+ if (!this._isAnimatedProperty[property])
+ this._style[property] = value;
+ }
+ });
+ })(property);
+ }
+
+ function ensureStyleIsPatched(element) {
+ if (element._webAnimationsPatchedStyle)
+ return;
+
+ // If this style patch fails (on Safari and iOS) use the apply-preserving-inline-style-methods.js
+ // module instead and restrict inline style interactions to the methods listed in styleMethods.
+ var animatedStyle = new AnimatedCSSStyleDeclaration(element);
+ configureProperty(element, 'style', { get: function() { return animatedStyle; } });
+
+ // We must keep a handle on the patched style to prevent it from getting GC'd.
+ element._webAnimationsPatchedStyle = element.style;
+ }
+
+ scope.apply = function(element, property, value) {
+ ensureStyleIsPatched(element);
+ element.style._set(scope.propertyName(property), value);
+ };
+
+ scope.clear = function(element, property) {
+ if (element._webAnimationsPatchedStyle) {
+ element.style._clear(scope.propertyName(property));
+ }
+ };
+
+ if (WEB_ANIMATIONS_TESTING)
+ testing.ensureStyleIsPatched = ensureStyleIsPatched;
+
+})(webAnimationsMinifill, webAnimationsTesting);

Powered by Google App Engine
This is Rietveld 408576698