1/** 2 * Creates and initialises the main Responsiville object. 3 * 4 * @class 5 * @extends Responsiville.Debug 6 * @extends Responsiville.Events 7 * 8 * @author Nevma, [email protected] 9 * @license Nevma Copyright (c) http://www.nevma.gr 10 * 11 * @fires Responsiville.Main#init 12 * 13 * @classdesc This is the main object of the Responsiville framework. The whole 14 * Responsiville framework depends on this object to function and so 15 * do all the plugins that belong to the framework as well. It 16 * contains core functions that handle the breakpoints and the 17 * responsiveness of the web page in development. 18 * 19 * @param {Object} options The initialisation options of the module. 20 * 21 * @property {Object} options The options that define the object 22 * behaviour. 23 * @property {boolean} options.debug Whether to print debug messages in 24 * the browser console. 25 * @property {boolean} options.debugUI Whether to show the debug panel at 26 * the edge of the screen. 27 * @property {string} options.debugPos Where to position the debug panel (br 28 * means bottom-right, tl means top-left 29 * and so on). 30 * @property {int} options.throttle Time delay to throttle expensive 31 * function calls as a result of 32 * repeated operations like the browser 33 * resize event. 34 * @property {boolean} options.slug A special codename for the instance 35 * of the element, to be used as a class 36 * on its container and as a key in 37 * arrays where it is grouped with other 38 * elements of its kind. 39 * @property {Array} options.breakpoints Array of extra breakpoints to include 40 * to the framework. Each breakpoint is 41 * an associative array like { name: 42 * 'small', width: 320, icon: 'uE800' }. 43 * One might need to add breakpoints to 44 * this array but they probably should 45 * not remove any beacuse this might 46 * break behaviour of other code that 47 * depends on them. 48 */ 49Responsiville.Main=function(options){if(!Responsiville.Main.instance){Responsiville.Main.instance=this}else{throw new Error('Responsiville instantiation error: the framework has already been initialised, new Responsiville.Main is a singleton.')} 50this.options={};this.options=jQuery.extend(this.options,Responsiville.Main.defaults,options);this.codeName='responsiville.main';this.width=0;this.height=0;this.$html=jQuery('html');this.$body=jQuery('body');this.$window=jQuery(window);if(this.options.slug==''){Responsiville.Main.elementsCounter=Responsiville.Main.elementsCounter!==undefined?++Responsiville.Main.elementsCounter:0;this.options.slug=this.codeName.replace('.','-')+'-'+Responsiville.Main.elementsCounter} 51this.adjustCallbacksCalled=!1;this.previousBreakpoint=null;this.currentBreakpoint=null;var toLog='\n'+' ____ _ _ ____\n'+' / __ \\___ _________ ____ ____ _____(_) __(_) / /__\n'+' / /_/ / _ \\/ ___/ __ \\/ __ \\/ __ \\/ ___/ / | / / / / / _ \\\n'+' / _, _/ __(__ ) /_/ / /_/ / / / (__ ) /| |/ / / / / __/\n'+'/_/ |_|\\___/____/ .___/\\____/_/ /_/____/_/ |___/_/_/_/\\___/\n'+' /_/\n'+' version '+Responsiville.VERSION+'\n\n';toLog+='breakpoints:\n';for(var k=0,length=this.options.breakpoints.length;k<length;k++){var breakpoint=this.options.breakpoints[k];toLog+=breakpoint.name+'\t'+breakpoint.width+'px'+(k<length-1?'\n':'')} 52this.log(toLog);this.$debugControls=null;this.$debugPerformance=null;this.$debugToggle=null;jQuery((function(){this.$html.addClass('responsiville-domcontentloaded')}).bind(this));this.$window.on('load',(function(){this.$html.addClass('responsiville-load')}).bind(this));this.calculateDimensions();this.adjust()};Responsiville.extend(Responsiville.Main,Responsiville.Debug.Extensions);Responsiville.extend(Responsiville.Main,Responsiville.Events);Responsiville.Main.AUTO_RUN=typeof RESPONSIVILLE_AUTO_INIT!=='undefined'?RESPONSIVILLE_AUTO_INIT:!0;Responsiville.Main.defaults={debug:!1,debugUI:!1,debugPos:'br',throttle:100,slug:'',breakpoints:[{name:'small',width:320,icon:'\uE800'},{name:'mobile',width:599,icon:'\uE801'},{name:'tablet',width:1023,icon:'\uE802'},{name:'laptop',width:1279,icon:'\uE803'},{name:'desktop',width:1439,icon:'\uE804'},{name:'large',width:1679,icon:'\uE804'},{name:'xlarge',width:99999,icon:'\uE804'}]};Responsiville.Main.autoRun=function(){var responsiville=new Responsiville.Main({debug:RESPONSIVILLE_DEBUG,debugUI:RESPONSIVILLE_DEBUG});jQuery((function(){this.init()}).bind(responsiville))};Responsiville.Main.getInstance=function(){return Responsiville.Main.instance};Responsiville.Main.prototype.init=function(){var bodyElementNotYetCreated=typeof this.$body==='undefined'||this.$body.length===0;if(bodyElementNotYetCreated){this.$body=jQuery('body');this.$document=jQuery(document)} 53this.on('init',function(){Responsiville.Debug.setupDebug()}) 54this.$window.on('resize',Responsiville.debounce(this.windowResize,this.options.throttle,this));this.fireEvent('init');this.runBreakpointChangeCallbacks();this.log('framework Responsiville has initialised')};Responsiville.Main.prototype.registerBreakpoint=function(breakpointName,breakpointWidth){var index=0;for(var k=0,length=this.options.breakpoints.length;k<length;k++){var breakpoint=this.options.breakpoints[k];if(breakpointWidth<breakpoint.width){index=k;break}} 55this.options.breakpoints.splice(k,0,{name:breakpointName,width:breakpointWidth});this.dir('breakpoint registered:',{name:breakpointName,width:breakpointWidth},'breakpoints:',this.options.breakpoints)};Responsiville.Main.prototype.deregisterBreakpoint=function(breakpointName){for(var k=0,length=this.options.breakpoints.length;k<length;k++){var breakpoint=this.options.breakpoints[k];if(breakpointName==breakpoint.name){this.options.breakpoints.splice(k+1,1);break}} 56this.dir('breakpoint deregistered: '+breakpointName,'new breakpoints: ',this.options.breakpoints)};Responsiville.Main.prototype.adjust=function(){this.log('adjusting to viewport');var removeClasses='';var k;var breakpoint;for(k=this.options.breakpoints.length-1;k>=0;k--){breakpoint=this.options.breakpoints[k];removeClasses+=breakpoint.name+' '} 57var addClasses='';for(k=0,length=this.options.breakpoints.length;k<length;k++){breakpoint=this.options.breakpoints[k];if(this.width>breakpoint.width){addClasses+=breakpoint.name+' '}else{break}} 58if(this.width<=breakpoint.width){addClasses+=breakpoint.name+' '} 59if(this.isDevice()){addClasses+='device '}else{removeClasses+='device '} 60if(this.width>=this.height){addClasses+='landscape ';removeClasses+='portrait '}else{addClasses+='portrait ';removeClasses+='landscape '} 61if(this.isDevice()){addClasses+='device ';removeClasses+='pc '}else{addClasses+='pc ';removeClasses+='device '} 62this.$html.removeClass(removeClasses);this.$html.addClass(addClasses);var firstRun=!1;if(!this.currentBreakpoint){firstRun=!0;this.currentBreakpoint=this.calculateCurrentBreakpoint()} 63var newBreakpoint=this.calculateCurrentBreakpoint();var oldBreakpoint=this.currentBreakpoint;var breakpointChanged=firstRun||oldBreakpoint.name!=newBreakpoint.name||!this.adjustCallbacksCalled;if(breakpointChanged){this.previousBreakpoint=this.currentBreakpoint;this.currentBreakpoint=newBreakpoint} 64if(breakpointChanged){this.runBreakpointChangeCallbacks();this.adjustCallbacksCalled=!0;this.fireEvent('change');this.fireEvent('change.breakpoint')} 65this.log('window resized','window width: '+this.width,(breakpointChanged?'breakpoint changed from: '+this.previousBreakpoint.name+'':'no breakpoint change'),'current breakpoint: '+this.currentBreakpoint.name)};Responsiville.Main.prototype.runBreakpointChangeCallbacks=function(){this.fireEvent('leave.'+this.previousBreakpoint.name);this.fireEvent('enter.'+this.currentBreakpoint.name)};Responsiville.Main.prototype.calculateDimensions=function(){this.width=window.innerWidth;this.height=window.innerHeight};Responsiville.Main.prototype.windowResize=function(){this.calculateDimensions();this.adjust();this.fireEvent('resize')};Responsiville.Main.prototype.isHiDPI=function(){if(window.devicePixelRatio>1){return!0} 66var mediaQuery='(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)';if(window.matchMedia&&window.matchMedia(mediaQuery).matches){return!0} 67return!1};Responsiville.Main.prototype.isDevice=function(){var deviceAgentQuery=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;return deviceAgentQuery.test(navigator.userAgent)};Responsiville.Main.prototype.compareTo=function(testBreakpointName){var testBreakpointIndex=0;var currentBreakpointIndex=0;for(var k=0,length=this.options.breakpoints.length;k<length;k++){var breakpoint=this.options.breakpoints[k];if(breakpoint.name==this.currentBreakpoint.name){currentBreakpointIndex=k} 68if(breakpoint.name==testBreakpointName){testBreakpointIndex=k}} 69return currentBreakpointIndex-testBreakpointIndex};Responsiville.Main.prototype.is=function(breakpointNames){var breakpointNamesArray=Responsiville.splitAndTrim(breakpointNames);for(var k=0,length=breakpointNamesArray.length;k<length;k++){var testBreakpointName=breakpointNamesArray[k];if(this.compareTo(testBreakpointName)){return!0}} 70return!1};Responsiville.Main.prototype.isSmallerThan=function(testBreakpointName){return this.compareTo(testBreakpointName)<0};Responsiville.Main.prototype.isEqualOrSmallerThan=function(testBreakpointName){return this.compareTo(testBreakpointName)<=0};Responsiville.Main.prototype.isBiggerThan=function(testBreakpointName){return this.compareTo(testBreakpointName)>0};Responsiville.Main.prototype.isEqualOrBiggerThan=function(testBreakpointName){return this.compareTo(testBreakpointName)>=0};Responsiville.Main.prototype.hasGrown=function(){if(this.currentBreakpoint.name==this.previousBreakpoint.name){return!1} 71var currentBreakpointWidth=0;var previousBreakpointWidth=0;for(var k=0,length=this.options.breakpoints.length;k<length;k++){var breakpoint=this.options.breakpoints[k];if(this.currentBreakpoint.name==breakpoint.name){currentBreakpointWidth=breakpoint.width}else if(this.previousBreakpoint.name==breakpoint.name){previousBreakpointWidth=breakpoint.width}} 72if(previousBreakpointWidth===0){return!0} 73return currentBreakpointWidth>previousBreakpointWidth};Responsiville.Main.prototype.calculateCurrentBreakpoint=function(){var tempBreakpoint;for(var k=0,length=this.options.breakpoints.length;k<length;k++){var breakpoint=this.options.breakpoints[k];if(this.width<=breakpoint.width){tempBreakpoint=breakpoint;break}} 74return tempBreakpoint};Responsiville.Main.prototype.getProperty=function(name){var localStorage=window.localStorage;var settings=localStorage.getItem(this.codeName);if(settings){settings=JSON.parse(settings);return settings[name]}};Responsiville.Main.prototype.setProperty=function(name,value){var localStorage=window.localStorage;var settings=localStorage.getItem(this.codeName);if(!settings){settings={}}else{settings=JSON.parse(settings)} 75settings[name]=value;localStorage.setItem(this.codeName,JSON.stringify(settings))};Responsiville.Main.prototype.printBreakpoints=function(){var debug=this.options.debug;this.options.debug=!0;
75var toLog=['Breakpoints'];for(var k=0,length=this.options.breakpoints.length;k<length;k++){var breakpoint=this.options.breakpoints[k];toLog.push(breakpoint.name+' - '+breakpoint.width)} 76this.log(toLog.join('\n'));this.options.debug=debug} 77;
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.