ui_effects.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. module.exports = {
  19. /**
  20. *
  21. * @param node {DOMElement} - DOM element which blinking
  22. * @param delay {number} - overall time of blinking
  23. * @param callback {function}
  24. * @param interval {number} - change frequence of blinking
  25. */
  26. pulsate: function (node, delay, callback, interval) {
  27. var self = this;
  28. /**
  29. * execute single blink
  30. * @param interval {number} - time of single blink
  31. * @param callback {function}
  32. * @param opacity {string|number}
  33. * @param iteration {number} - current iteration(default amount of iterations: 10)
  34. * @param isReverse {boolean} - flag, that mean opacity increase or decrease
  35. */
  36. var blink = function (interval, callback, opacity, iteration, isReverse) {
  37. var iterations = 10;
  38. opacity = opacity || 1;
  39. iteration = (iteration !== undefined) ? iteration : 10;
  40. if (iteration > 0) {
  41. iteration--;
  42. setTimeout(function () {
  43. isReverse = isReverse || (opacity <= 1 / (iterations / 2));
  44. opacity = (isReverse) ? opacity + (1 / (iterations / 2)) : opacity - (1 / (iterations / 2));
  45. node.css('opacity', opacity);
  46. blink(interval, callback, opacity, iteration, isReverse);
  47. }, interval / iterations);
  48. } else {
  49. node.css('opacity', 1);
  50. callback();
  51. }
  52. };
  53. interval = interval || 200;
  54. if (delay > 0) {
  55. delay -= interval;
  56. setTimeout(function () {
  57. blink(interval, function () {
  58. self.pulsate(node, delay, callback, interval);
  59. });
  60. }, interval);
  61. } else {
  62. callback();
  63. }
  64. }
  65. };