/** * User: TimAnderson * Date: 12/1/15 * Time: 1:25 PM *//** * Test responsive screen sizes by creating a visible-[screen]-block div. Passing multiple screen sizes will return true if one of them is true. * @requires jQuery * @param {(...string|array)} className - The screen(s) to check against. In bootstrap, these are 'xs', 'sm', 'md', 'lg'. * @returns {Boolean} */$.media_is=function(className){varclass_string='',$item,visible;varstringcheck=function(item){varallowed=['xs','sm','md','lg'];if(allowed.indexOf(item)===-1){console.warn('$.media_is: The string you passed ("'+item+'") does not match one of ['+allowed.join(',')+'], which are the bootstrap default screen sizes. Unless you have created a .visible-'+item+'-block class in your styles, this will likely return a false positive.');console.trace();}};if(classNameinstanceofArray){className.forEach(function(el,index){if(typeofel==='string'){stringcheck(el);class_string+='visible-'+el.trim()+'-block ';}else{console.error('$.media_is: Index '+index+' of your array must be a string. You passed in '+typeofel+'.');}})}elseif(arguments.length>1){[].slice.call(arguments).forEach(function(el){if(typeofel==='string'){stringcheck(el);class_string+='visible-'+el.trim()+'-block ';}else{console.error('$.media_is: '+[].slice.call(arguments).join(', ')+' cannot be used in this method because it is of type '+typeofclassName);returnfalse;}});}elseif(typeofclassName==='string'){stringcheck(className);class_string+='visible-'+className+'-block';}else{console.error('$.media_is: '+[].slice.call(arguments).join(', ')+' cannot be used in this method because it is of type '+typeofclassName+'.\nYou may use a string only.');returnfalse;}$item=$('<div class="'+class_string+'"></div>');$('body').append($item);visible=($item.css('display')!='none');$item.remove();returnvisible;};
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.