Skip to content

Commit 874daa5

Browse files
committed
Addressing #31, #32, #33
1 parent de21418 commit 874daa5

File tree

4 files changed

+59
-27
lines changed

4 files changed

+59
-27
lines changed

assets/front-end.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@
6868
font-style: normal;
6969
}
7070

71+
.pootle-slider-wrap {
72+
-webkit-transition: opacity 0.5s;
73+
transition: opacity 0.5s;
74+
position: relative;
75+
}
76+
77+
.pootle-slider-wrap:after {
78+
content: '';
79+
display: block;
80+
clear: both;
81+
}
82+
83+
.pootle-slider-wrap.pootle-slider-transparent {
84+
opacity: 0; /* Keep slider transparent in the beginning */
85+
}
86+
7187
.pootle-slider-wrap .flex-container a:hover,
7288
.pootle-slider-wrap .flex-slider a:hover {
7389
outline: 0;

assets/front-end.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ jQuery( function ( $ ) {
88
.not( '#wpadminbar, #wpadminbar *' )
99
.not( '.ppb-widget, .ppb-widget *' )
1010
.not( '.pootlepb-dialog, .pootlepb-dialog *' )
11+
.not( '.pootle-slider-wrap, .pootle-slider-wrap *' )
1112
.not( '#pootle-page-builder, #pootle-page-builder *' )
13+
.not( $('.pootle-slider-wrap').parents() )
1214
.not( $ppb.parents() )
1315
.hide();
1416
$bd.show();

class-pootle-slider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ private function _admin() {
156156
* @since 1.0.0
157157
*/
158158
private function _public() {
159-
//Adding front end JS and CSS in /assets folder
160-
add_action( 'wp_enqueue_scripts', array( $this->public, 'enqueue' ) );
161-
//Add/Modify content block html attributes
162-
add_filter( 'pootlepb_render_content_block', array( $this->public, 'content_block' ), 52, 4 );
159+
// Adding front end JS and CSS in /assets folder
160+
add_action( 'wp_enqueue_scripts', array( $this->public, 'enqueue' ) );
161+
// Add/Modify content block html attributes
162+
add_action( 'pootlepb_render_content_block', array( $this->public, 'content_block' ), 52, 4 );
163+
// Slider preview after publish
164+
add_filter( 'pootlepb_render', array( $this->public, 'render_slider_preview' ), 25, 2 );
163165

164166
} // End enqueue()
165167

inc/class-public.php

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Pootle_Slider_Public{
2626
protected $ratio;
2727

2828
/** @var string Stretch full width */
29-
protected $full_width;
29+
protected $full_width = 1;
3030

3131
private $defaults = array(
3232
'ratio' => '56.25',
@@ -83,7 +83,8 @@ public function content_block( $cb ) {
8383
$settings = json_decode( $cb['info']['style'], true );
8484
if ( ! empty( $settings["{$this->token}-id"]) ) {
8585
$this->get_properties( $settings );
86-
$this->render_slider();
86+
Pootle_Page_Builder_Live_Editor_Public::deactivate_le();
87+
echo Pootle_Page_Builder_Render_Layout::render( $this->id );
8788
}
8889
}
8990

@@ -102,10 +103,19 @@ private function get_properties( $settings ) {
102103
}
103104
}
104105

105-
private function render_slider() {
106-
$id = "pootle-slider-{$this->id}";
107-
Pootle_Page_Builder_Live_Editor_Public::enable_do_nothing();
108-
$pb = Pootle_Page_Builder_Render_Layout::render( $this->id );
106+
/**
107+
* Converts pootle slider rows into a slider
108+
*
109+
* @param string $ppb_html
110+
* @param int $post_id
111+
* @return string
112+
*/
113+
public function render_slider_preview( $ppb_html, $post_id ) {
114+
if ( 'pootle-slider' != get_post_type( $post_id ) || Pootle_Page_Builder_Live_Editor_Public::is_active() ) {
115+
return $ppb_html;
116+
}
117+
118+
$id = "pootle-slider-$post_id";
109119
$pb = str_replace(
110120
array(
111121
'id="pootle-page-builder"',
@@ -119,47 +129,49 @@ private function render_slider() {
119129
'',
120130
'',
121131
),
122-
$pb
132+
$ppb_html
123133
);
124134

125-
$class = 'pootle-slider-wrap';
135+
$class = 'pootle-slider-wrap pootle-slider-transparent';
126136
$class .= $this->full_width ? ' ppb-stretch-full-width' : '';
127137

128-
$this->style( $id );
129-
echo "<div class='$class' id='{$id}-wrap'>$pb</div>";
130-
$this->script( $id );
138+
return
139+
$this->style( $id ) .
140+
"<div class='$class' id='{$id}-wrap'>$pb</div>" .
141+
$this->script( $id );
131142
}
132143

133144
private function script( $id ) {
134-
?>
135-
<script>
145+
$js_props = 'start : playvids,selector : ".pootle-slider > .pootle-slide"';
146+
foreach ( $this->js_props as $p => $v ) {
147+
$js_props .= ",$p : $v";
148+
}
149+
150+
return /** @lang html */
151+
<<<SCRIPT
152+
<script id='$id-script'>
136153
jQuery( function( $ ) {
137154
138155
var playvids = function ( slider ) {
156+
slider.removeClass( 'pootle-slider-transparent' );
139157
slider.find( 'video' ).each( function () {
140158
$( this )[0].play();
141159
} );
142160
};
143161
144-
$( '#<?php echo $id ?>-wrap' ).flexslider( {
145-
start : playvids,selector : ".pootle-slider > .pootle-slide"<?php
146-
foreach ( $this->js_props as $p => $v ) {
147-
echo ",$p : $v";
148-
}
149-
?>
150-
} );
162+
$( '#$id-wrap' ).flexslider( { $js_props } );
151163
} );
152164
</script>
153-
<?php
165+
SCRIPT;
154166
}
155167

156168
private function style( $id ) {
157169
$ratio = $this->ratio;
158170
$ratio160p = $ratio * 1.60;
159171
$ratio250p = $ratio * 2.5;
160-
echo /** @lang html */
172+
return /** @lang html */
161173
<<<STYLE
162-
<style id="pootle-slider-style">
174+
<style id="$id-style">
163175
#$id .pootle-slide .panel-row-style{padding-top: 160%;}
164176
@media screen and (min-width:475px) {
165177
#$id .pootle-slide .panel-row-style{padding-top: {$ratio250p}%;}

0 commit comments

Comments
 (0)