From 264a9720587c3c19aa86314c2e1915c33ecd6954 Mon Sep 17 00:00:00 2001 From: Brad Frost Date: Sat, 22 Jun 2013 19:30:16 -0400 Subject: [PATCH] Viewport resizing manual mode Keyup and keydown functionality. Can press and hold up and down arrows to fine tune the viewport size. On-the-fly px-to-em (and vice-versa) conversion Consolidated Dave's duplicate functions into the main behavior --- public/styleguide/css/styleguide.css | 2 +- public/styleguide/css/styleguide.scss | 4 +- public/styleguide/js/styleguide.js | 414 +++++++++--------- .../templates/partials/ishControls.mustache | 7 +- 4 files changed, 215 insertions(+), 212 deletions(-) diff --git a/public/styleguide/css/styleguide.css b/public/styleguide/css/styleguide.css index aa1e2c0..bbc7bbd 100644 --- a/public/styleguide/css/styleguide.css +++ b/public/styleguide/css/styleguide.css @@ -380,7 +380,7 @@ html, body { font-family: "HelveticaNeue", "Helvetica", "Arial", sans-serif; font-size: 70%; font-weight: normal; - padding: 1em; } + padding: 1em 0; } .sg-head a { display: block; border-bottom: 1px solid #222222; diff --git a/public/styleguide/css/styleguide.scss b/public/styleguide/css/styleguide.scss index 55dd94e..2a7feba 100644 --- a/public/styleguide/css/styleguide.scss +++ b/public/styleguide/css/styleguide.scss @@ -540,12 +540,14 @@ html, body { font-family: $sg-font; font-size: $sg-font-size-sm; font-weight: normal; - padding: $sg-pad; + padding: $sg-pad 0; + a { display: block; border-bottom: 1px solid $sg-primary; color: #222; text-decoration: none; + &:hover { color: $sg-secondary; border-bottom-color: $sg-secondary; diff --git a/public/styleguide/js/styleguide.js b/public/styleguide/js/styleguide.js index c74eccc..f9c1938 100644 --- a/public/styleguide/js/styleguide.js +++ b/public/styleguide/js/styleguide.js @@ -3,11 +3,13 @@ sh = document.body.clientHeight, //Viewport Height minViewportWidth = 240, //Minimum Size for Viewport maxViewportWidth = 2600, //Maxiumum Size for Viewport + viewportResizeHandleWidth = 14, //Width of the viewport drag-to-resize handle $sgViewport = $('#sg-viewport'), //Viewport element $viewToggle = $('#sg-t-toggle'), //Toggle - $sizeToggle = $('#sg-size-toggle'), $tAnnotations = $('#sg-t-annotations'), - $tSize = $('#sg-size'), + $sizePx = $('.sg-size-px'), //Px size input element in toolbar + $sizeEms = $('.sg-size-em'), //Em size input element in toolbar + $bodySize = parseInt($('body').css('font-size')), //Body size of the document $vp = Object, $sgPattern = Object, discoID = false, @@ -18,7 +20,15 @@ $(w).resize(function(){ //Update dimensions on resize sw = document.body.clientWidth; sh = document.body.clientHeight; - displayWidth(); + }); + + /* Pattern Lab accordion dropdown */ + $('.sg-acc-handle').on("click", function(e){ + var $this = $(this), + $panel = $this.next('.sg-acc-panel'); + e.preventDefault(); + $this.toggleClass('active'); + $panel.toggleClass('active'); }); $('.sg-nav-toggle').on("click", function(e){ @@ -35,7 +45,7 @@ }); //Size Trigger - $sizeToggle.on("click", function(e){ + $('#sg-size-toggle').on("click", function(e){ e.preventDefault(); $(this).parents('ul').toggleClass('active'); }); @@ -53,15 +63,14 @@ killDisco(); killHay(); - var val = $(this).attr('data-size'), - bodySize = parseInt($('body').css('font-size')); + var val = $(this).attr('data-size'); if (val.indexOf('px') > -1) { - bodySize = 1; + $bodySize = 1; } val = val.replace(/[^\d.-]/g,'') - sizeiframe(Math.floor(val*bodySize)); + sizeiframe(Math.floor(val*$bodySize)); }); //Size View Events @@ -99,7 +108,7 @@ }); //Click Full Width Button - $('#sg-size-full').on("click", function(e){ + $('#sg-size-full').on("click", function(e){ //Resets e.preventDefault(); killDisco(); killHay(); @@ -128,6 +137,17 @@ } }); + /* Disco Mode */ + function disco() { + sizeiframe(getRandom(minViewportWidth,sw)); + } + + function killDisco() { + discoMode = false; + clearInterval(discoID); + discoID = false; + } + //Stephen Hay Mode - "Start with the small screen first, then expand until it looks like shit. Time for a breakpoint!" $('#sg-size-hay').on("click", function(e){ e.preventDefault(); @@ -137,50 +157,202 @@ killHay(); } else { hayMode = true; - $('#sg-gen-container').removeClass("vp-animate").width(minViewportWidth+14); - $('#sg-viewport').removeClass("vp-animate").width(minViewportWidth); + $('#sg-gen-container').removeClass("vp-animate").width(minViewportWidth+viewportResizeHandleWidth); + $sgViewport.removeClass("vp-animate").width(minViewportWidth); var timeoutID = window.setTimeout(function(){ - $('#sg-gen-container').addClass('hay-mode').width(maxViewportWidth+14); - $('#sg-viewport').addClass('hay-mode').width(maxViewportWidth); + $('#sg-gen-container').addClass('hay-mode').width(maxViewportWidth+viewportResizeHandleWidth); + $sgViewport.addClass('hay-mode').width(maxViewportWidth); }, 200); } }); - //Set Manual Pixel Contenteditable region - $('.sg-size-px').on("keydown", function(e){ - var val = $(this).val(); + //Stop Hay! Mode + function killHay() { + var currentWidth = $sgViewport.width(); + hayMode = false; + $sgViewport.removeClass('hay-mode'); + $('#sg-gen-container').removeClass('hay-mode'); + sizeiframe(Math.floor(currentWidth)); + } - if(e.keyCode == 13) { //If the Enter key is hit + //Pixel input + $sizePx.on('keydown', function(e){ + var val = Math.floor($(this).val()); + + if(e.keyCode == 38) { //If the up arrow key is hit + val++; + sizeiframe(val,false); + } else if(e.keyCode == 40) { //If the down arrow key is hit + val--; + sizeiframe(val,false); + } else if(e.keyCode == 13) { //If the Enter key is hit e.preventDefault(); - sizeiframe(Math.floor(val)); //Size Iframe to value of text box - updateEmSizeReading(val); + sizeiframe(val); //Size Iframe to value of text box $(this).blur(); - } else { //If any other character is entered - } + }); - //Set Manual - $('.sg-size-em').on("keydown", function(e){ - var val = $(this).val(); - var bodySize = parseInt($('body').css('font-size')); + $sizePx.on('keyup', function(e){ + var val = Math.floor($(this).val()); + updateSizeReading(val,'updateEmInput'); + }); - //if(e.keyCode == 13) { //If the Enter key is hit + //Em input + $sizeEms.on('keydown', function(e){ + var val = parseFloat($(this).val()); + + if(e.keyCode == 38) { //If the up arrow key is hit + val++; + sizeiframe(Math.floor(val*$bodySize),false); + } else if(e.keyCode == 40) { //If the down arrow key is hit + val--; + sizeiframe(Math.floor(val*$bodySize),false); + } else if(e.keyCode == 13) { //If the Enter key is hit e.preventDefault(); - sizeiframe(Math.floor(val*bodySize)); //Size Iframe to value of text box - updatePxSizeReading(val); - //} else { //If any other character is entered - // - //} + sizeiframe(Math.floor(val*$bodySize)); //Size Iframe to value of text box + } }); + $sizeEms.on('keyup', function(e){ + var val = parseFloat($(this).val()); + updateSizeReading(val,'em','updatePxInput'); + }); + + //Resize the viewport + //'size' is the target size of the viewport + //'animate' is a boolean for switching the CSS animation on or off. 'animate' is true by default, but can be set to false for things like nudging and dragging + function sizeiframe(size,animate) { + var theSize; + + if(size>maxViewportWidth) { //If the entered size is larger than the max allowed viewport size, cap value at max vp size + theSize = maxViewportWidth; + } else if(size