Skip to content

Commit

Permalink
Merge pull request #4 from TrySound/master
Browse files Browse the repository at this point in the history
scope and dist
  • Loading branch information
jakiestfu committed Jan 27, 2015
2 parents 6288b13 + 4bc4762 commit 578522c
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 32 deletions.
21 changes: 17 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ module.exports = function(grunt) {

pkg: pkg,

concat: {
options: {
banner: "/*! " + banner + " */\n\n"
},
copy: {
files: {
'dist/ripple.js': ["src/ripple.js"],
'dist/ripple.css': ["src/ripple.css"]
}
}
},

cssmin: {
options: {
banner: "/* " + banner + " */",
banner: "/*! " + banner + " */",
preserveComments: 'some'
},
main: {
Expand All @@ -28,7 +40,7 @@ module.exports = function(grunt) {

uglify: {
options: {
banner: "/* " + banner + " */\n",
banner: "/*! " + banner + " */\n",
footer: "$.ripple.version = \"<%= pkg.version %>\";",
preserveComments: 'some'
},
Expand All @@ -55,11 +67,12 @@ module.exports = function(grunt) {
}
});

grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('default', ['jshint', 'uglify', 'cssmin']);
grunt.registerTask('develop', ['jshint', 'uglify', 'cssmin', 'watch']);
grunt.registerTask('default', ['jshint', 'concat', 'uglify', 'cssmin']);
grunt.registerTask('develop', ['jshint', 'concat', 'uglify', 'cssmin', 'watch']);
};
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
],
"description": "Adds Material style ripple to anything",
"main": [
"src/ripple.js",
"src/ripple.css"
"dist/ripple.js",
"dist/ripple.css"
],
"keywords": [
"material",
Expand Down
49 changes: 49 additions & 0 deletions dist/ripple.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*! Ripple.js v1.2.1
* The MIT License (MIT)
* Copyright (c) 2014 Jacob Kelley */

.has-ripple {
position: relative;
overflow: hidden;
-webkit-transform: translate3d(0,0,0);
-o-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
.ripple {
display: block;
position: absolute;
pointer-events: none;
border-radius: 50%;

-webkit-transform: scale(0);
-o-transform: scale(0);
transform: scale(0);

background: #fff;
opacity: 1;
}
.ripple-animate {
-webkit-animation: ripple;
-o-animation: ripple;
animation: ripple;
}
@-webkit-keyframes ripple {
100% {
opacity: 0;
-webkit-transform: scale(2);
transform: scale(2);
}
}
@-o-keyframes ripple {
100% {
opacity: 0;
-o-transform: scale(2);
transform: scale(2);
}
}
@keyframes ripple {
100% {
opacity: 0;
transform: scale(2);
}
}
139 changes: 139 additions & 0 deletions dist/ripple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*! Ripple.js v1.2.1
* The MIT License (MIT)
* Copyright (c) 2014 Jacob Kelley */

;(function($, document, Math){
$.ripple = function(selector, options) {

var self = this;

var _log = self.log = function() {
if(self.defaults.debug && console && console.log) {
console.log.apply(console, arguments);
}
};

self.selector = selector;
self.defaults = {
debug: false,
on: 'mousedown',

opacity: 0.4,
color: "auto",
multi: false,

duration: 0.7,
rate: function(pxPerSecond) {
return pxPerSecond;
},

easing: 'linear'
};

self.defaults = $.extend({}, self.defaults, options);

var Trigger = function(e) {

var $this = $(this);
var $ripple;
var settings;

$this.addClass('has-ripple');

// This instances settings
settings = $.extend({}, self.defaults, $this.data());

// Create the ripple element
if ( settings.multi || (!settings.multi && $this.find(".ripple").length === 0) ) {
$ripple = $("<span></span>").addClass("ripple");
$ripple.appendTo($this);

_log('Create: Ripple');

// Set ripple size
if (!$ripple.height() && !$ripple.width()) {
var size = Math.max($this.outerWidth(), $this.outerHeight());
$ripple.css({
height: size,
width: size
});
_log('Set: Ripple size');
}

// Give the user the ability to change the rate of the animation
// based on element width
if(settings.rate && typeof settings.rate == "function") {

// rate = pixels per second
var rate = Math.round( $ripple.width() / settings.duration );

// new amount of pixels per second
var filteredRate = settings.rate(rate);

// Determine the new duration for the animation
var newDuration = ( $ripple.width() / filteredRate);

// Set the new duration if it has not changed
if(settings.duration.toFixed(2) !== newDuration.toFixed(2)) {
_log('Update: Ripple Duration', {
from: settings.duration,
to: newDuration
});
settings.duration = newDuration;
}
}

// Set the color and opacity
var color = (settings.color == "auto") ? $this.css('color') : settings.color;
var css = {
animationDuration: (settings.duration).toString() + 's',
animationTimingFunction: settings.easing,
background: color,
opacity: settings.opacity
};

_log('Set: Ripple CSS', css);
$ripple.css(css);
}

// Ensure we always have the ripple element
if(!settings.multi) {
_log('Set: Ripple Element');
$ripple = $this.find(".ripple");
}

// Kill animation
_log('Destroy: Ripple Animation');
$ripple.removeClass("ripple-animate");


// Retrieve coordinates
var x = e.pageX - $this.offset().left - $ripple.width() / 2;
var y = e.pageY - $this.offset().top - $ripple.height() / 2;

/**
* We want to delete the ripple elements if we allow multiple so we dont sacrifice any page
* performance. We don't do this on single ripples because once it has rendered, we only
* need to trigger paints thereafter.
*/
if(settings.multi) {
_log('Set: Ripple animationend event');
$ripple.one('animationend webkitAnimationEnd oanimationend MSAnimationEnd', function() {
_log('Note: Ripple animation ended');
_log('Destroy: Ripple');
$(this).remove();
});
}

// Set position and animate
_log('Set: Ripple location');
_log('Set: Ripple animation');
$ripple.css({
top: y + 'px',
left: x + 'px'
}).addClass("ripple-animate");
};

$(document).on(self.defaults.on, self.selector, Trigger);
};
})(jQuery, document, Math);
2 changes: 1 addition & 1 deletion dist/ripple.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/ripple.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"name": "Ripple.js",
"author": "Jacob Kelley",
"version": "1.2.1",
"repository": {
"type": "git",
"url": "https://github.com/jakiestfu/Ripple.js.git"
},
"scripts": {
"bower": "./node_modules/bower/bin/bower install",
"build": "./node_modules/grunt-cli/bin/grunt",
"build-watch": "./node_modules/grunt-cli/bin/grunt develop"
},
"devDependencies": {
"bower": "*",
"grunt": "~0.4.1",
"grunt-cli": "~0.1.9",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-uglify": "0.2.5",
"grunt-contrib-jshint": "0.8.0",
"grunt-contrib-cssmin": "0.10.0"
}
"name": "Ripple.js",
"author": "Jacob Kelley",
"version": "1.2.1",
"repository": {
"type": "git",
"url": "https://github.com/jakiestfu/Ripple.js.git"
},
"scripts": {
"bower": "./node_modules/bower/bin/bower install",
"build": "./node_modules/grunt-cli/bin/grunt",
"build-watch": "./node_modules/grunt-cli/bin/grunt develop"
},
"devDependencies": {
"bower": "*",
"grunt": "~0.4.1",
"grunt-cli": "~0.1.9",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-cssmin": "0.10.0",
"grunt-contrib-jshint": "0.8.0",
"grunt-contrib-uglify": "0.2.5",
"grunt-contrib-watch": "~0.5.3"
}
}
4 changes: 2 additions & 2 deletions src/ripple.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;(function($){
;(function($, document, Math){
$.ripple = function(selector, options) {

var self = this;
Expand Down Expand Up @@ -132,4 +132,4 @@

$(document).on(self.defaults.on, self.selector, Trigger);
};
})(jQuery);
})(jQuery, document, Math);

0 comments on commit 578522c

Please # to comment.