PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/smart-slider-3/library/smartslider/libraries/slider/features/fadeonload.php

https://bitbucket.org/juanlautaromartin/drogueria-paso
PHP | 105 lines | 79 code | 26 blank | 0 comment | 18 complexity | 5efe7ad7ae4825d4a447bbee1ef35a9d MD5 | raw file
Possible License(s): MIT, Apache-2.0
  1. <?php
  2. class N2SmartSliderFeatureFadeOnLoad {
  3. private $slider;
  4. public $fadeOnLoad = 1;
  5. public $fadeOnScroll = 0;
  6. public $playWhenVisible = 1;
  7. public $playWhenVisibleAt = 0.5;
  8. public function __construct($slider) {
  9. $this->slider = $slider;
  10. $this->fadeOnLoad = intval($slider->params->get('fadeOnLoad', 1));
  11. $this->fadeOnScroll = intval($slider->params->get('fadeOnScroll', 0));
  12. $this->playWhenVisible = intval($slider->params->get('playWhenVisible', 1));
  13. $this->playWhenVisibleAt = max(0, min(100, intval($slider->params->get('playWhenVisibleAt', 50)))) / 100;
  14. if (!empty($this->fadeOnScroll) && $this->fadeOnScroll) {
  15. $this->fadeOnLoad = 1;
  16. $this->fadeOnScroll = 1;
  17. } else {
  18. $this->fadeOnScroll = 0;
  19. }
  20. }
  21. public function forceFadeOnLoad() {
  22. if (!$this->fadeOnScroll && !$this->fadeOnLoad) {
  23. $this->fadeOnLoad = 1;
  24. }
  25. }
  26. public function getSliderClass() {
  27. if ($this->fadeOnLoad) {
  28. return 'n2-ss-load-fade ';
  29. }
  30. return '';
  31. }
  32. public function renderPlaceholder($sizes) {
  33. if (!$this->slider->isAdmin && $this->fadeOnLoad && ($this->slider->features->responsive->scaleDown || $this->slider->features->responsive->scaleUp)) {
  34. if (N2SystemHelper::testMemoryLimit()) {
  35. if ($sizes['width'] + $sizes['marginHorizontal'] > 0 && $sizes['height'] > 0) {
  36. return N2Html::tag("div", array(
  37. "id" => $this->slider->elementId . "-placeholder",
  38. "encode" => false,
  39. "style" => 'position: relative;z-index:2;color:RGBA(0,0,0,0);'
  40. ), $this->makeImage($sizes));
  41. } else {
  42. N2CSS::addCode("#{$this->slider->elementId} .n2-ss-load-fade{position: relative !important;}", $this->slider->cacheId);
  43. }
  44. } else {
  45. N2Message::error(n2_("It seems like the <a href='http://php.net/manual/en/ini.core.php#ini.memory-limit'>memory_limit</a> on the server is too low for the fade on load feature. Please set it minimum 60M and reload the page!"));
  46. }
  47. } else {
  48. N2CSS::addCode("#{$this->slider->elementId}.n2-ss-load-fade{position: relative !important;}", $this->slider->cacheId);
  49. }
  50. return '';
  51. }
  52. public function makeJavaScriptProperties(&$properties) {
  53. $properties['load'] = array(
  54. 'fade' => $this->fadeOnLoad,
  55. 'scroll' => ($this->fadeOnScroll & !$this->slider->isAdmin)
  56. );
  57. $properties['playWhenVisible'] = $this->playWhenVisible;
  58. $properties['playWhenVisibleAt'] = $this->playWhenVisibleAt;
  59. }
  60. private function makeImage($sizes) {
  61. $html = N2Html::image("data:image/svg+xml;base64," . $this->transparentImage($sizes['width'] + $sizes['marginHorizontal'], $sizes['height']), 'Slider', array(
  62. 'style' => 'width: 100%; max-width:' . ($this->slider->features->responsive->maximumSlideWidth + $sizes['marginHorizontal']) . 'px; display: block;',
  63. 'class' => 'n2-ow'
  64. ));
  65. if ($sizes['marginVertical'] > 0) {
  66. $html .= N2Html::image("data:image/svg+xml;base64," . $this->transparentImage($sizes['width'] + $sizes['marginHorizontal'], $sizes['marginVertical']), 'Slider', array(
  67. 'style' => 'width: 100%;',
  68. 'class' => 'n2-ow'
  69. ));
  70. }
  71. return $html;
  72. }
  73. private function transparentImage($width, $height) {
  74. return n2_base64_encode('<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="' . $width . '" height="' . $height . '" ></svg>');
  75. }
  76. private static function gcd($a, $b) {
  77. return ($a % $b) ? self::gcd($b, $a % $b) : $b;
  78. }
  79. }