@@ -55,6 +55,7 @@ window.Detectizr = (function(window, navigator, document, undefined) {
5555 resizeTimeoutId ,
5656 oldOrientation ;
5757
58+ // Create Global "extend" method, so Detectizr does not need jQuery.extend
5859 function extend ( obj , extObj ) {
5960 var a , b , i ;
6061 if ( arguments . length > 2 ) {
@@ -127,24 +128,6 @@ window.Detectizr = (function(window, navigator, document, undefined) {
127128 }
128129 }
129130
130- function checkOrientation ( ) {
131- //timeout wrapper points with doResizeCode as callback
132- window . clearTimeout ( resizeTimeoutId ) ;
133- resizeTimeoutId = window . setTimeout ( function ( ) {
134- oldOrientation = Detectizr . device . orientation ;
135- //wrapper for height/width check
136- if ( window . innerHeight > window . innerWidth ) {
137- Detectizr . device . orientation = "portrait" ;
138- } else {
139- Detectizr . device . orientation = "landscape" ;
140- }
141- addConditionalTest ( Detectizr . device . orientation , true ) ;
142- if ( oldOrientation !== Detectizr . device . orientation ) {
143- addConditionalTest ( oldOrientation , false ) ;
144- }
145- } , 10 ) ;
146- }
147-
148131 // add test to Modernizr based on a condition
149132 function addConditionalTest ( feature , test ) {
150133 if ( ! ! feature && ! ! Modernizr ) {
@@ -185,10 +168,58 @@ window.Detectizr = (function(window, navigator, document, undefined) {
185168 }
186169 }
187170
171+ function checkOrientation ( ) {
172+ //timeout wrapper points with doResizeCode as callback
173+ window . clearTimeout ( resizeTimeoutId ) ;
174+ resizeTimeoutId = window . setTimeout ( function ( ) {
175+ oldOrientation = Detectizr . device . orientation ;
176+ //wrapper for height/width check
177+ if ( window . innerHeight > window . innerWidth ) {
178+ Detectizr . device . orientation = "portrait" ;
179+ } else {
180+ Detectizr . device . orientation = "landscape" ;
181+ }
182+ addConditionalTest ( Detectizr . device . orientation , true ) ;
183+ if ( oldOrientation !== Detectizr . device . orientation ) {
184+ addConditionalTest ( oldOrientation , false ) ;
185+ }
186+ } , 10 ) ;
187+ }
188+
189+ function detectPlugin ( substrs ) {
190+ var plugins = navigator . plugins ,
191+ plugin , haystack , pluginFoundText , j , k ;
192+ for ( j = plugins . length - 1 ; j >= 0 ; j -- ) {
193+ plugin = plugins [ j ] ;
194+ haystack = plugin . name + plugin . description ;
195+ pluginFoundText = 0 ;
196+ for ( k = substrs . length ; k >= 0 ; k -- ) {
197+ if ( haystack . indexOf ( substrs [ k ] ) !== - 1 ) {
198+ pluginFoundText += 1 ;
199+ }
200+ }
201+ if ( pluginFoundText === substrs . length ) {
202+ return true ;
203+ }
204+ }
205+ return false ;
206+ }
207+
208+ function detectObject ( progIds ) {
209+ var j ;
210+ for ( j = progIds . length - 1 ; j >= 0 ; j -- ) {
211+ try {
212+ new ActiveXObject ( progIds [ j ] ) ;
213+ } catch ( e ) {
214+ // Ignore
215+ }
216+ }
217+ return false ;
218+ }
219+
188220 function detect ( opt ) {
189- // Create Global "extend" method, so Detectizr does not need jQuery.extend
190- var that = this ,
191- i , j , k , device , os , browser , plugin2detect , pluginFound ;
221+ var i , j , device , os , browser , plugin2detect , pluginFound ;
222+
192223 options = extend ( { } , options , opt || { } ) ;
193224
194225 /** Device detection **/
@@ -281,10 +312,24 @@ window.Detectizr = (function(window, navigator, document, undefined) {
281312
282313 /** Screen detection **/
283314 if ( options . detectScreen ) {
315+ device . screen = { } ;
284316 if ( ! ! Modernizr && ! ! Modernizr . mq ) {
285- addConditionalTest ( "smallScreen" , Modernizr . mq ( "only screen and (max-width: 480px)" ) ) ;
286- addConditionalTest ( "verySmallScreen" , Modernizr . mq ( "only screen and (max-width: 320px)" ) ) ;
287- addConditionalTest ( "veryVerySmallScreen" , Modernizr . mq ( "only screen and (max-width: 240px)" ) ) ;
317+ if ( Modernizr . mq ( "only screen and (max-width: 240px)" ) ) {
318+ device . screen . size = "veryVerySmall" ;
319+ addConditionalTest ( "veryVerySmallScreen" , true ) ;
320+ } else if ( Modernizr . mq ( "only screen and (max-width: 320px)" ) ) {
321+ device . screen . size = "verySmall" ;
322+ addConditionalTest ( "verySmallScreen" , true ) ;
323+ } else if ( Modernizr . mq ( "only screen and (max-width: 480px)" ) ) {
324+ device . screen . size = "small" ;
325+ addConditionalTest ( "smallScreen" , true ) ;
326+ }
327+ if ( device . type === deviceTypes [ 1 ] || device . type === deviceTypes [ 2 ] ) {
328+ if ( Modernizr . mq ( "only screen and (-moz-min-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3), only screen and (min-resolution: 1.3dppx)" ) ) {
329+ device . screen . resolution = "high" ;
330+ addConditionalTest ( "highresolution" , true ) ;
331+ }
332+ }
288333 }
289334 if ( device . type === deviceTypes [ 1 ] || device . type === deviceTypes [ 2 ] ) {
290335 window . onresize = function ( event ) {
@@ -440,41 +485,13 @@ window.Detectizr = (function(window, navigator, document, undefined) {
440485 /** Plugin detection **/
441486 if ( options . detectPlugins ) {
442487 browser . plugins = [ ] ;
443- that . detectPlugin = function ( substrs ) {
444- var plugins = navigator . plugins ,
445- plugin , haystack , pluginFoundText ;
446- for ( j = plugins . length - 1 ; j >= 0 ; j -- ) {
447- plugin = plugins [ j ] ;
448- haystack = plugin . name + plugin . description ;
449- pluginFoundText = 0 ;
450- for ( k = substrs . length ; k >= 0 ; k -- ) {
451- if ( haystack . indexOf ( substrs [ k ] ) !== - 1 ) {
452- pluginFoundText += 1 ;
453- }
454- }
455- if ( pluginFoundText === substrs . length ) {
456- return true ;
457- }
458- }
459- return false ;
460- } ;
461- that . detectObject = function ( progIds ) {
462- for ( j = progIds . length - 1 ; j >= 0 ; j -- ) {
463- try {
464- new ActiveXObject ( progIds [ j ] ) ;
465- } catch ( e ) {
466- // Ignore
467- }
468- }
469- return false ;
470- } ;
471488 for ( i = plugins2detect . length - 1 ; i >= 0 ; i -- ) {
472489 plugin2detect = plugins2detect [ i ] ;
473490 pluginFound = false ;
474491 if ( window . ActiveXObject ) {
475- pluginFound = that . detectObject ( plugin2detect . progIds ) ;
492+ pluginFound = detectObject ( plugin2detect . progIds ) ;
476493 } else if ( navigator . plugins ) {
477- pluginFound = that . detectPlugin ( plugin2detect . substrs ) ;
494+ pluginFound = detectPlugin ( plugin2detect . substrs ) ;
478495 }
479496 if ( pluginFound ) {
480497 browser . plugins . push ( plugin2detect . name ) ;
0 commit comments