Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Port to MooTools

  • Loading branch information...
commit 287e3b6bac0452c9afc7247fb81ce80559c9b2d3 1 parent 980c8c7
@arian authored
Showing with 50 additions and 49 deletions.
  1. +7 −8 index.html
  2. +43 −41 realshadow.js
View
15 index.html
@@ -20,10 +20,11 @@
<div class="demo"></div>
</div>
- <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
- <script type="text/javascript" src="https://raw.github.com/Indamix/real-shadow/master/realshadow.js"></script>
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools.js"></script>
+ <script type="text/javascript" src="./realshadow.js"></script>
<script type="text/javascript">
- $(function(){
+
+ window.addEvent('domready', function(){
var a = ['rect', 'circle', 'round', 'ur', 'll'],
c = ['', 'r', 'g', 'b', 'rgb', 'rg', 'gb', 'br'],
@@ -31,7 +32,7 @@
s = '', i, j;
for (i = 0; i < columns; ++i){
- s += '<p>';
+ s += '<p>';
for (j = 0; j < rows; ++j)
s += '<span rel="' +
c[(i * columns + j) % c.length] +
@@ -43,16 +44,14 @@
s += '</p>';
}
- $('.demo').html('<div class="wrapper">' + s + '</div>')
+ document.getElement('.demo').set('html', '<div class="wrapper">' + s + '</div>')
- $('.realshadow').realshadow({
+ $$('.realshadow').realshadow({
// followMouse: false
});
});
</script>
- <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
-
</body>
</html>
View
84 realshadow.js
@@ -1,3 +1,4 @@
+/*jshint mootools:true */
/*!
* Real Shadow v1.0.1
* https://github.com/Indamix/real-shadow
@@ -6,51 +7,52 @@
* Licensed under the MIT license
* https://raw.github.com/Indamix/real-shadow/master/license.txt
*/
-(function($, window, undefined){
+(function(window, undefined){
+ "use strict";
// TODO add fn(height) to pass shape form
var settings = {
- followMouse: true,
+ followMouse: true
},
pi = Math.PI,
els = [];
- $.fn.realshadow = function(options){
- $.extend(settings, options);
- if (!els.length && settings.followMouse) $(document.body).mousemove(frame);
- $(window).resize(updatePositions);
+ Element.implement('realshadow', function(options){
+
+ options = Object.merge({}, settings, options);
+ if (!els.length && settings.followMouse) $(document.body).addEvent('mousemove', frame);
+ $(window).addEvent('resize', updatePositions);
add(this);
+
frame({
- pageX: settings.pageX !== undefined ? settings.pageX : $(window).width() >> 1,
- pageY: settings.pageY !== undefined ? settings.pageY : 0
- });
-
- };
- // $.fn.realshadow.frame=frame; //TODO
-
- function add($els){
- $.each($els, function(i, el){
- var $el = $(el),
- offset = $el.offset(),
- c = $el.attr('rel'),
- p = {
- dom: el,
- x: offset.left + ($el.outerWidth () >> 1),
- y: offset.top + ($el.outerHeight() >> 1)
- };
-
- if (c)
- p.c = {
- r: c.indexOf('r') !== -1,
- g: c.indexOf('g') !== -1,
- b: c.indexOf('b') !== -1
- }
- else
- if (settings.c) p.c = settings.c;
-
- els.push(p);
+ page: {
+ x: settings.pageX !== undefined ? settings.pageX : $(window).getWidth() >> 1,
+ y: settings.pageY !== undefined ? settings.pageY : 0
+ }
});
+
+ });
+
+ function add(el){
+ var offset = el.getPosition(),
+ c = el.get('rel'),
+ p = {
+ dom: el,
+ x: offset.x + (el.getWidth () >> 1),
+ y: offset.y + (el.getHeight() >> 1)
+ };
+
+ if (c)
+ p.c = {
+ r: c.indexOf('r') !== -1,
+ g: c.indexOf('g') !== -1,
+ b: c.indexOf('b') !== -1
+ }
+ else
+ if (settings.c) p.c = settings.c;
+
+ els.push(p);
}
function updatePositions(){
@@ -60,9 +62,9 @@
while (i--) {
el = els[i];
- offset = $(el.dom).offset();
- el.x = offset.left;
- el.y = offset.top;
+ offset = el.dom.getPosition();
+ el.x = offset.x;
+ el.y = offset.y;
}
}
@@ -97,7 +99,7 @@
var params = {
nMax: 2.3,
- pow: .8,
+ pow: 0.8,
div: 1500
}
@@ -108,8 +110,8 @@
while (i--) {
el = els[i];
- var x = e.pageX - els[i].x,
- y = e.pageY - els[i].y,
+ var x = e.page.x - els[i].x,
+ y = e.page.y - els[i].y,
n = Math.pow(x * x + y * y, params.pow)
n = n / params.div + 1; // TODO n = f(obj.size, distance)
@@ -123,4 +125,4 @@
}
}
-})(jQuery, this);
+})(this);
Please sign in to comment.
Something went wrong with that request. Please try again.