From 1028a37b611b1cabb36afec629d8e0c6c003bdbe Mon Sep 17 00:00:00 2001 From: Ian Caunce Date: Mon, 8 Dec 2014 20:59:06 +0000 Subject: [PATCH 1/8] Added better calc detection and fallback support --- js/rrssb.js | 58 +++++++++++++++++++++++++++++++++++++------------ js/rrssb.min.js | 2 +- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/js/rrssb.js b/js/rrssb.js index efbdec3..fef63d9 100755 --- a/js/rrssb.js +++ b/js/rrssb.js @@ -4,27 +4,53 @@ Site: http://www.kurtnoble.com/labs/rrssb Twitter: @therealkni - ___ ___ - /__/| /__/\ ___ - | |:| \ \:\ / /\ - | |:| \ \:\ / /:/ - __| |:| _____\__\:\ /__/::\ + ___ ___ + /__/| /__/\ ___ + | |:| \ \:\ / /\ + | |:| \ \:\ / /:/ + __| |:| _____\__\:\ /__/::\ /__/\_|:|____ /__/::::::::\ \__\/\:\__ \ \:\/:::::/ \ \:\~~\~~\/ \ \:\/\ - \ \::/~~~~ \ \:\ ~~~ \__\::/ - \ \:\ \ \:\ /__/:/ - \ \:\ \ \:\ \__\/ - \__\/ \__\/ + \ \::/~~~~ \ \:\ ~~~ \__\::/ + \ \:\ \ \:\ /__/:/ + \ \:\ \ \:\ \__\/ + \__\/ \__\/ */ ;(function(window, jQuery, undefined) { 'use strict'; + var support = { + calc : false, + viewportUnits : false + }; /* * Utility functions */ + var detectCalcSupport = function(){ + //detect if calc is natively supported. + var $el = $('
'); + var calcProps = [ + 'calc', + '-webkit-calc', + '-moz-calc' + ]; + + $('body').append($el); + + for (var i=0; i < calcProps.length; i++) { + $el.css('width', calcProps[i] + '(1px)'); + if($el.width() === 1){ + support.calc = calcProps[i]; + break; + } + } + + $el.remove(); + }; + var setPercentBtns = function() { // loop through each instance of buttons jQuery('.rrssb-buttons').each(function(index) { @@ -159,13 +185,15 @@ regPercent = 100 / regButtonCount; smallBtnFraction = pixelsOff / regButtonCount; - if (navigator.userAgent.indexOf('Chrome') >= 0 || navigator.userAgent.indexOf('Safari') >= 0) { - magicWidth = '-webkit-calc('+regPercent+'% - '+smallBtnFraction+'px)'; - } else if (navigator.userAgent.indexOf('Firefox') >= 0) { - magicWidth = '-moz-calc('+regPercent+'% - '+smallBtnFraction+'px)'; + // if calc is not supported. calculate the width on the fly. + if (support.calc === false) { + magicWidth = (self.innerWidth() / regButtonCount) - smallBtnFraction; + magicWidth = Math.floor(magicWidth*1000) / 1000; + magicWidth += 'px'; } else { - magicWidth = 'calc('+regPercent+'% - '+smallBtnFraction+'px)'; + magicWidth = support.calc+'('+regPercent+'% - '+smallBtnFraction+'px)'; } + jQuery('li', self).not('.small').css('width', magicWidth); } else if (smallBtnCount === jQuery('li', self).length) { @@ -186,6 +214,8 @@ jQuery(this).addClass('rrssb-'+(index + 1)); }); + detectCalcSupport(); + setPercentBtns(); // grab initial text width of each button and add as data attr diff --git a/js/rrssb.min.js b/js/rrssb.min.js index dd4ed10..64dcd1d 100644 --- a/js/rrssb.min.js +++ b/js/rrssb.min.js @@ -15,4 +15,4 @@ \ \:\ \ \:\ /__/:/ \ \:\ \ \:\ \__\/ \__\/ \__\/ -*/(function(e,t,n){"use strict";var r=function(){t(".rrssb-buttons").each(function(e){var n=t(this),r=t("li",n).length,i=100/r;t("li",n).css("width",i+"%").attr("data-initwidth",i)})},i=function(){t(".rrssb-buttons").each(function(e){var n=t(this),r=parseFloat(t(n).width()),i=t("li",n).not(".small").first().width(),s=t("li.small",n).length;i>170&&s<1?t(n).addClass("large-format"):t(n).removeClass("large-format");r<200?t(n).removeClass("small-format").addClass("tiny-format"):t(n).removeClass("tiny-format")})},s=function(){t(".rrssb-buttons").each(function(e){var n=t(this),r=0,i=0,s,o,a=t("li.small",n).length;if(a===t("li",n).length){var f=a*42,l=parseFloat(t(n).width());s=t("li.small",n).first();o=parseFloat(t(s).attr("data-size"))+55;if(f+oo){var a=t("li",n).not(".small").last();t(a).addClass("small");u()}}--r||s()})});e===!0&&f(u)},u=function(){t(".rrssb-buttons").each(function(e){var n=t(this),i,s,o,u,a,f=t("li.small",n).length;if(f>0&&f!==t("li",n).length){t(n).removeClass("small-format");t("li.small",n).css("width","42px");o=f*42;i=t("li",n).not(".small").length;s=100/i;a=o/i;navigator.userAgent.indexOf("Chrome")>=0||navigator.userAgent.indexOf("Safari")>=0?u="-webkit-calc("+s+"% - "+a+"px)":navigator.userAgent.indexOf("Firefox")>=0?u="-moz-calc("+s+"% - "+a+"px)":u="calc("+s+"% - "+a+"px)";t("li",n).not(".small").css("width",u)}else if(f===t("li",n).length){t(n).addClass("small-format");r()}else{t(n).removeClass("small-format");r()}});i()},a=function(){t(".rrssb-buttons").each(function(e){t(this).addClass("rrssb-"+(e+1))});r();t(".rrssb-buttons li .rrssb-text").each(function(e){var n=parseFloat(t(this).width());t(this).closest("li").attr("data-size",n)});o(!0)},f=function(e){t(".rrssb-buttons li.small").removeClass("small");o();e()},l=function(t,r,i,s){var o=e.screenLeft!==n?e.screenLeft:screen.left,u=e.screenTop!==n?e.screenTop:screen.top,a=e.innerWidth?e.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,f=e.innerHeight?e.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,l=a/2-i/2+o,c=f/3-s/3+u,h=e.open(t,r,"scrollbars=yes, width="+i+", height="+s+", top="+c+", left="+l);e.focus&&h.focus()},c=function(){var e={};return function(t,n,r){r||(r="Don't call this twice without a uniqueId");e[r]&&clearTimeout(e[r]);e[r]=setTimeout(t,n)}}();t(document).ready(function(){t(".rrssb-buttons a.popup").on("click",function(e){var n=t(this);l(n.attr("href"),n.find(".rrssb-text").html(),580,470);e.preventDefault()});t(e).resize(function(){f(u);c(function(){f(u)},200,"finished resizing")});a()});e.rrssbInit=a})(window,jQuery); \ No newline at end of file +*/(function(window,jQuery,undefined){"use strict";var support={calc:false,viewportUnits:false};var detectCalcSupport=function(){var $el=$("
");var calcProps=["calc","-webkit-calc","-moz-calc"];$("body").append($el);for(var i=0;i170&&smallBtnCount<1){jQuery(self).addClass("large-format")}else{jQuery(self).removeClass("large-format")}if(containerWidth<200){jQuery(self).removeClass("small-format").addClass("tiny-format")}else{jQuery(self).removeClass("tiny-format")}})};var backUpFromSmall=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var totalBtnSze=0,totalTxtSze=0,upCandidate,nextBackUp;var smallBtnCount=jQuery("li.small",self).length;if(smallBtnCount===jQuery("li",self).length){var btnCalc=smallBtnCount*42;var containerWidth=parseFloat(jQuery(self).width());upCandidate=jQuery("li.small",self).first();nextBackUp=parseFloat(jQuery(upCandidate).attr("data-size"))+55;if(btnCalc+nextBackUpbtnWidth){var btn2small=jQuery("li",self).not(".small").last();jQuery(btn2small).addClass("small");sizeSmallBtns()}}if(!--count)backUpFromSmall()})});if(init===true){rrssbMagicLayout(sizeSmallBtns)}};var sizeSmallBtns=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var regButtonCount,regPercent,pixelsOff,magicWidth,smallBtnFraction;var smallBtnCount=jQuery("li.small",self).length;if(smallBtnCount>0&&smallBtnCount!==jQuery("li",self).length){jQuery(self).removeClass("small-format");jQuery("li.small",self).css("width","42px");pixelsOff=smallBtnCount*42;regButtonCount=jQuery("li",self).not(".small").length;regPercent=100/regButtonCount;smallBtnFraction=pixelsOff/regButtonCount;if(support.calc===false){magicWidth=self.innerWidth()/regButtonCount-smallBtnFraction;magicWidth=Math.floor(magicWidth*1e3)/1e3;magicWidth+="px"}else{magicWidth=support.calc+"("+regPercent+"% - "+smallBtnFraction+"px)"}jQuery("li",self).not(".small").css("width",magicWidth)}else if(smallBtnCount===jQuery("li",self).length){jQuery(self).addClass("small-format");setPercentBtns()}else{jQuery(self).removeClass("small-format");setPercentBtns()}});makeExtremityBtns()};var rrssbInit=function(){jQuery(".rrssb-buttons").each(function(index){jQuery(this).addClass("rrssb-"+(index+1))});detectCalcSupport();setPercentBtns();jQuery(".rrssb-buttons li .rrssb-text").each(function(index){var txtWdth=parseFloat(jQuery(this).width());jQuery(this).closest("li").attr("data-size",txtWdth)});checkSize(true)};var rrssbMagicLayout=function(callback){jQuery(".rrssb-buttons li.small").removeClass("small");checkSize();callback()};var popupCenter=function(url,title,w,h){var dualScreenLeft=window.screenLeft!==undefined?window.screenLeft:screen.left;var dualScreenTop=window.screenTop!==undefined?window.screenTop:screen.top;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;var left=width/2-w/2+dualScreenLeft;var top=height/3-h/3+dualScreenTop;var newWindow=window.open(url,title,"scrollbars=yes, width="+w+", height="+h+", top="+top+", left="+left);if(window.focus){newWindow.focus()}};var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}();jQuery(document).ready(function(){jQuery(".rrssb-buttons a.popup").on("click",function(e){var _this=jQuery(this);popupCenter(_this.attr("href"),_this.find(".rrssb-text").html(),580,470);e.preventDefault()});jQuery(window).resize(function(){rrssbMagicLayout(sizeSmallBtns);waitForFinalEvent(function(){rrssbMagicLayout(sizeSmallBtns)},200,"finished resizing")});rrssbInit()});window.rrssbInit=rrssbInit})(window,jQuery); \ No newline at end of file From a402ae361543c6e1e100b33027c07ce02503e74c Mon Sep 17 00:00:00 2001 From: Ian Caunce Date: Mon, 8 Dec 2014 22:00:54 +0000 Subject: [PATCH 2/8] Code cleanup, optimisation & replaced the leading ; with a + as some minifiers strip the first one out --- js/rrssb.js | 121 +++++++++++++++++++++++++----------------------- js/rrssb.min.js | 2 +- 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/js/rrssb.js b/js/rrssb.js index fef63d9..e557cbb 100755 --- a/js/rrssb.js +++ b/js/rrssb.js @@ -17,8 +17,7 @@ \__\/ \__\/ */ - -;(function(window, jQuery, undefined) { ++(function(window, jQuery, undefined) { 'use strict'; var support = { @@ -31,35 +30,36 @@ */ var detectCalcSupport = function(){ //detect if calc is natively supported. - var $el = $('
'); + var el = $('
'); var calcProps = [ 'calc', '-webkit-calc', '-moz-calc' ]; - $('body').append($el); + $('body').append(el); for (var i=0; i < calcProps.length; i++) { - $el.css('width', calcProps[i] + '(1px)'); - if($el.width() === 1){ + el.css('width', calcProps[i] + '(1px)'); + if(el.width() === 1){ support.calc = calcProps[i]; break; } } - $el.remove(); + el.remove(); }; var setPercentBtns = function() { // loop through each instance of buttons jQuery('.rrssb-buttons').each(function(index) { var self = jQuery(this); - var numOfButtons = jQuery('li:visible', self).length; + var buttons = jQuery('li:visible', self); + var numOfButtons = buttons.length; var initBtnWidth = 100 / numOfButtons; // set initial width of buttons - jQuery('li', self).css('width', initBtnWidth + '%').attr('data-initwidth',initBtnWidth); + buttons.css('width', initBtnWidth + '%').attr('data-initwidth',initBtnWidth); }); }; @@ -68,21 +68,20 @@ jQuery('.rrssb-buttons').each(function(index) { var self = jQuery(this); //get button width - var containerWidth = parseFloat(jQuery(self).width()); + var containerWidth = self.width(); var buttonWidth = jQuery('li', self).not('.small').first().width(); - var smallBtnCount = jQuery('li.small', self).length; // enlarge buttons if they get wide enough - if (buttonWidth > 170 && smallBtnCount < 1) { - jQuery(self).addClass('large-format'); + if (buttonWidth > 170 && jQuery('li.small', self).length < 1) { + self.addClass('large-format'); } else { - jQuery(self).removeClass('large-format'); + self.removeClass('large-format'); } if (containerWidth < 200) { - jQuery(self).removeClass('small-format').addClass('tiny-format'); + self.removeClass('small-format').addClass('tiny-format'); } else { - jQuery(self).removeClass('tiny-format'); + self.removeClass('tiny-format'); } }); }; @@ -91,37 +90,40 @@ // loop through each instance of buttons jQuery('.rrssb-buttons').each(function(index) { var self = jQuery(this); - var totalBtnSze = 0, totalTxtSze = 0, upCandidate, nextBackUp; - var smallBtnCount = jQuery('li.small', self).length; - if (smallBtnCount === jQuery('li', self).length) { + var buttons = jQuery('li', self); + var smallButtons = buttons.filter('.small'); + var totalBtnSze = 0; + var totalTxtSze = 0; + var upCandidate = smallButtons.first(); + var nextBackUp = parseFloat(upCandidate.attr('data-size')) + 55; + var smallBtnCount = smallButtons.length; + + if (smallBtnCount === buttons.length) { var btnCalc = smallBtnCount * 42; - var containerWidth = parseFloat(jQuery(self).width()); - upCandidate = jQuery('li.small', self).first(); - nextBackUp = parseFloat(jQuery(upCandidate).attr('data-size')) + 55; + var containerWidth = self.width(); if ((btnCalc + nextBackUp) < containerWidth) { - jQuery(self).removeClass('small-format'); - jQuery('li.small', self).first().removeClass('small'); + self.removeClass('small-format'); + smallButtons.first().removeClass('small'); sizeSmallBtns(); } } else { - jQuery('li', self).not('.small').each(function(index) { - var txtWidth = parseFloat(jQuery(this).attr('data-size')) + 55; - var btnWidth = parseFloat(jQuery(this).width()); + buttons.not('.small').each(function(index) { + var button = jQuery(this); + var txtWidth = parseFloat(button.attr('data-size')) + 55; + var btnWidth = parseFloat(button.width()); totalBtnSze = totalBtnSze + btnWidth; totalTxtSze = totalTxtSze + txtWidth; }); var spaceLeft = totalBtnSze - totalTxtSze; - upCandidate = jQuery('li.small', self).first(); - nextBackUp = parseFloat(jQuery(upCandidate).attr('data-size')) + 55; if (nextBackUp < spaceLeft) { - jQuery(upCandidate).removeClass('small'); + upCandidate.removeClass('small'); sizeSmallBtns(); } } @@ -131,22 +133,24 @@ var checkSize = function(init) { // loop through each instance of buttons jQuery('.rrssb-buttons').each(function(index) { - //console.log('starting check for: '+(index+1)); + var self = jQuery(this); - var elems = jQuery('li', self).nextAll(), count = elems.length; + var buttons = jQuery('li', self); + var elems = buttons.nextAll(); + var count = elems.length; // get buttons in reverse order and loop through each - jQuery(jQuery('li', self).get().reverse()).each(function(index, count) { + jQuery(buttons.get().reverse()).each(function(index, count) { - if (jQuery(this).hasClass('small') === false) { - var txtWidth = parseFloat(jQuery(this).attr('data-size')) + 55; - var btnWidth = parseFloat(jQuery(this).width()); + var button = jQuery(this); + + if (button.hasClass('small') === false) { + var txtWidth = parseFloat(button.attr('data-size')) + 55; + var btnWidth = parseFloat(button.width()); if (txtWidth > btnWidth) { - //console.log($(self).attr('class')+' '+$(this).attr('class')+' txtWidth: '+txtWidth+ ' & btnWidth: '+btnWidth); - var btn2small = jQuery('li', self).not('.small').last(); + var btn2small = buttons.not('.small').last(); jQuery(btn2small).addClass('small'); - //console.log($(btn2small).attr('class')); sizeSmallBtns(); } } @@ -165,23 +169,25 @@ // loop through each instance of buttons jQuery('.rrssb-buttons').each(function(index) { var self = jQuery(this); - var regButtonCount, - regPercent, - pixelsOff, - magicWidth, - smallBtnFraction; + var regButtonCount; + var regPercent; + var pixelsOff; + var magicWidth; + var smallBtnFraction; + var buttons = jQuery('li', self); + var smallButtons = buttons.filter('.small'); // readjust buttons for small display - var smallBtnCount = jQuery('li.small', self).length; + var smallBtnCount = smallButtons.length; // make sure there are small buttons - if (smallBtnCount > 0 && smallBtnCount !== jQuery('li', self).length) { - jQuery(self).removeClass('small-format'); + if (smallBtnCount > 0 && smallBtnCount !== buttons.length) { + self.removeClass('small-format'); //make sure small buttons are square when not all small - jQuery('li.small', self).css('width','42px'); + smallButtons.css('width','42px'); pixelsOff = smallBtnCount * 42; - regButtonCount = jQuery('li', self).not('.small').length; + regButtonCount = buttons.not('.small').length; regPercent = 100 / regButtonCount; smallBtnFraction = pixelsOff / regButtonCount; @@ -194,14 +200,14 @@ magicWidth = support.calc+'('+regPercent+'% - '+smallBtnFraction+'px)'; } - jQuery('li', self).not('.small').css('width', magicWidth); + buttons.not('.small').css('width', magicWidth); - } else if (smallBtnCount === jQuery('li', self).length) { + } else if (smallBtnCount === buttons.length) { // if all buttons are small, change back to percentage - jQuery(self).addClass('small-format'); + self.addClass('small-format'); setPercentBtns(); } else { - jQuery(self).removeClass('small-format'); + self.removeClass('small-format'); setPercentBtns(); } }); //end loop @@ -220,8 +226,9 @@ // grab initial text width of each button and add as data attr jQuery('.rrssb-buttons li .rrssb-text').each(function(index) { - var txtWdth = parseFloat(jQuery(this).width()); - jQuery(this).closest('li').attr('data-size', txtWdth); + var buttonTxt = jQuery(this); + var txtWdth = buttonTxt.width(); + buttonTxt.closest('li').attr('data-size', txtWdth); }); checkSize(true); @@ -275,8 +282,8 @@ */ jQuery('.rrssb-buttons a.popup').on('click', function(e){ - var _this = jQuery(this); - popupCenter(_this.attr('href'), _this.find('.rrssb-text').html(), 580, 470); + var self = jQuery(this); + popupCenter(self.attr('href'), self.find('.rrssb-text').html(), 580, 470); e.preventDefault(); }); diff --git a/js/rrssb.min.js b/js/rrssb.min.js index 64dcd1d..64d583b 100644 --- a/js/rrssb.min.js +++ b/js/rrssb.min.js @@ -15,4 +15,4 @@ \ \:\ \ \:\ /__/:/ \ \:\ \ \:\ \__\/ \__\/ \__\/ -*/(function(window,jQuery,undefined){"use strict";var support={calc:false,viewportUnits:false};var detectCalcSupport=function(){var $el=$("
");var calcProps=["calc","-webkit-calc","-moz-calc"];$("body").append($el);for(var i=0;i170&&smallBtnCount<1){jQuery(self).addClass("large-format")}else{jQuery(self).removeClass("large-format")}if(containerWidth<200){jQuery(self).removeClass("small-format").addClass("tiny-format")}else{jQuery(self).removeClass("tiny-format")}})};var backUpFromSmall=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var totalBtnSze=0,totalTxtSze=0,upCandidate,nextBackUp;var smallBtnCount=jQuery("li.small",self).length;if(smallBtnCount===jQuery("li",self).length){var btnCalc=smallBtnCount*42;var containerWidth=parseFloat(jQuery(self).width());upCandidate=jQuery("li.small",self).first();nextBackUp=parseFloat(jQuery(upCandidate).attr("data-size"))+55;if(btnCalc+nextBackUpbtnWidth){var btn2small=jQuery("li",self).not(".small").last();jQuery(btn2small).addClass("small");sizeSmallBtns()}}if(!--count)backUpFromSmall()})});if(init===true){rrssbMagicLayout(sizeSmallBtns)}};var sizeSmallBtns=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var regButtonCount,regPercent,pixelsOff,magicWidth,smallBtnFraction;var smallBtnCount=jQuery("li.small",self).length;if(smallBtnCount>0&&smallBtnCount!==jQuery("li",self).length){jQuery(self).removeClass("small-format");jQuery("li.small",self).css("width","42px");pixelsOff=smallBtnCount*42;regButtonCount=jQuery("li",self).not(".small").length;regPercent=100/regButtonCount;smallBtnFraction=pixelsOff/regButtonCount;if(support.calc===false){magicWidth=self.innerWidth()/regButtonCount-smallBtnFraction;magicWidth=Math.floor(magicWidth*1e3)/1e3;magicWidth+="px"}else{magicWidth=support.calc+"("+regPercent+"% - "+smallBtnFraction+"px)"}jQuery("li",self).not(".small").css("width",magicWidth)}else if(smallBtnCount===jQuery("li",self).length){jQuery(self).addClass("small-format");setPercentBtns()}else{jQuery(self).removeClass("small-format");setPercentBtns()}});makeExtremityBtns()};var rrssbInit=function(){jQuery(".rrssb-buttons").each(function(index){jQuery(this).addClass("rrssb-"+(index+1))});detectCalcSupport();setPercentBtns();jQuery(".rrssb-buttons li .rrssb-text").each(function(index){var txtWdth=parseFloat(jQuery(this).width());jQuery(this).closest("li").attr("data-size",txtWdth)});checkSize(true)};var rrssbMagicLayout=function(callback){jQuery(".rrssb-buttons li.small").removeClass("small");checkSize();callback()};var popupCenter=function(url,title,w,h){var dualScreenLeft=window.screenLeft!==undefined?window.screenLeft:screen.left;var dualScreenTop=window.screenTop!==undefined?window.screenTop:screen.top;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;var left=width/2-w/2+dualScreenLeft;var top=height/3-h/3+dualScreenTop;var newWindow=window.open(url,title,"scrollbars=yes, width="+w+", height="+h+", top="+top+", left="+left);if(window.focus){newWindow.focus()}};var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}();jQuery(document).ready(function(){jQuery(".rrssb-buttons a.popup").on("click",function(e){var _this=jQuery(this);popupCenter(_this.attr("href"),_this.find(".rrssb-text").html(),580,470);e.preventDefault()});jQuery(window).resize(function(){rrssbMagicLayout(sizeSmallBtns);waitForFinalEvent(function(){rrssbMagicLayout(sizeSmallBtns)},200,"finished resizing")});rrssbInit()});window.rrssbInit=rrssbInit})(window,jQuery); \ No newline at end of file +*/+function(window,jQuery,undefined){"use strict";var support={calc:false,viewportUnits:false};var detectCalcSupport=function(){var el=$("
");var calcProps=["calc","-webkit-calc","-moz-calc"];$("body").append(el);for(var i=0;i170&&jQuery("li.small",self).length<1){self.addClass("large-format")}else{self.removeClass("large-format")}if(containerWidth<200){self.removeClass("small-format").addClass("tiny-format")}else{self.removeClass("tiny-format")}})};var backUpFromSmall=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var totalBtnSze=0;var totalTxtSze=0;var upCandidate=smallButtons.first();var nextBackUp=parseFloat(upCandidate.attr("data-size"))+55;var smallBtnCount=smallButtons.length;if(smallBtnCount===buttons.length){var btnCalc=smallBtnCount*42;var containerWidth=self.width();if(btnCalc+nextBackUpbtnWidth){var btn2small=buttons.not(".small").last();jQuery(btn2small).addClass("small");sizeSmallBtns()}}if(!--count)backUpFromSmall()})});if(init===true){rrssbMagicLayout(sizeSmallBtns)}};var sizeSmallBtns=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var regButtonCount;var regPercent;var pixelsOff;var magicWidth;var smallBtnFraction;var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var smallBtnCount=smallButtons.length;if(smallBtnCount>0&&smallBtnCount!==buttons.length){self.removeClass("small-format");smallButtons.css("width","42px");pixelsOff=smallBtnCount*42;regButtonCount=buttons.not(".small").length;regPercent=100/regButtonCount;smallBtnFraction=pixelsOff/regButtonCount;if(support.calc===false){magicWidth=self.innerWidth()/regButtonCount-smallBtnFraction;magicWidth=Math.floor(magicWidth*1e3)/1e3;magicWidth+="px"}else{magicWidth=support.calc+"("+regPercent+"% - "+smallBtnFraction+"px)"}buttons.not(".small").css("width",magicWidth)}else if(smallBtnCount===buttons.length){self.addClass("small-format");setPercentBtns()}else{self.removeClass("small-format");setPercentBtns()}});makeExtremityBtns()};var rrssbInit=function(){jQuery(".rrssb-buttons").each(function(index){jQuery(this).addClass("rrssb-"+(index+1))});detectCalcSupport();setPercentBtns();jQuery(".rrssb-buttons li .rrssb-text").each(function(index){var buttonTxt=jQuery(this);var txtWdth=buttonTxt.width();buttonTxt.closest("li").attr("data-size",txtWdth)});checkSize(true)};var rrssbMagicLayout=function(callback){jQuery(".rrssb-buttons li.small").removeClass("small");checkSize();callback()};var popupCenter=function(url,title,w,h){var dualScreenLeft=window.screenLeft!==undefined?window.screenLeft:screen.left;var dualScreenTop=window.screenTop!==undefined?window.screenTop:screen.top;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;var left=width/2-w/2+dualScreenLeft;var top=height/3-h/3+dualScreenTop;var newWindow=window.open(url,title,"scrollbars=yes, width="+w+", height="+h+", top="+top+", left="+left);if(window.focus){newWindow.focus()}};var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}();jQuery(document).ready(function(){jQuery(".rrssb-buttons a.popup").on("click",function(e){var self=jQuery(this);popupCenter(self.attr("href"),self.find(".rrssb-text").html(),580,470);e.preventDefault()});jQuery(window).resize(function(){rrssbMagicLayout(sizeSmallBtns);waitForFinalEvent(function(){rrssbMagicLayout(sizeSmallBtns)},200,"finished resizing")});rrssbInit()});window.rrssbInit=rrssbInit}(window,jQuery); \ No newline at end of file From cafa7112d6f1956edf198bbf322dd6a92a2da32d Mon Sep 17 00:00:00 2001 From: Ian Caunce Date: Mon, 8 Dec 2014 22:05:11 +0000 Subject: [PATCH 3/8] Added a ! to the first comment to prevent minifiers by default from stripping it out --- js/rrssb.js | 2 +- js/rrssb.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/rrssb.js b/js/rrssb.js index e557cbb..0f4acc8 100755 --- a/js/rrssb.js +++ b/js/rrssb.js @@ -1,4 +1,4 @@ -/* +/*! Ridiculously Responsive Social Sharing Buttons Team: @dbox, @joshuatuscan Site: http://www.kurtnoble.com/labs/rrssb diff --git a/js/rrssb.min.js b/js/rrssb.min.js index 64d583b..072b226 100644 --- a/js/rrssb.min.js +++ b/js/rrssb.min.js @@ -1,4 +1,4 @@ -/* +/*! Ridiculously Responsive Social Sharing Buttons Team: @dbox, @joshuatuscan Site: http://www.kurtnoble.com/labs/rrssb From b467301489e1caebc0752a962a3463b19b3eb955 Mon Sep 17 00:00:00 2001 From: Ian Caunce Date: Mon, 8 Dec 2014 22:06:49 +0000 Subject: [PATCH 4/8] Removed requires calc as there is now a fallback --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 081603d..50239fe 100644 --- a/index.html +++ b/index.html @@ -202,7 +202,7 @@

Ridiculously Responsive Social Sharing Buttons

RRSSB is built with SASS, so you can easily customize it by tweaking a few variables. SVGs allow for tiny file size and retina support. Add or remove icons as you see fit — the rest will fill in automagically in the container.

-

Resize this page for demo. Currently tested between 140px and 15,465px on current versions of Chrome 33, Safari 7.0.2, Firefox 27, Opera 20, and IE9+. Requires calc and SVG support.

+

Resize this page for demo. Currently tested between 140px and 15,465px on current versions of Chrome 33, Safari 7.0.2, Firefox 27, Opera 20, and IE9+. Requires SVG support.

Grab the code on Github here →

From feeb79096f3e11607596ba457fbac6b3be2c5353 Mon Sep 17 00:00:00 2001 From: Ian Caunce Date: Sun, 14 Dec 2014 18:09:34 +0000 Subject: [PATCH 5/8] Fixed incorrect indentation. Removed unused viewportUnits support property. --- js/rrssb.js | 17 ++++++++--------- js/rrssb.min.js | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/js/rrssb.js b/js/rrssb.js index 0f4acc8..8c0fcb4 100755 --- a/js/rrssb.js +++ b/js/rrssb.js @@ -21,8 +21,7 @@ 'use strict'; var support = { - calc : false, - viewportUnits : false + calc : false }; /* @@ -93,11 +92,11 @@ var buttons = jQuery('li', self); var smallButtons = buttons.filter('.small'); - var totalBtnSze = 0; - var totalTxtSze = 0; - var upCandidate = smallButtons.first(); - var nextBackUp = parseFloat(upCandidate.attr('data-size')) + 55; - var smallBtnCount = smallButtons.length; + var totalBtnSze = 0; + var totalTxtSze = 0; + var upCandidate = smallButtons.first(); + var nextBackUp = parseFloat(upCandidate.attr('data-size')) + 55; + var smallBtnCount = smallButtons.length; if (smallBtnCount === buttons.length) { var btnCalc = smallBtnCount * 42; @@ -137,7 +136,7 @@ var self = jQuery(this); var buttons = jQuery('li', self); var elems = buttons.nextAll(); - var count = elems.length; + var count = elems.length; // get buttons in reverse order and loop through each jQuery(buttons.get().reverse()).each(function(index, count) { @@ -170,7 +169,7 @@ jQuery('.rrssb-buttons').each(function(index) { var self = jQuery(this); var regButtonCount; - var regPercent; + var regPercent; var pixelsOff; var magicWidth; var smallBtnFraction; diff --git a/js/rrssb.min.js b/js/rrssb.min.js index 072b226..2072635 100644 --- a/js/rrssb.min.js +++ b/js/rrssb.min.js @@ -1,4 +1,4 @@ -/*! +/* Ridiculously Responsive Social Sharing Buttons Team: @dbox, @joshuatuscan Site: http://www.kurtnoble.com/labs/rrssb @@ -15,4 +15,4 @@ \ \:\ \ \:\ /__/:/ \ \:\ \ \:\ \__\/ \__\/ \__\/ -*/+function(window,jQuery,undefined){"use strict";var support={calc:false,viewportUnits:false};var detectCalcSupport=function(){var el=$("
");var calcProps=["calc","-webkit-calc","-moz-calc"];$("body").append(el);for(var i=0;i170&&jQuery("li.small",self).length<1){self.addClass("large-format")}else{self.removeClass("large-format")}if(containerWidth<200){self.removeClass("small-format").addClass("tiny-format")}else{self.removeClass("tiny-format")}})};var backUpFromSmall=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var totalBtnSze=0;var totalTxtSze=0;var upCandidate=smallButtons.first();var nextBackUp=parseFloat(upCandidate.attr("data-size"))+55;var smallBtnCount=smallButtons.length;if(smallBtnCount===buttons.length){var btnCalc=smallBtnCount*42;var containerWidth=self.width();if(btnCalc+nextBackUpbtnWidth){var btn2small=buttons.not(".small").last();jQuery(btn2small).addClass("small");sizeSmallBtns()}}if(!--count)backUpFromSmall()})});if(init===true){rrssbMagicLayout(sizeSmallBtns)}};var sizeSmallBtns=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var regButtonCount;var regPercent;var pixelsOff;var magicWidth;var smallBtnFraction;var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var smallBtnCount=smallButtons.length;if(smallBtnCount>0&&smallBtnCount!==buttons.length){self.removeClass("small-format");smallButtons.css("width","42px");pixelsOff=smallBtnCount*42;regButtonCount=buttons.not(".small").length;regPercent=100/regButtonCount;smallBtnFraction=pixelsOff/regButtonCount;if(support.calc===false){magicWidth=self.innerWidth()/regButtonCount-smallBtnFraction;magicWidth=Math.floor(magicWidth*1e3)/1e3;magicWidth+="px"}else{magicWidth=support.calc+"("+regPercent+"% - "+smallBtnFraction+"px)"}buttons.not(".small").css("width",magicWidth)}else if(smallBtnCount===buttons.length){self.addClass("small-format");setPercentBtns()}else{self.removeClass("small-format");setPercentBtns()}});makeExtremityBtns()};var rrssbInit=function(){jQuery(".rrssb-buttons").each(function(index){jQuery(this).addClass("rrssb-"+(index+1))});detectCalcSupport();setPercentBtns();jQuery(".rrssb-buttons li .rrssb-text").each(function(index){var buttonTxt=jQuery(this);var txtWdth=buttonTxt.width();buttonTxt.closest("li").attr("data-size",txtWdth)});checkSize(true)};var rrssbMagicLayout=function(callback){jQuery(".rrssb-buttons li.small").removeClass("small");checkSize();callback()};var popupCenter=function(url,title,w,h){var dualScreenLeft=window.screenLeft!==undefined?window.screenLeft:screen.left;var dualScreenTop=window.screenTop!==undefined?window.screenTop:screen.top;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;var left=width/2-w/2+dualScreenLeft;var top=height/3-h/3+dualScreenTop;var newWindow=window.open(url,title,"scrollbars=yes, width="+w+", height="+h+", top="+top+", left="+left);if(window.focus){newWindow.focus()}};var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}();jQuery(document).ready(function(){jQuery(".rrssb-buttons a.popup").on("click",function(e){var self=jQuery(this);popupCenter(self.attr("href"),self.find(".rrssb-text").html(),580,470);e.preventDefault()});jQuery(window).resize(function(){rrssbMagicLayout(sizeSmallBtns);waitForFinalEvent(function(){rrssbMagicLayout(sizeSmallBtns)},200,"finished resizing")});rrssbInit()});window.rrssbInit=rrssbInit}(window,jQuery); \ No newline at end of file +*/+function(window,jQuery,undefined){"use strict";var support={calc:false};var detectCalcSupport=function(){var el=$("
");var calcProps=["calc","-webkit-calc","-moz-calc"];$("body").append(el);for(var i=0;i170&&jQuery("li.small",self).length<1){self.addClass("large-format")}else{self.removeClass("large-format")}if(containerWidth<200){self.removeClass("small-format").addClass("tiny-format")}else{self.removeClass("tiny-format")}})};var backUpFromSmall=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var totalBtnSze=0;var totalTxtSze=0;var upCandidate=smallButtons.first();var nextBackUp=parseFloat(upCandidate.attr("data-size"))+55;var smallBtnCount=smallButtons.length;if(smallBtnCount===buttons.length){var btnCalc=smallBtnCount*42;var containerWidth=self.width();if(btnCalc+nextBackUpbtnWidth){var btn2small=buttons.not(".small").last();jQuery(btn2small).addClass("small");sizeSmallBtns()}}if(!--count)backUpFromSmall()})});if(init===true){rrssbMagicLayout(sizeSmallBtns)}};var sizeSmallBtns=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var regButtonCount;var regPercent;var pixelsOff;var magicWidth;var smallBtnFraction;var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var smallBtnCount=smallButtons.length;if(smallBtnCount>0&&smallBtnCount!==buttons.length){self.removeClass("small-format");smallButtons.css("width","42px");pixelsOff=smallBtnCount*42;regButtonCount=buttons.not(".small").length;regPercent=100/regButtonCount;smallBtnFraction=pixelsOff/regButtonCount;if(support.calc===false){magicWidth=self.innerWidth()/regButtonCount-smallBtnFraction;magicWidth=Math.floor(magicWidth*1e3)/1e3;magicWidth+="px"}else{magicWidth=support.calc+"("+regPercent+"% - "+smallBtnFraction+"px)"}buttons.not(".small").css("width",magicWidth)}else if(smallBtnCount===buttons.length){self.addClass("small-format");setPercentBtns()}else{self.removeClass("small-format");setPercentBtns()}});makeExtremityBtns()};var rrssbInit=function(){jQuery(".rrssb-buttons").each(function(index){jQuery(this).addClass("rrssb-"+(index+1))});detectCalcSupport();setPercentBtns();jQuery(".rrssb-buttons li .rrssb-text").each(function(index){var buttonTxt=jQuery(this);var txtWdth=buttonTxt.width();buttonTxt.closest("li").attr("data-size",txtWdth)});checkSize(true)};var rrssbMagicLayout=function(callback){jQuery(".rrssb-buttons li.small").removeClass("small");checkSize();callback()};var popupCenter=function(url,title,w,h){var dualScreenLeft=window.screenLeft!==undefined?window.screenLeft:screen.left;var dualScreenTop=window.screenTop!==undefined?window.screenTop:screen.top;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;var left=width/2-w/2+dualScreenLeft;var top=height/3-h/3+dualScreenTop;var newWindow=window.open(url,title,"scrollbars=yes, width="+w+", height="+h+", top="+top+", left="+left);if(window.focus){newWindow.focus()}};var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}();jQuery(document).ready(function(){jQuery(".rrssb-buttons a.popup").on("click",function(e){var self=jQuery(this);popupCenter(self.attr("href"),self.find(".rrssb-text").html(),580,470);e.preventDefault()});jQuery(window).resize(function(){rrssbMagicLayout(sizeSmallBtns);waitForFinalEvent(function(){rrssbMagicLayout(sizeSmallBtns)},200,"finished resizing")});rrssbInit()});window.rrssbInit=rrssbInit}(window,jQuery); \ No newline at end of file From 4d9a3a87d5b164c061eab52843fb4662163fb16c Mon Sep 17 00:00:00 2001 From: Ian Caunce Date: Sun, 14 Dec 2014 22:37:08 +0000 Subject: [PATCH 6/8] Added a saftey net of 1px with the calc polyfill --- js/rrssb.js | 4 ++-- js/rrssb.min.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/rrssb.js b/js/rrssb.js index 8c0fcb4..b0fdc6c 100755 --- a/js/rrssb.js +++ b/js/rrssb.js @@ -191,8 +191,8 @@ smallBtnFraction = pixelsOff / regButtonCount; // if calc is not supported. calculate the width on the fly. - if (support.calc === false) { - magicWidth = (self.innerWidth() / regButtonCount) - smallBtnFraction; + if (true ||support.calc === false) { + magicWidth = ((self.innerWidth()-1) / regButtonCount) - smallBtnFraction; magicWidth = Math.floor(magicWidth*1000) / 1000; magicWidth += 'px'; } else { diff --git a/js/rrssb.min.js b/js/rrssb.min.js index 2072635..901da6f 100644 --- a/js/rrssb.min.js +++ b/js/rrssb.min.js @@ -1,4 +1,4 @@ -/* +/*! Ridiculously Responsive Social Sharing Buttons Team: @dbox, @joshuatuscan Site: http://www.kurtnoble.com/labs/rrssb @@ -15,4 +15,4 @@ \ \:\ \ \:\ /__/:/ \ \:\ \ \:\ \__\/ \__\/ \__\/ -*/+function(window,jQuery,undefined){"use strict";var support={calc:false};var detectCalcSupport=function(){var el=$("
");var calcProps=["calc","-webkit-calc","-moz-calc"];$("body").append(el);for(var i=0;i170&&jQuery("li.small",self).length<1){self.addClass("large-format")}else{self.removeClass("large-format")}if(containerWidth<200){self.removeClass("small-format").addClass("tiny-format")}else{self.removeClass("tiny-format")}})};var backUpFromSmall=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var totalBtnSze=0;var totalTxtSze=0;var upCandidate=smallButtons.first();var nextBackUp=parseFloat(upCandidate.attr("data-size"))+55;var smallBtnCount=smallButtons.length;if(smallBtnCount===buttons.length){var btnCalc=smallBtnCount*42;var containerWidth=self.width();if(btnCalc+nextBackUpbtnWidth){var btn2small=buttons.not(".small").last();jQuery(btn2small).addClass("small");sizeSmallBtns()}}if(!--count)backUpFromSmall()})});if(init===true){rrssbMagicLayout(sizeSmallBtns)}};var sizeSmallBtns=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var regButtonCount;var regPercent;var pixelsOff;var magicWidth;var smallBtnFraction;var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var smallBtnCount=smallButtons.length;if(smallBtnCount>0&&smallBtnCount!==buttons.length){self.removeClass("small-format");smallButtons.css("width","42px");pixelsOff=smallBtnCount*42;regButtonCount=buttons.not(".small").length;regPercent=100/regButtonCount;smallBtnFraction=pixelsOff/regButtonCount;if(support.calc===false){magicWidth=self.innerWidth()/regButtonCount-smallBtnFraction;magicWidth=Math.floor(magicWidth*1e3)/1e3;magicWidth+="px"}else{magicWidth=support.calc+"("+regPercent+"% - "+smallBtnFraction+"px)"}buttons.not(".small").css("width",magicWidth)}else if(smallBtnCount===buttons.length){self.addClass("small-format");setPercentBtns()}else{self.removeClass("small-format");setPercentBtns()}});makeExtremityBtns()};var rrssbInit=function(){jQuery(".rrssb-buttons").each(function(index){jQuery(this).addClass("rrssb-"+(index+1))});detectCalcSupport();setPercentBtns();jQuery(".rrssb-buttons li .rrssb-text").each(function(index){var buttonTxt=jQuery(this);var txtWdth=buttonTxt.width();buttonTxt.closest("li").attr("data-size",txtWdth)});checkSize(true)};var rrssbMagicLayout=function(callback){jQuery(".rrssb-buttons li.small").removeClass("small");checkSize();callback()};var popupCenter=function(url,title,w,h){var dualScreenLeft=window.screenLeft!==undefined?window.screenLeft:screen.left;var dualScreenTop=window.screenTop!==undefined?window.screenTop:screen.top;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;var left=width/2-w/2+dualScreenLeft;var top=height/3-h/3+dualScreenTop;var newWindow=window.open(url,title,"scrollbars=yes, width="+w+", height="+h+", top="+top+", left="+left);if(window.focus){newWindow.focus()}};var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}();jQuery(document).ready(function(){jQuery(".rrssb-buttons a.popup").on("click",function(e){var self=jQuery(this);popupCenter(self.attr("href"),self.find(".rrssb-text").html(),580,470);e.preventDefault()});jQuery(window).resize(function(){rrssbMagicLayout(sizeSmallBtns);waitForFinalEvent(function(){rrssbMagicLayout(sizeSmallBtns)},200,"finished resizing")});rrssbInit()});window.rrssbInit=rrssbInit}(window,jQuery); \ No newline at end of file +*/+function(window,jQuery,undefined){"use strict";var support={calc:false};var detectCalcSupport=function(){var el=$("
");var calcProps=["calc","-webkit-calc","-moz-calc"];$("body").append(el);for(var i=0;i170&&jQuery("li.small",self).length<1){self.addClass("large-format")}else{self.removeClass("large-format")}if(containerWidth<200){self.removeClass("small-format").addClass("tiny-format")}else{self.removeClass("tiny-format")}})};var backUpFromSmall=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var totalBtnSze=0;var totalTxtSze=0;var upCandidate=smallButtons.first();var nextBackUp=parseFloat(upCandidate.attr("data-size"))+55;var smallBtnCount=smallButtons.length;if(smallBtnCount===buttons.length){var btnCalc=smallBtnCount*42;var containerWidth=self.width();if(btnCalc+nextBackUpbtnWidth){var btn2small=buttons.not(".small").last();jQuery(btn2small).addClass("small");sizeSmallBtns()}}if(!--count)backUpFromSmall()})});if(init===true){rrssbMagicLayout(sizeSmallBtns)}};var sizeSmallBtns=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var regButtonCount;var regPercent;var pixelsOff;var magicWidth;var smallBtnFraction;var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var smallBtnCount=smallButtons.length;if(smallBtnCount>0&&smallBtnCount!==buttons.length){self.removeClass("small-format");smallButtons.css("width","42px");pixelsOff=smallBtnCount*42;regButtonCount=buttons.not(".small").length;regPercent=100/regButtonCount;smallBtnFraction=pixelsOff/regButtonCount;if(true||support.calc===false){magicWidth=(self.innerWidth()-1)/regButtonCount-smallBtnFraction;magicWidth=Math.floor(magicWidth*1e3)/1e3;magicWidth+="px"}else{magicWidth=support.calc+"("+regPercent+"% - "+smallBtnFraction+"px)"}buttons.not(".small").css("width",magicWidth)}else if(smallBtnCount===buttons.length){self.addClass("small-format");setPercentBtns()}else{self.removeClass("small-format");setPercentBtns()}});makeExtremityBtns()};var rrssbInit=function(){jQuery(".rrssb-buttons").each(function(index){jQuery(this).addClass("rrssb-"+(index+1))});detectCalcSupport();setPercentBtns();jQuery(".rrssb-buttons li .rrssb-text").each(function(index){var buttonTxt=jQuery(this);var txtWdth=buttonTxt.width();buttonTxt.closest("li").attr("data-size",txtWdth)});checkSize(true)};var rrssbMagicLayout=function(callback){jQuery(".rrssb-buttons li.small").removeClass("small");checkSize();callback()};var popupCenter=function(url,title,w,h){var dualScreenLeft=window.screenLeft!==undefined?window.screenLeft:screen.left;var dualScreenTop=window.screenTop!==undefined?window.screenTop:screen.top;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;var left=width/2-w/2+dualScreenLeft;var top=height/3-h/3+dualScreenTop;var newWindow=window.open(url,title,"scrollbars=yes, width="+w+", height="+h+", top="+top+", left="+left);if(window.focus){newWindow.focus()}};var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}();jQuery(document).ready(function(){jQuery(".rrssb-buttons a.popup").on("click",function(e){var self=jQuery(this);popupCenter(self.attr("href"),self.find(".rrssb-text").html(),580,470);e.preventDefault()});jQuery(window).resize(function(){rrssbMagicLayout(sizeSmallBtns);waitForFinalEvent(function(){rrssbMagicLayout(sizeSmallBtns)},200,"finished resizing")});rrssbInit()});window.rrssbInit=rrssbInit}(window,jQuery); \ No newline at end of file From 4fef78313855fc9646af39e8ad50289a946bece2 Mon Sep 17 00:00:00 2001 From: Ian Caunce Date: Wed, 17 Dec 2014 19:28:34 +0000 Subject: [PATCH 7/8] removed debug code --- js/rrssb.js | 2 +- js/rrssb.min.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/rrssb.js b/js/rrssb.js index b0fdc6c..a7820f8 100755 --- a/js/rrssb.js +++ b/js/rrssb.js @@ -191,7 +191,7 @@ smallBtnFraction = pixelsOff / regButtonCount; // if calc is not supported. calculate the width on the fly. - if (true ||support.calc === false) { + if (support.calc === false) { magicWidth = ((self.innerWidth()-1) / regButtonCount) - smallBtnFraction; magicWidth = Math.floor(magicWidth*1000) / 1000; magicWidth += 'px'; diff --git a/js/rrssb.min.js b/js/rrssb.min.js index 901da6f..ef73058 100644 --- a/js/rrssb.min.js +++ b/js/rrssb.min.js @@ -1,4 +1,4 @@ -/*! +/* Ridiculously Responsive Social Sharing Buttons Team: @dbox, @joshuatuscan Site: http://www.kurtnoble.com/labs/rrssb @@ -15,4 +15,4 @@ \ \:\ \ \:\ /__/:/ \ \:\ \ \:\ \__\/ \__\/ \__\/ -*/+function(window,jQuery,undefined){"use strict";var support={calc:false};var detectCalcSupport=function(){var el=$("
");var calcProps=["calc","-webkit-calc","-moz-calc"];$("body").append(el);for(var i=0;i170&&jQuery("li.small",self).length<1){self.addClass("large-format")}else{self.removeClass("large-format")}if(containerWidth<200){self.removeClass("small-format").addClass("tiny-format")}else{self.removeClass("tiny-format")}})};var backUpFromSmall=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var totalBtnSze=0;var totalTxtSze=0;var upCandidate=smallButtons.first();var nextBackUp=parseFloat(upCandidate.attr("data-size"))+55;var smallBtnCount=smallButtons.length;if(smallBtnCount===buttons.length){var btnCalc=smallBtnCount*42;var containerWidth=self.width();if(btnCalc+nextBackUpbtnWidth){var btn2small=buttons.not(".small").last();jQuery(btn2small).addClass("small");sizeSmallBtns()}}if(!--count)backUpFromSmall()})});if(init===true){rrssbMagicLayout(sizeSmallBtns)}};var sizeSmallBtns=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var regButtonCount;var regPercent;var pixelsOff;var magicWidth;var smallBtnFraction;var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var smallBtnCount=smallButtons.length;if(smallBtnCount>0&&smallBtnCount!==buttons.length){self.removeClass("small-format");smallButtons.css("width","42px");pixelsOff=smallBtnCount*42;regButtonCount=buttons.not(".small").length;regPercent=100/regButtonCount;smallBtnFraction=pixelsOff/regButtonCount;if(true||support.calc===false){magicWidth=(self.innerWidth()-1)/regButtonCount-smallBtnFraction;magicWidth=Math.floor(magicWidth*1e3)/1e3;magicWidth+="px"}else{magicWidth=support.calc+"("+regPercent+"% - "+smallBtnFraction+"px)"}buttons.not(".small").css("width",magicWidth)}else if(smallBtnCount===buttons.length){self.addClass("small-format");setPercentBtns()}else{self.removeClass("small-format");setPercentBtns()}});makeExtremityBtns()};var rrssbInit=function(){jQuery(".rrssb-buttons").each(function(index){jQuery(this).addClass("rrssb-"+(index+1))});detectCalcSupport();setPercentBtns();jQuery(".rrssb-buttons li .rrssb-text").each(function(index){var buttonTxt=jQuery(this);var txtWdth=buttonTxt.width();buttonTxt.closest("li").attr("data-size",txtWdth)});checkSize(true)};var rrssbMagicLayout=function(callback){jQuery(".rrssb-buttons li.small").removeClass("small");checkSize();callback()};var popupCenter=function(url,title,w,h){var dualScreenLeft=window.screenLeft!==undefined?window.screenLeft:screen.left;var dualScreenTop=window.screenTop!==undefined?window.screenTop:screen.top;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;var left=width/2-w/2+dualScreenLeft;var top=height/3-h/3+dualScreenTop;var newWindow=window.open(url,title,"scrollbars=yes, width="+w+", height="+h+", top="+top+", left="+left);if(window.focus){newWindow.focus()}};var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}();jQuery(document).ready(function(){jQuery(".rrssb-buttons a.popup").on("click",function(e){var self=jQuery(this);popupCenter(self.attr("href"),self.find(".rrssb-text").html(),580,470);e.preventDefault()});jQuery(window).resize(function(){rrssbMagicLayout(sizeSmallBtns);waitForFinalEvent(function(){rrssbMagicLayout(sizeSmallBtns)},200,"finished resizing")});rrssbInit()});window.rrssbInit=rrssbInit}(window,jQuery); \ No newline at end of file +*/+function(window,jQuery,undefined){"use strict";var support={calc:false};var detectCalcSupport=function(){var el=$("
");var calcProps=["calc","-webkit-calc","-moz-calc"];$("body").append(el);for(var i=0;i170&&jQuery("li.small",self).length<1){self.addClass("large-format")}else{self.removeClass("large-format")}if(containerWidth<200){self.removeClass("small-format").addClass("tiny-format")}else{self.removeClass("tiny-format")}})};var backUpFromSmall=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var totalBtnSze=0;var totalTxtSze=0;var upCandidate=smallButtons.first();var nextBackUp=parseFloat(upCandidate.attr("data-size"))+55;var smallBtnCount=smallButtons.length;if(smallBtnCount===buttons.length){var btnCalc=smallBtnCount*42;var containerWidth=self.width();if(btnCalc+nextBackUpbtnWidth){var btn2small=buttons.not(".small").last();jQuery(btn2small).addClass("small");sizeSmallBtns()}}if(!--count)backUpFromSmall()})});if(init===true){rrssbMagicLayout(sizeSmallBtns)}};var sizeSmallBtns=function(){jQuery(".rrssb-buttons").each(function(index){var self=jQuery(this);var regButtonCount;var regPercent;var pixelsOff;var magicWidth;var smallBtnFraction;var buttons=jQuery("li",self);var smallButtons=buttons.filter(".small");var smallBtnCount=smallButtons.length;if(smallBtnCount>0&&smallBtnCount!==buttons.length){self.removeClass("small-format");smallButtons.css("width","42px");pixelsOff=smallBtnCount*42;regButtonCount=buttons.not(".small").length;regPercent=100/regButtonCount;smallBtnFraction=pixelsOff/regButtonCount;if(support.calc===false){magicWidth=(self.innerWidth()-1)/regButtonCount-smallBtnFraction;magicWidth=Math.floor(magicWidth*1e3)/1e3;magicWidth+="px"}else{magicWidth=support.calc+"("+regPercent+"% - "+smallBtnFraction+"px)"}buttons.not(".small").css("width",magicWidth)}else if(smallBtnCount===buttons.length){self.addClass("small-format");setPercentBtns()}else{self.removeClass("small-format");setPercentBtns()}});makeExtremityBtns()};var rrssbInit=function(){jQuery(".rrssb-buttons").each(function(index){jQuery(this).addClass("rrssb-"+(index+1))});detectCalcSupport();setPercentBtns();jQuery(".rrssb-buttons li .rrssb-text").each(function(index){var buttonTxt=jQuery(this);var txtWdth=buttonTxt.width();buttonTxt.closest("li").attr("data-size",txtWdth)});checkSize(true)};var rrssbMagicLayout=function(callback){jQuery(".rrssb-buttons li.small").removeClass("small");checkSize();callback()};var popupCenter=function(url,title,w,h){var dualScreenLeft=window.screenLeft!==undefined?window.screenLeft:screen.left;var dualScreenTop=window.screenTop!==undefined?window.screenTop:screen.top;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;var left=width/2-w/2+dualScreenLeft;var top=height/3-h/3+dualScreenTop;var newWindow=window.open(url,title,"scrollbars=yes, width="+w+", height="+h+", top="+top+", left="+left);if(window.focus){newWindow.focus()}};var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}();jQuery(document).ready(function(){jQuery(".rrssb-buttons a.popup").on("click",function(e){var self=jQuery(this);popupCenter(self.attr("href"),self.find(".rrssb-text").html(),580,470);e.preventDefault()});jQuery(window).resize(function(){rrssbMagicLayout(sizeSmallBtns);waitForFinalEvent(function(){rrssbMagicLayout(sizeSmallBtns)},200,"finished resizing")});rrssbInit()});window.rrssbInit=rrssbInit}(window,jQuery); \ No newline at end of file From 4a3a924e3ac02ee203c1299735949941d5af93a1 Mon Sep 17 00:00:00 2001 From: Ian Caunce Date: Wed, 17 Dec 2014 22:22:28 +0000 Subject: [PATCH 8/8] Removed requires calc from the readme file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d144fa1..b99e753 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ RRSSB is built with [**SASS**](http://sass-lang.com/), so you can easily customi Currently tested between [**140px**](https://www.dropbox.com/s/2k6lcebg2887ge3/Screenshot%202014-02-18%2009.45.45.png) and [**15,465px**](https://www.dropbox.com/s/1juq03011lixk3r/Screenshot%202014-02-18%2009.43.57.png) on current versions of Chrome 33, Safari 7.0.2, Firefox 27, Opera 20, and IE9+. -Requires [**calc**](http://caniuse.com/calc) and [**SVG**](http://caniuse.com/svg) +Requires [**SVG**](http://caniuse.com/svg) ### Version Notes