Archive for the “Web Shots” Category

Count CSS Rules in Console

Posted on July 11th, 2013 by webninjataylor

In your console, type… var sheets = document.styleSheets; var rules = 0; for(i=0; i < sheets.length; i++){ if(sheets[i].cssRules !== null){ rules = rules + sheets[i].cssRules.length; } } console.log(‘Rules = ‘+rules); IE limits rules to 4,095.

Trigger Event in Plain JavaScript

Posted on June 10th, 2013 by webninjataylor

var elem = document.getElementById(‘myForm’); var event = new Event(‘submit’); elem.dispatchEvent(event);

Data URI in CSS (IE8+)

Posted on June 6th, 2013 by webninjataylor

You don’t have to link to an external image file when using an <img> element in HTML, or declaring a background-image in CSS.  You can embed the image data directly into the document with data URIs. data:[<mime type>][;charset=<charset>][;base64],<encoded data> Resources Conversion Tool CSS Tricks: Data URIs Data URIs Explained

Tags:
Posted in Web ShotsComments Off on Data URI in CSS (IE8+)

CSS Justify Magic for RWD

Posted on June 5th, 2013 by webninjataylor

text-align: justify; works on any inline element. Fiddle Resources Text-align: Justify and RWD

PHP Reload Page on Browser Back

Posted on May 30th, 2013 by webninjataylor

Add this to your PHP file to allow the page to reload when the user clicks their browser’s back button; it’s very handy when navigating back-and-forth from a search results page… header(“Cache-Control: private, must-revalidate, max-age=0”); header(“Pragma: no-cache”); header(“Expires: Sat, 26 Jul 1997 05:00:00 GMT”); // A date in the past

Tags:
Posted in Web ShotsComments Off on PHP Reload Page on Browser Back

5 HTML5 Features you need to know

Posted on May 29th, 2013 by webninjataylor

DNS Prefetching to speed page loads <link rel=”dns-prefetch” href=”//fonts.googleapis.com”> Link Prefetching to speed subsequent page loads on your site <link rel=”prefetch” href=”http://daker.me/2013/05/hello-world.html” /> or for even faster loads use <link rel=”prerender” href=”http://daker.me/2013/05/hello-world.html” /> Download Attribute to force a file to download rather than going to that page …<a href=”download_pdf.php?id=15″ download=”myfile.pdf”>Download PDF</a> Regular Expressions to validate form fields with […]

CSS IE Hack

Posted on May 29th, 2013 by webninjataylor

top: 17px; /* For Non-IE */ top: 8px\9; /* For IE */

@font-face

Posted on May 29th, 2013 by webninjataylor

@font-face { font-family: ‘MyWebFont’; src: url(‘webfont.eot’); /* IE9 Compat Modes */ src: url(‘webfont.eot?#iefix’) format(’embedded-opentype’), /* IE6-IE8 */ url(‘webfont.woff’) format(‘woff’), /* Modern Browsers */ url(‘webfont.ttf’) format(‘truetype’), /* Safari, Android, iOS */ url(‘webfont.svg#svgFontName’) format(‘svg’); /* Legacy iOS */ }

Tags:
Posted in Web ShotsComments Off on @font-face

3D Graphics with WebGL

Posted on May 25th, 2013 by webninjataylor

The principal options for 3D objects are Canvas and WebGL WebGL provides a method to talk to the graphics card of the host computer directly so you can take advantage of its hardware acceleration WebGL is normally in JavaScript and can be quite challenging to pick up, but there are libraries like three.js to make […]

Tags:
Posted in Web ShotsComments Off on 3D Graphics with WebGL

Password Protect a Folder

Posted on May 23rd, 2013 by webninjataylor

Create .htaccess and .htpasswd files in the folder One username and password per line, separated by a colon Make sure to set the right privileges to the files so Apache can use them chmod 0644 .htaccess chmod 0644 .htpasswd .htaccess File AuthType Basic AuthName “restricted area” AuthUserFile /home6/path/to/the/directory/you/are/protecting/.htpasswd require valid-user .htpasswd File username:encryptedPassword Resources Password Generator

Tags:
Posted in Web ShotsComments Off on Password Protect a Folder

JavaScript Unit Testing

Posted on May 22nd, 2013 by webninjataylor

Integration tests are for how users interact with an app, and unit tests are for small modules of code QUnit is a framework for writing JavaScript unit tests Simple Implementation Page (tests.php) … <link rel=”stylesheet” href=”css/qunit-1.11.0.css”> … <div id=”qunit”></div> <div id=”qunit-fixture”></div> … <script type=”text/javascript” src=”js/qunit-1.11.0.js”></script> <script type=”text/javascript” src=”js/tests.js”></script> tests.js test(“hello test”, function(){ ok( 1 == “1”, […]

High DPI Images

Posted on May 22nd, 2013 by webninjataylor

Create images that are 2x the size they need to be at 72dpi and resize to 1x in the CSS via width and height (Easy High DPI Images). In the early days, computer displays had a pixel density of 72 or 96dpi (dots per inch). Displays gradually improved in pixel density, largely driven by the mobile […]

Using Dispatch Tables to Avoid Conditionals in JavaScript

Posted on May 21st, 2013 by webninjataylor

function processUserInput(command) { switch (command) { case “north”: movePlayer(“north”); break; case “east”: movePlayer(“east”); break; case “south”: movePlayer(“south”); break; case “west”: movePlayer(“west”); break; case “look”: describeLocation(); break; case “backpack”: showBackpack(); break; } } Can be turned into… var commandTable = { north: function() { movePlayer(“north”); }, east: function() { movePlayer(“east”); }, south: function() { movePlayer(“south”); }, […]

Tags:
Posted in Web ShotsComments Off on Using Dispatch Tables to Avoid Conditionals in JavaScript

jQuery Chaining and .fail()

Posted on May 17th, 2013 by webninjataylor

Examples of using .fail() method to handle errors via chaining… onSubmitEmailForm: function(e) { e.preventDefault(); if (this.isValid(this.$emailForm)) { $.ajax({ type: ‘POST’, url: this.$emailForm.attr(‘action’), data: this.$emailForm.serialize() }).done(_.bind(function(response) { this.$container.hide(); this.$(‘.email-success’).show(); PubSub.trigger(‘uotrack’, ‘UtilityBarShareEmail’); }, this)).fail(_.bind(function(response){ alert(“Your text did not match the image.”); }, this)); } }, $.get(“test.php”) .done(function(){ alert(“$.get succeeded”); }) .fail(function(){ alert(“$.get failed!”); }); Resources jQuery API

RWD Techniques

Posted on May 15th, 2013 by webninjataylor

box-sizing: border-box; will take padding into account so 100% width doesn’t spill off the page and 100px item with 10px padding stays at 100px instead of 120px…  The padding is counted inside the width… [NOTE: May need vendor prefixes and IE hack] % values for widths… target(px)/context(px) = result%) Media queries Resources http://www.youtube.com/watch?feature=player_embedded&v=wDdrI7N-mWM

HTML5 + CSS3: Figure Numbering

Posted on May 15th, 2013 by webninjataylor

<figure> <img alt=”” src=”path/to/your/image.jpg” /> <figcaption>Here is the legend for your image</figcaption> </figure> counter-reset which is used to initialize and reset one or several counters counter-increment which is used to increment one or several counters counter() is a valid value for ::before and ::after pseudo-elements, accepting a counter name as parameter in order to display […]

Tags: ,
Posted in Web ShotsComments Off on HTML5 + CSS3: Figure Numbering

JavaScript Callback Functions

Posted on May 14th, 2013 by webninjataylor

 Functions are objects A Function object contains a string which contains the Javascript code of the function For Javascript, the distinction between code and data is sometimes blurred One benefit of this function-as-object concept is that you can pass code to another function in the same way you would pass a regular variable or object […]

Responsive Menu Layout

Posted on May 14th, 2013 by webninjataylor

Define CSS breakpoints with media queries (ie. button for small width vs. full menu for wider) Hide button for wider, thus… The JS can react when the button is visible or not for appropriate device behaviors Resources Behavioral Breakpoints

Multi-device Web

Posted on May 14th, 2013 by webninjataylor

Things to consider when developing in today’s web landscape: Screen size Input types (keyboard, mouse, touch) Common postures/modes of use (ie. phone users mostly use just their thumb which warrants larger touch areas and single-column layout) Consider having content on sides of screen for tablets instead of the traditional middle of the screen for laptops and […]

Underscore.js Basics

Posted on May 10th, 2013 by webninjataylor

Underscore.js is a tiny JavaScript utility library that makes working with some of the common data structures used in JavaScript much easier Common Methods _.union(myArray2, myArray3) to concatenate two arrays _.uniq(myArray3) to strip duplicates from array _.zip(myArray, myArray2) to return arrays where the nth value of each array is paired [0, 0], [1, 1], [2, […]

CSS :empty Selector

Posted on May 8th, 2013 by webninjataylor

Styling rules for empty cells in a table… td:empty { background: #777; } Resources Vanishing Acts: The CSS :empty Selector

Tags:
Posted in Web ShotsComments Off on CSS :empty Selector

CSS3 Transitions Gotchas

Posted on May 8th, 2013 by webninjataylor

Be very careful when using transition-property: all. You will get TransitionEnd events for properties that you didn’t expect to ever transition Be careful when using shorthand properties, because the number of triggered events varies between browsers Opera and IE don’t trigger events when a negative delay cancels out the duration WebKit has real issues with the priority of properties such […]

HTML5 Local Storage via JavaScript

Posted on May 7th, 2013 by webninjataylor

Save to local storage via .setItem() with a key/value pair localStorage.setItem(‘my_key’, ‘array,string,whatever’); Pull from local storage via .getItem() using the key localStorage.getItem(‘my_key’);