PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / Models / Options / Script.php

Script.php in Depicter — Popup & Slider Builder 1.9.2, at app/src/Document/Models/Options/Script.php

156 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Document\Models\Options;
3
4 use Averta\WordPress\Utility\JSON;
5 use Depicter\Document\Models\Document;
6
7 class Script
8 {
9 /**
10 * @param Document $document
11 *
12 * @return string
13 */
14 public function getDocumentInitScript( $document )
15 {
16 $width = array_values( $document->options->getSizes( 'width' ) );
17 $height = array_values( $document->options->getSizes( 'height') );
18
19 $attributes = [
20 'width' => $width,
21 'height' => $height,
22 'keepAspectRatio' => isset( $document->options->general->keepAspect ) ? $document->options->general->keepAspect : false,
23 'preload' => isset( $document->options->loading ) ? $document->options->loading->getValue() : 0,
24 'layout' => $document->options->getLayout(),
25 'rtl' => isset( $document->options->navigation->rtl ) ? $document->options->navigation->rtl : false
26 ];
27
28 if ( $document->isBuildWithAI ) {
29 $attributes['disableAnimations'] = true;
30 }
31
32 if( isset( $document->options->sectionTransition->type ) ){
33 $attributes['view'] = !empty( $document->options->sectionTransition->type ) ? $document->options->sectionTransition->type : 'basic';
34 }
35
36 // viewOptions property
37 $viewOptions = [];
38 if( isset( $document->options->navigation->loop ) ){
39 $viewOptions['loop'] = $document->options->navigation->loop;
40 }
41 if( $attributes['view'] === 'mask' ){
42 if( isset( $document->options->sectionTransition->options->mask->maskParallax ) ){
43 $viewOptions['maskParallax'] = $document->options->sectionTransition->options->mask->maskParallax;
44 }
45 } elseif( $attributes['view'] === 'transform' ){
46 if( isset( $document->options->sectionTransition->options->transform->transformType ) ){
47 $viewOptions['transformStyle'] = $document->options->sectionTransition->options->transform->transformType;
48 }
49 } elseif( $attributes['view'] === 'cube' ){
50 if( isset( $document->options->sectionTransition->options->cube->shadow ) ){
51 $viewOptions['shadow'] = $document->options->sectionTransition->options->cube->shadow;
52 }
53 if( isset( $document->options->sectionTransition->options->cube->dolly ) ){
54 $viewOptions['dolly'] = $document->options->sectionTransition->options->cube->dolly;
55 }
56 }
57 if( $attributes['view'] !== 'fade' ) {
58 if ( isset( $document->options->sectionTransition->options->basic->space ) ) {
59 $viewOptions['space'] = $document->options->sectionTransition->options->basic->space;
60 }
61 if ( isset( $document->options->sectionTransition->options->basic->direction ) ) {
62 $viewOptions['dir'] = $document->options->sectionTransition->options->basic->direction;
63 }
64 }
65
66 if( in_array( $attributes['view'], ['basic', 'transform'] ) ){
67 if ( isset( $document->options->sectionTransition->options->basic->nearbyVisibility ) ) {
68 $viewOptions['nearbyVisibility'] = $document->options->sectionTransition->options->basic->nearbyVisibility;
69 }
70 if ( isset( $document->options->sectionTransition->options->basic->nearbyVisibilityAmount->value ) ) {
71 $viewOptions['nearbyVisibilityAmount'] = $document->options->sectionTransition->options->basic->nearbyVisibilityAmount->value . $document->options->sectionTransition->options->basic->nearbyVisibilityAmount->unit;
72 }
73 }
74
75 if( $viewOptions ){
76 $attributes['viewOptions'] = $viewOptions;
77 }
78
79 // slideShow property
80 if( ! empty( $document->options->navigation->slideshow->enable ) ){
81 $slideShow = [];
82 if( isset( $document->options->navigation->slideshow->duration ) ){
83 $slideShow['duration'] = $document->options->navigation->slideshow->duration;
84 }
85 if( isset( $document->options->navigation->slideshow->pauseOnLastSlide ) ){
86 $slideShow['pauseAtEnd'] = $document->options->navigation->slideshow->pauseOnLastSlide;
87 }
88 if( isset( $document->options->navigation->slideshow->pauseOnHover ) ){
89 $slideShow['pauseOnHover'] = $document->options->navigation->slideshow->pauseOnHover;
90 }
91 $slideShow['autostart'] = $document->options->navigation->slideshow->enable;
92
93 $attributes['slideshow'] = $slideShow;
94 }
95
96 if( !empty( $document->options->navigation->swipe->enable ) ){
97 if( isset( $document->options->navigation->swipe->mouseSwipe ) ){
98 $attributes['mouseSwipe'] = $document->options->navigation->swipe->mouseSwipe;
99 }
100 if( isset( $document->options->navigation->swipe->touchSwipe ) ){
101 $attributes['touchSwipe'] = $document->options->navigation->swipe->touchSwipe;
102 }
103 if( isset( $document->options->navigation->swipe->direction ) ){
104 $attributes['swipeDir'] = $document->options->navigation->swipe->direction;
105 }
106 } else {
107 $attributes['mouseSwipe'] = false;
108 $attributes['touchSwipe'] = false;
109 }
110
111 if( isset( $document->options->navigation->mouseWheel ) ){
112 $attributes['mouseWheel'] = $document->options->navigation->mouseWheel;
113 }
114
115 if( isset( $document->options->navigation->keyboardNavigation ) ){
116 $attributes['keyboard'] = $document->options->navigation->keyboardNavigation;
117 }
118
119 if( isset( $document->options->general->fullscreenMargin ) ){
120 $attributes['fullscreenMargin'] = $document->options->general->fullscreenMargin;
121 }
122
123 // navigator property
124 $navigator = [];
125
126 if( !empty( $document->options->navigator ) ){
127 $navigator = (array) $document->options->navigator;
128 }
129 if( !empty( $document->options->navigator->duration->value ) ){
130 $navigator['duration'] = $document->options->navigator->duration->value;
131 }
132 if( !empty( $document->startSection ) ){
133 $navigator['start'] = $document->startSection;
134 }
135
136 if( $navigator ){
137 $attributes['navigator'] = $navigator;
138 }
139
140 $sliderName = 'slider';
141
142 $script = "\n(window.depicterSetups = window.depicterSetups || []).push(function(){";
143 $script .= "\n\tvar $sliderName = Depicter.setup('.{$document->getSelector()}',\n\t\t";
144
145 $attributesString = JSON::encode( $attributes );
146
147 $script .= "{$attributesString}\n\t);\n";
148
149 $script .= $document->options->getCallbacks( $sliderName );
150 $script .= "});\n";
151
152 return $script;
153 }
154
155 }
156