Guest User

Untitled

a guest
Mar 18th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. var tdLoadingBox = {};
  2.  
  3.  
  4. ( function() {
  5. "use strict";
  6. tdLoadingBox = {
  7.  
  8. //arrayColors: ['#ffffff', '#fafafa', '#ececec', '#dddddd', '#bfbfbf', '#9a9a9a', '#7e7e7e', '#636363'],//whiter -> darker
  9.  
  10. speed: 40,
  11.  
  12. arrayColorsTemp: [
  13. 'rgba(99, 99, 99, 0)',
  14. 'rgba(99, 99, 99, 0.05)',
  15. 'rgba(99, 99, 99, 0.08)',
  16. 'rgba(99, 99, 99, 0.2)',
  17. 'rgba(99, 99, 99, 0.3)',
  18. 'rgba(99, 99, 99, 0.5)',
  19. 'rgba(99, 99, 99, 0.6)',
  20. 'rgba(99, 99, 99, 1)'
  21. ],//whiter -> darker
  22.  
  23. arrayColors: [],
  24.  
  25. statusAnimation: 'stop',
  26.  
  27. //stop loading box
  28. stop : function stop () {
  29. tdLoadingBox.statusAnimation = 'stop';
  30. //jQuery('.td-loader-gif').html("");
  31. },
  32.  
  33.  
  34. //init loading box
  35. init : function init (color, speed) {
  36.  
  37. // set up the speed
  38. if (false === tdUtil.isUndefined(speed)) {
  39. tdLoadingBox.speed = speed;
  40. }
  41.  
  42. //console.log('test');
  43. var tdColorRegExp = /^#[a-zA-Z0-9]{3,6}$/;
  44. if(color && tdColorRegExp.test(color)) {
  45.  
  46. var colRgba = tdLoadingBox.hexToRgb(color);
  47.  
  48. var rgbaString = "rgba(" + colRgba.r + ", " + colRgba.g + ", " + colRgba.b + ", ";
  49.  
  50. tdLoadingBox.arrayColors[7] = rgbaString + " 1)";
  51. tdLoadingBox.arrayColors[6] = rgbaString + " 0.6)";
  52. tdLoadingBox.arrayColors[5] = rgbaString + " 0.5)";
  53. tdLoadingBox.arrayColors[4] = rgbaString + " 0.3)";
  54. tdLoadingBox.arrayColors[3] = rgbaString + " 0.2)";
  55. tdLoadingBox.arrayColors[2] = rgbaString + " 0.08)";
  56. tdLoadingBox.arrayColors[1] = rgbaString + " 0.05)";
  57. tdLoadingBox.arrayColors[0] = rgbaString + " 0)";
  58.  
  59. } else {
  60. //default array
  61. tdLoadingBox.arrayColors = tdLoadingBox.arrayColorsTemp.slice(0);
  62.  
  63. }
  64.  
  65. if(tdLoadingBox.statusAnimation === 'stop') {
  66. tdLoadingBox.statusAnimation = 'display';
  67. this.render();
  68. }
  69. },
  70.  
  71.  
  72. //create the animation
  73. render: function render (color) {
  74.  
  75. //call the animationDisplay function
  76. tdLoadingBox.animationDisplay(
  77. '<div class="td-lb-box td-lb-box-1" style="background-color:' + tdLoadingBox.arrayColors[0] + '"></div>' +
  78. '<div class="td-lb-box td-lb-box-2" style="background-color:' + tdLoadingBox.arrayColors[1] + '"></div>' +
  79. '<div class="td-lb-box td-lb-box-3" style="background-color:' + tdLoadingBox.arrayColors[2] + '"></div>' +
  80. '<div class="td-lb-box td-lb-box-4" style="background-color:' + tdLoadingBox.arrayColors[3] + '"></div>' +
  81. '<div class="td-lb-box td-lb-box-5" style="background-color:' + tdLoadingBox.arrayColors[4] + '"></div>' +
  82. '<div class="td-lb-box td-lb-box-6" style="background-color:' + tdLoadingBox.arrayColors[5] + '"></div>' +
  83. '<div class="td-lb-box td-lb-box-7" style="background-color:' + tdLoadingBox.arrayColors[6] + '"></div>' +
  84. '<div class="td-lb-box td-lb-box-8" style="background-color:' + tdLoadingBox.arrayColors[7] + '"></div>'
  85. );
  86.  
  87. //direction right
  88. var tempColorArray = [
  89. tdLoadingBox.arrayColors[0],
  90. tdLoadingBox.arrayColors[1],
  91. tdLoadingBox.arrayColors[2],
  92. tdLoadingBox.arrayColors[3],
  93. tdLoadingBox.arrayColors[4],
  94. tdLoadingBox.arrayColors[5],
  95. tdLoadingBox.arrayColors[6],
  96. tdLoadingBox.arrayColors[7]
  97. ];
  98.  
  99. tdLoadingBox.arrayColors[0] = tempColorArray[7];
  100. tdLoadingBox.arrayColors[1] = tempColorArray[0];
  101. tdLoadingBox.arrayColors[2] = tempColorArray[1];
  102. tdLoadingBox.arrayColors[3] = tempColorArray[2];
  103. tdLoadingBox.arrayColors[4] = tempColorArray[3];
  104. tdLoadingBox.arrayColors[5] = tempColorArray[4];
  105. tdLoadingBox.arrayColors[6] = tempColorArray[5];
  106. tdLoadingBox.arrayColors[7] = tempColorArray[6];
  107.  
  108. if(tdLoadingBox.statusAnimation === 'display') {
  109.  
  110.  
  111. setTimeout(tdLoadingBox.render, tdLoadingBox.speed);
  112. } else {
  113. tdLoadingBox.animationDisplay('');
  114. }
  115. },
  116.  
  117.  
  118. //display the animation
  119. animationDisplay: function (animation_str) {
  120. jQuery('.td-loader-gif').html(animation_str);
  121. },
  122.  
  123.  
  124. //converts hex to rgba
  125. hexToRgb: function (hex) {
  126. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  127.  
  128. return result ? {
  129. r: parseInt(result[1], 16),
  130. g: parseInt(result[2], 16),
  131. b: parseInt(result[3], 16)
  132. } : null;
  133. }
  134. }; //tdLoadingBox.init();//tdLoadingBox.stop();
  135. })();
Advertisement
Add Comment
Please, Sign In to add comment