Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Last active December 19, 2016 15:07
Show Gist options
  • Save tomhodgins/bfca1b640d10427072c1 to your computer and use it in GitHub Desktop.
Save tomhodgins/bfca1b640d10427072c1 to your computer and use it in GitHub Desktop.
Atom snippets file! This is a collection of my most often used lines of code, as well as a few other examples I want to have ready at a moment's notice. These snippets focus on building HTML from scratch, linking in good web fonts, and setting up responsive styles for your pages.
# The Mad CSScientist's Snippets
# written by Tommy Hodgins: https://gist.github.com/tomhodgins/bfca1b640d10427072c1
#
# This is a collection of my most often used lines of code, as well as
# a few other examples I want to have ready at a moment's notice.
# These snippets focus on building HTML from scratch, linking in
# good web fonts, and setting up responsive styles for your pages.
#
# An example single-line snippet:
#
# 'Snippet Name':
# 'prefix': 'trigger'
# 'body': 'code to be inserted'
#
# An example multi-line snippet:
#
# 'Snippet Name':
# 'prefix': 'trigger'
# 'body': """
# code to be inserted
# """
#
'.text':
'Five lines of Lorem Ipsum':
'prefix': 'lorem'
'body': """
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Donec fermentum augue sem. Sed eleifend, erat a venenatis euismod, felis arcu tempus quam, imperdiet vestibulum ipsum orci eget dui. Praesent semper commodo urna, vitae sodales tellus aliquet a. Suspendisse varius condimentum enim id ornare. Mauris porttitor interdum sem et convallis. Cras dictum, diam ut feugiat bibendum, tortor tellus aliquet massa, pulvinar posuere tortor enim vitae turpis. Sed ultrices augue turpis, et pellentesque est sagittis in. Aliquam ac quam nibh. Quisque et fringilla dolor. Nullam massa ipsum, semper convallis purus sit amet, mollis interdum leo. Vivamus ut tempor nunc.
Nunc finibus lacus eget orci pellentesque lacinia. Nullam vitae dui facilisis, venenatis velit vehicula, fringilla eros. Vestibulum interdum nulla eu nunc convallis rhoncus. Sed eget sapien magna. Nam quis finibus velit, eu dictum mauris. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nam et libero quis velit consectetur lobortis. Donec a libero vel mauris faucibus porta.
Vestibulum malesuada pulvinar dolor vitae eleifend. Nunc maximus quam et tempus tempus. Cras tempus nibh quam, vitae sodales nisi egestas laoreet. Aenean sed tincidunt ex. Pellentesque blandit pharetra arcu, non volutpat nunc dapibus ut. Suspendisse convallis at nunc sit amet euismod. Suspendisse non sem elit. Ut pharetra enim in purus porttitor facilisis mollis ut nisl. Sed varius semper sollicitudin. Nullam aliquam sodales pulvinar. Nam tellus sapien, hendrerit ac mollis eget, rhoncus a diam.
Nunc eu lorem vitae nisl laoreet imperdiet. Etiam nunc velit, auctor ut felis id, vestibulum efficitur quam. Pellentesque commodo sit amet velit ut accumsan. Ut malesuada lacinia arcu, volutpat accumsan lorem rutrum ac. Integer tincidunt dui a neque accumsan, ut hendrerit leo cursus. Nulla sed mollis tortor, vitae luctus odio. Praesent gravida sed mauris ac laoreet. Pellentesque a lorem purus. Ut tincidunt ante ac nibh maximus, et suscipit risus sagittis. Nullam rhoncus augue eu semper ultrices. Quisque nec mollis ex. Suspendisse potenti.
"""
'HTML Boilerplate':
'prefix': 'html'
'body': """
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>$1</title>
<style>$2</style>
</head>
<body>
$3
<script>$4</script>
</body>
</html>
"""
'Basic HTML Template':
'prefix': 'basichtml'
'body': """
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1">
<title>$1</title>
<link href=http://fonts.googleapis.com/css?family=Fira+Sans:300,400,500,700,300italic,400italic,500italic,700italic rel=stylesheet>
<link href=http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700,900,200italic,300italic,400italic,600italic,700italic,900italic rel=stylesheet>
<link href=http://staticresource.com/basic.css rel=stylesheet>
<style>$2</style>
</head>
<body>
$3
<script>$4</script>
<!--[if lt IE 9]><script src=http://elementqueries.com/EQCSS-polyfills.js></script><![endif]-->
<script src=http://elementqueries.com/EQCSS.js></script>
</body>
</html>
"""
'Mobile-friendly Meta Tags':
'prefix': 'meta'
'body': """
<meta name=apple-mobile-web-app-capable content=no>
<meta name=apple-mobile-web-app-status-bar-style content=black>
<meta name=format-detection content="telephone=no">
<meta name=viewport content="width=device-width, initial-scale=1">
"""
'Data Buttons':
'prefix': 'data-buttons'
'body': '<link href=http://staticresource.com/data-buttons.css rel=stylesheet>'
'Basic CSS Stylesheet':
'prefix': 'basic'
'body': '<link href="http://staticresource.com/basic.css rel=stylesheet>'
'EQCSS Demo':
'prefix': 'eqcss-demo'
'body': '<script src=http://staticresource.com/eqcss-demo.js></script>'
'Green Lock Favicon':
'prefix': 'lock'
'body': '<link href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABwElEQVR42pWST0sbURTFr7hzET+CmwouxA+gUvAPbbNTFIqCtH4D0Y2ubMAUIRlK0NZKiJjEjdqCKEZBFD+BQgJOdKAjCtKmghOVmlCa0znPOCbGEXzw49x377lnFm/k4TEMeRGLxRAIBODz+Yiq2Ts6knp56ui6NIRCIaRSKWQyGViWRVirHmf0uAaEw2FlNE2TXy6DvWQyCXpcA/x+PwzDUAvZrHhKZ+xxRo9rAE26roNaKEiVy+zpgHQ6DepzZvKvINUTG6K9j77BLV6qw2DMS5z7REK0gr3jBOT+Ss27eS8O8jvYz61hL7eK/bzSO9i3WbU926D3xt5xAq7z4hmYe43dPxEkroNYvwo6qlB3jT3lGYi8AnecgKu81PbPdmLL+ooV6+MtF35bFWW9rews6OVOaYCnb6YDifMpLP0aL/LBgffFn6pve6bR96W9IqD27ec2rJxpiJ+MKhZOxqhFnFp56K0I6A29xLI5iYgxXGSkoqYuH0+C3oqAnk+t2DyN4LsZxLcfAVfooZc7Za8wvCDRLq0ZXcFmdFM1ass9JfehuMTLXoFvenYpdca5NB7+lqbDjA31Eeih9+4/+A+4dfTbehtGHQAAAABJRU5ErkJggg==" rel="shortcut icon">'
'Data Module':
'prefix': 'data-module'
'body': """
<section data-module>
</section>
<style>
[data-module],
[data-module]:before,
[data-module]:after,
[data-module] *,
[data-module] *:before,
[data-module] *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-kerning: auto;
font-family: inherit;
margin: 0;
padding: 0;
}
[data-module],
[data-module] * {
line-height: 1;
font-size: 10pt;
font-family: 'Open Sans', 'Source Sans Pro', Roboto, 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', 'Myriad Pro', 'Segoe UI', Myriad, Helvetica, 'Lucida Grande', 'DejaVu Sans Condensed', 'Liberation Sans', 'Nimbus Sans L', Tahoma, Geneva, Arial, sans-serif;
}
</style>
"""
'Wishlist (Open Sans)':
'prefix': 'wishlist'
'body': 'font-family: "Open Sans", "Source Sans Pro", Roboto, "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", "Myriad Pro", "Segoe UI", Myriad, Helvetica, "Lucida Grande", "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, Arial, sans-serif;'
'Wishlist Alt (Source Sans Pro)':
'prefix': 'wishlist'
'body': 'font-family: "Source Sans Pro", "Open Sans", Roboto, "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", "Myriad Pro", "Segoe UI", Myriad, Helvetica, "Lucida Grande", "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, Arial, sans-serif;'
'Serif Font Stack':
'prefix': 'serif'
'body': 'font-family: "PT Serif", Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif;'
'Monospace Font Stack':
'prefix': 'monospace'
'body': 'font-family: "Source Code Pro", Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace;'
'Open Sans Font':
'prefix': 'open-sans'
'body': '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel=stylesheet type=text/css>'
'Source Sans Pro Font':
'prefix': 'source-sans'
'body': '<link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700,900,200italic,300italic,400italic,600italic,700italic,900italic" rel=stylesheet type=text/css>'
'Source Code Pro Font':
'prefix': 'source-code'
'body': '<link href="//fonts.googleapis.com/css?family=Source+Code+Pro:300,400,500,600,700,900" rel=stylesheet type=text/css>'
'Fira Sans Font':
'prefix': 'fira'
'body': '<link href="//fonts.googleapis.com/css?family=Fira+Sans:300,400,500,700,300italic,400italic,500italic,700italic" rel=stylesheet type=text/css>'
'FontAwesome Font':
'prefix': 'fontawesome'
'body': '<link href=//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css rel=stylesheet type=text/css>'
'Ionicons Font':
'prefix': 'ionicons'
'body': '<link href=//cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css rel=stylesheet>'
'PT Serif Font':
'prefix': 'pt-serif'
'body': '<link href=//fonts.googleapis.com/css?family=PT+Serif:400,700,400italic,700italic rel=stylesheet>'
'Playfair Font':
'prefix': 'playfair'
'body': '<link href=fonts.googleapis.com/css?family=Playfair+Display:400,400italic,700,700italic,900,900italic rel=stylesheet>'
'Roboto Font':
'prefix': 'roboto'
'body': '<link href=//fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic,500,500italic,700,700italic,900,900italic rel=stylesheet>'
'Permissive Wildcard':
'prefix': 'wildcard'
'body': """
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-kerning: auto;
}
"""
'Css Preset':
'prefix': 'preset'
'body': """
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-kerning: auto;
}
html {
font-size: 10pt;
line-height: 1.4;
font-weight: 400;
font-family: 'Open Sans', 'Source Sans Pro', Roboto, 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', 'Myriad Pro', 'Segoe UI', Myriad, Helvetica, 'Lucida Grande', 'DejaVu Sans Condensed', 'Liberation Sans', 'Nimbus Sans L', Tahoma, Geneva, Arial, sans-serif;
-webkit-text-size-adjust: 100%;
}
body {
margin: 0;
}
q:before {content: '\\201c'}
q:after {content: '\\201d'}
q q:before {content: '\\2018'}
q q:after {content: '\\2019'}
"""
'HTML Text Size':
'prefix': 'text-size'
'body': """
html {
-webkit-text-size-adjust: 100%;
}
"""
'Box Sizing':
'prefix': 'box-sizing'
'body': """
-webkit-box-sizing: border-box;
-moz-box-size: border-box;
box-sizing: border-box;
"""
'Placeholder Text Color':
'prefix': 'placeholder'
'body': """
::-webkit-input-placeholder {
color: rgba(0,0,0,.5);
}
:-moz-placeholder {
color: rgba(0,0,0,.5);
}
::-moz-placeholder {
color: rgba(0,0,0,.5);
}
:-ms-input-placeholder {
color: rgba(0,0,0,.5);
}
::-ms-input-placeholder {
color: rgba(0,0,0,.5);
}
:placeholder-shown {
color: rgba(0,0,0,.5);
}
"""
'MS Expand for Select Boxes':
'prefix': 'expand'
'body': """
select::-ms-expand {
display: none;
}
"""
'CSS Image Floats':
'prefix': 'float'
'body': """
[class*="float-"] {
display: block;
width: auto;
max-width: 100%;
margin: 0 auto;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
cursor: default;
pointer-events: none;
}
@media (min-width: 500px) {
.float-left {
float: left;
margin: 0 .5em .5em 0;
max-width: 50%;
}
.float-right {
float: right;
margin: 0 0 .5em .5em;
max-width: 50%;
}
}
"""
'Background Cover':
'prefix': 'cover'
'body': """
background: url('../img/bg.jpg$1') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
"""
'Remove Tap Delay':
'prefix': 'touch'
'body': 'touch-action: manipulation;'
'Tap Highlight Color':
'prefix': 'highlight'
'body': '-webkit-tap-highlight-color: #f60 !important;'
'User Select':
'prefix': 'user-select'
'body': """
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
cursor: default;
"""
'Pretty Quotes':
'prefix': 'quotes'
'body': """
q:before { content: '“'}
q:after { content: '”'}
q q:before { content: '‘'}
q q:after { content: '’'}
"""
'Clear :after':
'prefix': 'after'
'body': """
$1:after {
content: '';
display: block;
clear: both;
}
"""
'Firefox-only Styles':
'prefix': 'firefox'
'body': """
@-moz-document url-prefix() {
div {
color: red;
}
}
"""
'CSS Mobile Breakpoints':
'prefix': 'breakpoints'
'body': """
@media (min-width: 481px) {
}
@media (min-width: 769px) {
}
"""
'EQCSS Mobile Breakpoints':
'prefix': 'eqcss-breakpoints'
'body': """
@element 'html' {
}
@element 'html' and (min-width: 481px) {
}
@element 'html' and (min-width: 769px) {
}
"""
'Print the Date with JS':
'prefix': 'date'
'body': '<script>document.write(new Date().getFullYear())</script>'
'EQCSS Embed':
'prefix': 'eqcss'
'body': """
<!--[if lt IE 9]><script src=http://elementqueries.com/EQCSS-polyfills.js></script><![endif]-->
<script src=http://elementqueries.com/EQCSS.js></script>
"""
'EQCSS Minified Inline':
'prefix': 'eqcss-min'
'body': """
/*EQCSSv1.1.0*/EQCSS={data:[],load:function(){for(var a=document.querySelectorAll("style"),c=0;c<a.length;c++)null===a[c].getAttribute("data-eqcss-read")&&(a[c].setAttribute("data-eqcss-read","true"),EQCSS.parse(a[c].innerHTML),EQCSS.apply());a=document.querySelectorAll("script");for(c=0;c<a.length;c++)null===a[c].getAttribute("data-eqcss-read")&&"text/eqcss"===a[c].getAttribute("type")&&(a[c].src?function(){var b=new XMLHttpRequest;b.open("GET",a[c].src,!0);b.send(null);b.onload=function(){EQCSS.parse(b.responseText);
EQCSS.apply()}}():(EQCSS.parse(a[c].innerHTML),EQCSS.apply()),a[c].setAttribute("data-eqcss-read","true"));a=document.querySelectorAll("link");for(c=0;c<a.length;c++)null===a[c].getAttribute("data-eqcss-read")&&"stylesheet"==a[c].getAttribute("rel")&&(a[c].href&&function(){var b=new XMLHttpRequest;b.open("GET",a[c].href,!0);b.send(null);b.onload=function(){EQCSS.parse(b.responseText);EQCSS.apply()}}(),a[c].setAttribute("data-eqcss-read","true"))},parse:function(a){a=a.replace(/\\s+/g," ");a=a.replace(/\\/\\*[\\w\\W]*?\\*\\//g,
"");a=a.replace(/@element/g,"\\n@element");a=a.replace(/(@element.*?\\{([^}]*?\\{[^}]*?\\}[^}]*?)*\\}).*/g,"$1");a.replace(/(@element.*(?!@element))/g,function(a,b){dataEntry={};b.replace(/@element ?["']([^"']*)["']/g,function(a,b){dataEntry.g=b});dataEntry.a=[];b.replace(/and ?\\( ?([^:]*) ?: ?([^)]*) ?\\)/g,function(a,b,c){a=null;a=c.replace(/^\\d+(\\D+)$/,"$1");a==c&&(a=null);c=c.replace(/^(\\d+)\\D+$/,"$1");dataEntry.a.push({measure:b,value:c,b:a})});b.replace(/{(.*)}/g,function(a,b){dataEntry.style=b});
EQCSS.data.push(dataEntry)})},apply:function(){var a,c,b,f,m,l,n,d,e,h,k;for(a=0;a<EQCSS.data.length;a++)for(f=document.querySelectorAll(EQCSS.data[a].g),c=0;c<f.length;c++){m="data-eqcss-"+a+"-"+c;f[c].setAttribute(m,"");n="data-eqcss-"+a+"-"+c+"-parent";f[c]!=document.documentElement&&f[c].parentNode.setAttribute(n,"");element_guid_prev="data-eqcss-"+a+"-"+c+"-prev";f[c].previousElementSibling&&f[c].previousElementSibling.setAttribute(element_guid_prev,"");element_guid_next="data-eqcss-"+a+"-"+
c+"-next";f[c].nextElementSibling&&f[c].nextElementSibling.setAttribute(element_guid_next,"");l=document.querySelector("#"+m);l||(l=document.createElement("STYLE"),l.id=m,l.setAttribute("data-eqcss-read","true"),document.querySelector("head").appendChild(l));l=document.querySelector("#"+m);h=!0;b=0;a:for(;b<EQCSS.data[a].a.length;b++){e=window.getComputedStyle(f[c],null);k=null;f[c]!=document.documentElement&&(k=window.getComputedStyle(f[c].parentNode,null));d=!1;if("vw"===EQCSS.data[a].a[b].b){d=
!0;var g=parseInt(EQCSS.data[a].a[b].value);EQCSS.data[a].a[b].c=g*window.innerWidth/100}else if("vh"===EQCSS.data[a].a[b].b)d=!0,g=parseInt(EQCSS.data[a].a[b].value),EQCSS.data[a].a[b].c=g*window.innerHeight/100;else if("vmin"===EQCSS.data[a].a[b].b)d=!0,g=parseInt(EQCSS.data[a].a[b].value),EQCSS.data[a].a[b].c=g*Math.min(window.innerWidth,window.innerHeight)/100;else if("vmax"===EQCSS.data[a].a[b].b)d=!0,g=parseInt(EQCSS.data[a].a[b].value),EQCSS.data[a].a[b].c=g*Math.max(window.innerWidth,window.innerHeight)/
100;else if(null!=EQCSS.data[a].a[b].b&&"px"!=EQCSS.data[a].a[b].b&&"%"!=EQCSS.data[a].a[b].b){g=document.createElement("DIV");g.style.visibility="hidden";g.style.border="1px solid red";g.style.width=EQCSS.data[a].a[b].value+EQCSS.data[a].a[b].b;var p=f[c];f[c]!=document.documentElement&&(p=f[c].parentNode);p.appendChild(g);EQCSS.data[a].a[b].value=parseInt(window.getComputedStyle(g,null).getPropertyValue("width"));EQCSS.data[a].a[b].b="px";p.removeChild(g)}g=d?EQCSS.data[a].a[b].c:parseInt(EQCSS.data[a].a[b].value);
switch(EQCSS.data[a].a[b].measure){case "min-width":if(1==d||"px"==EQCSS.data[a].a[b].b)if(d=parseInt(e.getPropertyValue("width")),!(d>=g)){h=!1;break a}if("%"==EQCSS.data[a].a[b].b&&(d=parseInt(e.getPropertyValue("width")),e=parseInt(k.getPropertyValue("width")),!(e/d<=100/g))){h=!1;break a}break;case "max-width":if(1==d||"px"==EQCSS.data[a].a[b].b)if(d=parseInt(e.getPropertyValue("width")),!(d<=g)){h=!1;break a}if("%"==EQCSS.data[a].a[b].b&&(d=parseInt(e.getPropertyValue("width")),e=parseInt(k.getPropertyValue("width")),
!(e/d>=100/g))){h=!1;break a}break;case "min-height":if(1==d||"px"==EQCSS.data[a].a[b].b)if(d=parseInt(e.getPropertyValue("height")),!(d>=g)){h=!1;break a}if("%"==EQCSS.data[a].a[b].b&&(d=parseInt(e.getPropertyValue("height")),e=parseInt(k.getPropertyValue("height")),!(e/d<=100/g))){h=!1;break a}break;case "max-height":if(1==d||"px"==EQCSS.data[a].a[b].b)if(d=parseInt(e.getPropertyValue("height")),!(d<=g)){h=!1;break a}if("%"==EQCSS.data[a].a[b].b&&(d=parseInt(e.getPropertyValue("height")),e=parseInt(k.getPropertyValue("height")),
!(e/d>=100/g))){h=!1;break a}break;case "min-scroll-x":k=f[c].scrollLeft;if(1==d||"px"==EQCSS.data[a].a[b].b){if(!(k>=g)){h=!1;break a}}else if("%"==EQCSS.data[a].a[b].b&&(d=f[c].scrollWidth,e=f[c]==document.documentElement||f[c]==document.body?window.innerWidth:parseInt(e.getPropertyValue("width")),!(k/(d-e)*100>=g))){h=!1;break a}break;case "min-scroll-y":k=f[c].scrollTop;if(1==d||"px"==EQCSS.data[a].a[b].b){if(!(k>=g)){h=!1;break a}}else if("%"==EQCSS.data[a].a[b].b&&(d=f[c].scrollHeight,e=f[c]==
document.documentElement||f[c]==document.body?window.innerHeight:parseInt(e.getPropertyValue("height")),!(k/(d-e)*100>=g))){h=!1;break a}break;case "max-scroll-x":k=f[c].scrollLeft;if(1==d||"px"==EQCSS.data[a].a[b].b){if(!(k<=g)){h=!1;break a}}else if("%"==EQCSS.data[a].a[b].b&&(d=f[c].scrollWidth,e=f[c]==document.documentElement||f[c]==document.body?window.innerWidth:parseInt(e.getPropertyValue("width")),!(k/(d-e)*100<=g))){h=!1;break a}break;case "max-scroll-y":k=f[c].scrollTop;if(1==d||"px"==EQCSS.data[a].a[b].b){if(!(k<=
g)){h=!1;break a}}else if("%"==EQCSS.data[a].a[b].b&&(d=f[c].scrollHeight,e=f[c]==document.documentElement||f[c]==document.body?window.innerHeight:parseInt(e.getPropertyValue("height")),!(k/(d-e)*100<=g))){h=!1;break a}break;case "min-characters":if(f[c].value){if(!(f[c].value.length>=g)){h=!1;break a}}else if(!(f[c].textContent.length>=g)){h=!1;break a}break;case "max-characters":if(f[c].value){if(!(f[c].value.length<=g)){h=!1;break a}}else if(!(f[c].textContent.length<=g)){h=!1;break a}break;case "min-children":if(!(f[c].children.length>=
g)){h=!1;break a}break;case "max-children":if(!(f[c].children.length<=g)){h=!1;break a}break;case "min-lines":d=parseInt(e.getPropertyValue("height"))-parseInt(e.getPropertyValue("border-top-width"))-parseInt(e.getPropertyValue("border-bottom-width"))-parseInt(e.getPropertyValue("padding-top"))-parseInt(e.getPropertyValue("padding-bottom"));e=parseInt(e.getPropertyValue("line-height"));if(!(d/e>=g)){h=!1;break a}break;case "max-lines":if(d=parseInt(e.getPropertyValue("height"))-parseInt(e.getPropertyValue("border-top-width"))-
parseInt(e.getPropertyValue("border-bottom-width"))-parseInt(e.getPropertyValue("padding-top"))-parseInt(e.getPropertyValue("padding-bottom")),e=parseInt(e.getPropertyValue("line-height")),!(d/e+1<=g)){h=!1;break a}}}if(!0===h){b=EQCSS.data[a].style;b=b.replace(/eval\\( *((".*?")|('.*?')) *\\)/g,function(a,b){var e=f[c],d="";try{with(e)d=eval(b.slice(1,-1))}catch(g){d=""}return d});b=b.replace(/\\$this/g,"["+m+"]");b=b.replace(/\\$parent/g,"["+n+"]");b=b.replace(/\\$prev/g,"["+element_guid_prev+"]");b=
b.replace(/\\$next/g,"["+element_guid_next+"]");b=b.replace(/\\$root/g,"html");try{l.innerHTML=b}catch(q){l.styleSheet.cssText=b}}else try{l.innerHTML=""}catch(q){l.styleSheet.cssText=""}}},f:function(a){function c(){try{n.doScroll("left")}catch(a){setTimeout(c,50);return}b("poll")}function b(c){if("readystatechange"!=c.type||"complete"==l.readyState)("load"==c.type?window:l)[h](k+c.type,b,!1),!f&&(f=!0)&&a.call(window,c.type||c)}var f=!1,m=!0,l=window.document,n=l.documentElement,d=!~navigator.userAgent.indexOf("MSIE 8"),
e=d?"addEventListener":"attachEvent",h=d?"removeEventListener":"detachEvent",k=d?"":"on";if("complete"==l.readyState)a.call(window,"lazy");else{if(!d&&n.doScroll){try{m=!window.frameElement}catch(g){}m&&c()}l[e](k+"DOMContentLoaded",b,!1);l[e](k+"readystatechange",b,!1);window[e](k+"load",b,!1)}}};EQCSS.f(function(){EQCSS.load();EQCSS.apply()});window.addEventListener("resize",function(){EQCSS.apply()});window.addEventListener("scroll",function(){EQCSS.apply()});
"""
'Load EQCSS if not loaded':
'prefix': 'eqcss-shy'
'body': """
(function() {
if (typeof EQCSS === 'undefined' && typeof EQCSS_loaded === 'undefined'){
var elementQueries = document.createElement('script')
elementQueries.src = 'http://elementqueries.com/EQCSS.js'
document.body.appendChild(elementQueries)
elementQueries.insertAdjacentHTML('beforebegin', '<!--[if lt IE 9]><script src="http://elementqueries.com/EQCSS-polyfills.js"></script><![endif]-->')
EQCSS_loaded = true
}
})();
"""
'Load EQCSS One-liner':
'prefix': 'eqcss-one'
'body': "if(typeof EQCSS==='undefined'&&typeof EQCSS_loaded==='undefined'){var eq=document.createElement('script');eq.src='http://elementqueries.com/EQCSS.js';document.body.appendChild(eq);eq.insertAdjacentHTML('beforebegin','<!--[if lt IE 9]><script src=http://elementqueries.com/EQCSS-polyfills.js></script><![endif]-->');EQCSS_loaded=true;};"
'Block Autofocus for Touchscreen Users':
'prefix': 'autofocus'
'body': """
// Block autofocus for touchscreen users
onload = function(){
if(('ontouchstart' in window)||(navigator.msMaxTouchPoints>0)){
var field = document.querySelectorAll('[autofocus]');
for(var i=0;i<field.length;i++) {
field[i].blur();
}
}
}
"""
'Days of the Week':
'prefix': 'days'
'body': """
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
"""
'Months of the Year':
'prefix': 'months'
'body': """
var months = ['January','February','March','April','May','June','July','August','September','October','November','December']
"""
'Numerals':
'prefix': 'numerals'
'body': """
var numerals = ['0','1','2','3','4','5','6','7','8','9']
"""
'Lowercase':
'prefix': 'lowercase'
'body': """
var lowercase = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
"""
'Uppercase':
'prefix': 'uppercase'
'body': """
var uppercase = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
"""
'Alphabet':
'prefix': 'alphabet'
'body': """
var alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
"""
'Alphanumeric':
'prefix': 'alphanumeric'
'body': """
var alphanumeric = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9']
"""
'Ascii':
'prefix': 'ascii'
'body': """
var ascii = [' ','!','"','#','$','%','&','\\'','(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\\\',']','^','_','`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','{','|','}','~']
"""
'Syntax Highlighting':
'prefix': 'syntax'
'body': """
<link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/solarized_dark.min.css" rel=stylesheet>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad()</script>
"""
'Print External URLs':
'prefix': 'print'
'body': """
@media print {
[href]:not([href^="#"]):after {
content: ' ('attr(href)') ';
}
}
"""
'Android Address Bar Color':
'prefix': 'theme'
'body': '<meta name="theme-color" content="#f60">'
'Meta Description and Keywords':
'prefix': 'seo'
'body': """
<meta name=description content="">
<meta name=keywords content="">
"""
'By ID':
'prefix': 'id'
'body': "document.getElementById('$1')"
'By Class':
'prefix': 'class'
'body': """
var el = document.getElementsByClassName('$1')
for (i=0; i<el.length; i++) {
el[i].$2
}
"""
'By Attribute':
'prefix': 'attr'
'body': """
var el = document.querySelectorAll('[$1]')
for (i=0; i<el.length; i++) {
el[i].$2
}
"""
'By Tag Name':
'prefix': 'tag'
'body': """
var el = document.getElementsByTagName('$1')
for (i=0; i<el.length; i++) {
el[i].$2
}
"""
'New JavaScript Plugin':
'prefix': 'plugin'
'body': """
var tag = document.querySelectorAll('[data-$1]')
for (i=0;i<tag.length;i++){
tag[i].setAttribute('data-$2',i)
// do stuff
}
function doMoreStuff(id){
var element = document.querySelector('["'+id+'"]')
// do stuff to or inside the selected element here
}
"""
'Add Inline Event Listener':
'prefix': 'event'
'body': "addEventListener('$1',function(e){})"
'Add Event Listener':
'prefix': 'listen'
'body': """
addEventListener('$1',function(e){
e.preventDefault()
})
"""
'JavaScript Keyboard Shortcuts':
'prefix': 'keypress'
'body': """
document.onkeypress = function(e){
e = e||window.event
e.preventDefault()
var charCode = (typeof e.which=='number')?e.which:e.keyCode;
charCode==27 && console.log('esc key') // esc key
charCode==13 && console.log('enter key') // enter key
console.log(charCode)
}
"""
'Simple JavaScript Gestures':
'prefix': 'swipe'
'body': """
var tol = 100,
swipe = {
x:[],
y:[],
track: function(e){
for (i=0; i<e.touches.length; i++){
swipe.x.push(e.touches[i].clientX)
swipe.y.push(e.touches[i].clientY)
}
},
calc: function(e){
var xTravel = swipe.x[swipe.x.length-1] - swipe.x[0],
yTravel = swipe.y[swipe.y.length-1] - swipe.y[0];
if (xTravel<tol && xTravel>-tol && yTravel<-tol){
console.log('Swiped Up')
}
if (xTravel<tol && xTravel>-tol && yTravel>tol){
console.log('Swiped Down')
}
if (yTravel<tol && yTravel>-tol && xTravel<-tol){
console.log('Swiped Left')
}
if (yTravel<tol && yTravel>-tol && xTravel>tol){
console.log('Swiped Right')
}
swipe.x = []
swipe.y = []
xTravel = yTravel = ''
}
}
window.addEventListener('touchstart',function(e){swipe.track(e)})
window.addEventListener('touchmove',function(e){swipe.track(e)})
window.addEventListener('touchend',function(e){swipe.calc(e)})
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment