Debian Codegraph @

dojox/mobile/_css3.js

raw symbols SCIP
1 define([
2 "dojo/_base/window",
3 "dojo/_base/array",
4 "dojo/has"
5 ], function(win, arr, has){
6
7 // caches for capitalized names and hypen names
8 var cnames = [], hnames = [];
9
10 // element style used for feature testing
11 var style = win.doc.createElement("div").style;
12
13 // We just test webkit prefix for now since our themes only have standard and webkit
14 // (see dojox/mobile/themes/common/css3.less)
15 // More prefixes can be added if/when we add them to css3.less.
16 var prefixes = ["webkit"];
17
18 // Does the browser support CSS3 animations?
19 has.add("css3-animations", function(global, document, element){
20 var style = element.style;
21 return (style["animation"] !== undefined && style["transition"] !== undefined) ||
22 arr.some(prefixes, function(p){
23 return style[p+"Animation"] !== undefined && style[p+"Transition"] !== undefined;
24 });
25 });
26
27 // Indicates whether style 'transition' returns empty string instead of
28 // undefined, although TransitionEvent is not supported.
29 // Reported on Android 4.1.x on some devices: https://bugs.dojotoolkit.org/ticket/17164
30 has.add("t17164", function(global, document, element){
31 return (element.style["transition"] !== undefined) && !('TransitionEvent' in window);
32 });
33
34 var css3 = {
35 // summary:
36 // This module provide some cross-browser support for CSS3 properties.
37
38 name: function(/*String*/p, /*Boolean?*/hyphen){
39 // summary:
40 // Returns the name of a CSS3 property with the correct prefix depending on the browser.
41 // p:
42 // The (non-prefixed) property name. The property name is assumed to be consistent with
43 // the hyphen argument, for example "transition-property" if hyphen is true, or "transitionProperty"
44 // if hyphen is false. If the browser supports the non-prefixed property, the property name will be
45 // returned unchanged.
46 // hyphen:
47 // Optional, true if hyphen notation should be used (for example "transition-property" or "-webkit-transition-property"),
48 // false for camel-case notation (for example "transitionProperty" or "webkitTransitionProperty").
49
50 var n = (hyphen?hnames:cnames)[p];
51 if(!n){
52
53 if(/End|Start/.test(p)){
54 // event names: no good way to feature-detect, so we
55 // assume they have the same prefix as the corresponding style property
56 var idx = p.length - (p.match(/End/) ? 3 : 5);
57 var s = p.substr(0, idx);
58 var pp = this.name(s);
59 if(pp == s){
60 // no prefix, standard event names are all lowercase
61 n = p.toLowerCase();
62 }else{
63 // prefix, e.g. webkitTransitionEnd (camel case)
64 n = pp + p.substr(idx);
65 }
66 }else if(p == "keyframes"){
67 // special case for keyframes, we also rely on consistency between 'animation' and 'keyframes'
68 var pk = this.name("animation", hyphen);
69 if(pk == "animation"){
70 n = p;
71 }else if(hyphen){
72 n = pk.replace(/animation/, "keyframes");
73 }else{
74 n = pk.replace(/Animation/, "Keyframes");
75 }
76 }else{
77 // convert name to camel-case for feature test
78 var cn = hyphen ? p.replace(/-(.)/g, function(match, p1){
79 return p1.toUpperCase();
80 }) : p;
81 if(style[cn] !== undefined && !has('t17164')){
82 // standard non-prefixed property is supported
83 n = p;
84 }else{
85 // try prefixed versions
86 cn = cn.charAt(0).toUpperCase() + cn.slice(1);
87 arr.some(prefixes, function(prefix){
88 if(style[prefix+cn] !== undefined){
89 if(hyphen){
90 n = "-" + prefix + "-" + p;
91 }else{
92 n = prefix + cn;
93 }
94 }
95 });
96 }
97 }
98
99 if(!n){
100 // The property is not supported, just return it unchanged, it will be ignored.
101 n = p;
102 }
103
104 (hyphen?hnames:cnames)[p] = n;
105 }
106 return n;
107 },
108
109 add: function(/*Object*/styles, /*Object*/css3Styles){
110 // summary:
111 // Prefixes all property names in "css3Styles" and adds the prefixed properties in "styles".
112 // Used as a convenience when an object is passed to domStyle.set to set multiple styles.
113 // example:
114 // domStyle.set(bar, css3.add({
115 // opacity: 0.6,
116 // position: "absolute",
117 // backgroundColor: "#606060"
118 // }, {
119 // borderRadius: "2px",
120 // transformOrigin: "0 0"
121 // }));
122 // returns:
123 // The "styles" argument where the CSS3 styles have been added.
124
125 for(var p in css3Styles){
126 if(css3Styles.hasOwnProperty(p)){
127 styles[css3.name(p)] = css3Styles[p];
128 }
129 }
130 return styles;
131 }
132 };
133
134 return css3;
135 });