├── .gitignore
├── README.md
├── angular-ripple.js
├── bower.json
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | npm-debug.log
2 | .DS_Store
3 | bower_components
4 | node_modules
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | angular-ripple
2 | ==============
3 |
4 | 
5 |
6 | A pure javascript (no polymer, no jQuery) AngularJS directive that adds a Google Material Design ripple effect when clicked or touched.
7 |
8 | [Angular Material](https://material.angularjs.org/) is cool, but sometimes you just want the ripple effect in your angular app without all the bloat. That’s why we made this.
9 |
10 | Ain't nobody f*ckin' with my [Clique](https://www.youtube.com/watch?v=FOrLNHbEzMg)
11 |
12 | # Demo
13 |
14 | Here's a demo
15 |
16 | # Bower
17 |
18 | ```bash
19 | bower install --save angular-ripple
20 | ```
21 |
22 |
23 | # Usage
24 |
25 | Include the script in your HTML
26 |
27 | ```html
28 |
29 | ```
30 |
31 | Then include `angularRipple` in your module dependencies
32 |
33 | ```js
34 | angular.module('yourApp', ['angularRipple']);
35 | ```
36 |
37 | Then add the `angular-ripple` attribute to elements
38 |
39 | ```html
40 |
41 | ```
42 |
43 | Add some styles to the ripple (remember to include browser specific prefixes)
44 |
45 | ```css
46 | [angular-ripple] {
47 | position: relative;
48 | overflow: hidden;
49 | }
50 | .angular-ripple {
51 | display: block;
52 | position: absolute;
53 | background-color: rgba(0,0,0,0.1);
54 | border-radius: 50%;
55 | transform: scale(0);
56 | }
57 | .angular-ripple.animate {
58 | animation: ripple 0.35s linear;
59 | }
60 | @keyframes ripple {
61 | 100% {
62 | opacity: 0;
63 | transform: scale(2.5);
64 | }
65 | }
66 | ```
67 |
68 | # License
69 | The MIT License
70 |
71 | Copyright (c) 2014 Nelson Cash http://www.nelsoncash.com
72 |
73 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
74 |
75 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
76 |
77 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
78 |
79 | # Contributors
80 |
81 | - Mike McMillan ([@MikeMcChillin](http://twitter.com/mikemcchillin))
82 | - Matthew Frey ([mmmeff](https://github.com/mmmeff))
83 | - [storuky](https://github.com/storuky)
84 |
85 | # Changelog
86 | ## 0.0.7 - 06/03/2016
87 | - Fixed [GH Issue #13](https://github.com/nelsoncash/angular-ripple/issues/13), which changes mouseup to mousedown and touchend to touchstart.
88 |
89 | ## 0.0.6 - 06/03/2016
90 | - Merged in @storuky's [commit](https://github.com/nelsoncash/angular-ripple/pull/8/commits/36dbc9e8ffc6550bbc6c145076b4f78d86ac0b12) to fix double event call on iOS.
91 |
92 | ## 0.0.5 - 06/26/2015
93 | - Merged in @mmmeff's [commit](https://github.com/mmmeff/angular-ripple/commit/5173af8e84302e56223edab492973aba3d0855d7) to fix degredation and event handling
94 |
95 | ## 0.0.4 - 05/28/2015
96 | - Added scope.$on('$destroy')
97 |
98 | ## 0.0.3 - 03/21/2015
99 | ### Fixed
100 | - Changed ripple position calculation to work with scrolling divs, using [this method](http://stackoverflow.com/a/28857255). Closes out [GH issue #1](https://github.com/nelsoncash/angular-ripple/issues/1).
101 |
102 | ## 0.0.2 - 02/14/2015
103 | ### Fixed
104 | - Changed ripple position calculation from getClientBoundingRect() to getPos() to be much more accurate.
105 |
106 | ## 0.0.1 - 02/14/2015
107 | ### Added
108 | - This changelog
109 |
110 | ### Fixed
111 | - Ripple position calculation, based on antoinepairet's [fork](https://github.com/b12consulting/angular-ripple)
112 | - Added moz & webkit prefixes to demo page's CSS.
113 |
114 |
115 |
116 | # Credits
117 |
118 | Big props to [this demo](http://codepen.io/fronterweb/pen/jcwgx)
119 | Built by [Nelson Cash](http://nelsoncash.com).
120 | We're hiring in Chicago. Hit us up.
--------------------------------------------------------------------------------
/angular-ripple.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * angular-ripple.js v0.0.7 - A standalone AngularJS implementation of the Google Material Design ripple effect.
3 | * Copyright (c) 2014 Nelson Cash - http://github.com/nelsoncash/angular-ripple
4 | * http://codepen.io/MikeMcChillin/pen/XJrLwg
5 | * License: MIT
6 | */
7 |
8 | (function(window, angular, undefined) {
9 | 'use strict';
10 |
11 | if(!angular) {
12 | return;
13 | }
14 |
15 | var rip = angular.module('angularRipple', []);
16 |
17 | rip.directive('angularRipple', function() {
18 | return {
19 | restrict: 'A',
20 | link: function (scope, element, attrs) {
21 | var x, y, size, offsets,
22 | func = function(e){
23 | var ripple = this.querySelector('.angular-ripple');
24 | var eventType = e.type;
25 | // Ripple
26 | if (ripple === null) {
27 | // Create ripple
28 | ripple = document.createElement('span');
29 | ripple.className += ' angular-ripple';
30 |
31 | // Prepend ripple to element
32 | this.insertBefore(ripple, this.firstChild);
33 |
34 | // Set ripple size
35 | if (!ripple.offsetHeight && !ripple.offsetWidth) {
36 | size = Math.max(element[0].offsetWidth, element[0].offsetHeight);
37 | ripple.style.width = size + 'px';
38 | ripple.style.height = size + 'px';
39 | }
40 | }
41 |
42 | // Remove animation effect
43 | ripple.className = ripple.className.replace(/ ?(animate)/g, '');
44 |
45 | // get click coordinates by event type
46 | if (eventType === 'mousedown') {
47 | x = e.pageX;
48 | y = e.pageY;
49 | } else if (eventType === 'touchstart') {
50 | try {
51 | var origEvent;
52 |
53 | if (typeof e.changedTouches !== 'undefined') {
54 | origEvent = e.changedTouches[0];
55 | } else {
56 | origEvent = e.originalEvent;
57 | }
58 |
59 | x = origEvent.pageX;
60 | y = origEvent.pageY;
61 | } catch (e) {
62 | // fall back to center of el
63 | x = ripple.offsetWidth / 2;
64 | y = ripple.offsetHeight / 2;
65 | }
66 | }
67 |
68 | // set new ripple position by click or touch position
69 | function getPos(element) {
70 | var de = document.documentElement;
71 | var box = element.getBoundingClientRect();
72 | var top = box.top + window.pageYOffset - de.clientTop;
73 | var left = box.left + window.pageXOffset - de.clientLeft;
74 | return { top: top, left: left };
75 | }
76 |
77 | offsets = getPos(element[0]);
78 | ripple.style.left = (x - offsets.left - size / 2) + 'px';
79 | ripple.style.top = (y - offsets.top - size / 2) + 'px';
80 |
81 | // Add animation effect
82 | ripple.className += ' animate';
83 | }
84 |
85 | var eventType = ('ontouchstart' in document) ? 'touchstart' : 'mousedown';
86 | element.on(eventType, func);
87 |
88 | //remove the event listener on scope destroy
89 | scope.$on('$destroy',function() {
90 | element.off(eventType, func);
91 | });
92 | }
93 | };
94 | });
95 | })(window, window.angular);
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-ripple",
3 | "version": "0.0.7",
4 | "homepage": "http://github.com/nelsoncash/angular-ripple",
5 | "authors": [
6 | "Nelson Cash"
7 | ],
8 | "description": "A standalone AngularJS implementation of the Google Material Design ripple effect.",
9 | "main": "angular-ripple.js",
10 | "dependencies": {
11 | "angular": "^1.2.0"
12 | },
13 | "keywords": [
14 | "angularjs",
15 | "angular",
16 | "ripple",
17 | "google",
18 | "material"
19 | ],
20 | "license": "MIT",
21 | "ignore": [
22 | "**/.*",
23 | "node_modules"
24 | ]
25 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ngRipple",
3 | "description": "A standalone Angular implementation of the Google Material Design ripple effect.",
4 | "version": "0.0.7",
5 | "author": "Nelson Cash",
6 | "homepage": "https://github.com/nelsoncash/ngRipple",
7 | "bugs": "https://github.com/nelsoncash/ngRipple/issues",
8 | "keywords": ["angular", "ripple", "ngRipple", "ng-ripple", "google", "material", "material design", "click"],
9 | "license": "MIT",
10 | "contributors": "MikeMcChillin",
11 | "repository": {
12 | "type": "git",
13 | "url": "https://github.com/nelsoncash/ngRipple.git"
14 | },
15 | "dependencies": {},
16 | "devDependencies": {
17 | "gulp": "^3.8.7",
18 | "gulp-jshint": "^1.8.4",
19 | "gulp-karma": "0.0.4",
20 | "gulp-rename": "^1.2.0",
21 | "gulp-uglify": "^0.3.2",
22 | "jshint-stylish": "^0.4.0",
23 | "karma": "^0.12.22"
24 | },
25 | "engines": {
26 | "node": "0.10.x",
27 | "npm": "1.4.x"
28 | }
29 | }
--------------------------------------------------------------------------------