@@ -24,6 +24,7 @@ License: MIT License (see homepage)
24
24
REGEXP = RegExp ,
25
25
DOCUMENT = document ,
26
26
WINDOW = window ,
27
+ SCREEN = screen ,
27
28
LOCATION = WINDOW . location . href ,
28
29
EMPTY_FN = function ( ) { } ,
29
30
@@ -147,7 +148,7 @@ License: MIT License (see homepage)
147
148
// eCSStender Object
148
149
eCSStender = {
149
150
name : ECSSTENDER ,
150
- version : '1.2.8 ' ,
151
+ version : '1.2.7 ' ,
151
152
fonts : [ ] ,
152
153
pages : { } ,
153
154
at : { } ,
@@ -1231,6 +1232,10 @@ License: MIT License (see homepage)
1231
1232
{
1232
1233
return DOCUMENT . createElement ( el ) ;
1233
1234
}
1235
+ function getElements ( tag )
1236
+ {
1237
+ return DOCUMENT . getElementsByTagName ( tag ) ;
1238
+ }
1234
1239
function newRegExp ( rxp )
1235
1240
{
1236
1241
return new RegExp ( rxp ) ;
@@ -2471,12 +2476,17 @@ License: MIT License (see homepage)
2471
2476
*
2472
2477
* @param str query - the media query to test
2473
2478
*/
2474
- function matchMedia ( query ) {
2475
- if ( defined ( WINDOW . matchMedia ) ) {
2476
- console . log ( query , WINDOW . matchMedia ( query ) . matches ) ;
2479
+ function matchMedia ( query )
2480
+ {
2481
+ if ( defined ( WINDOW . matchMedia ) )
2482
+ {
2477
2483
return WINDOW . matchMedia ( query ) . matches ;
2478
- } else {
2479
- function convertToPixels ( val ) {
2484
+ }
2485
+ else
2486
+ {
2487
+ /* Helpers */
2488
+ function convertToPixels ( val )
2489
+ {
2480
2490
var
2481
2491
number = parseInt ( val . replace ( / [ ^ \d ] + / g, '' ) , 10 ) ,
2482
2492
unit = val . replace ( number , '' ) ;
@@ -2494,156 +2504,106 @@ License: MIT License (see homepage)
2494
2504
var
2495
2505
getWidth ,
2496
2506
getHeight ;
2497
- getWidth = function ( ) {
2498
- var _body = document . getElementsByTagName ( BODY ) [ 0 ] ;
2499
- return _body . clientWidth + convertToPixels ( getCSSValue ( _body , 'margin-left' ) ) + convertToPixels ( getCSSValue ( _body , 'margin-right' ) ) ;
2507
+ getWidth = function ( )
2508
+ {
2509
+ var _body = getElements ( BODY ) [ 0 ] ;
2510
+ return _body . clientWidth +
2511
+ convertToPixels ( getCSSValue ( _body , 'margin-left' ) ) +
2512
+ convertToPixels ( getCSSValue ( _body , 'margin-right' ) ) ;
2513
+ }
2514
+ if ( defined ( WINDOW . innerHeight ) )
2515
+ {
2516
+ getHeight = function ( )
2517
+ {
2518
+ return WINDOW . innerHeight ;
2519
+ }
2500
2520
}
2501
- if ( defined ( window . innerHeight ) ) {
2502
- getHeight = function ( ) { return window . innerHeight ; }
2503
- } else if ( defined ( document . documentElement ) && defined ( document . documentElement . clientHeight ) && document . documentElement . clientHeight ) {
2504
- getHeight = function ( ) { return document . documentElement . clientHeight ; }
2505
- } else {
2506
- getHeight = function ( ) { return document . getElementsByTagName ( BODY ) [ 0 ] . clientHeight ; }
2521
+ else if ( defined ( DOCUMENT . documentElement ) &&
2522
+ defined ( DOCUMENT . documentElement . clientHeight ) &&
2523
+ DOCUMENT . documentElement . clientHeight )
2524
+ {
2525
+ getHeight = function ( )
2526
+ {
2527
+ return document . documentElement . clientHeight ;
2528
+ }
2507
2529
}
2508
-
2509
- matchMedia = function ( query ) {
2510
- if ( query . indexOf ( COMMA ) > - 1 ) { // handle OR conditions
2511
- var
2512
- queries = query . split ( COMMA ) ,
2530
+ else
2531
+ {
2532
+ getHeight = function ( )
2533
+ {
2534
+ return getElements ( BODY ) [ 0 ] . clientHeight ;
2535
+ }
2536
+ }
2537
+ /* Method */
2538
+ matchMedia = function ( query )
2539
+ {
2540
+ var queries , matches , mediaQueryRegex , W , DW , H , DH , i , q , prop , val ;
2541
+
2542
+ // handle OR conditions
2543
+ if ( query . indexOf ( COMMA ) > - 1 )
2544
+ {
2545
+ queries = query . split ( COMMA ) ;
2513
2546
i = queries . length ;
2514
- while ( i ) {
2515
- var q = queries [ i - 1 ] ;
2516
- q = trim ( q ) ;
2517
- if ( matchMedia ( q ) ) { // if any of the conditions match, we can return true and bail
2547
+ while ( i -- )
2548
+ {
2549
+ q = trim ( queries [ i ] ) ;
2550
+ if ( matchMedia ( q ) )
2551
+ {
2552
+ // if any of the conditions match, we can return true and bail
2518
2553
return TRUE ;
2519
2554
}
2520
- i -- ;
2521
2555
}
2522
2556
}
2523
- var
2557
+ //isInheritedProperty( obj, prop )
2524
2558
queries = query . split ( ' and ' ) , // split the query into each condition
2525
2559
matches = TRUE , // optimism
2526
2560
mediaQueryRegex = newRegExp ( REGEXP_MQ_PARENS ) ,
2527
2561
W = getWidth ( ) ,
2528
- DW = screen . width ,
2562
+ DW = SCREEN . width ,
2529
2563
H = getHeight ( ) ,
2530
- DH = screen . height ;
2564
+ DH = SCREEN . height ;
2531
2565
i = queries . length ;
2532
- while ( i ) {
2533
- var q = queries [ i - 1 ] ;
2534
- if ( mediaQueryRegex . test ( q ) ) { // we only test query parts in the style of (property:value)
2535
- var
2536
- q = q . split ( COLON ) ,
2537
- prop = q [ 0 ] . toLowerCase ( ) ,
2566
+ while ( i -- )
2567
+ {
2568
+ q = queries [ i ] ;
2569
+ // we only test query parts in the style of (property:value)
2570
+ if ( mediaQueryRegex . test ( q ) )
2571
+ {
2572
+ q = q . split ( COLON ) ;
2573
+ prop = q [ 0 ] . toLowerCase ( ) ;
2538
2574
val = q [ 1 ] ;
2539
2575
2540
2576
prop = prop . replace ( / ^ \( / , EMPTY ) ;
2541
2577
val = val . replace ( / \) $ / , EMPTY ) ;
2542
2578
2543
- if ( prop != ORIENTATION ) {
2579
+ if ( prop != ORIENTATION )
2580
+ {
2544
2581
val = convertToPixels ( val ) ;
2545
2582
}
2546
- switch ( prop ) {
2547
- case ORIENTATION :
2548
- switch ( val ) {
2549
- case LANDSCAPE :
2550
- if ( W < H )
2551
- {
2552
- matches = FALSE ;
2553
- }
2554
- break ;
2555
- case PORTRAIT :
2556
- if ( W > H )
2557
- {
2558
- matches = FALSE ;
2559
- }
2560
- break ;
2561
- default :
2562
- // we only support landscape and portrait
2563
- break ;
2564
- }
2565
- break ;
2566
- case WIDTH :
2567
- if ( W != val )
2568
- {
2569
- matches = FALSE ;
2570
- }
2571
- break ;
2572
- case MAXWIDTH :
2573
- if ( W > val )
2574
- {
2575
- matches = FALSE ;
2576
- }
2577
- break ;
2578
- case MINWIDTH :
2579
- if ( W < val )
2580
- {
2581
- matches = FALSE ;
2582
- }
2583
- break ;
2584
- case DEVWIDTH :
2585
- if ( DW != val )
2586
- {
2587
- matches = FALSE ;
2588
- }
2589
- break ;
2590
- case DEVMAXWIDTH :
2591
- if ( DW > val )
2592
- {
2593
- matches = FALSE ;
2594
- }
2595
- break ;
2596
- case DEVMINWIDTH :
2597
- if ( DW < val )
2598
- {
2599
- matches = FALSE ;
2600
- }
2601
- break ;
2602
- case HEIGHT :
2603
- if ( H != val )
2604
- {
2605
- matches = FALSE ;
2606
- }
2607
- break ;
2608
- case MAXHEIGHT :
2609
- if ( H > val )
2610
- {
2611
- matches = FALSE ;
2612
- }
2613
- break ;
2614
- case MINHEIGHT :
2615
- if ( H < val )
2616
- {
2617
- matches = FALSE ;
2618
- }
2619
- break ;
2620
- case DEVHEIGHT :
2621
- if ( DH != val )
2622
- {
2623
- matches = FALSE ;
2624
- }
2625
- break ;
2626
- case DEVMAXHEIGHT :
2627
- if ( DH > val )
2628
- {
2629
- matches = FALSE ;
2630
- }
2631
- break ;
2632
- case DEVMINHEIGHT :
2633
- if ( DH < val )
2634
- {
2635
- matches = FALSE ;
2636
- }
2637
- break ;
2638
- default :
2583
+
2584
+ switch ( TRUE )
2585
+ {
2586
+ case ( prop == ORIENTATION && val == LANDSCAPE && W < H ) :
2587
+ case ( prop == ORIENTATION && val == PORTRAIT && W > H ) :
2588
+ case ( prop == WIDTH && W != val ) :
2589
+ case ( prop == MAXWIDTH && W > val ) :
2590
+ case ( prop == MINWIDTH && W < val ) :
2591
+ case ( prop == DEVWIDTH && DW != val ) :
2592
+ case ( prop == DEVMAXWIDTH && DW > val ) :
2593
+ case ( prop == DEVMINWIDTH && DW < val ) :
2594
+ case ( prop == HEIGHT && H != val ) :
2595
+ case ( prop == MAXHEIGHT && H > val ) :
2596
+ case ( prop == MINHEIGHT && H < val ) :
2597
+ case ( prop == DEVHEIGHT && DH != val ) :
2598
+ case ( prop == DEVMAXHEIGHT && DH > val ) :
2599
+ case ( prop == DEVMINHEIGHT && DH < val ) :
2600
+ matches = FALSE ;
2639
2601
break ;
2640
2602
}
2641
2603
}
2642
- i -- ;
2643
- } ;
2644
-
2604
+ }
2645
2605
return matches ;
2646
- }
2606
+ } ;
2647
2607
return matchMedia ( query ) ;
2648
2608
}
2649
2609
}
0 commit comments