Projet

Général

Profil

Révision 74f6bef0

Ajouté par Assos Assos il y a plus de 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/themes/adaptivetheme/at_core/scripts/scalefix.js
1
// Optimized scalefix by jdalton: https://gist.github.com/903131
2
// Prevents iOS from overscaling the page on orientation change.
3
// 1) won't restrict viewport if JS is disabled
4
// 2) uses capture phase
5
// 3) assumes last viewport meta is the one to edit (incase for some odd reason there is more than one)
6
// 4) feature inference (no sniffs, behavior should be ignored on other enviros)
7
// 5) removes event handler after fired
8
!function(doc) {
9
  var addEvent = 'addEventListener',
10
      type = 'gesturestart',
11
      qsa = 'querySelectorAll',
12
      scales = [1, 1],
13
      meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
14

  
15
  function fix() {
16
    meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
17
    doc.removeEventListener(type, fix, !0);
18
  }
19
  if ((meta = meta[meta.length - 1]) && addEvent in doc) {
20
    fix();
21
    scales = [.25, 1.6];
22
    doc[addEvent](type, fix, !0);
23
  }
24
}(document);
1
/*! A fix for the iOS orientationchange zoom bug.
2
 Script by @scottjehl, rebound by @wilto.
3
 MIT / GPLv2 License.
4
*/
5
(function(w){
6

  
7
	// This fix addresses an iOS bug, so return early if the UA claims it's something else.
8
	var ua = navigator.userAgent;
9
	if( !( /iPhone|iPad|iPod/.test( navigator.platform ) && /OS [1-5]_[0-9_]* like Mac OS X/i.test(ua) && ua.indexOf( "AppleWebKit" ) > -1 ) ){
10
		return;
11
	}
12

  
13
    var doc = w.document;
14

  
15
    if( !doc.querySelector ){ return; }
16

  
17
    var meta = doc.querySelector( "meta[name=viewport]" ),
18
        initialContent = meta && meta.getAttribute( "content" ),
19
        disabledZoom = initialContent + ",maximum-scale=1",
20
        enabledZoom = initialContent + ",maximum-scale=10",
21
        enabled = true,
22
		x, y, z, aig;
23

  
24
    if( !meta ){ return; }
25

  
26
    function restoreZoom(){
27
        meta.setAttribute( "content", enabledZoom );
28
        enabled = true;
29
    }
30

  
31
    function disableZoom(){
32
        meta.setAttribute( "content", disabledZoom );
33
        enabled = false;
34
    }
35

  
36
    function checkTilt( e ){
37
		aig = e.accelerationIncludingGravity;
38
		x = Math.abs( aig.x );
39
		y = Math.abs( aig.y );
40
		z = Math.abs( aig.z );
41

  
42
		// If portrait orientation and in one of the danger zones
43
        if( (!w.orientation || w.orientation === 180) && ( x > 7 || ( ( z > 6 && y < 8 || z < 8 && y > 6 ) && x > 5 ) ) ){
44
			if( enabled ){
45
				disableZoom();
46
			}
47
        }
48
		else if( !enabled ){
49
			restoreZoom();
50
        }
51
    }
52

  
53
	w.addEventListener( "orientationchange", restoreZoom, false );
54
	w.addEventListener( "devicemotion", checkTilt, false );
55

  
56
})( this );

Formats disponibles : Unified diff