Debian Codegraph @

dojox/mobile/_compat.js

raw symbols SCIP
1 define([
2 "dojo/_base/array", // array.forEach
3 "dojo/_base/config",
4 "dojo/_base/connect", // connect.connect
5 "dojo/_base/fx", // fx.fadeOut, fx.fadeIn
6 "dojo/_base/lang", // lang.extend, lang.isArray
7 "dojo/sniff", // has("webkit"), has("ie")
8 "dojo/_base/window", // win.doc, win.body
9 "dojo/dom-class",
10 "dojo/dom-construct",
11 "dojo/dom-geometry",
12 "dojo/dom-style",
13 "dojo/dom-attr",
14 "dojo/fx",
15 "dojo/fx/easing",
16 "dojo/ready",
17 "dojo/uacss",
18 "dijit/registry", // registry.byNode
19 "dojox/fx",
20 "dojox/fx/flip",
21 "./EdgeToEdgeList",
22 "./IconContainer",
23 "./ProgressIndicator",
24 "./RoundRect",
25 "./RoundRectList",
26 "./ScrollableView",
27 "./Switch",
28 "./View",
29 "./Heading",
30 "require"
31 ], function(array, config, connect, bfx, lang, has, win, domClass, domConstruct, domGeometry, domStyle, domAttr, fx, easing, ready, uacss, registry, xfx, flip, EdgeToEdgeList, IconContainer, ProgressIndicator, RoundRect, RoundRectList, ScrollableView, Switch, View, Heading, require){
32
33 // module:
34 // dojox/mobile/compat
35
36 /*=====
37 return {
38 // summary:
39 // CSS3 compatibility module.
40 // description:
41 // This module provides to dojox/mobile support for some of the CSS3 features
42 // in non-CSS3 browsers, such as IE or Firefox.
43 // If you require this module, when running in a non-CSS3 browser it directly
44 // replaces some of the methods of dojox/mobile classes, without any subclassing.
45 // This way, HTML pages remain the same regardless of whether this compatibility
46 // module is used or not.
47 //
48 // Example of usage:
49 // | require([
50 // | "dojox/mobile",
51 // | "dojox/mobile/compat",
52 // | ...
53 // | ], function(...){
54 // | ...
55 // | });
56 //
57 // This module also loads compatibility CSS files, which have a -compat.css
58 // suffix. You can use either the `<link>` tag or `@import` to load theme
59 // CSS files. Then, this module searches for the loaded CSS files and loads
60 // compatibility CSS files. For example, if you load dojox/mobile/themes/iphone/iphone.css
61 // in a page, this module automatically loads dojox/mobile/themes/iphone/iphone-compat.css.
62 // If you explicitly load iphone-compat.css with `<link>` or `@import`,
63 // this module will not load again the already loaded file.
64 //
65 // Note that, by default, compatibility CSS files are only loaded for CSS files located
66 // in a directory containing a "mobile/themes" path. For that, a matching is done using
67 // the default pattern "/\/mobile\/themes\/.*\.css$/". If a custom theme is not located
68 // in a directory containing this path, the data-dojo-config needs to specify a custom
69 // pattern using the "mblLoadCompatPattern" configuration parameter, for instance:
70 // | data-dojo-config="mblLoadCompatPattern: /\/mycustomtheme\/.*\.css$/"
71 };
72 =====*/
73
74 var dm = lang.getObject("dojox.mobile", true);
75
76 if(!(has("webkit") || has("ie") === 10 || (!has("ie") && has("trident") > 6))){
77 lang.extend(View, {
78 _doTransition: function(fromNode, toNode, transition, dir){
79 var anim;
80 this.wakeUp(toNode);
81 var s1, s2;
82 if(!transition || transition == "none"){
83 toNode.style.display = "";
84 fromNode.style.display = "none";
85 toNode.style.left = "0px";
86 this.invokeCallback();
87 }else if(transition == "slide" || transition == "cover" || transition == "reveal"){
88 var w = fromNode.offsetWidth;
89 s1 = fx.slideTo({
90 node: fromNode,
91 duration: 400,
92 left: -w*dir,
93 top: domStyle.get(fromNode, "top")
94 });
95 s2 = fx.slideTo({
96 node: toNode,
97 duration: 400,
98 left: 0,
99 top: domStyle.get(toNode, "top")
100 });
101 toNode.style.position = "absolute";
102 toNode.style.left = w*dir + "px";
103 toNode.style.display = "";
104 anim = fx.combine([s1,s2]);
105 connect.connect(anim, "onEnd", this, function(){
106 if(!this._inProgress){ return; } // transition has been aborted
107 fromNode.style.display = "none";
108 fromNode.style.left = "0px";
109 toNode.style.position = "relative";
110 var toWidget = registry.byNode(toNode);
111 if(toWidget && !domClass.contains(toWidget.domNode, "out")){
112 // Reset the temporary padding
113 toWidget.containerNode.style.paddingTop = "";
114 }
115 this.invokeCallback();
116 });
117 anim.play();
118 }else if(transition == "slidev" || transition == "coverv" || transition == "reavealv"){
119 var h = fromNode.offsetHeight;
120 s1 = fx.slideTo({
121 node: fromNode,
122 duration: 400,
123 left: 0,
124 top: -h*dir
125 });
126 s2 = fx.slideTo({
127 node: toNode,
128 duration: 400,
129 left: 0,
130 top: 0
131 });
132 toNode.style.position = "absolute";
133 toNode.style.top = h*dir + "px";
134 toNode.style.left = "0px";
135 toNode.style.display = "";
136 anim = fx.combine([s1,s2]);
137 connect.connect(anim, "onEnd", this, function(){
138 if(!this._inProgress){ return; } // transition has been aborted
139 fromNode.style.display = "none";
140 toNode.style.position = "relative";
141 this.invokeCallback();
142 });
143 anim.play();
144 }else if(transition == "flip"){
145 anim = xfx.flip({
146 node: fromNode,
147 dir: "right",
148 depth: 0.5,
149 duration: 400
150 });
151 toNode.style.position = "absolute";
152 toNode.style.left = "0px";
153 connect.connect(anim, "onEnd", this, function(){
154 if(!this._inProgress){ return; } // transition has been aborted
155 fromNode.style.display = "none";
156 toNode.style.position = "relative";
157 toNode.style.display = "";
158 this.invokeCallback();
159 });
160 anim.play();
161 }else {
162 // other transitions - "fade", "dissolve", "swirl"
163 anim = fx.chain([
164 bfx.fadeOut({
165 node: fromNode,
166 duration: 600
167 }),
168 bfx.fadeIn({
169 node: toNode,
170 duration: 600
171 })
172 ]);
173 toNode.style.position = "absolute";
174 toNode.style.left = "0px";
175 toNode.style.display = "";
176 domStyle.set(toNode, "opacity", 0);
177 connect.connect(anim, "onEnd", this, function(){
178 if(!this._inProgress){ return; } // transition has been aborted
179 fromNode.style.display = "none";
180 toNode.style.position = "relative";
181 domStyle.set(fromNode, "opacity", 1);
182 this.invokeCallback();
183 });
184 anim.play();
185 }
186 },
187
188 wakeUp: function(/*DomNode*/node){
189 // summary:
190 // Function to force IE to redraw a node since its layout
191 // code tends to misrender in partial draws.
192 // node: DomNode
193 // The node to forcibly redraw.
194 // tags:
195 // public
196 if(has("ie") && !node._wokeup){
197 node._wokeup = true;
198 var disp = node.style.display;
199 node.style.display = "";
200 var nodes = node.getElementsByTagName("*");
201 for(var i = 0, len = nodes.length; i < len; i++){
202 var val = nodes[i].style.display;
203 nodes[i].style.display = "none";
204 nodes[i].style.display = "";
205 nodes[i].style.display = val;
206 }
207 node.style.display = disp;
208 }
209 }
210 });
211
212
213 lang.extend(ProgressIndicator, {
214 scale: function(/*Number*/size){
215 if(has("ie")){
216 var dim = {w:size, h:size};
217 domGeometry.setMarginBox(this.domNode, dim);
218 domGeometry.setMarginBox(this.containerNode, dim);
219 }else if(has("ff")){
220 var scale = size / 40;
221 domStyle.set(this.containerNode, {
222 MozTransform: "scale(" + scale + ")",
223 MozTransformOrigin: "0 0"
224 });
225
226 domGeometry.setMarginBox(this.domNode, {w:size, h:size});
227 domGeometry.setMarginBox(this.containerNode, {w:size / scale, h:size / scale});
228 }
229 }
230 });
231
232
233 if(has("ie")){
234 lang.extend(RoundRect, {
235 buildRendering: function(){
236 // summary:
237 // Function to simulate the borderRadius appearance on
238 // IE, since IE does not support this CSS style.
239 // tags:
240 // protected
241 dm.createRoundRect(this);
242 this.domNode.className = "mblRoundRect";
243 }
244 });
245
246
247 RoundRectList._addChild = RoundRectList.prototype.addChild;
248 RoundRectList._postCreate = RoundRectList.prototype.postCreate;
249 lang.extend(RoundRectList, {
250 buildRendering: function(){
251 // summary:
252 // Function to simulate the borderRadius appearance on
253 // IE, since IE does not support this CSS style.
254 // tags:
255 // protected
256 dm.createRoundRect(this, true);
257 this.domNode.className = "mblRoundRectList";
258 if(has("ie") && has("dojo-bidi") && !this.isLeftToRight()){
259 this.domNode.className = "mblRoundRectList mblRoundRectListRtl"
260 }
261 },
262
263 postCreate: function(){
264 RoundRectList._postCreate.apply(this, arguments);
265 this.redrawBorders();
266 },
267
268 addChild: function(widget, /*Number?*/insertIndex){
269 RoundRectList._addChild.apply(this, arguments);
270 this.redrawBorders();
271 if(dm.applyPngFilter){
272 dm.applyPngFilter(widget.domNode);
273 }
274 },
275
276 redrawBorders: function(){
277 // summary:
278 // Function to adjust the creation of RoundRectLists on IE.
279 // Removed undesired styles.
280 // tags:
281 // public
282
283 // Remove a border of the last ListItem.
284 // This is for browsers that do not support the last-child CSS pseudo-class.
285
286 if(this instanceof EdgeToEdgeList){ return; }
287 var lastChildFound = false;
288 for(var i = this.containerNode.childNodes.length - 1; i >= 0; i--){
289 var c = this.containerNode.childNodes[i];
290 if(c.tagName == "LI"){
291 c.style.borderBottomStyle = lastChildFound ? "solid" : "none";
292 lastChildFound = true;
293 }
294 }
295 }
296 });
297
298
299 lang.extend(EdgeToEdgeList, {
300 buildRendering: function(){
301 this.domNode = this.containerNode = this.srcNodeRef || win.doc.createElement("ul");
302 this.domNode.className = "mblEdgeToEdgeList";
303 }
304 });
305
306
307 IconContainer._addChild = IconContainer.prototype.addChild;
308 lang.extend(IconContainer, {
309 addChild: function(widget, /*Number?*/insertIndex){
310 IconContainer._addChild.apply(this, arguments);
311 if(dm.applyPngFilter){
312 dm.applyPngFilter(widget.domNode);
313 }
314 }
315 });
316
317
318 lang.mixin(dm, {
319 createRoundRect: function(_this, isList){
320 // summary:
321 // Function to adjust the creation of rounded rectangles on IE.
322 // Deals with IE's lack of borderRadius support
323 // tags:
324 // public
325 var i, len;
326 _this.domNode = win.doc.createElement("div");
327 _this.domNode.style.padding = "0px";
328 _this.domNode.style.backgroundColor = "transparent";
329 _this.domNode.style.border = "none"; // borderStyle = "none"; doesn't work on IE9
330 _this.containerNode = win.doc.createElement(isList?"ul":"div");
331 _this.containerNode.className = "mblRoundRectContainer";
332 if(_this.srcNodeRef){
333 _this.srcNodeRef.parentNode.replaceChild(_this.domNode, _this.srcNodeRef);
334 for(i = 0, len = _this.srcNodeRef.childNodes.length; i < len; i++){
335 _this.containerNode.appendChild(_this.srcNodeRef.removeChild(_this.srcNodeRef.firstChild));
336 }
337 _this.srcNodeRef = null;
338 }
339 _this.domNode.appendChild(_this.containerNode);
340
341 for(i = 0; i <= 5; i++){
342 var top = domConstruct.create("div");
343 top.className = "mblRoundCorner mblRoundCorner"+i+"T";
344 _this.domNode.insertBefore(top, _this.containerNode);
345
346 var bottom = domConstruct.create("div");
347 bottom.className = "mblRoundCorner mblRoundCorner"+i+"B";
348 _this.domNode.appendChild(bottom);
349 }
350 }
351 });
352
353
354 lang.extend(ScrollableView, {
355 postCreate: function(){
356 // On IE, margin-top of the first child does not seem to be effective,
357 // probably because padding-top is specified for containerNode
358 // to make room for a fixed header. This dummy node is a workaround for that.
359 var dummy = domConstruct.create("div", {className:"mblDummyForIE", innerHTML:"&nbsp;"}, this.containerNode, "first");
360 domStyle.set(dummy, {
361 position: "relative",
362 marginBottom: "-2px",
363 fontSize: "1px"
364 });
365 }
366 });
367 } // if (has("ie"))
368
369
370 if(has("ie") <= 6){
371 dm.applyPngFilter = function(root){
372 root = root || win.body();
373 var nodes = root.getElementsByTagName("IMG");
374 var blank = require.toUrl("dojo/resources/blank.gif");
375 for(var i = 0, len = nodes.length; i < len; i++){
376 var img = nodes[i];
377 var w = img.offsetWidth;
378 var h = img.offsetHeight;
379 if(w === 0 || h === 0){
380 // The reason why the image has no width/height may be because
381 // display is "none". If that is the case, let's change the
382 // display to "" temporarily and see if the image returns them.
383 if(domStyle.get(img, "display") != "none"){ continue; }
384 img.style.display = "";
385 w = img.offsetWidth;
386 h = img.offsetHeight;
387 img.style.display = "none";
388 if(w === 0 || h === 0){ continue; }
389 }
390 var src = img.src;
391 if(src.indexOf("resources/blank.gif") != -1){ continue; }
392 img.src = blank;
393 img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src+"')";
394 img.style.width = w + "px";
395 img.style.height = h + "px";
396 }
397 };
398
399 if(!dm._disableBgFilter && dm.createDomButton){
400 dm._createDomButton_orig = dm.createDomButton;
401 dm.createDomButton = function(/*DomNode*/refNode, /*Object?*/style, /*DomNode?*/toNode){
402 var node = dm._createDomButton_orig.apply(this, arguments);
403 if(node && node.className && node.className.indexOf("mblDomButton") !== -1){
404 var f = function(){
405 if(node.currentStyle && node.currentStyle.backgroundImage.match(/url.*(mblDomButton.*\.png)/)){
406 var img = RegExp.$1;
407 var src = require.toUrl("dojox/mobile/themes/common/domButtons/compat/") + img;
408 node.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src+"',sizingMethod='crop')";
409 node.style.background = "none";
410 }
411 };
412 setTimeout(f, 1000);
413 setTimeout(f, 5000);
414 }
415 return node;
416 };
417 }
418 } // if(has("ie") <= 6)
419
420 dm.loadCssFile = function(/*String*/file){
421 // summary:
422 // Overrides dojox/mobile.loadCssFile() defined in
423 // deviceTheme.js.
424 if(!dm.loadedCssFiles){ dm.loadedCssFiles = []; }
425 if(win.doc.createStyleSheet){
426 // for some reason, IE hangs when you try to load
427 // multiple css files almost at once.
428 setTimeout(function(file){
429 return function(){
430 var ss = win.doc.createStyleSheet(file);
431 ss && dm.loadedCssFiles.push(ss.owningElement);
432 };
433 }(file), 0);
434 }else{
435 dm.loadedCssFiles.push(domConstruct.create("link", {
436 href: file,
437 type: "text/css",
438 rel: "stylesheet"
439 }, win.doc.getElementsByTagName('head')[0]));
440 }
441 };
442
443 dm.loadCss = function(/*String|Array*/files){
444 // summary:
445 // Function to load and register CSS files with the page
446 // files: String|Array
447 // The CSS files to load and register with the page.
448 // tags:
449 // private
450 if(!dm._loadedCss){
451 var obj = {};
452 array.forEach(dm.getCssPaths(), function(path){
453 obj[path] = true;
454 });
455 dm._loadedCss = obj;
456 }
457 if(!lang.isArray(files)){ files = [files]; }
458 for(var i = 0; i < files.length; i++){
459 var file = files[i];
460 if(!dm._loadedCss[file]){
461 dm._loadedCss[file] = true;
462 dm.loadCssFile(file);
463 }
464 }
465 };
466
467 dm.getCssPaths = function(){
468 var paths = [];
469 var i, j, len;
470
471 // find @import
472 var s = win.doc.styleSheets;
473 for(i = 0; i < s.length; i++){
474 if(s[i].href){ continue; }
475 var r = s[i].cssRules || s[i].imports;
476 if(!r){ continue; }
477 for(j = 0; j < r.length; j++){
478 if(r[j].href){
479 paths.push(r[j].href);
480 }
481 }
482 }
483
484 // find <link>
485 var elems = win.doc.getElementsByTagName("link");
486 for(i = 0, len = elems.length; i < len; i++){
487 if(elems[i].href){
488 paths.push(elems[i].href);
489 }
490 }
491 return paths;
492 };
493
494 dm.loadCompatPattern = /\/mobile\/themes\/.*\.css$/;
495
496 dm.loadCompatCssFiles = function(/*Boolean?*/force){
497 // summary:
498 // Function to perform page-level adjustments on browsers such as
499 // IE and firefox. It loads compat specific css files into the
500 // page header.
501 if(has("ie") && !force){
502 setTimeout(function(){ // IE needs setTimeout
503 dm.loadCompatCssFiles(true);
504 }, 0);
505 return;
506 }
507 dm._loadedCss = undefined;
508 var paths = dm.getCssPaths();
509 // dojox.mobile mirroring support
510 if(has("dojo-bidi")){
511 paths = dm.loadRtlCssFiles(paths);
512 }
513 for(var i = 0; i < paths.length; i++){
514 var href = paths[i];
515 // Load the -compat.css only for css files that belong to a theme. For that, by default
516 // we match on directories containing "mobile/themes". If a custom theme is located
517 // outside a "mobile/themes" directory, the dojoConfig needs to specify a custom
518 // pattern using the "mblLoadCompatPattern" configuration parameter, for instance:
519 // data-dojo-config="mblLoadCompatPattern: /\/mycustom\/.*\.css$/"
520 // Additionally, compat css files are loaded for css in the mobile/tests directory.
521 if((href.match(config.mblLoadCompatPattern || dm.loadCompatPattern) ||
522 location.href.indexOf("mobile/tests/") !== -1) && href.indexOf("-compat.css") === -1){
523 var compatCss = href.substring(0, href.length-4)+"-compat.css";
524 dm.loadCss(compatCss);
525 }
526 }
527 };
528 if(has("dojo-bidi")){
529 dm.loadRtlCssFiles = function(/*Array*/paths){
530 // summary:
531 // Function to load the corresponding *_rtl.css file for every *.css file.
532 // Enable mobile mirroring support
533 // paths: Array
534 // Array of css files within the page.
535 for(var i = 0; i < paths.length; i++){
536 var href = paths[i];
537 if(href.indexOf("_rtl") == -1){
538 var rtlCssList = "android.css blackberry.css custom.css iphone.css holodark.css base.css Carousel.css ComboBox.css IconContainer.css IconMenu.css ListItem.css RoundRectCategory.css SpinWheel.css Switch.css TabBar.css ToggleButton.css ToolBarButton.css ProgressIndicator.css Accordion.css GridLayout.css FormLayout.css";
539 var cssName = href.substr(href.lastIndexOf('/') + 1);
540 if(rtlCssList.indexOf(cssName) != -1){
541 var rtlPath = href.replace(".css", "_rtl.css");
542 paths.push(rtlPath);
543 dm.loadCss(rtlPath);
544 }
545 }
546 }
547 return paths;
548 };
549 }
550 dm.hideAddressBar = function(/*Event?*/evt, /*Boolean?*/doResize){
551 if(doResize !== false){ dm.resizeAll(); }
552 };
553
554 ready(function(){
555 if(config.mblLoadCompatCssFiles !== false){
556 dm.loadCompatCssFiles();
557 }
558 if(dm.applyPngFilter){
559 dm.applyPngFilter();
560 }
561 });
562
563 } // end of if(!has("webkit")){
564
565 return dm;
566 });