├── bower.json
├── ionic-ripple.js
└── README.md
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ionic-ripple",
3 | "version": "0.1.0",
4 | "homepage": "http://github.com/darryld/ionic-ripple",
5 | "authors": [
6 | "Darryl D."
7 | ],
8 | "description": "Simple way to add material design ripple effect to elements.",
9 | "main": "ionic-ripple.js",
10 | "dependencies": {
11 | "angular": "^1.2.0"
12 | },
13 | "keywords": [
14 | "ionic",
15 | "angularjs",
16 | "angular",
17 | "ripple",
18 | "google",
19 | "material"
20 | ],
21 | "license": "MIT",
22 | "ignore": [
23 | "**/.*",
24 | "node_modules"
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/ionic-ripple.js:
--------------------------------------------------------------------------------
1 | /**
2 | * ionic-ripple v0.0.4 - Simple way to add material design ripple effect to elements.
3 | * Copyright (c) 2015 Darryl D. - http://github.com/darryld/ionic-ripple
4 | * License: MIT
5 | */
6 |
7 | (function(window, angular, undefined) {
8 | 'use strict';
9 |
10 | if(!angular) {
11 | return;
12 | }
13 |
14 | function onRippleEvent(dark, pos){
15 | return function(e){
16 | var rippledElement = $(this);
17 | var hasRippleEl = rippledElement.find(".rip").length === 0;
18 |
19 | //if we have a ripple element from a previous click, we'll just use that
20 | if(hasRippleEl){
21 |
22 | //if we're adding this to an item, the ripple element needs to
23 | //be inside the anchor inside the ion-item directive
24 | if(rippledElement[0].tagName === 'ION-ITEM'){
25 | rippledElement.find('a').prepend("");
26 | }else{
27 | rippledElement.prepend("");
28 | }
29 | }
30 |
31 | var rip = rippledElement.find(".rip");
32 |
33 | rip.removeClass("animate-ripple");
34 |
35 | if(!rip.height() && !rip.width()){
36 | var d = Math.max(rippledElement.outerWidth(), rippledElement.outerHeight());
37 | rip.css({height: d, width: d});
38 | }
39 |
40 | var x = pos ? pos.pageX : e.pageX;
41 | var y = pos ? pos.pageY : e.pageY;
42 | x = x - rippledElement.offset().left - rip.width()/2;
43 | y = y - rippledElement.offset().top - rip.height()/2;
44 |
45 | if( dark ){
46 | rip.css({background: 'rgba(0, 0, 0, 0.3)'});
47 | }
48 |
49 | rip.css({top: y+'px', left: x+'px'}).addClass("animate-ripple");
50 | };
51 | }
52 |
53 | var mod = angular.module('ionicRipple', []);
54 |
55 | mod.directive('ripple', function() {
56 | return {
57 | restrict: 'A',
58 | link: function (scope, element, attrs) {
59 | element.on('click', onRippleEvent(attrs.hasOwnProperty('rippleDark')));
60 | }
61 | };
62 | });
63 |
64 | mod.directive('rippleHold', function() {
65 | return {
66 | restrict: 'A',
67 | link: function (scope, element, attrs) {
68 | var pos = {};
69 |
70 | // as hold won't send location, save location on mousedown / touchstart event
71 | element.on('mousedown', function (e){
72 | pos.pageX = e.pageX;
73 | pos.pageY = e.pageY;
74 | });
75 | element.on('touchstart', function (e){
76 | if(!e.originalEvent){ pos = {}; return; }
77 | pos.pageX = e.originalEvent.targetTouches[0].pageX;
78 | pos.pageY = e.originalEvent.targetTouches[0].pageY;
79 | });
80 | element.on('hold', onRippleEvent(attrs.hasOwnProperty('rippleDark'), pos));
81 | }
82 | };
83 | });
84 |
85 | })(window, window.angular);
86 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ionic-ripple
2 | ==============
3 |
4 | Simple way to add material design ripple effect to elements.
5 |
6 | For the people who just want to implement the Google Material Design ripple effect and not the whole suite of material'y stuff.
7 |
8 |
9 | # Bower
10 |
11 | ```bash
12 | bower install --save ionic-ripple
13 | ```
14 |
15 |
16 | # Usage
17 |
18 | Include the script in your HTML (need jquery for now...)
19 |
20 | ```html
21 |
22 |
23 |
24 |
25 | ```
26 |
27 | Then include `ionicRipple` in your module dependencies
28 |
29 | ```js
30 | angular.module('yourApp', ['ionicRipple']);
31 | ```
32 |
33 | Then add the `ripple` attribute to elements (make sure the elements have color since the ripple is white)
34 |
35 | ```html
36 |
37 |
38 | ```
39 |
40 | In order to trigger the ripple on a long-press (ie. tap hold) event
41 | ```html
42 |
43 |
44 | ```
45 |
46 | If you want a dark ripple...
47 |
48 | ```html
49 |
50 |
51 | ```
52 |
53 | Add these styles
54 |
55 | ```css
56 | [ripple]{
57 | overflow: hidden;
58 | }
59 |
60 | .rip {
61 | display: block;
62 | position: absolute;
63 | background:rgba(255, 255, 255, 0.3);
64 | border-radius: 100%;
65 | -webkit-transform:scale(0);
66 | -moz-transform:scale(0);
67 | -o-transform:scale(0);
68 | transform:scale(0);
69 | }
70 |
71 | .animate-ripple {
72 | -webkit-animation:ripple 0.65s linear;
73 | -moz-animation:ripple 0.65s linear;
74 | -ms-animation:ripple 0.65s linear;
75 | -o-animation:ripple 0.65s linear;
76 | animation:ripple 0.65s linear;
77 | }
78 |
79 | @-webkit-keyframes ripple {
80 | 100% {opacity: 0; -webkit-transform: scale(2.5);}
81 | }
82 | @-moz-keyframes ripple {
83 | 100% {opacity: 0; -moz-transform: scale(2.5);}
84 | }
85 | @-o-keyframes ripple {
86 | 100% {opacity: 0; -o-transform: scale(2.5);}
87 | }
88 | @keyframes ripple {
89 | 100% {opacity: 0; transform: scale(2.5);}
90 | }
91 | ```
92 |
93 | Add your done!
94 |
95 |
96 | # Credits
97 |
98 | Inspired by [this demo](http://codepen.io/440design/pen/iEztk)
99 |
100 | # License
101 | The MIT License
102 |
103 | Copyright (c) 2015 Darryl D.
104 |
105 | 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:
106 |
107 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
108 |
109 | 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.
110 |
111 |
112 |
113 | bower register ionic-ripple https://github.com/DarrylD/ionic-ripple.git
114 |
--------------------------------------------------------------------------------