Permalink
Browse files

bump to 1.1

  • Loading branch information...
1 parent 2cd33fc commit 75b08b944e58a6b0a60e4a9671757d619f57d1e3 @jgv jgv committed Jan 2, 2012
Showing with 210 additions and 193 deletions.
  1. +98 −93 demos/okshadow.js
  2. +0 −96 src/okshadow-1.0.js
  3. +0 −4 src/okshadow-1.0.min.js
  4. +108 −0 src/okshadow.js
  5. +4 −0 src/okshadow.min.js
View
@@ -1,103 +1,108 @@
-(function($){
-
- $.okshadow = function(el, options){
- var base = this;
- base.$el = $(el);
- base.el = el;
- base.$el.data("okshadow", base);
-
- base.init = function(){
- base.options = $.extend({}, $.okshadow.options, options);
- base.build();
- };
-
- base.build = function(){
- base.start();
- };
-
- base.clamp = function (x, min, max) {
- return Math.max(min, Math.min(max, x));
- };
+/*
+ * OKShadow by OKFocus - http://okfoc.us - @okfocus
+ * Version 1.1
+ * Licensed under MIT.
+ *
+ */
- base.setoption = function (key, value) {
- if (typeof key === "string") {
- base.options[key] = value;
- if (key === 'color')
- return base.update();
- } else {
- base.options = $.extend(base.options, key);
- }
- base.mousemove(base);
- };
-
- base.start = function () {
- $(window).bind({
- mousemove: base.mousemove
- });
- base.mousemove({ pageX: $(window).width() / 2, pageY: $(window).height() / 2 });
- if (base.options.transparent) {
- base.el.style.color = "transparent";
- }
- };
+(function($){
- base.mousemove = function (e){
- var offset = base.$el.offset(),
- x = e.pageX,
- y = e.pageY,
- cy = offset.top + base.$el.height() / 2,
- cx = offset.left + base.$el.width() / 2,
- dx = (cx - x),
- dy = (cy - y)
- sx = dx / base.options.xFactor,
- sy = dy / base.options.yFactor,
- distance = Math.sqrt(dx*dx + dy*dy),
- fuzz = distance / base.options.fuzz + base.options.fuzzMin;
- if (base.options.xMax !== null)
- sx = base.clamp(sx, -1 * base.options.xMax, base.options.xMax)
- if (base.options.yMax !== null)
- sy = base.clamp(sy, -1 * base.options.yMax, base.options.yMax)
- if (base.options.fuzzMax !== null)
- fuzz = base.clamp(fuzz, base.options.fuzzMin, base.options.fuzzMax)
- sx += base.options.xOffset;
- sy += base.options.yOffset;
- base.pageX = x;
- base.pageY = y;
- base.sx = sx;
- base.sy = sy;
- base.fuzz = fuzz;
- base.update();
- };
+ $.okshadow = function(el, options){
+ var base = this;
+ base.$el = $(el);
+ base.el = el;
+ base.$el.data("okshadow", base);
+
+ base.init = function(){
+ base.options = $.extend({}, $.okshadow.options, options);
+ base.build();
+ };
+
+ base.build = function(){
+ base.start();
+ };
+
+ base.clamp = function (x, min, max) {
+ return Math.max(min, Math.min(max, x));
+ };
- base.update = function () {
- if (base.options.textShadow) {
- base.$el.css('text-shadow', sx + "px " + sy + "px " + fuzz + "px " + base.options.color);
- } else {
- base.$el.css('box-shadow', sx + "px " + sy + "px " + fuzz + "px " + base.options.color);
- }
- }
+ base.setoption = function (key, value) {
+ if (typeof key === "string") {
+ base.options[key] = value;
+ if (key === 'color')
+ return base.update();
+ } else {
+ base.options = $.extend(base.options, key);
+ }
+ base.mousemove(base);
+ };
- base.init();
+ base.start = function () {
+ $(window).bind({ mousemove: base.mousemove });
+ base.mousemove({ pageX: $(window).width() / 2, pageY: $(window).height() / 2 });
+ if (base.options.transparent) base.el.style.color = "transparent";
};
- $.okshadow.options = {
- color: '#888',
- fuzz: 40,
- fuzzMin: 0,
- fuzzMax: null,
- xOffset: 0,
- xFactor: 30,
- xMax: null,
- yOffset: 0,
- yFactor: 30,
- yMax: null,
- textShadow: false,
- transparent: false
+ base.mousemove = function (e){
+ var offset = base.$el.offset(),
+ x = e.pageX,
+ y = e.pageY,
+ cy = offset.top + base.$el.height() / 2,
+ cx = offset.left + base.$el.width() / 2,
+ dx = (cx - x),
+ dy = (cy - y)
+ sx = dx / base.options.xFactor,
+ sy = dy / base.options.yFactor,
+ distance = Math.sqrt(dx*dx + dy*dy),
+ fuzz = distance / base.options.fuzz + base.options.fuzzMin;
+
+ if (base.options.xMax) sx = base.clamp(sx, -1 * base.options.xMax, base.options.xMax);
+ if (base.options.yMax) sy = base.clamp(sy, -1 * base.options.yMax, base.options.yMax);
+ if (base.options.fuzzMax) fuzz = base.clamp(fuzz, base.options.fuzzMin, base.options.fuzzMax)
+
+ sx += base.options.xOffset;
+ sy += base.options.yOffset;
+ base.pageX = x;
+ base.pageY = y;
+ base.sx = sx;
+ base.sy = sy;
+ base.fuzz = fuzz;
+ base.update();
};
- $.fn.okshadow = function(options){
- return this.each(function(){
- (new $.okshadow(this, options));
- });
- };
+ base.browsers = " -moz- -webkit- -ms-".split(" ");
+ base.update = function () {
+ var val = sx + "px " + sy + "px " + fuzz + "px " + base.options.color;
+ var prop = base.options.textShadow ? "text-shadow" : "box-shadow";
+ var styles = {};
+ for (var i in base.browsers) {
+ styles[base.browsers[i] + prop] = val;
+ }
+ base.$el.css(styles);
+ }
+ base.init();
+ };
+
+ $.okshadow.options = {
+ color: '#888',
+ fuzz: 40,
+ fuzzMin: 0,
+ fuzzMax: null,
+ xOffset: 0,
+ xFactor: 30,
+ xMax: null,
+ yOffset: 0,
+ yFactor: 30,
+ yMax: null,
+ textShadow: false,
+ transparent: false
+ };
+
+ $.fn.okshadow = function(options){
+ return this.each(function(){
+ (new $.okshadow(this, options));
+ });
+ };
+
})(jQuery);
View
@@ -1,96 +0,0 @@
-(function($){
-
- $.okshadow = function(el, options){
- var base = this;
- base.$el = $(el);
- base.el = el;
- base.$el.data("okshadow", base);
-
- base.init = function(){
- base.options = $.extend({}, $.okshadow.options, options);
- base.build();
- };
-
- base.build = function(){
- base.start();
- };
-
- base.clamp = function (x, min, max) {
- return Math.max(min, Math.min(max, x));
- };
-
- base.setoption = function (key, value) {
- if (typeof key === "string") base.options[key] = value;
- if (key === 'color') return base.update();
- else base.options = $.extend(base.options, key);
- base.mousemove(base);
- };
-
- base.start = function () {
- $(window).bind({
- mousemove: base.mousemove
- });
- base.mousemove({ pageX: $(window).width() / 2, pageY: $(window).height() / 2 });
- if (base.options.transparent) base.el.style.color = "transparent";
- };
-
- base.mousemove = function (e){
- var offset = base.$el.offset(),
- x = e.pageX,
- y = e.pageY,
- cy = offset.top + base.$el.height() / 2,
- cx = offset.left + base.$el.width() / 2,
- dx = (cx - x),
- dy = (cy - y)
- sx = dx / base.options.xFactor,
- sy = dy / base.options.yFactor,
- distance = Math.sqrt(dx*dx + dy*dy),
- fuzz = distance / base.options.fuzz + base.options.fuzzMin;
-
- if (base.options.xMax) sx = base.clamp(sx, -1 * base.options.xMax, base.options.xMax);
- if (base.options.yMax) sy = base.clamp(sy, -1 * base.options.yMax, base.options.yMax);
- if (base.options.fuzzMax) fuzz = base.clamp(fuzz, base.options.fuzzMin, base.options.fuzzMax)
-
- sx += base.options.xOffset;
- sy += base.options.yOffset;
- base.pageX = x;
- base.pageY = y;
- base.sx = sx;
- base.sy = sy;
- base.fuzz = fuzz;
- base.update();
- };
-
- base.update = function () {
- if (base.options.textShadow) {
- base.$el.css('text-shadow', sx + "px " + sy + "px " + fuzz + "px " + base.options.color);
- } else {
- base.$el.css('box-shadow', sx + "px " + sy + "px " + fuzz + "px " + base.options.color);
- }
- }
-
- base.init();
- };
-
- $.okshadow.options = {
- color: '#888',
- fuzz: 40,
- fuzzMin: 0,
- fuzzMax: null,
- xOffset: 0,
- xFactor: 30,
- xMax: null,
- yOffset: 0,
- yFactor: 30,
- yMax: null,
- textShadow: false,
- transparent: false
- };
-
- $.fn.okshadow = function(options){
- return this.each(function(){
- (new $.okshadow(this, options));
- });
- };
-
-})(jQuery);
View
Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 75b08b9

Please sign in to comment.