UNPKG

cssjs

Version:
67 lines (57 loc) 1.73 kB
// Generated by CoffeeScript 1.8.0 (function() { var computations, normalize, process, processAll, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; computations = []; window.cssjsProperty = function(selectors, property, fn) { var global; global = __indexOf.call(fn, "this") < 0; if (typeof fn === "string") { fn = fn.replace(/\s*;\s*$/, ''); if (/^\s*return\s/.test(fn)) { fn = "function(){ " + fn + " }"; } fn = eval('(' + fn + ')'); } return computations.push({ selectors: selectors, property: property, global: global, fn: fn }); }; normalize = function(value) { if (typeof value === 'number') { return value + "px"; } else if (!value) { return null; } else { return value; } }; process = function(computation) { var $elements, value; $elements = $(computation.selectors.join(", ")); if (computation.global) { value = normalize(computation.fn()); return $elements.css(computation.property, value); } else { return $elements.each(function() { value = normalize(computation.fn.call(this)); return $(this).css(computation.property, value); }); } }; processAll = function() { var computation, _i, _len, _results; _results = []; for (_i = 0, _len = computations.length; _i < _len; _i++) { computation = computations[_i]; _results.push(process(computation)); } return _results; }; $(window).resize(processAll); $(window).scroll(processAll); $(document).ready(processAll); }).call(this);