1/* 2 Breakpoints.js 3 version 1.0 4 5 Creates handy events for your responsive design breakpoints 6 7 Copyright 2011 XOXCO, Inc 8 http://xoxco.com/ 9 10 Documentation for this plugin lives here: 11 http://xoxco.com/projects/code/breakpoints 12 13 Licensed under the MIT license: 14 http://www.opensource.org/licenses/mit-license.php 15 16*/ 17(function($) { 18 19 var lastSize = 0; 20 var interval = null; 21 22 $.fn.resetBreakpoints = function() { 23 $(window).unbind('resize'); 24 if (interval) { 25 clearInterval(interval); 26 } 27 lastSize = 0; 28 }; 29 30 $.fn.setBreakpoints = function(settings) { 31 var options = jQuery.extend({ 32 distinct: true, 33 breakpoints: new Array(320,480,768,1024) 34 },settings); 35 36 var fireBreakpoints = function() { 37 38 var w = $(window).width(); 39 var done = false; 40 41 for (var bp in options.breakpoints.sort(function(a,b) { return (b-a) })) { 42 43 // fire onEnter when a browser expands into a new breakpoint 44 // if in distinct mode, remove all other breakpoints first. 45 if (!done && w >= options.breakpoints[bp] && lastSize < options.breakpoints[bp]) { 46 if (options.distinct) { 47 for (var x in options.breakpoints.sort(function(a,b) { return (b-a) })) { 48 if ($('body').hasClass('breakpoint-' + options.breakpoints[x])) { 49 $('body').removeClass('breakpoint-' + options.breakpoints[x]); 50 $(window).trigger('exitBreakpoint' + options.breakpoints[x]); 51 } 52 } 53 done = true; 54 } 55 $('body').addClass('breakpoint-' + options.breakpoints[bp]); 56 $(window).trigger('enterBreakpoint' + options.breakpoints[bp]); 57 58 } 59 60 // fire onExit when browser contracts out of a larger breakpoint 61 if (w < options.breakpoints[bp] && lastSize >= options.breakpoints[bp]) { 62 $('body').removeClass('breakpoint-' + options.breakpoints[bp]); 63 $(window).trigger('exitBreakpoint' + options.breakpoints[bp]); 64 65 } 66 67 // if in distinct mode, fire onEnter when browser contracts into a smaller breakpoint 68 if ( 69 options.distinct && // only one breakpoint at a time 70 w >= options.breakpoints[bp] && // and we are in this one 71 w < options.breakpoints[bp-1] && // and smaller than the bigger one 72 lastSize > w && // and we contracted 73 lastSize >0 && // and this is not the first time 74 !$('body').hasClass('breakpoint-' + options.breakpoints[bp]) // and we aren't already in this breakpoint 75 ) { 76 $('body').addClass('breakpoint-' + options.breakpoints[bp]); 77 $(window).trigger('enterBreakpoint' + options.breakpoints[bp]); 78 79 } 80 } 81 82 // set up for next call 83 if (lastSize != w) { 84 lastSize = w; 85 } 86 }; 87 88 // fire breakpoints checking only when a window size changes 89 $(window).resize(fireBreakpoints); 90 window.g1_breakpoints_api = { 91 'fireBreakpoints': fireBreakpoints 92 }; 93 }; 94})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.