@@ -59,6 +59,8 @@ License: MIT License (see homepage)
59
59
CLOSE_CURLY = '}' ,
60
60
COMMA = ',' ,
61
61
DIV = 'div' ,
62
+ SCRIPT = 'script' ,
63
+ SRC = 'src' ,
62
64
TYPE = 'type' ,
63
65
COMPLETE = 'complete' ,
64
66
BODY = 'body' ,
@@ -131,7 +133,7 @@ License: MIT License (see homepage)
131
133
clearBrowserCache = EMPTY_FN ,
132
134
133
135
// other stuff
134
- __script = newElement ( 'script' ) ,
136
+ __script = newElement ( SCRIPT ) ,
135
137
136
138
// useful RegExps
137
139
// for breaking on commas
@@ -2056,34 +2058,68 @@ License: MIT License (see homepage)
2056
2058
}
2057
2059
eCSStender . addRules = addRules ;
2058
2060
2061
+ /**
2062
+ * eCSStender::emptyStyleSheets()
2063
+ * clears the contents of embedded stylesheets
2064
+ *
2065
+ * @return null
2066
+ */
2067
+ function emptyStyleSheets ( )
2068
+ {
2069
+ if ( defined ( stylesheet . styleSheet ) )
2070
+ {
2071
+ emptyStyleSheets = function ( )
2072
+ {
2073
+ var i = arguments . length ;
2074
+ while ( i -- )
2075
+ {
2076
+ arguments [ i ] . styleSheet . cssText = EMPTY ;
2077
+ }
2078
+ } ;
2079
+ }
2080
+ else
2081
+ {
2082
+ emptyStyleSheets = function ( )
2083
+ {
2084
+ var i = arguments . length ;
2085
+ while ( i -- )
2086
+ {
2087
+ arguments [ i ] . innerHTML = EMPTY ;
2088
+ }
2089
+ } ;
2090
+ }
2091
+ emptyStyleSheets . apply ( NULL , arguments ) ;
2092
+ }
2093
+ eCSStender . emptyStyleSheets = emptyStyleSheets ;
2094
+
2059
2095
/**
2060
2096
* eCSStender::isSupported()
2061
2097
* tests support for properties and selectors
2062
2098
*
2063
2099
* Option 1: Selector test
2064
2100
* eCSStender::isSupported( type, selector, html, el )
2065
- * @param str type - 'property '
2101
+ * @param str type - 'selector '
2066
2102
* @param str selector - the selector
2067
2103
* @param obj html - HTML to test against
2068
2104
* @param obj el - the element the selector should select
2069
2105
* @return bool - TRUE for success, FALSE for failure
2070
2106
*
2071
2107
* Option 2: Property Test (simple)
2072
2108
* eCSStender::isSupported( type, test )
2073
- * @param str type - 'selector '
2109
+ * @param str type - 'property '
2074
2110
* @param str test - the property: value pair to test
2075
2111
* @return bool - TRUE for success, FALSE for failure
2076
2112
*
2077
2113
* Option 3: Property Test (complex)
2078
2114
* eCSStender::isSupported( type, property, value )
2079
- * @param str type - 'selector '
2115
+ * @param str type - 'property '
2080
2116
* @param str property - the property to test
2081
2117
* @param mixed value - the string value or an array of possible values
2082
2118
* @return bool - TRUE for success, FALSE for failure
2083
2119
*
2084
2120
* Option 3: Storage
2085
2121
* eCSStender::isSupported( type, what, result )
2086
- * @param str type - 'selector'
2122
+ * @param str type - 'selector' or 'property'
2087
2123
* @param str what - the key to store
2088
2124
* @param bool result - the result of the test you want stored
2089
2125
* @return bool - the result you passed in
@@ -2263,6 +2299,33 @@ License: MIT License (see homepage)
2263
2299
return str ;
2264
2300
}
2265
2301
eCSStender . trim = trim ;
2302
+
2303
+ /**
2304
+ * eCSStender::getPathTo()
2305
+ * finds the path to a given resource in the document (scripts by default)
2306
+ *
2307
+ * @param str resource - the filename you're looking for
2308
+ * @param str tag - the tag family you're searching in
2309
+ * @return str - the complete resource path
2310
+ */
2311
+ eCSStender . getPathTo = function ( resource , tag )
2312
+ {
2313
+ tag = tag || SCRIPT ;
2314
+ var
2315
+ regex = new RegExp ( resource ) ,
2316
+ attr = tag == 'link' ? 'href' : SRC ,
2317
+ collection = getElements ( tag ) ,
2318
+ i = collection . length ,
2319
+ value ;
2320
+ while ( i -- )
2321
+ {
2322
+ value = collection [ i ] . getAttribute ( attr ) ;
2323
+ if ( regex . test ( value ) )
2324
+ {
2325
+ return value . replace ( regex , EMPTY ) ;
2326
+ }
2327
+ }
2328
+ } ;
2266
2329
2267
2330
/**
2268
2331
* eCSStender::loadScript()
@@ -2275,7 +2338,7 @@ License: MIT License (see homepage)
2275
2338
eCSStender . loadScript = function ( src , callback )
2276
2339
{
2277
2340
var
2278
- scripts = DOCUMENT . getElementsByTagName ( 'script' ) ,
2341
+ scripts = DOCUMENT . getElementsByTagName ( SCRIPT ) ,
2279
2342
i = scripts . length ,
2280
2343
script = __script . cloneNode ( TRUE ) ,
2281
2344
loaded = FALSE ;
@@ -2300,7 +2363,7 @@ License: MIT License (see homepage)
2300
2363
callback ( ) ;
2301
2364
}
2302
2365
} ;
2303
- script . setAttribute ( 'src' , src ) ;
2366
+ script . setAttribute ( SRC , src ) ;
2304
2367
__head . appendChild ( script ) ;
2305
2368
}
2306
2369
else
@@ -2377,9 +2440,10 @@ License: MIT License (see homepage)
2377
2440
return FALSE ;
2378
2441
} ;
2379
2442
}
2380
- eCSStender . getCSSValue = getCSSValue ;
2381
2443
return getCSSValue ( el , prop ) ;
2382
2444
}
2445
+ eCSStender . getCSSValue = getCSSValue ;
2446
+
2383
2447
/**
2384
2448
* eCSStender::makeUniqueClass()
2385
2449
* creates a unique class for an element
@@ -2465,6 +2529,53 @@ License: MIT License (see homepage)
2465
2529
}
2466
2530
} ;
2467
2531
eCSStender . toggleClass = toggleClass ;
2532
+ /**
2533
+ * eCSStender::elementMatchesSelector()
2534
+ * checks to see if a given element matches the selector you've passed to it
2535
+ *
2536
+ * @return bool
2537
+ */
2538
+ eCSStender . elementMatchesSelector = function ( element , selector )
2539
+ {
2540
+ if ( defined ( element . matchesSelector ) )
2541
+ {
2542
+ elementMatchesSelector = function ( element , selector )
2543
+ {
2544
+ return element . matchesSelector ( selector ) ;
2545
+ } ;
2546
+ }
2547
+ else if ( defined ( element . mozMatchesSelector ) )
2548
+ {
2549
+ elementMatchesSelector = function ( element , selector )
2550
+ {
2551
+ return element . mozMatchesSelector ( selector ) ;
2552
+ } ;
2553
+ }
2554
+ else if ( defined ( element . webkitMatchesSelector ) )
2555
+ {
2556
+ elementMatchesSelector = function ( element , selector )
2557
+ {
2558
+ return element . webkitMatchesSelector ( selector ) ;
2559
+ } ;
2560
+ }
2561
+ else
2562
+ {
2563
+ var
2564
+ testStyleSheet = e . newStyleElement ( SCREEN , 'selector-matching-test' , FALSE ) ;
2565
+ elementMatchesSelector = function ( element , selector )
2566
+ {
2567
+ var
2568
+ property = 'page-break-after' ,
2569
+ value = 'avoid' ,
2570
+ ret ;
2571
+ e . addRules ( testStyleSheet , selector + OPEN_CURLY + property + COLON + value + SEMICOLON + CLOSE_CURLY ) ;
2572
+ ret = ( e . getCSSValue ( element , property ) == value ) ;
2573
+ emptyStyleSheet ( testStyleSheet ) ;
2574
+ return ret ;
2575
+ } ;
2576
+ }
2577
+ return elementMatchesSelector ( element , selector ) ;
2578
+ } ;
2468
2579
/**
2469
2580
* eCSStender.matchMedia()
2470
2581
* returns true if the media query matches the state of rendered document
@@ -2489,7 +2600,7 @@ License: MIT License (see homepage)
2489
2600
{
2490
2601
var
2491
2602
number = parseInt ( val , 10 ) ,
2492
- unit = val . replace ( number , '' ) ;
2603
+ unit = val . replace ( number , EMPTY ) ;
2493
2604
switch ( unit ) {
2494
2605
case PX :
2495
2606
break ;
@@ -2506,10 +2617,9 @@ License: MIT License (see homepage)
2506
2617
getHeight ;
2507
2618
getWidth = function ( )
2508
2619
{
2509
- var _body = getElements ( BODY ) [ 0 ] ;
2510
- return _body . clientWidth +
2511
- convertToPixels ( getCSSValue ( _body , 'margin-left' ) ) +
2512
- convertToPixels ( getCSSValue ( _body , 'margin-right' ) ) ;
2620
+ return __body . clientWidth +
2621
+ convertToPixels ( getCSSValue ( __body , 'margin-left' ) ) +
2622
+ convertToPixels ( getCSSValue ( __body , 'margin-right' ) ) ;
2513
2623
} ;
2514
2624
if ( defined ( WINDOW . innerHeight ) )
2515
2625
{
@@ -2531,7 +2641,7 @@ License: MIT License (see homepage)
2531
2641
{
2532
2642
getHeight = function ( )
2533
2643
{
2534
- return getElements ( BODY ) [ 0 ] . clientHeight ;
2644
+ return __body . clientHeight ;
2535
2645
} ;
2536
2646
}
2537
2647
/* Method */
@@ -2570,7 +2680,7 @@ License: MIT License (see homepage)
2570
2680
if ( mediaQueryRegex . test ( q ) )
2571
2681
{
2572
2682
q = q . split ( COLON ) ;
2573
- prop = q [ 0 ] . toLowerCase ( ) ;
2683
+ prop = low ( q [ 0 ] ) ;
2574
2684
val = q [ 1 ] ;
2575
2685
2576
2686
prop = prop . replace ( / ^ \( / , EMPTY ) ;
0 commit comments