Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Syze 1.1.1

  • Loading branch information...
commit 14109756a3642559711fc40599f0680b2ef51784 0 parents
@jonathantneal jonathantneal authored
Showing with 66 additions and 0 deletions.
  1. +64 −0 syze.js
  2. +2 −0  syze.min.js
64 syze.js
@@ -0,0 +1,64 @@
+/*! syze v1.1.1 MIT/GPL2 @rezitech */
+(function (win, docEl) {
+ // syze variables
+ var
+ _sizes = [],
+ _names = {},
+ _from = 'browser',
+ _debounceRate = 50,
+ _callback;
+ // add window event
+ function addWinEvent(type, fn) {
+ if (win.addEventListener) addEventListener(type, fn, false); else attachEvent('on' + type, fn);
+ }
+ // debouncer
+ function debounce(fn) {
+ var timeout;
+ return function () {
+ var obj = this, args = arguments;
+ function delayed () {
+ fn.apply(obj, args);
+ timeout = null;
+ }
+ if (timeout) clearTimeout(timeout);
+ timeout = setTimeout(delayed, _debounceRate);
+ };
+ }
+ // resizer
+ function onResize() {
+ var
+ currentSize =
+ /^device$/i.test(String(_from)) ? !win.orientation || orientation == 180 ? screen.width : screen.height
+ : /^browser$/i.test(String(_from)) ? docEl.clientWidth
+ : (_from instanceof String) ? Function('return ' + _from)()
+ : parseInt(_from, 10) || 0,
+ docElClassNames = docEl.className.replace(/^\s+|(^|\s)(gt|is|lt)[^\s]+|\s+$/g, '').split(/\s+/),
+ classNames = [], i = -1, e, arr = _sizes, len = arr.length;
+ //
+ arr.sort(function (a, b) { return(a - b); });
+ //
+ while (++i < len) if (currentSize < arr[i]) break;
+ currentSize = arr[Math.max(Math.min(--i, len - 1), 0)];
+ //
+ i = -1;
+ while (++i < len) {
+ classNames.push((currentSize > arr[i] ? 'gt' : currentSize < arr[i] ? 'lt' : 'is') + (_names[arr[i]] || arr[i]));
+ }
+ //
+ docEl.className = (!docElClassNames[0] ? [] : docElClassNames).concat(classNames).join(' ');
+ //
+ if (_callback) _callback(currentSize);
+ }
+ // syze controls
+ win.syze = {
+ sizes: function (val) { _sizes = [].concat.apply([], arguments); onResize(); return this; },
+ names: function (val) { if (val instanceof Object) { _names = val; onResize(); } return this; },
+ from: function (val) { _from = val; onResize(); return this; },
+ debounceRate: function (val) { _debounceRate = parseInt(val, 10) || 0; onResize(); return this; },
+ callback: function (val) { if (val instanceof Function) { _callback = val; onResize(); } return this; }
+ };
+ // start syze
+ addWinEvent('resize', debounce(onResize));
+ addWinEvent('orientationchange', onResize);
+ onResize();
+}(this, document.documentElement));
2  syze.min.js
@@ -0,0 +1,2 @@
+// syze v1.1.1 MIT/GPL2 @rezitech
+(function(a,b){function j(){var f=/^device$/i.test(String(e))?!a.orientation||orientation==180?screen.width:screen.height:/^browser$/i.test(String(e))?b.clientWidth:e instanceof String?Function("return "+e)():parseInt(e,10)||0,h=b.className.replace(/^\s+|(^|\s)(gt|is|lt)[^\s]+|\s+$/g,"").split(/\s+/),i=[],j=-1,k,l=c,m=l.length;l.sort(function(a,b){return a-b});while(++j<m)if(f<l[j])break;f=l[Math.max(Math.min(--j,m-1),0)];j=-1;while(++j<m){i.push((f>l[j]?"gt":f<l[j]?"lt":"is")+(d[l[j]]||l[j]))}b.className=(!h[0]?[]:h).concat(i).join(" ");if(g)g(f)}function i(a){var b;return function(){function e(){a.apply(c,d);b=null}var c=this,d=arguments;if(b)clearTimeout(b);b=setTimeout(e,f)}}function h(b,c){if(a.addEventListener)addEventListener(b,c,false);else attachEvent("on"+b,c)}var c=[],d={},e="browser",f=50,g;a.syze={sizes:function(a){c=[].concat.apply([],arguments);j();return this},names:function(a){if(a instanceof Object){d=a;j()}return this},from:function(a){e=a;j();return this},debounceRate:function(a){f=parseInt(a,10)||0;j();return this},callback:function(a){if(a instanceof Function){g=a;j()}return this}};h("resize",i(j));h("orientationchange",j);j()})(this,document.documentElement)
Please sign in to comment.
Something went wrong with that request. Please try again.